From 686213a2425f4b364cae8efdf4b07ccb203b9504 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Tue, 9 Sep 2014 21:50:26 +0200 Subject: [PATCH] first shot on fixing ext/oci8 --- ext/oci8/oci8.c | 42 ++++++++-------- ext/oci8/oci8_collection.c | 20 +++----- ext/oci8/oci8_interface.c | 42 +++++++--------- ext/oci8/oci8_lob.c | 2 +- ext/oci8/oci8_statement.c | 98 +++++++++++++++++++------------------- ext/oci8/php_oci8_int.h | 2 +- 6 files changed, 96 insertions(+), 110 deletions(-) diff --git a/ext/oci8/oci8.c b/ext/oci8/oci8.c index 6f78524fca..dca9d409a1 100644 --- a/ext/oci8/oci8.c +++ b/ext/oci8/oci8.c @@ -1789,7 +1789,7 @@ void php_oci_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent, int exclus if (!connection) { RETURN_FALSE; } - RETURN_RESOURCE(connection->id); + RETURN_RES(connection->id); } /* }}} */ @@ -1949,9 +1949,8 @@ php_oci_connection *php_oci_do_connect_ex(char *username, int username_len, char int type, link; void *ptr; - link = OCI8_PTR_TO_INT(le->ptr); - ptr = zend_list_find(link, &type); /* PHPNG TODO */ - if (ptr && (type == le_connection)) { + ptr = le->ptr; /* PHPNG TODO */ + if (ptr && (le->type == le_connection)) { connection = (php_oci_connection *)ptr; } } @@ -2007,10 +2006,10 @@ php_oci_connection *php_oci_do_connect_ex(char *username, int username_len, char /* okay, the connection is open and the server is still alive */ connection->used_this_request = 1; - tmp = (php_oci_connection *)zend_list_find(connection->id, &rsrc_type); + tmp = (php_oci_connection *)connection->id->ptr; if (tmp != NULL && rsrc_type == le_pconnection && tmp->hash_key->len == hashed_details.s->len && - memcmp(tmp->hash_key->val, hashed_details.s->val, tmp->hash_key->len) == 0 && zend_list_addref(connection->id) == SUCCESS) { + memcmp(tmp->hash_key->val, hashed_details.s->val, tmp->hash_key->len) == 0 && Z_ADDREF_P(connection->id) == SUCCESS) { /* do nothing */ } else { PHP_OCI_REGISTER_RESOURCE(connection, le_pconnection); @@ -2020,7 +2019,7 @@ php_oci_connection *php_oci_do_connect_ex(char *username, int username_len, char * decremented in the persistent helper */ if (OCI_G(old_oci_close_semantics)) { - zend_list_addref(connection->id); + Z_ADDREF_P(connection->id); } } smart_str_free_ex(&hashed_details, 0); @@ -2031,7 +2030,7 @@ php_oci_connection *php_oci_do_connect_ex(char *username, int username_len, char } else { /* we do not ping non-persistent connections */ smart_str_free_ex(&hashed_details, 0); - zend_list_addref(connection->id); + Z_ADDREF_P(connection->id); return connection; } } /* is_open is true? */ @@ -2048,7 +2047,7 @@ php_oci_connection *php_oci_do_connect_ex(char *username, int username_len, char /* We have to do a hash_del but need to preserve the resource if there is a positive * refcount. Set the data pointer in the list entry to NULL */ - if (connection == zend_list_find(connection->id, &rsrc_type) && rsrc_type == le_pconnection) { + if (connection == connection->id->ptr && rsrc_type == le_pconnection) { le->ptr = NULL; } @@ -2181,14 +2180,14 @@ php_oci_connection *php_oci_do_connect_ex(char *username, int username_len, char * refcount is decremented in the persistent helper */ if (OCI_G(old_oci_close_semantics)) { - zend_list_addref(connection->id); + Z_ADDREF_P(connection->id); } zend_hash_update_mem(&EG(persistent_list), connection->hash_key, (void *)&new_le, sizeof(zend_resource)); OCI_G(num_persistent)++; OCI_G(num_links)++; } else if (!exclusive) { PHP_OCI_REGISTER_RESOURCE(connection, le_connection); - new_le.ptr = OCI8_INT_TO_PTR(connection->id); + new_le.ptr = connection->id; new_le.type = le_index_ptr; zend_hash_update_mem(&EG(regular_list), connection->hash_key, (void *)&new_le, sizeof(zend_resource)); OCI_G(num_links)++; @@ -2564,15 +2563,15 @@ int php_oci_column_to_zval(php_oci_out_column *column, zval *value, int mode TSR } if (column->is_cursor) { /* REFCURSOR -> simply return the statement id */ - ZVAL_RESOURCE(value, column->stmtid); - zend_list_addref(column->stmtid); + zend_register_resource(value, column->stmtid, 0 TSRMLS_CC); /* XXX type correct? */ + Z_ADDREF_P(column->stmtid); } else if (column->is_descr) { if (column->data_type != SQLT_RDD) { int rsrc_type; /* reset descriptor's length */ - descriptor = (php_oci_descriptor *) zend_list_find(column->descid, &rsrc_type); + descriptor = (php_oci_descriptor *) column->descid->ptr; if (!descriptor || rsrc_type != le_descriptor) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find LOB descriptor #%d", column->descid); @@ -2608,7 +2607,7 @@ int php_oci_column_to_zval(php_oci_out_column *column, zval *value, int mode TSR /* return the locator */ object_init_ex(value, oci_lob_class_entry_ptr); add_property_resource(value, "descriptor", column->descid); - zend_list_addref(column->descid); + Z_ADDREF_P(column->descid); } } else { switch (column->retcode) { @@ -2762,19 +2761,18 @@ void php_oci_fetch_row (INTERNAL_FUNCTION_PARAMETERS, int mode, int expected_arg } if (!(column->indicator == -1)) { - zval *element; + zval element; - MAKE_STD_ZVAL(element); - php_oci_column_to_zval(column, element, fetch_mode TSRMLS_CC); + php_oci_column_to_zval(column, &element, fetch_mode TSRMLS_CC); if (fetch_mode & PHP_OCI_NUM || !(fetch_mode & PHP_OCI_ASSOC)) { - add_index_zval(return_value, i, element); + add_index_zval(return_value, i, &element); } if (fetch_mode & PHP_OCI_ASSOC) { if (fetch_mode & PHP_OCI_NUM) { - Z_ADDREF_P(element); + Z_ADDREF(element); } - add_assoc_zval(return_value, column->name, element); + add_assoc_zval(return_value, column->name, &element); } } else { @@ -2789,7 +2787,7 @@ void php_oci_fetch_row (INTERNAL_FUNCTION_PARAMETERS, int mode, int expected_arg if (expected_args > 2) { /* Only for ocifetchinto BC. In all other cases we return array, not long */ - REPLACE_ZVAL_VALUE(&array, return_value, 1); /* copy return_value to given reference */ + ZVAL_COPY_VALUE(&array, return_value); /* copy return_value to given reference */ zval_dtor(return_value); RETURN_LONG(statement->ncolumns); } diff --git a/ext/oci8/oci8_collection.c b/ext/oci8/oci8_collection.c index e1ed10877d..6b7dde25e7 100644 --- a/ext/oci8/oci8_collection.c +++ b/ext/oci8/oci8_collection.c @@ -56,7 +56,7 @@ php_oci_collection *php_oci_collection_create(php_oci_connection *connection, ch collection->connection = connection; collection->collection = NULL; - zend_list_addref(collection->connection->id); + Z_ADDREF_P(collection->connection->id); /* get type handle by name */ PHP_OCI_CALL_RETURN(errstatus, OCITypeByName, @@ -473,7 +473,7 @@ int php_oci_collection_append(php_oci_collection *collection, char *element, int /* {{{ php_oci_collection_element_get() Get the element with the given index */ -int php_oci_collection_element_get(php_oci_collection *collection, zend_long index, zval **result_element TSRMLS_DC) +int php_oci_collection_element_get(php_oci_collection *collection, zend_long index, zval *result_element TSRMLS_DC) { php_oci_connection *connection = collection->connection; dvoid *element; @@ -483,8 +483,7 @@ int php_oci_collection_element_get(php_oci_collection *collection, zend_long ind ub4 buff_len = 1024; sword errstatus; - MAKE_STD_ZVAL(*result_element); - ZVAL_NULL(*result_element); + ZVAL_NULL(result_element); connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */ @@ -503,13 +502,11 @@ int php_oci_collection_element_get(php_oci_collection *collection, zend_long ind if (errstatus != OCI_SUCCESS) { connection->errcode = php_oci_error(connection->err, errstatus TSRMLS_CC); PHP_OCI_HANDLE_ERROR(connection, connection->errcode); - FREE_ZVAL(*result_element); return 1; } if (exists == 0) { /* element doesn't exist */ - FREE_ZVAL(*result_element); return 1; } @@ -525,12 +522,11 @@ int php_oci_collection_element_get(php_oci_collection *collection, zend_long ind if (errstatus != OCI_SUCCESS) { connection->errcode = php_oci_error(connection->err, errstatus TSRMLS_CC); PHP_OCI_HANDLE_ERROR(connection, connection->errcode); - FREE_ZVAL(*result_element); return 1; } - ZVAL_STRINGL(*result_element, (char *)buff, buff_len, 1); - Z_STRVAL_P(*result_element)[buff_len] = '\0'; + ZVAL_STRINGL(result_element, (char *)buff, buff_len, 1); + Z_STRVAL_P(result_element)[buff_len] = '\0'; return 0; break; @@ -543,7 +539,7 @@ int php_oci_collection_element_get(php_oci_collection *collection, zend_long ind PHP_OCI_CALL_RETURN(str, OCIStringPtr, (connection->env, oci_string)); if (str) { - ZVAL_STRING(*result_element, (char *)str, 1); + ZVAL_STRING(result_element, (char *)str); } return 0; } @@ -568,18 +564,16 @@ int php_oci_collection_element_get(php_oci_collection *collection, zend_long ind if (errstatus != OCI_SUCCESS) { connection->errcode = php_oci_error(connection->err, errstatus TSRMLS_CC); PHP_OCI_HANDLE_ERROR(connection, connection->errcode); - FREE_ZVAL(*result_element); return 1; } - ZVAL_DOUBLE(*result_element, double_number); + ZVAL_DOUBLE(result_element, double_number); return 0; } break; default: php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unknown or unsupported type of element: %d", collection->element_typecode); - FREE_ZVAL(*result_element); return 1; break; } diff --git a/ext/oci8/oci8_interface.c b/ext/oci8/oci8_interface.c index 39ab399516..a55d131748 100644 --- a/ext/oci8/oci8_interface.c +++ b/ext/oci8/oci8_interface.c @@ -85,7 +85,7 @@ PHP_FUNCTION(oci_define_by_name) define->name = (text*) estrndup(name, name_len); define->name_len = name_len; define->type = type; - define->zval = var; + memmove(&define->zval, var, sizeof(zval)); zval_add_ref(&var); RETURN_TRUE; @@ -1386,7 +1386,8 @@ PHP_FUNCTION(ocifetchinto) Fetch all rows of result data into an array */ PHP_FUNCTION(oci_fetch_all) { - zval *z_statement, *array, *element, *tmp; + zval *z_statement, *array; + zval element, tmp; php_oci_statement *statement; php_oci_out_column **columns; zval ***outarrs; @@ -1417,19 +1418,17 @@ PHP_FUNCTION(oci_fetch_all) } while (!php_oci_statement_fetch(statement, nrows TSRMLS_CC)) { - zval *row; + zval row; - MAKE_STD_ZVAL(row); - array_init(row); + array_init(&row); for (i = 0; i < statement->ncolumns; i++) { - MAKE_STD_ZVAL(element); - php_oci_column_to_zval(columns[ i ], element, PHP_OCI_RETURN_LOBS TSRMLS_CC); + php_oci_column_to_zval(columns[ i ], &element, PHP_OCI_RETURN_LOBS TSRMLS_CC); if (flags & PHP_OCI_NUM) { - zend_hash_next_index_insert(Z_ARRVAL_P(row), &element, sizeof(zval*), NULL); + zend_hash_next_index_insert(Z_ARRVAL(row), &element, sizeof(zval*), NULL); } else { /* default to ASSOC */ - zend_symtable_update(Z_ARRVAL_P(row), columns[ i ]->name, columns[ i ]->name_len+1, &element, sizeof(zval*), NULL); + zend_symtable_update(Z_ARRVAL(row), columns[ i ]->name, columns[ i ]->name_len+1, &element, sizeof(zval*), NULL); } } @@ -1451,25 +1450,22 @@ PHP_FUNCTION(oci_fetch_all) for (i = 0; i < statement->ncolumns; i++) { columns[ i ] = php_oci_statement_get_column(statement, i + 1, NULL, 0 TSRMLS_CC); - MAKE_STD_ZVAL(tmp); - array_init(tmp); + array_init(&tmp); zend_hash_next_index_insert(Z_ARRVAL_P(array), &tmp, sizeof(zval*), (void **) &(outarrs[ i ])); } } else { /* default to ASSOC */ for (i = 0; i < statement->ncolumns; i++) { columns[ i ] = php_oci_statement_get_column(statement, i + 1, NULL, 0 TSRMLS_CC); - MAKE_STD_ZVAL(tmp); - array_init(tmp); + array_init(&tmp); zend_symtable_update(Z_ARRVAL_P(array), columns[ i ]->name, columns[ i ]->name_len+1, (void *) &tmp, sizeof(zval*), (void **) &(outarrs[ i ])); } } while (!php_oci_statement_fetch(statement, nrows TSRMLS_CC)) { for (i = 0; i < statement->ncolumns; i++) { - MAKE_STD_ZVAL(element); - php_oci_column_to_zval(columns[ i ], element, PHP_OCI_RETURN_LOBS TSRMLS_CC); - zend_hash_index_update((*(outarrs[ i ]))->value.ht, rows, (void *)&element, sizeof(zval*), NULL); + php_oci_column_to_zval(columns[ i ], &element, PHP_OCI_RETURN_LOBS TSRMLS_CC); + zend_hash_index_update(&(*(outarrs[ i ]))->value.arr->ht, &rows, (void *)&element, sizeof(zval*), NULL); } rows++; @@ -1707,7 +1703,7 @@ PHP_FUNCTION(oci_parse) statement = php_oci_statement_create(connection, query, query_len TSRMLS_CC); if (statement) { - RETURN_RESOURCE(statement->id); + RETURN_RES(statement->id); } RETURN_FALSE; } @@ -2006,7 +2002,7 @@ PHP_FUNCTION(oci_password_change) if (!connection) { RETURN_FALSE; } - RETURN_RESOURCE(connection->id); + RETURN_RES(connection->id); } WRONG_PARAM_COUNT; } @@ -2029,7 +2025,7 @@ PHP_FUNCTION(oci_new_cursor) statement = php_oci_statement_create(connection, NULL, 0 TSRMLS_CC); if (statement) { - RETURN_RESOURCE(statement->id); + RETURN_RES(statement->id); } RETURN_FALSE; } @@ -2226,7 +2222,7 @@ PHP_FUNCTION(oci_collection_element_get) zval **tmp, *z_collection = getThis(); php_oci_collection *collection; zend_long element_index; - zval *value; + zval value; if (getThis()) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &element_index) == FAILURE) { @@ -2250,9 +2246,7 @@ PHP_FUNCTION(oci_collection_element_get) RETURN_FALSE; } - *return_value = *value; - zval_copy_ctor(return_value); - zval_ptr_dtor(&value); + RETURN_ZVAL(&value, 1, 1); } /* }}} */ @@ -2463,7 +2457,7 @@ PHP_FUNCTION(oci_get_implicit_resultset) if (imp_statement) { if (php_oci_statement_execute(imp_statement, (ub4)OCI_DEFAULT TSRMLS_CC)) RETURN_FALSE; - RETURN_RESOURCE(imp_statement->id); + RETURN_RES(imp_statement->id); } RETURN_FALSE; } diff --git a/ext/oci8/oci8_lob.c b/ext/oci8/oci8_lob.c index deeaafd58f..6f7edef84d 100644 --- a/ext/oci8/oci8_lob.c +++ b/ext/oci8/oci8_lob.c @@ -71,7 +71,7 @@ php_oci_descriptor *php_oci_lob_create (php_oci_connection *connection, zend_lon descriptor = ecalloc(1, sizeof(php_oci_descriptor)); descriptor->type = type; descriptor->connection = connection; - zend_list_addref(descriptor->connection->id); + Z_ADDREF_P(descriptor->connection->id); PHP_OCI_CALL_RETURN(errstatus, OCIDescriptorAlloc, (connection->env, (dvoid*)&(descriptor->descriptor), descriptor->type, (size_t) 0, (dvoid **) 0)); diff --git a/ext/oci8/oci8_statement.c b/ext/oci8/oci8_statement.c index b9ad0643e3..167f1ce228 100644 --- a/ext/oci8/oci8_statement.c +++ b/ext/oci8/oci8_statement.c @@ -106,7 +106,7 @@ php_oci_statement *php_oci_statement_create(php_oci_connection *connection, char statement->impres_child_stmt = NULL; statement->impres_count = 0; statement->impres_flag = PHP_OCI_IMPRES_UNKNOWN; /* may or may not have Implicit Result Set children */ - zend_list_addref(statement->connection->id); + Z_ADDREF_P(statement->connection->id); if (OCI_G(default_prefetch) >= 0) { php_oci_statement_set_prefetch(statement, (ub4)OCI_G(default_prefetch) TSRMLS_CC); @@ -166,8 +166,8 @@ php_oci_statement *php_oci_get_implicit_resultset(php_oci_statement *statement T statement2->has_descr = 0; statement2->stmttype = 0; - zend_list_addref(statement->id); - zend_list_addref(statement2->connection->id); + Z_ADDREF_P(statement->id); + Z_ADDREF_P(statement2->connection->id); php_oci_statement_set_prefetch(statement2, statement->prefetch_count TSRMLS_CC); @@ -359,8 +359,8 @@ int php_oci_statement_fetch(php_oci_statement *statement, ub4 nrows TSRMLS_DC) continue; } - zval_dtor(column->define->zval); - php_oci_column_to_zval(column, column->define->zval, 0 TSRMLS_CC); + zval_dtor(&column->define->zval); + php_oci_column_to_zval(column, &column->define->zval, 0 TSRMLS_CC); } return 0; @@ -427,7 +427,7 @@ sb4 php_oci_define_callback(dvoid *ctx, OCIDefine *define, ub4 iter, dvoid **buf return OCI_ERROR; } nested_stmt->parent_stmtid = outcol->statement->id; - zend_list_addref(outcol->statement->id); + Z_ADDREF_P(outcol->statement->id); outcol->nested_statement = nested_stmt; outcol->stmtid = nested_stmt->id; @@ -909,7 +909,7 @@ int php_oci_bind_pre_exec(void *data, void *result TSRMLS_DC) *(int *)result = 0; - if (Z_TYPE_P(bind->zval) == IS_ARRAY) { + if (Z_TYPE(bind->zval) == IS_ARRAY) { /* These checks are currently valid for oci_bind_by_name, not * oci_bind_array_by_name. Also bind->type and * bind->indicator are not used for oci_bind_array_by_name. @@ -923,7 +923,7 @@ int php_oci_bind_pre_exec(void *data, void *result TSRMLS_DC) case SQLT_CLOB: case SQLT_BLOB: case SQLT_RDD: - if (Z_TYPE_P(bind->zval) != IS_OBJECT) { + if (Z_TYPE(bind->zval) != IS_OBJECT) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid variable used for bind"); *(int *)result = 1; } @@ -939,14 +939,14 @@ int php_oci_bind_pre_exec(void *data, void *result TSRMLS_DC) case SQLT_LBI: case SQLT_BIN: case SQLT_LNG: - if (Z_TYPE_P(bind->zval) == IS_RESOURCE || Z_TYPE_P(bind->zval) == IS_OBJECT) { + if (Z_TYPE(bind->zval) == IS_RESOURCE || Z_TYPE(bind->zval) == IS_OBJECT) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid variable used for bind"); *(int *)result = 1; } break; case SQLT_RSET: - if (Z_TYPE_P(bind->zval) != IS_RESOURCE) { + if (Z_TYPE(bind->zval) != IS_RESOURCE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid variable used for bind"); *(int *)result = 1; } @@ -969,27 +969,27 @@ int php_oci_bind_post_exec(void *data TSRMLS_DC) sword errstatus; if (bind->indicator == -1) { /* NULL */ - zval *val = bind->zval; + zval *val = &bind->zval; if (Z_TYPE_P(val) == IS_STRING) { *Z_STRVAL_P(val) = '\0'; /* XXX avoid warning in debug mode */ } zval_dtor(val); ZVAL_NULL(val); - } else if (Z_TYPE_P(bind->zval) == IS_STRING - && Z_STRLEN_P(bind->zval) > 0 - && Z_STRVAL_P(bind->zval)[ Z_STRLEN_P(bind->zval) ] != '\0') { + } else if (Z_TYPE(bind->zval) == IS_STRING + && Z_STRLEN(bind->zval) > 0 + && Z_STRVAL(bind->zval)[ Z_STRLEN(bind->zval) ] != '\0') { /* The post- PHP 5.3 feature for "interned" strings disallows * their reallocation but (i) any IN binds either interned or * not should already be null terminated and (ii) for OUT * binds, php_oci_bind_out_callback() should have allocated a * new string that we can modify here. */ - Z_STRVAL_P(bind->zval) = erealloc(Z_STRVAL_P(bind->zval), Z_STRLEN_P(bind->zval)+1); - Z_STRVAL_P(bind->zval)[ Z_STRLEN_P(bind->zval) ] = '\0'; - } else if (Z_TYPE_P(bind->zval) == IS_ARRAY) { + Z_STR(bind->zval) = zend_string_realloc(Z_STR(bind->zval), Z_STRLEN(bind->zval)+1, 0); + Z_STRVAL(bind->zval)[ Z_STRLEN(bind->zval) ] = '\0'; + } else if (Z_TYPE(bind->zval) == IS_ARRAY) { int i; zval **entry; - HashTable *hash = HASH_OF(bind->zval); + HashTable *hash = HASH_OF(&bind->zval); zend_hash_internal_pointer_reset(hash); @@ -1003,7 +1003,7 @@ int php_oci_bind_post_exec(void *data TSRMLS_DC) ZVAL_LONG(*entry, ((ub4 *)(bind->array.elements))[i]); zend_hash_move_forward(hash); } else { - add_next_index_long(bind->zval, ((ub4 *)(bind->array.elements))[i]); + add_next_index_long(&bind->zval, ((ub4 *)(bind->array.elements))[i]); } } break; @@ -1014,7 +1014,7 @@ int php_oci_bind_post_exec(void *data TSRMLS_DC) ZVAL_DOUBLE(*entry, ((double *)(bind->array.elements))[i]); zend_hash_move_forward(hash); } else { - add_next_index_double(bind->zval, ((double *)(bind->array.elements))[i]); + add_next_index_double(&bind->zval, ((double *)(bind->array.elements))[i]); } } break; @@ -1043,10 +1043,10 @@ int php_oci_bind_post_exec(void *data TSRMLS_DC) if (errstatus != OCI_SUCCESS) { connection->errcode = php_oci_error(connection->err, errstatus TSRMLS_CC); PHP_OCI_HANDLE_ERROR(connection, connection->errcode); - add_next_index_null(bind->zval); + add_next_index_null(&bind->zval); } else { connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */ - add_next_index_stringl(bind->zval, (char *)buff, buff_len); + add_next_index_stringl(&bind->zval, (char *)buff, buff_len); } } } @@ -1063,10 +1063,10 @@ int php_oci_bind_post_exec(void *data TSRMLS_DC) int curr_element_length = bind->array.element_lengths[i]; if ((i < bind->array.old_length) && (zend_hash_get_current_data(hash, (void **) &entry) != FAILURE)) { zval_dtor(*entry); - ZVAL_STRINGL(*entry, (char *)(((text *)bind->array.elements)+i*bind->array.max_length), curr_element_length, 1); + ZVAL_STRINGL(*entry, (char *)(((text *)bind->array.elements)+i*bind->array.max_length), curr_element_length); zend_hash_move_forward(hash); } else { - add_next_index_stringl(bind->zval, (char *)(((text *)bind->array.elements)+i*bind->array.max_length), curr_element_length); + add_next_index_stringl(&bind->zval, (char *)(((text *)bind->array.elements)+i*bind->array.max_length), curr_element_length); } } break; @@ -1215,9 +1215,7 @@ int php_oci_bind_by_name(php_oci_statement *statement, char *name, int name_len, memset((void*)&bind,0,sizeof(php_oci_bind)); if (zend_hash_find(statement->binds, name, name_len + 1, (void **)&old_bind) == SUCCESS) { bindp = old_bind; - if (bindp->zval) { - zval_ptr_dtor(&bindp->zval); - } + zval_ptr_dtor(&bindp->zval); } else { zend_hash_update(statement->binds, name, name_len + 1, &bind, sizeof(php_oci_bind), (void **)&bindp); } @@ -1225,7 +1223,7 @@ int php_oci_bind_by_name(php_oci_statement *statement, char *name, int name_len, bindp->descriptor = oci_desc; bindp->statement = oci_stmt; bindp->parent_statement = statement; - bindp->zval = var; + ZVAL_COPY(&bindp->zval, var); bindp->type = type; zval_add_ref(&var); @@ -1316,7 +1314,7 @@ sb4 php_oci_bind_in_callback( zval *val; TSRMLS_FETCH(); - if (!(phpbind=(php_oci_bind *)ictxp) || !(val = phpbind->zval)) { + if (!(phpbind=(php_oci_bind *)ictxp) || !(val = &phpbind->zval)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid phpbind pointer value"); return OCI_ERROR; } @@ -1370,7 +1368,7 @@ sb4 php_oci_bind_out_callback( sb4 retval = OCI_ERROR; TSRMLS_FETCH(); - if (!(phpbind=(php_oci_bind *)octxp) || !(val = phpbind->zval)) { + if (!(phpbind=(php_oci_bind *)octxp) || !(val = &phpbind->zval)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid phpbind pointer value"); return retval; } @@ -1414,12 +1412,14 @@ sb4 php_oci_bind_out_callback( convert_to_string(val); zval_dtor(val); - Z_STRLEN_P(val) = PHP_OCI_PIECE_SIZE; /* 64K-1 is max XXX */ - Z_STRVAL_P(val) = ecalloc(1, Z_STRLEN_P(phpbind->zval) + 1); - + //Z_STRLEN_P(val) = PHP_OCI_PIECE_SIZE; /* 64K-1 is max XXX */ + //Z_STRVAL_P(val) = ecalloc(1, Z_STRLEN_P(phpbind->zval) + 1); + // XXX is this right? + ZVAL_STRINGL(val, NULL, Z_STRLEN(phpbind->zval) + 1); + /* XXX we assume that zend-zval len has 4 bytes */ - *alenpp = (ub4*) &Z_STRLEN_P(phpbind->zval); - *bufpp = Z_STRVAL_P(phpbind->zval); + *alenpp = (ub4*) &Z_STRLEN(phpbind->zval); + *bufpp = Z_STRVAL(phpbind->zval); *piecep = OCI_ONE_PIECE; *rcodepp = &phpbind->retcode; *indpp = &phpbind->indicator; @@ -1584,7 +1584,7 @@ int php_oci_bind_array_by_name(php_oci_statement *statement, char *name, int nam bindp->statement = NULL; bindp->parent_statement = statement; bindp->bind = NULL; - bindp->zval = var; + ZVAL_COPY(&bindp->zval, var); bindp->array.type = type; bindp->indicator = 0; /* not used for array binds */ bindp->type = 0; /* not used for array binds */ @@ -1631,7 +1631,7 @@ php_oci_bind *php_oci_bind_array_helper_string(zval *var, zend_long max_table_le php_oci_bind *bind; ub4 i; HashTable *hash; - zval **entry; + zval *entry; hash = HASH_OF(var); @@ -1639,8 +1639,8 @@ php_oci_bind *php_oci_bind_array_helper_string(zval *var, zend_long max_table_le zend_hash_internal_pointer_reset(hash); while (zend_hash_get_current_data(hash, (void **) &entry) != FAILURE) { convert_to_string_ex(entry); - if (Z_STRLEN_PP(entry) > maxlength) { - maxlength = Z_STRLEN_PP(entry) + 1; + if (Z_STRLEN_P(entry) > maxlength) { + maxlength = Z_STRLEN_P(entry) + 1; } zend_hash_move_forward(hash); } @@ -1662,8 +1662,8 @@ php_oci_bind *php_oci_bind_array_helper_string(zval *var, zend_long max_table_le for (i = 0; i < bind->array.current_length; i++) { if (zend_hash_get_current_data(hash, (void **) &entry) != FAILURE) { convert_to_string_ex(entry); - bind->array.element_lengths[i] = Z_STRLEN_PP(entry); - if (Z_STRLEN_PP(entry) == 0) { + bind->array.element_lengths[i] = Z_STRLEN_P(entry); + if (Z_STRLEN_P(entry) == 0) { bind->array.indicators[i] = -1; } zend_hash_move_forward(hash); @@ -1678,9 +1678,9 @@ php_oci_bind *php_oci_bind_array_helper_string(zval *var, zend_long max_table_le int element_length; convert_to_string_ex(entry); - element_length = (maxlength > Z_STRLEN_PP(entry)) ? Z_STRLEN_PP(entry) : maxlength; + element_length = (maxlength > Z_STRLEN_P(entry)) ? Z_STRLEN_P(entry) : maxlength; - memcpy((text *)bind->array.elements + i*maxlength, Z_STRVAL_PP(entry), element_length); + memcpy((text *)bind->array.elements + i*maxlength, Z_STRVAL_P(entry), element_length); ((text *)bind->array.elements)[i*maxlength + element_length] = '\0'; zend_hash_move_forward(hash); @@ -1701,7 +1701,7 @@ php_oci_bind *php_oci_bind_array_helper_number(zval *var, zend_long max_table_le php_oci_bind *bind; ub4 i; HashTable *hash; - zval **entry; + zval *entry; hash = HASH_OF(var); @@ -1721,7 +1721,7 @@ php_oci_bind *php_oci_bind_array_helper_number(zval *var, zend_long max_table_le } if ((i < bind->array.current_length) && (zend_hash_get_current_data(hash, (void **) &entry) != FAILURE)) { convert_to_long_ex(entry); - ((ub4 *)bind->array.elements)[i] = (ub4) Z_LVAL_PP(entry); + ((ub4 *)bind->array.elements)[i] = (ub4) Z_LVAL_P(entry); zend_hash_move_forward(hash); } else { ((ub4 *)bind->array.elements)[i] = 0; @@ -1740,7 +1740,7 @@ php_oci_bind *php_oci_bind_array_helper_double(zval *var, zend_long max_table_le php_oci_bind *bind; ub4 i; HashTable *hash; - zval **entry; + zval *entry; hash = HASH_OF(var); @@ -1760,7 +1760,7 @@ php_oci_bind *php_oci_bind_array_helper_double(zval *var, zend_long max_table_le } if ((i < bind->array.current_length) && (zend_hash_get_current_data(hash, (void **) &entry) != FAILURE)) { convert_to_double_ex(entry); - ((double *)bind->array.elements)[i] = (double) Z_DVAL_PP(entry); + ((double *)bind->array.elements)[i] = (double) Z_DVAL_P(entry); zend_hash_move_forward(hash); } else { ((double *)bind->array.elements)[i] = 0; @@ -1779,7 +1779,7 @@ php_oci_bind *php_oci_bind_array_helper_date(zval *var, zend_long max_table_leng php_oci_bind *bind; ub4 i; HashTable *hash; - zval **entry; + zval *entry; sword errstatus; hash = HASH_OF(var); @@ -1802,7 +1802,7 @@ php_oci_bind *php_oci_bind_array_helper_date(zval *var, zend_long max_table_leng if ((i < bind->array.current_length) && (zend_hash_get_current_data(hash, (void **) &entry) != FAILURE)) { convert_to_string_ex(entry); - PHP_OCI_CALL_RETURN(errstatus, OCIDateFromText, (connection->err, (CONST text *)Z_STRVAL_PP(entry), Z_STRLEN_PP(entry), NULL, 0, NULL, 0, &oci_date)); + PHP_OCI_CALL_RETURN(errstatus, OCIDateFromText, (connection->err, (CONST text *)Z_STRVAL_P(entry), Z_STRLEN_P(entry), NULL, 0, NULL, 0, &oci_date)); if (errstatus != OCI_SUCCESS) { /* failed to convert string to date */ diff --git a/ext/oci8/php_oci8_int.h b/ext/oci8/php_oci8_int.h index 7c67ba3716..80e0e5d8a6 100644 --- a/ext/oci8/php_oci8_int.h +++ b/ext/oci8/php_oci8_int.h @@ -449,7 +449,7 @@ int php_oci_collection_size(php_oci_collection *collection, sb4 *size TSRMLS_DC) int php_oci_collection_max(php_oci_collection *collection, zend_long *max TSRMLS_DC); int php_oci_collection_trim(php_oci_collection *collection, zend_long trim_size TSRMLS_DC); int php_oci_collection_append(php_oci_collection *collection, char *element, int element_len TSRMLS_DC); -int php_oci_collection_element_get(php_oci_collection *collection, zend_long index, zval **result_element TSRMLS_DC); +int php_oci_collection_element_get(php_oci_collection *collection, zend_long index, zval *result_element TSRMLS_DC); int php_oci_collection_element_set(php_oci_collection *collection, zend_long index, char *value, int value_len TSRMLS_DC); int php_oci_collection_element_set_null(php_oci_collection *collection, zend_long index TSRMLS_DC); int php_oci_collection_element_set_date(php_oci_collection *collection, zend_long index, char *date, int date_len TSRMLS_DC); -- 2.40.0