Skip to content

Instantly share code, notes, and snippets.

@laruence
Last active December 23, 2015 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laruence/f3af903012902818d7da to your computer and use it in GitHub Desktop.
Save laruence/f3af903012902818d7da to your computer and use it in GitHub Desktop.
diff --git a/ext/interbase/ibase_blobs.c b/ext/interbase/ibase_blobs.c
index d492f55..884ff29 100644
--- a/ext/interbase/ibase_blobs.c
+++ b/ext/interbase/ibase_blobs.c
@@ -36,7 +36,7 @@ static void _php_ibase_free_blob(zend_resource *rsrc) /* {{{ */
{
ibase_blob *ib_blob = (ibase_blob *)rsrc->ptr;
- if (ib_blob->bl_handle != NULL) { /* blob open*/
+ if (ib_blob->bl_handle != 0) { /* blob open*/
if (isc_cancel_blob(IB_STATUS, &ib_blob->bl_handle)) {
_php_ibase_module_error("You can lose data. Close any blob after reading from or "
"writing to it. Use ibase_blob_close() before calling ibase_close()");
@@ -216,7 +216,7 @@ PHP_FUNCTION(ibase_blob_create)
PHP_IBASE_LINK_TRANS(link, ib_link, trans);
ib_blob = (ibase_blob *) emalloc(sizeof(ibase_blob));
- ib_blob->bl_handle = NULL;
+ ib_blob->bl_handle = 0;
ib_blob->type = BLOB_INPUT;
if (isc_create_blob(IB_STATUS, &ib_link->handle, &trans->handle, &ib_blob->bl_handle, &ib_blob->bl_qd)) {
@@ -261,7 +261,7 @@ PHP_FUNCTION(ibase_blob_open)
PHP_IBASE_LINK_TRANS(link, ib_link, trans);
ib_blob = (ibase_blob *) emalloc(sizeof(ibase_blob));
- ib_blob->bl_handle = NULL;
+ ib_blob->bl_handle = 0;
ib_blob->type = BLOB_OUTPUT;
do {
@@ -296,7 +296,7 @@ PHP_FUNCTION(ibase_blob_add)
RESET_ERRMSG;
- if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "rr", &blob_arg, &string_arg)) {
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "rz", &blob_arg, &string_arg)) {
return;
}
@@ -361,7 +361,7 @@ static void _php_ibase_blob_end(INTERNAL_FUNCTION_PARAMETERS, int bl_end) /* {{{
RETURN_FALSE;
}
}
- ib_blob->bl_handle = NULL;
+ ib_blob->bl_handle = 0;
RETVAL_NEW_STR(_php_ibase_quad_to_string(ib_blob->bl_qd));
} else { /* discard created blob */
@@ -369,7 +369,7 @@ static void _php_ibase_blob_end(INTERNAL_FUNCTION_PARAMETERS, int bl_end) /* {{{
_php_ibase_error();
RETURN_FALSE;
}
- ib_blob->bl_handle = NULL;
+ ib_blob->bl_handle = 0;
RETVAL_TRUE;
}
zend_list_delete(Z_RES_P(blob_arg));
@@ -401,7 +401,7 @@ PHP_FUNCTION(ibase_blob_info)
zval *link = NULL;
ibase_db_link *ib_link;
ibase_trans *trans = NULL;
- ibase_blob ib_blob = { NULL, BLOB_INPUT };
+ ibase_blob ib_blob = { 0, BLOB_INPUT };
IBASE_BLOBINFO bl_info;
RESET_ERRMSG;
@@ -477,7 +477,7 @@ PHP_FUNCTION(ibase_blob_echo)
zval *link = NULL;
ibase_db_link *ib_link;
ibase_trans *trans = NULL;
- ibase_blob ib_blob_id = { NULL, BLOB_OUTPUT };
+ ibase_blob ib_blob_id = { 0, BLOB_OUTPUT };
char bl_data[IBASE_BLOB_SEG];
unsigned short seg_len;
@@ -538,7 +538,7 @@ PHP_FUNCTION(ibase_blob_import)
zval *link = NULL, *file;
int size;
unsigned short b;
- ibase_blob ib_blob = { NULL, 0 };
+ ibase_blob ib_blob = { 0, 0 };
ibase_db_link *ib_link;
ibase_trans *trans = NULL;
char bl_data[IBASE_BLOB_SEG];
diff --git a/ext/interbase/ibase_events.c b/ext/interbase/ibase_events.c
index 26656f8..ba9b318 100644
--- a/ext/interbase/ibase_events.c
+++ b/ext/interbase/ibase_events.c
@@ -45,7 +45,8 @@ void _php_ibase_free_event(ibase_event *event) /* {{{ */
if (event->link != NULL) {
ibase_event **node;
- if (event->link->handle != NULL &&
+ zend_list_delete(event->link_res);
+ if (event->link->handle != 0 &&
isc_cancel_events(IB_STATUS, &event->link->handle, &event->event_id)) {
_php_ibase_error();
}
@@ -62,7 +63,9 @@ void _php_ibase_free_event(ibase_event *event) /* {{{ */
_php_ibase_event_free(event->event_buffer,event->result_buffer);
for (i = 0; i < event->event_count; ++i) {
- efree(event->events[i]);
+ if (event->events[i]) {
+ efree(event->events[i]);
+ }
}
efree(event->events);
}
@@ -150,7 +153,7 @@ PHP_FUNCTION(ibase_wait_event)
if (ZEND_NUM_ARGS() > 15) {
WRONG_PARAM_COUNT;
}
- if ((ib_link = (ibase_db_link *)zend_fetch_resource2_ex(IBG(default_link), "InterBase link", le_link, le_plink)) == NULL) {
+ if ((ib_link = (ibase_db_link *)zend_fetch_resource2(IBG(default_link), "InterBase link", le_link, le_plink)) == NULL) {
RETURN_FALSE;
}
}
@@ -190,8 +193,6 @@ PHP_FUNCTION(ibase_wait_event)
static isc_callback _php_ibase_callback(ibase_event *event, /* {{{ */
unsigned short buffer_size, char *result_buf)
{
- zval *res;
-
/* this function is called asynchronously by the Interbase client library. */
TSRMLS_FETCH_FROM_CTX(event->thread_ctx);
@@ -211,15 +212,14 @@ static isc_callback _php_ibase_callback(ibase_event *event, /* {{{ */
/* copy the updated results into the result buffer */
memcpy(event->result_buffer, result_buf, buffer_size);
- res = zend_hash_index_find(&EG(regular_list), event->link_res_id);
- ZVAL_RES(&args[1], Z_RES_P(res));
+ ZVAL_RES(&args[1], event->link_res);
/* find out which event occurred */
isc_event_counts(occurred_event, buffer_size, event->event_buffer, event->result_buffer);
for (i = 0; i < event->event_count; ++i) {
if (occurred_event[i]) {
ZVAL_STRING(&args[0], event->events[i]);
- efree(event->events[i]);
+ //efree(event->events[i]);
break;
}
}
@@ -262,7 +262,8 @@ PHP_FUNCTION(ibase_set_event_handler)
ibase_db_link *ib_link;
ibase_event *event;
unsigned short i = 1, buffer_size;
- int link_res_id, num_args;
+ int num_args;
+ zend_resource *link_res;
RESET_ERRMSG;
@@ -291,8 +292,7 @@ PHP_FUNCTION(ibase_set_event_handler)
RETURN_FALSE;
}
- convert_to_long_ex(&args[0]);
- link_res_id = Z_LVAL(args[0]);
+ link_res = Z_RES(args[0]);
} else {
/* callback, event_1 [, ... event_15]
@@ -304,10 +304,10 @@ PHP_FUNCTION(ibase_set_event_handler)
cb_arg = &args[0];
- if ((ib_link = (ibase_db_link *)zend_fetch_resource2_ex(IBG(default_link), "InterBase link", le_link, le_plink)) == NULL) {
+ if ((ib_link = (ibase_db_link *)zend_fetch_resource2(IBG(default_link), "InterBase link", le_link, le_plink)) == NULL) {
RETURN_FALSE;
}
- link_res_id = IBG(default_link);
+ link_res = IBG(default_link);
}
/* get the callback */
@@ -321,17 +321,22 @@ PHP_FUNCTION(ibase_set_event_handler)
/* allocate the event resource */
event = (ibase_event *) safe_emalloc(sizeof(ibase_event), 1, 0);
TSRMLS_SET_CTX(event->thread_ctx);
- event->link_res_id = link_res_id;
+ event->link_res = link_res;
+ GC_REFCOUNT(link_res)++;
event->link = ib_link;
event->event_count = 0;
event->state = NEW;
- event->events = (char **) safe_emalloc(sizeof(char *),ZEND_NUM_ARGS()-i,0);
+ event->events = (char **) safe_emalloc(sizeof(char *), 15, 0);
ZVAL_DUP(&event->callback, cb_arg);
- for (; i < ZEND_NUM_ARGS(); ++i) {
- convert_to_string_ex(&args[i]);
- event->events[event->event_count++] = estrdup(Z_STRVAL(args[i]));
+ for (; i < 15; ++i) {
+ if (i < ZEND_NUM_ARGS()) {
+ convert_to_string_ex(&args[i]);
+ event->events[event->event_count++] = estrdup(Z_STRVAL(args[i]));
+ } else {
+ event->events[i] = NULL;
+ }
}
/* fills the required data structure with information about the events */
diff --git a/ext/interbase/ibase_query.c b/ext/interbase/ibase_query.c
index fce9206..4e0a718 100644
--- a/ext/interbase/ibase_query.c
+++ b/ext/interbase/ibase_query.c
@@ -59,7 +59,7 @@ typedef struct _ib_query {
ibase_db_link *link;
ibase_trans *trans;
ibase_result *result;
- int result_res_id;
+ zend_resource *result_res;
isc_stmt_handle stmt;
XSQLDA *in_sqlda, *out_sqlda;
ibase_array *in_array, *out_array;
@@ -67,7 +67,7 @@ typedef struct _ib_query {
unsigned short dialect;
char statement_type;
char *query;
- long trans_res_id;
+ zend_resource *trans_res;
} ibase_query;
typedef struct {
@@ -313,7 +313,7 @@ static int _php_ibase_alloc_array(ibase_array **ib_arrayp, XSQLDA *sqlda, /* {{{
/* allocate and prepare query */
static int _php_ibase_alloc_query(ibase_query *ib_query, ibase_db_link *link, /* {{{ */
- ibase_trans *trans, char *query, unsigned short dialect, int trans_res_id)
+ ibase_trans *trans, char *query, unsigned short dialect, zend_resource *trans_res)
{
static char info_type[] = {isc_info_sql_stmt_type};
char result[8];
@@ -326,14 +326,14 @@ static int _php_ibase_alloc_query(ibase_query *ib_query, ibase_db_link *link, /*
ib_query->link = link;
ib_query->trans = trans;
- ib_query->result_res_id = 0;
+ ib_query->result_res = NULL;
ib_query->result = NULL;
- ib_query->stmt = NULL;
+ ib_query->stmt = 0;
ib_query->in_array = NULL;
ib_query->out_array = NULL;
ib_query->dialect = dialect;
ib_query->query = estrdup(query);
- ib_query->trans_res_id = trans_res_id;
+ ib_query->trans_res = trans_res;
ib_query->out_sqlda = NULL;
ib_query->in_sqlda = NULL;
@@ -530,8 +530,12 @@ static int _php_ibase_bind_array(zval *val, char *buf, unsigned long buf_size, /
struct tm t = { 0, 0, 0, 0, 0, 0 };
switch (array->el_type) {
+#ifndef HAVE_STRFTIME
unsigned short n;
+#endif
+#if (SIZEOF_LONG < 8)
ISC_INT64 l;
+#endif
case SQL_SHORT:
convert_to_long(val);
@@ -737,7 +741,7 @@ static int _php_ibase_bind(XSQLDA *sqlda, zval *b_vars, BIND_BUF *buf, /* {{{ */
if (Z_STRLEN_P(b_var) != BLOB_ID_LEN ||
!_php_ibase_string_to_quad(Z_STRVAL_P(b_var), &buf[i].val.qval)) {
- ibase_blob ib_blob = { NULL, BLOB_INPUT };
+ ibase_blob ib_blob = { 0, BLOB_INPUT };
if (isc_create_blob(IB_STATUS, &ib_query->link->handle,
&ib_query->trans->handle, &ib_blob.bl_handle, &ib_blob.bl_qd)) {
@@ -883,7 +887,7 @@ static int _php_ibase_exec(INTERNAL_FUNCTION_PARAMETERS, ibase_result **ib_resul
case isc_info_sql_stmt_start_trans:
/* a SET TRANSACTION statement should be executed with a NULL trans handle */
- tr = NULL;
+ tr = 0;
if (isc_dsql_execute_immediate(IB_STATUS, &ib_query->link->handle, &tr, 0,
ib_query->query, ib_query->dialect, NULL)) {
@@ -923,11 +927,11 @@ static int _php_ibase_exec(INTERNAL_FUNCTION_PARAMETERS, ibase_result **ib_resul
goto _php_ibase_exec_error;
}
- if (ib_query->trans->handle == NULL && ib_query->trans_res_id != 0) {
+ if (ib_query->trans->handle == 0 && ib_query->trans_res != NULL) {
/* transaction was released by the query and was a registered resource,
so we have to release it */
- zval *res = zend_hash_index_find(&EG(regular_list), ib_query->trans_res_id);
- zend_list_delete(Z_RES_P(res));
+ zend_list_delete(ib_query->trans_res);
+ ib_query->trans_res = NULL;
}
RETVAL_TRUE;
@@ -1063,7 +1067,7 @@ PHP_FUNCTION(ibase_query)
char *query;
size_t query_len;
int bind_i, bind_num;
- long trans_res_id = 0;
+ zend_resource *trans_res = NULL;
ibase_db_link *ib_link = NULL;
ibase_trans *trans = NULL;
ibase_query ib_query = { NULL, NULL, 0, 0 };
@@ -1083,7 +1087,7 @@ PHP_FUNCTION(ibase_query)
ib_link = (ibase_db_link*)zend_fetch_resource2_ex(zlink, LE_LINK, le_link, le_plink);
trans = (ibase_trans*)zend_fetch_resource_ex(ztrans, LE_TRANS, le_trans);
- trans_res_id = Z_RES_P(ztrans)->handle;
+ trans_res = Z_RES_P(ztrans);
bind_i = 3;
break;
}
@@ -1093,7 +1097,7 @@ PHP_FUNCTION(ibase_query)
_php_ibase_get_link_trans(INTERNAL_FUNCTION_PARAM_PASSTHRU, zlink, &ib_link, &trans);
if (trans != NULL) {
- trans_res_id = Z_RES_P(zlink)->handle;
+ trans_res = Z_RES_P(zlink);
}
bind_i = 2;
break;
@@ -1102,8 +1106,8 @@ PHP_FUNCTION(ibase_query)
/* the statement is 'CREATE DATABASE ...' if the link argument is IBASE_CREATE */
if (SUCCESS == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(),
"ls", &l, &query, &query_len) && l == PHP_IBASE_CREATE) {
- isc_db_handle db = NULL;
- isc_tr_handle trans = NULL;
+ isc_db_handle db = 0;
+ isc_tr_handle trans = 0;
if (PG(sql_safe_mode)) {
_php_ibase_module_error("CREATE DATABASE is not allowed in SQL safe mode"
@@ -1133,8 +1137,8 @@ PHP_FUNCTION(ibase_query)
RETVAL_RES(zend_register_resource(ib_link, le_link));
Z_TRY_ADDREF_P(return_value);
- IBG(default_link) = Z_RES_P(return_value)->handle;
- ++IBG(num_links);
+ Z_TRY_ADDREF_P(return_value);
+ IBG(default_link) = Z_RES_P(return_value);
}
return;
}
@@ -1142,8 +1146,7 @@ PHP_FUNCTION(ibase_query)
case 0:
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() ? 1 : 0, "s", &query,
&query_len)) {
- ib_link = (ibase_db_link *)zend_fetch_resource2_ex(IBG(default_link), LE_LINK,
- le_link, le_plink);
+ ib_link = (ibase_db_link *)zend_fetch_resource2(IBG(default_link), LE_LINK, le_link, le_plink);
bind_i = 1;
break;
@@ -1153,8 +1156,7 @@ PHP_FUNCTION(ibase_query)
/* open default transaction */
if (ib_link == NULL || FAILURE == _php_ibase_def_trans(ib_link, &trans)
- || FAILURE == _php_ibase_alloc_query(&ib_query, ib_link, trans, query, ib_link->dialect,
- trans_res_id)) {
+ || FAILURE == _php_ibase_alloc_query(&ib_query, ib_link, trans, query, ib_link->dialect, trans_res)) {
return;
}
@@ -1184,7 +1186,7 @@ PHP_FUNCTION(ibase_query)
/* EXECUTE PROCEDURE returns only one row => statement can be released immediately */
if (ib_query.statement_type != isc_info_sql_stmt_exec_procedure) {
- ib_query.stmt = NULL; /* keep stmt when free query */
+ ib_query.stmt = 0; /* keep stmt when free query */
}
RETVAL_RES(zend_register_resource(result, le_result));
Z_TRY_ADDREF_P(return_value);
@@ -1211,7 +1213,7 @@ PHP_FUNCTION(ibase_affected_rows)
}
if (!arg) {
- ib_link = (ibase_db_link *)zend_fetch_resource2_ex(IBG(default_link), LE_LINK, le_link, le_plink);
+ ib_link = (ibase_db_link *)zend_fetch_resource2(IBG(default_link), LE_LINK, le_link, le_plink);
if (ib_link->tr_list == NULL || ib_link->tr_list->trans == NULL) {
RETURN_FALSE;
}
@@ -1549,7 +1551,7 @@ static void _php_ibase_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int fetch_type)
char bl_info[20];
unsigned short i;
- blob_handle.bl_handle = NULL;
+ blob_handle.bl_handle = 0;
blob_handle.bl_qd = *(ISC_QUAD *) var->sqldata;
if (isc_open_blob(IB_STATUS, &ib_result->link->handle, &ib_result->trans->handle,
@@ -1599,7 +1601,6 @@ static void _php_ibase_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int fetch_type)
}
} else { /* blob id only */
- char *s;
ISC_QUAD bl_qd = *(ISC_QUAD *) var->sqldata;
ZVAL_NEW_STR(&result, _php_ibase_quad_to_string(bl_qd));
}
@@ -1732,7 +1733,8 @@ PHP_FUNCTION(ibase_prepare)
zval *link_arg, *trans_arg;
ibase_db_link *ib_link;
ibase_trans *trans = NULL;
- size_t query_len, trans_res_id = 0;
+ size_t query_len;
+ zend_resource *trans_res = NULL;
ibase_query *ib_query;
char *query;
@@ -1742,7 +1744,7 @@ PHP_FUNCTION(ibase_prepare)
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &query, &query_len) == FAILURE) {
return;
}
- ib_link = (ibase_db_link *)zend_fetch_resource2_ex(IBG(default_link), LE_LINK, le_link, le_plink);
+ ib_link = (ibase_db_link *)zend_fetch_resource2(IBG(default_link), LE_LINK, le_link, le_plink);
} else if (ZEND_NUM_ARGS() == 2) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &link_arg, &query, &query_len) == FAILURE) {
return;
@@ -1750,7 +1752,7 @@ PHP_FUNCTION(ibase_prepare)
_php_ibase_get_link_trans(INTERNAL_FUNCTION_PARAM_PASSTHRU, link_arg, &ib_link, &trans);
if (trans != NULL) {
- trans_res_id = Z_RES_P(link_arg)->handle;
+ trans_res = Z_RES_P(link_arg);
}
} else {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rrs", &link_arg, &trans_arg, &query, &query_len) == FAILURE) {
@@ -1758,7 +1760,7 @@ PHP_FUNCTION(ibase_prepare)
}
ib_link = (ibase_db_link *)zend_fetch_resource2_ex(link_arg, LE_LINK, le_link, le_plink);
trans = (ibase_trans *)zend_fetch_resource_ex(trans_arg, LE_TRANS, le_trans);
- trans_res_id = Z_RES_P(trans_arg)->handle;
+ trans_res = Z_RES_P(trans_arg);
}
if (FAILURE == _php_ibase_def_trans(ib_link, &trans)) {
@@ -1767,7 +1769,7 @@ PHP_FUNCTION(ibase_prepare)
ib_query = (ibase_query *) emalloc(sizeof(ibase_query));
- if (FAILURE == _php_ibase_alloc_query(ib_query, ib_link, trans, query, ib_link->dialect, trans_res_id)) {
+ if (FAILURE == _php_ibase_alloc_query(ib_query, ib_link, trans, query, ib_link->dialect, trans_res)) {
efree(ib_query);
RETURN_FALSE;
}
@@ -1808,21 +1810,16 @@ PHP_FUNCTION(ibase_execute)
}
/* Have we used this cursor before and it's still open (exec proc has no cursor) ? */
- if (ib_query->result_res_id != 0
+ if (ib_query->result_res != NULL
&& ib_query->statement_type != isc_info_sql_stmt_exec_procedure) {
- zval *res;
-
IBDEBUG("Implicitly closing a cursor");
if (isc_dsql_free_statement(IB_STATUS, &ib_query->stmt, DSQL_close)) {
_php_ibase_error();
break;
}
- /* invalidate previous results returned by this query (not necessary for exec proc) */
- res = zend_hash_index_find(&EG(regular_list), ib_query->result_res_id);
- if (res) {
- zend_list_delete(Z_RES_P(res));
- }
+ zend_list_delete(ib_query->result_res);
+ ib_query->result_res = NULL;
}
if (FAILURE == _php_ibase_exec(INTERNAL_FUNCTION_PARAM_PASSTHRU, &result, ib_query,
@@ -1831,7 +1828,7 @@ PHP_FUNCTION(ibase_execute)
}
/* free the query if trans handle was released */
- if (ib_query->trans->handle == NULL) {
+ if (ib_query->trans->handle == 0) {
zend_list_delete(Z_RES_P(query));
}
@@ -1840,11 +1837,11 @@ PHP_FUNCTION(ibase_execute)
result->type = EXECUTE_RESULT;
if (ib_query->statement_type == isc_info_sql_stmt_exec_procedure) {
- result->stmt = NULL;
+ result->stmt = 0;
}
ret = zend_list_insert(result, le_result);
- ib_query->result_res_id = Z_RES_HANDLE_P(ret);
+ ib_query->result_res = Z_RES_P(ret);
ZVAL_COPY_VALUE(return_value, ret);
Z_TRY_ADDREF_P(return_value);
Z_TRY_ADDREF_P(return_value);
@@ -1867,6 +1864,10 @@ PHP_FUNCTION(ibase_free_query)
}
ib_query = (ibase_query *)zend_fetch_resource_ex(query_arg, LE_QUERY, le_query);
+ if (!ib_query) {
+ RETURN_FALSE;
+ }
+
zend_list_close(Z_RES_P(query_arg));
RETURN_TRUE;
}
diff --git a/ext/interbase/ibase_service.c b/ext/interbase/ibase_service.c
index 628d457..8ced758 100644
--- a/ext/interbase/ibase_service.c
+++ b/ext/interbase/ibase_service.c
@@ -210,7 +210,7 @@ PHP_FUNCTION(ibase_service_attach)
size_t hlen, ulen, plen, spb_len;
ibase_service *svm;
char buf[128], *host, *user, *pass, *loc;
- isc_svc_handle handle = NULL;
+ isc_svc_handle handle = 0;
RESET_ERRMSG;
diff --git a/ext/interbase/interbase.c b/ext/interbase/interbase.c
index cb6baad..0ac494f 100644
--- a/ext/interbase/interbase.c
+++ b/ext/interbase/interbase.c
@@ -41,7 +41,7 @@
#define COMMIT 1
#define RETAIN 2
-#define CHECK_LINK(link) { if (link==-1) { php_error_docref(NULL, E_WARNING, "A link to the server could not be established"); RETURN_FALSE; } }
+#define CHECK_LINK(link) { if (link==NULL) { php_error_docref(NULL, E_WARNING, "A link to the server could not be established"); RETURN_FALSE; } }
ZEND_DECLARE_MODULE_GLOBALS(ibase)
static PHP_GINIT_FUNCTION(ibase);
@@ -580,9 +580,9 @@ static void _php_ibase_commit_link(ibase_db_link *link) /* {{{ */
for (l = link->tr_list; l != NULL; ++i) {
ibase_tr_list *p = l;
- if (p->trans != NULL) {
+ if (p->trans != 0) {
if (i == 0) {
- if (p->trans->handle != NULL) {
+ if (p->trans->handle != 0) {
IBDEBUG("Committing default transaction...");
if (isc_commit_transaction(IB_STATUS, &p->trans->handle)) {
_php_ibase_error();
@@ -590,7 +590,7 @@ static void _php_ibase_commit_link(ibase_db_link *link) /* {{{ */
}
efree(p->trans); /* default transaction is not a registered resource: clean up */
} else {
- if (p->trans->handle != NULL) {
+ if (p->trans->handle != 0) {
/* non-default trans might have been rolled back by other call of this dtor */
IBDEBUG("Rolling back other transactions...");
if (isc_rollback_transaction(IB_STATUS, &p->trans->handle)) {
@@ -632,7 +632,7 @@ static void _php_ibase_close_link(zend_resource *rsrc) /* {{{ */
ibase_db_link *link = (ibase_db_link *) rsrc->ptr;
_php_ibase_commit_link(link);
- if (link->handle != NULL) {
+ if (link->handle != 0) {
IBDEBUG("Closing normal link...");
isc_detach_database(IB_STATUS, &link->handle);
}
@@ -647,7 +647,7 @@ static void _php_ibase_close_plink(zend_resource *rsrc) /* {{{ */
_php_ibase_commit_link(link);
IBDEBUG("Closing permanent link...");
- if (link->handle != NULL) {
+ if (link->handle != 0) {
isc_detach_database(IB_STATUS, &link->handle);
}
IBG(num_persistent)--;
@@ -662,7 +662,7 @@ static void _php_ibase_free_trans(zend_resource *rsrc) /* {{{ */
unsigned short i;
IBDEBUG("Cleaning up transaction resource...");
- if (trans->handle != NULL) {
+ if (trans->handle != 0) {
IBDEBUG("Rolling back unhandled transaction...");
if (isc_rollback_transaction(IB_STATUS, &trans->handle)) {
_php_ibase_error();
@@ -719,7 +719,7 @@ static PHP_GINIT_FUNCTION(ibase)
{
ibase_globals->num_persistent = ibase_globals->num_links = 0;
ibase_globals->sql_code = *ibase_globals->errmsg = 0;
- ibase_globals->default_link = -1;
+ ibase_globals->default_link = NULL;
}
PHP_MINIT_FUNCTION(ibase)
@@ -774,7 +774,7 @@ PHP_MSHUTDOWN_FUNCTION(ibase)
zend_module_entry *ibase_entry;
if ((ibase_entry = zend_hash_str_find_ptr(&module_registry, ibase_module_entry.name,
strlen(ibase_module_entry.name))) != NULL) {
- ibase_entry->handle = NULL;
+ ibase_entry->handle = 0;
}
#endif
UNREGISTER_INI_ENTRIES();
@@ -784,7 +784,7 @@ PHP_MSHUTDOWN_FUNCTION(ibase)
PHP_RSHUTDOWN_FUNCTION(ibase)
{
IBG(num_links) = IBG(num_persistent);
- IBG(default_link)= -1;
+ IBG(default_link)= NULL;
RESET_ERRMSG;
@@ -842,7 +842,7 @@ static char const dpb_args[] = {
0, isc_dpb_user_name, isc_dpb_password, isc_dpb_lc_ctype, isc_dpb_sql_role_name, 0
};
-int _php_ibase_attach_db(char **args, int *len, long *largs, isc_db_handle *db)
+int _php_ibase_attach_db(char **args, int *len, long *largs, isc_db_handle *db) /* {{{ */
{
short i, dpb_len, buf_len = 257-2; /* version byte at the front, and a null at the end */
char dpb_buffer[257] = { isc_dpb_version1, 0 }, *dpb;
@@ -882,7 +882,7 @@ static void _php_ibase_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) /*
long largs[] = { 0, 0, 0 };
PHP_MD5_CTX hash_context;
zend_resource new_index_ptr, *le;
- isc_db_handle db_handle = NULL;
+ isc_db_handle db_handle = 0;
ibase_db_link *ib_link;
RESET_ERRMSG;
@@ -932,15 +932,12 @@ static void _php_ibase_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) /*
xlink = (zend_resource*) le->ptr;
if ((!persistent && xlink->type == le_link) || xlink->type == le_plink) {
- if (IBG(default_link) > 0) {
- zval *link = zend_hash_index_find(&EG(regular_list), IBG(default_link));
- if (link) {
- zend_list_delete(Z_RES_P(link));
- }
+ if (IBG(default_link)) {
+ zend_list_close(IBG(default_link));
}
xlink->gc.refcount++;
xlink->gc.refcount++;
- IBG(default_link) = xlink->handle;
+ IBG(default_link) = xlink;
RETVAL_RES(xlink);
} else {
zend_hash_str_del(&EG(regular_list), hash, sizeof(hash)-1);
@@ -1017,13 +1014,10 @@ static void _php_ibase_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) /*
(void *) &new_index_ptr, sizeof(zend_resource)) == NULL) {
RETURN_FALSE;
}
- if (IBG(default_link) > 0) {
- zval *link = zend_hash_index_find(&EG(regular_list), IBG(default_link));
- if (link) {
- zend_list_delete(Z_RES_P(link));
- }
+ if (IBG(default_link)) {
+ zend_list_delete(IBG(default_link));
}
- IBG(default_link) = Z_RES_P(return_value)->handle;
+ IBG(default_link) = Z_RES_P(return_value);
Z_TRY_ADDREF_P(return_value);
Z_TRY_ADDREF_P(return_value);
}
@@ -1050,8 +1044,7 @@ PHP_FUNCTION(ibase_pconnect)
PHP_FUNCTION(ibase_close)
{
zval *link_arg = NULL;
- ibase_db_link *ib_link;
- int link_id;
+ zend_resource *link_res;
RESET_ERRMSG;
@@ -1060,23 +1053,18 @@ PHP_FUNCTION(ibase_close)
}
if (ZEND_NUM_ARGS() == 0) {
- link_id = IBG(default_link);
- CHECK_LINK(link_id);
- IBG(default_link) = -1;
+ link_res = IBG(default_link);
+ CHECK_LINK(link_res);
+ IBG(default_link) = NULL;
} else {
- link_id = Z_RES_P(link_arg)->handle;
+ link_res = Z_RES_P(link_arg);
}
- ib_link = (ibase_db_link *)zend_fetch_resource2_ex(link_arg, LE_LINK, le_link, le_plink);
- if (!link_arg) {
- link_arg = zend_hash_index_find(&EG(regular_list), link_id);
- zend_list_delete(Z_RES_P(link_arg));
- }
/* we have at least 3 additional references to this resource ??? */
- if (GC_REFCOUNT(Z_RES_P(link_arg)) < 4) {
- zend_list_close(Z_RES_P(link_arg));
+ if (GC_REFCOUNT(link_res) < 4) {
+ zend_list_close(link_res);
} else {
- zend_list_delete(Z_RES_P(link_arg));
+ zend_list_delete(link_res);
}
RETURN_TRUE;
}
@@ -1089,7 +1077,7 @@ PHP_FUNCTION(ibase_drop_db)
zval *link_arg = NULL;
ibase_db_link *ib_link;
ibase_tr_list *l;
- int link_id;
+ zend_resource *link_res;
RESET_ERRMSG;
@@ -1098,14 +1086,18 @@ PHP_FUNCTION(ibase_drop_db)
}
if (ZEND_NUM_ARGS() == 0) {
- link_id = IBG(default_link);
- CHECK_LINK(link_id);
- IBG(default_link) = -1;
+ link_res = IBG(default_link);
+ CHECK_LINK(link_res);
+ IBG(default_link) = NULL;
} else {
- link_id = Z_RES_P(link_arg)->handle;
+ link_res = Z_RES_P(link_arg);
}
- ib_link = (ibase_db_link *)zend_fetch_resource2_ex(link_arg, LE_LINK, le_link, le_plink);
+ ib_link = (ibase_db_link *)zend_fetch_resource2(link_res, LE_LINK, le_link, le_plink);
+
+ if (!ib_link) {
+ RETURN_FALSE;
+ }
if (isc_drop_database(IB_STATUS, &ib_link->handle)) {
_php_ibase_error();
@@ -1114,14 +1106,11 @@ PHP_FUNCTION(ibase_drop_db)
/* isc_drop_database() doesn't invalidate the transaction handles */
for (l = ib_link->tr_list; l != NULL; l = l->next) {
- if (l->trans != NULL) l->trans->handle = NULL;
+ if (l->trans != NULL) l->trans->handle = 0;
}
- if (!link_arg) {
- link_arg = zend_hash_index_find(&EG(regular_list), link_id);
- zend_list_delete(Z_RES_P(link_arg));
- }
- zend_list_delete(Z_RES_P(link_arg));
+ zend_list_delete(link_res);
+
RETURN_TRUE;
}
/* }}} */
@@ -1138,7 +1127,7 @@ PHP_FUNCTION(ibase_trans)
char last_tpb[TPB_MAX_SIZE];
ibase_db_link **ib_link = NULL;
ibase_trans *ib_trans;
- isc_tr_handle tr_handle = NULL;
+ isc_tr_handle tr_handle = 0;
ISC_STATUS result;
RESET_ERRMSG;
@@ -1236,7 +1225,7 @@ PHP_FUNCTION(ibase_trans)
if (link_cnt == 0) {
link_cnt = 1;
- if ((ib_link[0] = (ibase_db_link *)zend_fetch_resource2_ex(IBG(default_link), LE_LINK, le_link, le_plink)) == NULL) {
+ if ((ib_link[0] = (ibase_db_link *)zend_fetch_resource2(IBG(default_link), LE_LINK, le_link, le_plink)) == NULL) {
efree(ib_link);
RETURN_FALSE;
}
@@ -1297,13 +1286,13 @@ int _php_ibase_def_trans(ibase_db_link *ib_link, ibase_trans **trans) /* {{{ */
if (tr == NULL) {
tr = (ibase_trans *) emalloc(sizeof(ibase_trans));
- tr->handle = NULL;
+ tr->handle = 0;
tr->link_cnt = 1;
tr->affected_rows = 0;
tr->db_link[0] = ib_link;
ib_link->tr_list->trans = tr;
}
- if (tr->handle == NULL) {
+ if (tr->handle == 0) {
if (isc_start_transaction(IB_STATUS, &tr->handle, 1, &ib_link->handle, 0, NULL)) {
_php_ibase_error();
return FAILURE;
@@ -1330,7 +1319,7 @@ static void _php_ibase_trans_end(INTERNAL_FUNCTION_PARAMETERS, int commit) /* {{
}
if (ZEND_NUM_ARGS() == 0) {
- ib_link = (ibase_db_link *)zend_fetch_resource2_ex(IBG(default_link), LE_LINK, le_link, le_plink);
+ ib_link = (ibase_db_link *)zend_fetch_resource2(IBG(default_link), LE_LINK, le_link, le_plink);
if (ib_link->tr_list == NULL || ib_link->tr_list->trans == NULL) {
/* this link doesn't have a default transaction */
_php_ibase_module_error("Default link has no default transaction");
diff --git a/ext/interbase/php_ibase_includes.h b/ext/interbase/php_ibase_includes.h
index 63a61ed..94a8b0c 100644
--- a/ext/interbase/php_ibase_includes.h
+++ b/ext/interbase/php_ibase_includes.h
@@ -60,7 +60,7 @@ extern int le_link, le_plink, le_trans;
ZEND_BEGIN_MODULE_GLOBALS(ibase)
ISC_STATUS status[20];
- long default_link;
+ zend_resource *default_link;
long num_links, num_persistent;
char errmsg[MAX_ERRMSG];
long sql_code;
@@ -95,7 +95,7 @@ typedef struct {
typedef struct event {
ibase_db_link *link;
- long link_res_id;
+ zend_resource* link_res;
ISC_LONG event_id;
unsigned short event_count;
char **events;
@@ -155,13 +155,15 @@ void _php_ibase_module_error(char *, ...)
/* determine if a resource is a link or transaction handle */
#define PHP_IBASE_LINK_TRANS(zv, lh, th) \
- do { if (!zv) { \
- lh = (ibase_db_link *)zend_fetch_resource2(IBG(default_link), \
- "InterBase link", le_link, le_plink); } \
- else \
- _php_ibase_get_link_trans(INTERNAL_FUNCTION_PARAM_PASSTHRU, zv, &lh, &th); \
- if (SUCCESS != _php_ibase_def_trans(lh, &th)) { RETURN_FALSE; } \
- } while (0)
+ do { \
+ if (!zv) { \
+ lh = (ibase_db_link *)zend_fetch_resource2( \
+ IBG(default_link), "InterBase link", le_link, le_plink); \
+ } else { \
+ _php_ibase_get_link_trans(INTERNAL_FUNCTION_PARAM_PASSTHRU, zv, &lh, &th); \
+ } \
+ if (SUCCESS != _php_ibase_def_trans(lh, &th)) { RETURN_FALSE; } \
+ } while (0)
int _php_ibase_def_trans(ibase_db_link *ib_link, ibase_trans **trans);
void _php_ibase_get_link_trans(INTERNAL_FUNCTION_PARAMETERS, zval *link_id,
diff --git a/ext/interbase/tests/bug46543.phpt b/ext/interbase/tests/bug46543.phpt
index 59e088c..88f38a6 100644
--- a/ext/interbase/tests/bug46543.phpt
+++ b/ext/interbase/tests/bug46543.phpt
@@ -19,10 +19,10 @@ ibase_trans(1, 2, $x, $x, 3);
?>
--EXPECTF--
-Warning: ibase_trans(): no Firebird/InterBase link resource supplied in %s on line %d
+Warning: ibase_trans(): supplied resource is not a valid Firebird/InterBase link resource in %sbug46543.php on line %d
-Warning: ibase_trans(): no Firebird/InterBase link resource supplied in %s on line %d
+Warning: ibase_trans(): supplied resource is not a valid Firebird/InterBase link resource in %sbug46543.php on line %d
-Warning: ibase_trans(): no Firebird/InterBase link resource supplied in %s on line %d
+Warning: ibase_trans(): supplied resource is not a valid Firebird/InterBase link resource in %sbug46543.php on line %d
-Warning: ibase_trans(): supplied resource is not a valid Firebird/InterBase link resource in %s on line %d
+Warning: ibase_trans(): supplied resource is not a valid Firebird/InterBase link resource in %sbug46543.php on line %d
diff --git a/ext/interbase/tests/ibase_close_001.phpt b/ext/interbase/tests/ibase_close_001.phpt
index f74d109..cb91e8a 100644
--- a/ext/interbase/tests/ibase_close_001.phpt
+++ b/ext/interbase/tests/ibase_close_001.phpt
@@ -17,9 +17,7 @@ var_dump(ibase_close('foo'));
--EXPECTF--
bool(true)
bool(true)
-
-Warning: ibase_close(): supplied resource is not a valid Firebird/InterBase link resource in %s on line %d
-bool(false)
+bool(true)
Warning: ibase_close() expects parameter 1 to be resource,%string given in %s on line %d
NULL
diff --git a/ext/interbase/tests/ibase_trans_001.phpt b/ext/interbase/tests/ibase_trans_001.phpt
index d8b7c81..cceb60e 100644
--- a/ext/interbase/tests/ibase_trans_001.phpt
+++ b/ext/interbase/tests/ibase_trans_001.phpt
@@ -18,6 +18,4 @@ var_dump(ibase_close($x));
resource(%d) of type (Firebird/InterBase transaction)
resource(%d) of type (Firebird/InterBase transaction)
bool(true)
-
-Warning: ibase_close(): supplied resource is not a valid Firebird/InterBase link resource in %s on line %d
-bool(false)
+bool(true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment