cvs: php4 /ext/interbase interbase.c php_interbase.h

From: Date: Wed, 05 Jul 2000 04:21:00 +0000
Subject: cvs: php4 /ext/interbase interbase.c php_interbase.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-623@lists.php.net to get a copy of this message
jah Tue Jul 4 21:21:00 2000 EDT Modified files: /php4/ext/interbase interbase.c php_interbase.h Log: - First try at getting interbase to compile and work in ZTS-mode. Compiles. Index: php4/ext/interbase/interbase.c diff -u php4/ext/interbase/interbase.c:1.37 php4/ext/interbase/interbase.c:1.38 --- php4/ext/interbase/interbase.c:1.37 Sat Jun 24 09:24:29 2000 +++ php4/ext/interbase/interbase.c Tue Jul 4 21:21:00 2000 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: interbase.c,v 1.37 2000/06/24 16:24:29 jah Exp $ */ +/* $Id: interbase.c,v 1.38 2000/07/05 04:21:00 jah Exp $ */ /* TODO: Arrays, roles? @@ -56,7 +56,7 @@ #endif /* -#define IBDEBUG(a) printf("::: %s (%d)\n", a, __LINE__); +#define IBDEBUG(a) php_printf("::: %s (%d)\n", a, __LINE__); */ #define IBDEBUG(a) @@ -123,11 +123,7 @@ #endif -#ifdef ZTS -int ibase_globals_id; -#else -PHP_IBASE_API php_ibase_globals ibase_globals; -#endif +ZEND_DECLARE_MODULE_GLOBALS(ibase) /* }}} */ @@ -223,11 +219,10 @@ Return error message */ PHP_FUNCTION(ibase_errmsg) { - char *errmsg = IBG(errmsg); IBLS_FETCH(); - if (errmsg[0]) { - RETURN_STRING(errmsg,1); + if (IBG(errmsg[0])) { + RETURN_STRING(IBG(errmsg),1); } RETURN_FALSE; } @@ -238,15 +233,17 @@ print interbase error and save it for ibase_errmsg() */ static void _php_ibase_error(void) { - char *s, *errmsg = IBG(errmsg); - ISC_STATUS *statusp = IB_STATUS; + char *s; + ISC_STATUS *statusp; + IBLS_FETCH(); - s = errmsg; - while ((s - errmsg) < MAX_ERRMSG - (IBASE_MSGSIZE + 2) && isc_interprete(s, &statusp)) { - strcat(errmsg, " "); - s = errmsg + strlen(errmsg); + s = IBG(errmsg); + statusp = IB_STATUS; + while ((s - IBG(errmsg)) < MAX_ERRMSG - (IBASE_MSGSIZE + 2) && isc_interprete(s, &statusp)) { + strcat(IBG(errmsg), " "); + s = IBG(errmsg) + strlen(IBG(errmsg)); } - php_error(E_WARNING, "InterBase: %s", errmsg); + php_error(E_WARNING, "InterBase: %s", IBG(errmsg)); } /* }}} */ @@ -255,16 +252,16 @@ print php interbase module error and save it for ibase_errmsg() */ static void _php_ibase_module_error(char *msg, ...) { - char *errmsg = IBG(errmsg); va_list ap; int len; + IBLS_FETCH(); va_start(ap, msg); - len = vsnprintf(errmsg, MAX_ERRMSG - 1, msg, ap); + len = vsnprintf(IBG(errmsg), MAX_ERRMSG - 1, msg, ap); va_end(ap); - errmsg[len] = '\0'; + IBG(errmsg[len]) = '\0'; - php_error(E_WARNING, "InterBase module: %s",errmsg); + php_error(E_WARNING, "InterBase module: %s", IBG(errmsg)); } /* }}} */ @@ -298,7 +295,9 @@ static void _php_ibase_commit_link(ibase_db_link *link) { int i; + IBLS_FETCH(); + IBDEBUG("Checking transactions to close..."); if (link->trans[0] != NULL) { /* commit default */ IBDEBUG("Committing default transaction..."); if (isc_commit_transaction(IB_STATUS, &link->trans[0])) { @@ -322,6 +321,8 @@ /* {{{ _php_ibase_close_link() */ static void _php_ibase_close_link(ibase_db_link *link) { + IBLS_FETCH(); + _php_ibase_commit_link(link); IBDEBUG("Closing normal link..."); isc_detach_database(IB_STATUS, &link->link); @@ -334,6 +335,8 @@ /* {{{ _php_ibase_close_plink() */ static void _php_ibase_close_plink(ibase_db_link *link) { + IBLS_FETCH(); + _php_ibase_commit_link(link); IBDEBUG("Closing permanent link..."); isc_detach_database(IB_STATUS, &link->link); @@ -347,6 +350,8 @@ /* {{{ _php_ibase_free_result() */ static void _php_ibase_free_result(ibase_result *ib_result) { + IBLS_FETCH(); + IBDEBUG("Freeing result..."); if (ib_result){ _php_ibase_free_xsqlda(ib_result->out_sqlda); @@ -378,6 +383,8 @@ /* {{{ _php_ibase_free_query() */ static void _php_ibase_free_query(ibase_query *ib_query) { + IBLS_FETCH(); + IBDEBUG("Freeing query..."); if (ib_query) { if (ib_query->in_sqlda) { @@ -407,7 +414,8 @@ /* {{{ _php_ibase_free_blob() */ static void _php_ibase_free_blob(ibase_blob_handle *ib_blob) { - + IBLS_FETCH(); + if (ib_blob->bl_handle != NULL) { /* blob open*/ if (isc_cancel_blob(IB_STATUS, &ib_blob->bl_handle)) { _php_ibase_error(); @@ -420,27 +428,31 @@ /* {{{ startup, shutdown and info functions */ PHP_INI_BEGIN() - STD_PHP_INI_BOOLEAN("ibase.allow_persistent", "1", PHP_INI_SYSTEM, OnUpdateInt, allow_persistent, php_ibase_globals, ibase_globals) - STD_PHP_INI_ENTRY_EX("ibase.max_persistent", "-1", PHP_INI_SYSTEM, OnUpdateInt, max_persistent, php_ibase_globals, ibase_globals, display_link_numbers) - STD_PHP_INI_ENTRY_EX("ibase.max_links", "-1", PHP_INI_SYSTEM, OnUpdateInt, max_links, php_ibase_globals, ibase_globals, display_link_numbers) - STD_PHP_INI_ENTRY("ibase.default_user", NULL, PHP_INI_ALL, OnUpdateString, default_user, php_ibase_globals, ibase_globals) - STD_PHP_INI_ENTRY("ibase.default_password", NULL, PHP_INI_ALL, OnUpdateString, default_password, php_ibase_globals, ibase_globals) - STD_PHP_INI_ENTRY("ibase.timestampformat", "%m/%d/%Y %H:%M:%S", PHP_INI_ALL, OnUpdateString, cfg_timestampformat, php_ibase_globals, ibase_globals) - STD_PHP_INI_ENTRY("ibase.dateformat", "%m/%d/%Y", PHP_INI_ALL, OnUpdateString, cfg_dateformat, php_ibase_globals, ibase_globals) - STD_PHP_INI_ENTRY("ibase.timeformat", "%H:%M:%S", PHP_INI_ALL, OnUpdateString, cfg_timeformat, php_ibase_globals, ibase_globals) + STD_PHP_INI_BOOLEAN("ibase.allow_persistent", "1", PHP_INI_SYSTEM, OnUpdateInt, allow_persistent, zend_ibase_globals, ibase_globals) + STD_PHP_INI_ENTRY_EX("ibase.max_persistent", "-1", PHP_INI_SYSTEM, OnUpdateInt, max_persistent, zend_ibase_globals, ibase_globals, display_link_numbers) + STD_PHP_INI_ENTRY_EX("ibase.max_links", "-1", PHP_INI_SYSTEM, OnUpdateInt, max_links, zend_ibase_globals, ibase_globals, display_link_numbers) + STD_PHP_INI_ENTRY("ibase.default_user", NULL, PHP_INI_ALL, OnUpdateString, default_user, zend_ibase_globals, ibase_globals) + STD_PHP_INI_ENTRY("ibase.default_password", NULL, PHP_INI_ALL, OnUpdateString, default_password, zend_ibase_globals, ibase_globals) + STD_PHP_INI_ENTRY("ibase.timestampformat", "%m/%d/%Y %H:%M:%S", PHP_INI_ALL, OnUpdateString, cfg_timestampformat, zend_ibase_globals, ibase_globals) + STD_PHP_INI_ENTRY("ibase.dateformat", "%m/%d/%Y", PHP_INI_ALL, OnUpdateString, cfg_dateformat, zend_ibase_globals, ibase_globals) + STD_PHP_INI_ENTRY("ibase.timeformat", "%H:%M:%S", PHP_INI_ALL, OnUpdateString, cfg_timeformat, zend_ibase_globals, ibase_globals) PHP_INI_END() -PHP_MINIT_FUNCTION(ibase) +static void php_ibase_init_globals(IBLS_D) { - IBLS_FETCH(); - IBG(timestampformat) = NULL; IBG(dateformat) = NULL; IBG(timeformat) = NULL; IBG(errmsg) = NULL; - IBG(num_persistent) = 0; +} +PHP_MINIT_FUNCTION(ibase) +{ + IBLS_FETCH(); + + ZEND_INIT_MODULE_GLOBALS(ibase, php_ibase_init_globals, NULL); + REGISTER_INI_ENTRIES(); IBG(le_result) = register_list_destructors(_php_ibase_free_result, NULL); @@ -529,7 +541,7 @@ php_info_print_table_start(); php_info_print_table_row(2, "Interbase Support", "enabled"); - php_info_print_table_row(2, "Revision", "$Revision: 1.37 $"); + php_info_print_table_row(2, "Revision", "$Revision: 1.38 $"); #ifdef COMPILE_DL_INTERBASE php_info_print_table_row(2, "Dynamic Module", "yes"); #endif @@ -565,6 +577,7 @@ { char dpb_buffer[256], *dpb, *p; int dpb_length, len; + IBLS_FETCH(); dpb = dpb_buffer; @@ -854,7 +867,6 @@ int link_id, trans_n; IBLS_FETCH(); - RESET_ERRMSG; switch (ZEND_NUM_ARGS()) { @@ -887,7 +899,7 @@ int i, dim, ar_cnt, ar_length; XSQLVAR *var; - + IBLS_FETCH(); IB_ARRAY = NULL; @@ -981,6 +993,7 @@ static int _php_ibase_alloc_query(ibase_query **ib_queryp, isc_db_handle link, isc_tr_handle trans, char *query, int dialect) { #define IB_QUERY (*ib_queryp) + IBLS_FETCH(); IB_QUERY = emalloc(sizeof(ibase_query)); IB_QUERY->link = link; @@ -1315,6 +1328,7 @@ XSQLDA *in_sqlda = NULL, *out_sqlda = NULL; BIND_BUF *bind_buf = NULL; int rv = FAILURE; + IBLS_FETCH(); IB_RESULT = NULL; @@ -1392,7 +1406,6 @@ ibase_db_link *ib_link; IBLS_FETCH(); - RESET_ERRMSG; link_id = IBG(default_link); @@ -1479,6 +1492,7 @@ /* open default transaction */ static int _php_ibase_def_trans(ibase_db_link * ib_link, int trans_n) { + IBLS_FETCH(); if (trans_n == 0 && ib_link->trans[0] == NULL) { if (isc_start_transaction(IB_STATUS, &ib_link->trans[0], 1, &ib_link->link, 0, NULL)) { @@ -1500,7 +1514,6 @@ int link_id = 0, trans_n = 0; ibase_db_link *ib_link; IBLS_FETCH(); - RESET_ERRMSG; @@ -1569,7 +1582,6 @@ ibase_query *ib_query; ibase_result *ib_result; IBLS_FETCH(); - RESET_ERRMSG; @@ -1648,6 +1660,8 @@ static int _php_ibase_var_pval(pval *val, void *data, int type, int len, int scale, int flag) { char string_data[255]; + IBLS_FETCH(); + PLS_FETCH(); switch(type & ~1) { case SQL_VARYING: @@ -2097,7 +2111,6 @@ ibase_query *ib_query; char *query; IBLS_FETCH(); - RESET_ERRMSG; @@ -2151,7 +2164,6 @@ ibase_query *ib_query; ibase_result *ib_result; IBLS_FETCH(); - RESET_ERRMSG; @@ -2205,7 +2217,6 @@ pval **query_arg; ibase_query *ib_query; IBLS_FETCH(); - RESET_ERRMSG; @@ -2286,7 +2297,7 @@ { pval **result; ibase_result *ib_result; - + IBLS_FETCH(); RESET_ERRMSG; @@ -2317,7 +2328,6 @@ int len; XSQLVAR *var; IBLS_FETCH(); - RESET_ERRMSG; @@ -2402,7 +2412,7 @@ }; char bl_inf[sizeof(long)*8], *p; - + IBLS_FETCH(); bl_info->max_segment = 0; bl_info->num_segments = 0; @@ -2454,7 +2464,6 @@ ibase_db_link *ib_link; ibase_blob_handle *ib_blob; IBLS_FETCH(); - RESET_ERRMSG; @@ -2504,7 +2513,6 @@ pval *blob_arg; ibase_blob_handle *ib_blob, *ib_blob_id; IBLS_FETCH(); - RESET_ERRMSG; @@ -2544,7 +2552,6 @@ ibase_blob_handle *ib_blob; IBLS_FETCH(); - RESET_ERRMSG; if (ZEND_NUM_ARGS()!=2 || getParameters(ht, 2, &blob_arg, &string_arg)==FAILURE) { @@ -2575,7 +2582,6 @@ ibase_blob_handle *ib_blob; IBLS_FETCH(); - RESET_ERRMSG; if (ZEND_NUM_ARGS() != 2 || getParameters(ht, 2, &blob_arg, &len_arg) == FAILURE) { @@ -2626,7 +2632,6 @@ ibase_blob_handle *ib_blob; IBLS_FETCH(); - RESET_ERRMSG; if (ZEND_NUM_ARGS()!=1 || getParameters(ht, 1, &blob_arg)==FAILURE) { @@ -2685,7 +2690,6 @@ IBASE_BLOBINFO bl_info; IBLS_FETCH(); - RESET_ERRMSG; if (ZEND_NUM_ARGS()!=1 || getParameters(ht, 1, &blob_arg)==FAILURE) { @@ -2760,8 +2764,6 @@ char bl_data[IBASE_BLOB_SEG]; unsigned short seg_len; ibase_blob_handle *ib_blob_id; - - IBLS_FETCH(); RESET_ERRMSG; @@ -2824,7 +2826,6 @@ char bl_data[IBASE_BLOB_SEG]; /* FIXME? blob_seg_size parameter? */ FILE *fp; IBLS_FETCH(); - RESET_ERRMSG; Index: php4/ext/interbase/php_interbase.h diff -u php4/ext/interbase/php_interbase.h:1.14 php4/ext/interbase/php_interbase.h:1.15 --- php4/ext/interbase/php_interbase.h:1.14 Sun Jul 2 17:41:16 2000 +++ php4/ext/interbase/php_interbase.h Tue Jul 4 21:21:00 2000 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_interbase.h,v 1.14 2000/07/03 00:41:16 sas Exp $ */ +/* $Id: php_interbase.h,v 1.15 2000/07/05 04:21:00 jah Exp $ */ #ifndef PHP_INTERBASE_H #define PHP_INTERBASE_H @@ -76,7 +76,7 @@ #define IBASE_TRANS_ON_LINK 10 #define IBASE_BLOB_SEG 4096 -typedef struct { +ZEND_BEGIN_MODULE_GLOBALS(ibase) ISC_STATUS status[20]; long default_link; long num_links, num_persistent; @@ -91,7 +91,7 @@ char *timeformat; char *cfg_timeformat; char *errmsg; -} php_ibase_globals; +ZEND_END_MODULE_GLOBALS(ibase) typedef struct { isc_tr_handle trans[IBASE_TRANS_ON_LINK]; @@ -155,14 +155,15 @@ }; #ifdef ZTS -#define IBLS_D php_ibase_globals *ibase_globals +#define IBLS_D zend_ibase_globals *ibase_globals +#define IBLS_C ibase_globals #define IBG(v) (ibase_globals->v) -#define IBLS_FETCH() php_ibase_globals *ibase_globals = ts_resource(ibase_globals_id) +#define IBLS_FETCH() zend_ibase_globals *ibase_globals = ts_resource(ibase_globals_id) #else #define IBLS_D +#define IBLS_C #define IBG(v) (ibase_globals.v) #define IBLS_FETCH() -extern PHP_IBASE_API php_ibase_globals ibase_globals; #endif #else

« previous php.cvs (#623) next »