From 97381369a3be5b917e968c33adb7b1af746ef904 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Wed, 23 Apr 2014 00:17:29 +0800 Subject: Refactored sqlite3 (all tests passes) --- ext/sqlite3/php_sqlite3_structs.h | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) (limited to 'ext/sqlite3/php_sqlite3_structs.h') diff --git a/ext/sqlite3/php_sqlite3_structs.h b/ext/sqlite3/php_sqlite3_structs.h index 5336d116fc..dd81317df2 100644 --- a/ext/sqlite3/php_sqlite3_structs.h +++ b/ext/sqlite3/php_sqlite3_structs.h @@ -43,7 +43,7 @@ struct php_sqlite3_bound_param { int name_len; long type; - zval *parameter; + zval parameter; }; struct php_sqlite3_fci { @@ -58,7 +58,7 @@ typedef struct _php_sqlite3_func { const char *func_name; int argc; - zval *func, *step, *fini; + zval func, step, fini; struct php_sqlite3_fci afunc, astep, afini; } php_sqlite3_func; @@ -67,13 +67,12 @@ typedef struct _php_sqlite3_collation { struct _php_sqlite3_collation *next; const char *collation_name; - zval *cmp_func; + zval cmp_func; struct php_sqlite3_fci fci; } php_sqlite3_collation; /* Structure for SQLite Database object. */ typedef struct _php_sqlite3_db_object { - zend_object zo; int initialised; sqlite3 *db; php_sqlite3_func *funcs; @@ -82,11 +81,18 @@ typedef struct _php_sqlite3_db_object { zend_bool exception; zend_llist free_list; + zend_object zo; } php_sqlite3_db_object; +static inline php_sqlite3_db_object *php_sqlite3_db_from_obj(zend_object *obj) { + return (php_sqlite3_db_object*)((char*)(obj) - XtOffsetOf(php_sqlite3_db_object, zo)); +} + +#define Z_SQLITE3_DB_P(zv) php_sqlite3_db_from_obj(Z_OBJ_P((zv))) + /* Structure for SQLite Database object. */ typedef struct _php_sqlite3_agg_context { - zval *zval_context; + zval zval_context; long row_count; } php_sqlite3_agg_context; @@ -95,34 +101,46 @@ typedef struct _php_sqlite3_result_object php_sqlite3_result; /* sqlite3 objects to be destroyed */ typedef struct _php_sqlite3_free_list { - zval *stmt_obj_zval; + zval stmt_obj_zval; php_sqlite3_stmt *stmt_obj; } php_sqlite3_free_list; /* Structure for SQLite Result object. */ struct _php_sqlite3_result_object { - zend_object zo; php_sqlite3_db_object *db_obj; php_sqlite3_stmt *stmt_obj; - zval *stmt_obj_zval; + zval stmt_obj_zval; int is_prepared_statement; int complete; + zend_object zo; }; +static inline php_sqlite3_result *php_sqlite3_result_from_obj(zend_object *obj) { + return (php_sqlite3_result*)((char*)(obj) - XtOffsetOf(php_sqlite3_result, zo)); +} + +#define Z_SQLITE3_RESULT_P(zv) php_sqlite3_result_from_obj(Z_OBJ_P((zv))) + /* Structure for SQLite Statement object. */ struct _php_sqlite3_stmt_object { - zend_object zo; sqlite3_stmt *stmt; php_sqlite3_db_object *db_obj; - zval *db_obj_zval; + zval db_obj_zval; int initialised; /* Keep track of the zvals for bound parameters */ HashTable *bound_params; + zend_object zo; }; +static inline php_sqlite3_stmt *php_sqlite3_stmt_from_obj(zend_object *obj) { + return (php_sqlite3_stmt*)((char*)(obj) - XtOffsetOf(php_sqlite3_stmt, zo)); +} + +#define Z_SQLITE3_STMT_P(zv) php_sqlite3_stmt_from_obj(Z_OBJ_P((zv))) + #endif -- cgit v1.2.1 From bd9f5755172e0c73153a1286480b0e2a31908d7f Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Wed, 23 Apr 2014 10:58:08 +0800 Subject: Clean up (use zend_string and foreach macros) --- ext/sqlite3/php_sqlite3_structs.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'ext/sqlite3/php_sqlite3_structs.h') diff --git a/ext/sqlite3/php_sqlite3_structs.h b/ext/sqlite3/php_sqlite3_structs.h index dd81317df2..e988ac20d0 100644 --- a/ext/sqlite3/php_sqlite3_structs.h +++ b/ext/sqlite3/php_sqlite3_structs.h @@ -39,10 +39,8 @@ /* Structure for SQLite Statement Parameter. */ struct php_sqlite3_bound_param { long param_number; - char *name; - int name_len; + zend_string *name; long type; - zval parameter; }; -- cgit v1.2.1