Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove some usages of hashtable internals

  • Loading branch information...
commit eaf44ec397cc3286107166ce51bac03bf6bc8f83 1 parent 6006a3e
@nikic nikic authored
View
21 ext/mysql/php_mysql.c
@@ -2173,19 +2173,12 @@ static void php_mysql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, long result_type,
fci.symbol_table = NULL;
fci.object_ptr = return_value;
fci.retval_ptr_ptr = &retval_ptr;
+ fci.params = NULL;
+ fci.param_count = 0;
+ fci.no_separation = 1;
+
if (ctor_params && Z_TYPE_P(ctor_params) != IS_NULL) {
- if (Z_TYPE_P(ctor_params) == IS_ARRAY) {
- HashTable *htl = Z_ARRVAL_P(ctor_params);
- Bucket *p;
-
- fci.param_count = 0;
- fci.params = safe_emalloc(sizeof(zval*), htl->nNumOfElements, 0);
- p = htl->pListHead;
- while (p != NULL) {
- fci.params[fci.param_count++] = (zval**)p->pData;
- p = p->pListNext;
- }
- } else {
+ if (zend_fcall_info_args(&fci, ctor_params TSRMLS_CC) == FAILURE) {
/* Two problems why we throw exceptions here: PHP is typeless
* and hence passing one argument that's not an array could be
* by mistake and the other way round is possible, too. The
@@ -2195,11 +2188,7 @@ static void php_mysql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, long result_type,
zend_throw_exception(zend_exception_get_default(TSRMLS_C), "Parameter ctor_params must be an array", 0 TSRMLS_CC);
return;
}
- } else {
- fci.param_count = 0;
- fci.params = NULL;
}
- fci.no_separation = 1;
fcc.initialized = 1;
fcc.function_handler = ce->constructor;
View
21 ext/mysqli/mysqli.c
@@ -1296,19 +1296,12 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags
fci.symbol_table = NULL;
fci.object_ptr = return_value;
fci.retval_ptr_ptr = &retval_ptr;
+ fci.params = NULL;
+ fci.param_count = 0;
+ fci.no_separation = 1;
+
if (ctor_params && Z_TYPE_P(ctor_params) != IS_NULL) {
- if (Z_TYPE_P(ctor_params) == IS_ARRAY) {
- HashTable *params_ht = Z_ARRVAL_P(ctor_params);
- Bucket *p;
-
- fci.param_count = 0;
- fci.params = safe_emalloc(sizeof(zval*), params_ht->nNumOfElements, 0);
- p = params_ht->pListHead;
- while (p != NULL) {
- fci.params[fci.param_count++] = (zval**)p->pData;
- p = p->pListNext;
- }
- } else {
+ if (zend_fcall_info_args(&fci, ctor_params TSRMLS_CC) == FAILURE) {
/* Two problems why we throw exceptions here: PHP is typeless
* and hence passing one argument that's not an array could be
* by mistake and the other way round is possible, too. The
@@ -1318,11 +1311,7 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags
zend_throw_exception(zend_exception_get_default(TSRMLS_C), "Parameter ctor_params must be an array", 0 TSRMLS_CC);
return;
}
- } else {
- fci.param_count = 0;
- fci.params = NULL;
}
- fci.no_separation = 1;
fcc.initialized = 1;
fcc.function_handler = ce->constructor;
View
2  ext/mysqlnd/mysqlnd_reverse_api.c
@@ -61,7 +61,7 @@ PHPAPI void
mysqlnd_reverse_api_register_api(MYSQLND_REVERSE_API * apiext TSRMLS_DC)
{
zend_hash_add(&mysqlnd_api_ext_ht, apiext->module->name, strlen(apiext->module->name) + 1, &apiext,
- sizeof(MYSQLND_REVERSE_API), NULL);
+ sizeof(MYSQLND_REVERSE_API *), NULL);
}
/* }}} */
View
14 ext/mysqlnd/php_mysqlnd.c
@@ -107,17 +107,17 @@ static void
mysqlnd_minfo_dump_api_plugins(smart_str * buffer TSRMLS_DC)
{
HashTable *ht = mysqlnd_reverse_api_get_api_list(TSRMLS_C);
- Bucket *p;
+ HashPosition pos;
+ MYSQLND_REVERSE_API **ext;
- p = ht->pListHead;
- while(p != NULL) {
- MYSQLND_REVERSE_API * ext = *(MYSQLND_REVERSE_API **) p->pData;
+ for (zend_hash_internal_pointer_reset_ex(ht, &pos);
+ zend_hash_get_current_data_ex(ht, (void **) &ext, &pos);
+ zend_hash_move_forward_ex(ht, &pos)
+ ) {
if (buffer->len) {
smart_str_appendc(buffer, ',');
}
- smart_str_appends(buffer, ext->module->name);
-
- p = p->pListNext;
+ smart_str_appends(buffer, (*ext)->module->name);
}
}
/* }}} */
View
18 ext/pdo/pdo_dbh.c
@@ -468,23 +468,11 @@ static void pdo_stmt_construct(pdo_stmt_t *stmt, zval *object, zend_class_entry
fci.object_ptr = object;
fci.symbol_table = NULL;
fci.retval_ptr_ptr = &retval;
- if (ctor_args) {
- HashTable *ht = Z_ARRVAL_P(ctor_args);
- Bucket *p;
-
- fci.param_count = 0;
- fci.params = safe_emalloc(sizeof(zval*), ht->nNumOfElements, 0);
- p = ht->pListHead;
- while (p != NULL) {
- fci.params[fci.param_count++] = (zval**)p->pData;
- p = p->pListNext;
- }
- } else {
- fci.param_count = 0;
- fci.params = NULL;
- }
+ fci.params = NULL;
fci.no_separation = 1;
+ zend_fcall_info_args(&fci, ctor_args TSRMLS_CC);
+
fcc.initialized = 1;
fcc.function_handler = dbstmt_ce->constructor;
fcc.calling_scope = EG(scope);
View
18 ext/pdo/pdo_stmt.c
@@ -757,23 +757,11 @@ static int do_fetch_class_prepare(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */
fci->function_name = NULL;
fci->symbol_table = NULL;
fci->retval_ptr_ptr = &stmt->fetch.cls.retval_ptr;
- if (stmt->fetch.cls.ctor_args) {
- HashTable *ht = Z_ARRVAL_P(stmt->fetch.cls.ctor_args);
- Bucket *p;
-
- fci->param_count = 0;
- fci->params = safe_emalloc(sizeof(zval**), ht->nNumOfElements, 0);
- p = ht->pListHead;
- while (p != NULL) {
- fci->params[fci->param_count++] = (zval**)p->pData;
- p = p->pListNext;
- }
- } else {
- fci->param_count = 0;
- fci->params = NULL;
- }
+ fci->params = NULL;
fci->no_separation = 1;
+ zend_fcall_info_args(fci, stmt->fetch.cls.ctor_args TSRMLS_CC);
+
fcc->initialized = 1;
fcc->function_handler = ce->constructor;
fcc->calling_scope = EG(scope);
View
23 ext/pgsql/pgsql.c
@@ -2793,33 +2793,22 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, long result_type,
fci.symbol_table = NULL;
fci.object_ptr = return_value;
fci.retval_ptr_ptr = &retval_ptr;
+ fci.params = NULL;
+ fci.param_count = 0;
+ fci.no_separation = 1;
+
if (ctor_params && Z_TYPE_P(ctor_params) != IS_NULL) {
- if (Z_TYPE_P(ctor_params) == IS_ARRAY) {
- HashTable *ht = Z_ARRVAL_P(ctor_params);
- Bucket *p;
-
- fci.param_count = 0;
- fci.params = safe_emalloc(sizeof(zval***), ht->nNumOfElements, 0);
- p = ht->pListHead;
- while (p != NULL) {
- fci.params[fci.param_count++] = (zval**)p->pData;
- p = p->pListNext;
- }
- } else {
+ if (zend_fcall_info_args(&fci, ctor_params TSRMLS_CC) == FAILURE) {
/* Two problems why we throw exceptions here: PHP is typeless
* and hence passing one argument that's not an array could be
- * by mistake and the other way round is possible, too. The
+ * by mistake and the other way round is possible, too. The
* single value is an array. Also we'd have to make that one
* argument passed by reference.
*/
zend_throw_exception(zend_exception_get_default(TSRMLS_C), "Parameter ctor_params must be an array", 0 TSRMLS_CC);
return;
}
- } else {
- fci.param_count = 0;
- fci.params = NULL;
}
- fci.no_separation = 1;
fcc.initialized = 1;
fcc.function_handler = ce->constructor;
Please sign in to comment.
Something went wrong with that request. Please try again.