Browse Source

valgrind memory test

viest 7 năm trước cách đây
mục cha
commit
65ac666085
5 tập tin đã thay đổi với 134 bổ sung31 xóa
  1. 110 1
      kernel/excel.c
  2. 16 0
      kernel/write.c
  3. 2 0
      kernel/write.h
  4. 1 1
      php_vtiful.h
  5. 5 29
      vtiful.c

+ 110 - 1
kernel/excel.c

@@ -43,6 +43,24 @@ ZEND_BEGIN_ARG_INFO_EX(excel_data_arginfo, 0, 0, 1)
                 ZEND_ARG_INFO(0, data)
 ZEND_END_ARG_INFO()
 
+ZEND_BEGIN_ARG_INFO_EX(excel_insert_text_arginfo, 0, 0, 3)
+                ZEND_ARG_INFO(0, row)
+                ZEND_ARG_INFO(0, column)
+                ZEND_ARG_INFO(0, data)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(excel_insert_image_arginfo, 0, 0, 3)
+                ZEND_ARG_INFO(0, row)
+                ZEND_ARG_INFO(0, column)
+                ZEND_ARG_INFO(0, image)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(excel_insert_formula_arginfo, 0, 0, 3)
+                ZEND_ARG_INFO(0, row)
+                ZEND_ARG_INFO(0, column)
+                ZEND_ARG_INFO(0, formula)
+ZEND_END_ARG_INFO()
+
 /* {{{ \Vtiful\Kernel\Excel::__construct(array $config)
  */
 PHP_METHOD(vtiful_excel, __construct)
@@ -185,8 +203,9 @@ PHP_METHOD(vtiful_excel, output)
 
     workbook_file(res, handle);
 
-    ZVAL_NULL(&null_handle);
+    efree(res);
 
+    ZVAL_NULL(&null_handle);
     zend_update_property(vtiful_excel_ce, getThis(), ZEND_STRL(V_EXCEL_HANDLE), &null_handle);
 }
 /* }}} */
@@ -204,6 +223,93 @@ PHP_METHOD(vtiful_excel, getHandle)
 }
 /* }}} */
 
+/* {{{ \Vtiful\Kernel\Excel::insertText(int $row, int $column, string|int|double $data)
+ */
+PHP_METHOD(vtiful_excel, insertText)
+{
+    zval rv, res_handle;
+    zval *attr_handle, *data;
+    zend_long *row, *column;
+    excel_resource_t *res;
+
+    ZEND_PARSE_PARAMETERS_START(3, 3)
+            Z_PARAM_LONG(row)
+            Z_PARAM_LONG(column)
+            Z_PARAM_ZVAL(data)
+    ZEND_PARSE_PARAMETERS_END();
+
+    ZVAL_COPY(return_value, getThis());
+
+    attr_handle = zend_read_property(vtiful_excel_ce, return_value, ZEND_STRL(V_EXCEL_HANDLE), 0, &rv TSRMLS_DC);
+    if((res = (excel_resource_t *)zend_fetch_resource(Z_RES_P(attr_handle), VTIFUL_RESOURCE_NAME, le_vtiful)) == NULL) {
+        zend_throw_exception(vtiful_exception_ce, "Excel resources resolution fail", 210);
+    }
+
+    type_writer(data, row, column, res);
+
+    ZVAL_RES(&res_handle, zend_register_resource(res, le_vtiful));
+    zend_update_property(vtiful_excel_ce, return_value, ZEND_STRL(V_EXCEL_HANDLE), &res_handle);
+}
+/* }}} */
+
+/* {{{ \Vtiful\Kernel\Excel::insertImage(int $row, int $column, string $imagePath)
+ */
+PHP_METHOD(vtiful_excel, insertImage)
+{
+    zval rv, res_handle;
+    zval *attr_handle, *image;
+    zend_long *row, *column;
+    excel_resource_t *res;
+
+    ZEND_PARSE_PARAMETERS_START(3, 3)
+            Z_PARAM_LONG(row)
+            Z_PARAM_LONG(column)
+            Z_PARAM_ZVAL(image)
+    ZEND_PARSE_PARAMETERS_END();
+
+    ZVAL_COPY(return_value, getThis());
+
+    attr_handle = zend_read_property(vtiful_excel_ce, return_value, ZEND_STRL(V_EXCEL_HANDLE), 0, &rv TSRMLS_DC);
+    if((res = (excel_resource_t *)zend_fetch_resource(Z_RES_P(attr_handle), VTIFUL_RESOURCE_NAME, le_vtiful)) == NULL) {
+        zend_throw_exception(vtiful_exception_ce, "Excel resources resolution fail", 210);
+    }
+
+    image_writer(image, row, column, res);
+
+    ZVAL_RES(&res_handle, zend_register_resource(res, le_vtiful));
+    zend_update_property(vtiful_excel_ce, return_value, ZEND_STRL(V_EXCEL_HANDLE), &res_handle);
+}
+/* }}} */
+
+/* {{{ \Vtiful\Kernel\Excel::insertImage(int $row, int $column, string $imagePath)
+ */
+PHP_METHOD(vtiful_excel, insertFormula)
+{
+    zval rv, res_handle;
+    zval *attr_handle, *formula;
+    zend_long *row, *column;
+    excel_resource_t *res;
+
+    ZEND_PARSE_PARAMETERS_START(3, 3)
+            Z_PARAM_LONG(row)
+            Z_PARAM_LONG(column)
+            Z_PARAM_ZVAL(formula)
+    ZEND_PARSE_PARAMETERS_END();
+
+    ZVAL_COPY(return_value, getThis());
+
+    attr_handle = zend_read_property(vtiful_excel_ce, return_value, ZEND_STRL(V_EXCEL_HANDLE), 0, &rv TSRMLS_DC);
+    if((res = (excel_resource_t *)zend_fetch_resource(Z_RES_P(attr_handle), VTIFUL_RESOURCE_NAME, le_vtiful)) == NULL) {
+        zend_throw_exception(vtiful_exception_ce, "Excel resources resolution fail", 210);
+    }
+
+    formula_writer(formula, row, column, res);
+
+    ZVAL_RES(&res_handle, zend_register_resource(res, le_vtiful));
+    zend_update_property(vtiful_excel_ce, return_value, ZEND_STRL(V_EXCEL_HANDLE), &res_handle);
+}
+/* }}} */
+
 zend_function_entry excel_methods[] = {
         PHP_ME(vtiful_excel, __construct, excel_construct_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
         PHP_ME(vtiful_excel, fileName,    excel_file_name_arginfo, ZEND_ACC_PUBLIC)
@@ -211,6 +317,9 @@ zend_function_entry excel_methods[] = {
         PHP_ME(vtiful_excel, data,        excel_data_arginfo,      ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_excel, output,      NULL,                    ZEND_ACC_PUBLIC)
         PHP_ME(vtiful_excel, getHandle,   NULL,                    ZEND_ACC_PUBLIC)
+        PHP_ME(vtiful_excel, insertText,  excel_insert_text_arginfo,   ZEND_ACC_PUBLIC)
+        PHP_ME(vtiful_excel, insertImage, excel_insert_image_arginfo,  ZEND_ACC_PUBLIC)
+        PHP_ME(vtiful_excel, insertFormula, excel_insert_formula_arginfo, ZEND_ACC_PUBLIC)
         PHP_FE_END
 };
 

+ 16 - 0
kernel/write.c

@@ -38,6 +38,22 @@ void type_writer(zval *value, zend_long row, zend_long columns, excel_resource_t
     }
 }
 
+/*
+ * Write the image to the file
+ */
+void image_writer(zval *value, zend_long row, zend_long columns, excel_resource_t *res)
+{
+    worksheet_insert_image(res->worksheet, row, columns, ZSTR_VAL(zval_get_string(value)));
+}
+
+/*
+ * Write the image to the file
+ */
+void formula_writer(zval *value, zend_long row, zend_long columns, excel_resource_t *res)
+{
+    worksheet_write_formula(res->worksheet, row, columns, ZSTR_VAL(zval_get_string(value)), NULL);
+}
+
 /*
  * Call finalization code and close file.
  */

+ 2 - 0
kernel/write.h

@@ -14,6 +14,8 @@
 #define VTIFUL_EXCEL_WRITE_H
 
 void type_writer(zval *value, zend_long row, zend_long columns, excel_resource_t *res);
+void image_writer(zval *value, zend_long row, zend_long columns, excel_resource_t *res);
+void formula_writer(zval *value, zend_long row, zend_long columns, excel_resource_t *res);
 lxw_error workbook_file(excel_resource_t *self, zval *handle);
 
 #endif

+ 1 - 1
php_vtiful.h

@@ -16,7 +16,7 @@
 extern zend_module_entry vtiful_module_entry;
 #define phpext_vtiful_ptr &vtiful_module_entry
 
-#define PHP_VTIFUL_VERSION "0.1.0"
+#define PHP_VTIFUL_VERSION "1.0.0"
 
 #ifdef PHP_WIN32
 #	define PHP_VTIFUL_API __declspec(dllexport)

+ 5 - 29
vtiful.c

@@ -24,12 +24,10 @@
 
 int le_vtiful;
 
+/* {{{ PHP_MINIT_FUNCTION
+ */
 PHP_MINIT_FUNCTION(vtiful)
 {
-	/* If you have INI entries, uncomment these lines
-	REGISTER_INI_ENTRIES();
-	*/
-
     VTIFUL_STARTUP_MODULE(vtiful_exception);
 	VTIFUL_STARTUP_MODULE(excel);
 
@@ -44,15 +42,10 @@ PHP_MINIT_FUNCTION(vtiful)
  */
 PHP_MSHUTDOWN_FUNCTION(vtiful)
 {
-	/* uncomment this line if you have INI entries
-	UNREGISTER_INI_ENTRIES();
-	*/
 	return SUCCESS;
 }
 /* }}} */
 
-
-/* Remove if there's nothing to do at request start */
 /* {{{ PHP_RINIT_FUNCTION
  */
 PHP_RINIT_FUNCTION(vtiful)
@@ -64,8 +57,6 @@ PHP_RINIT_FUNCTION(vtiful)
 }
 /* }}} */
 
-
-/* Remove if there's nothing to do at request end */
 /* {{{ PHP_RSHUTDOWN_FUNCTION
  */
 PHP_RSHUTDOWN_FUNCTION(vtiful)
@@ -81,28 +72,13 @@ PHP_MINFO_FUNCTION(vtiful)
 {
 	php_info_print_table_start();
 	php_info_print_table_header(2, "vtiful support", "enabled");
+#if defined(PHP_VTIFUL_VERSION)
+    php_info_print_table_row(2, "Version", PHP_VTIFUL_VERSION);
+#endif
 	php_info_print_table_end();
-
-	/* Remove comments if you have entries in php.ini
-	DISPLAY_INI_ENTRIES();
-	*/
 }
 /* }}} */
 
-
-/* {{{ _php_fss_close
- *
- * List destructor for FSS handles
- */
-//static void _php_vtiful_excel_close(zend_resource *rsrc TSRMLS_DC)
-//{
-//	excel_resource_t * res = (excel_resource_t *)rsrc->ptr;
-//	/* Destroy the resource structure itself */
-//	efree(res);
-//}
-/* }}} */
-
-
 /* {{{ vtiful_functions[]
  *
  * Every user visible function must have an entry in vtiful_functions[].