]> granicus.if.org Git - php/commitdiff
Remove some usages of hashtable internals
authorNikita Popov <nikic@php.net>
Mon, 7 Apr 2014 18:46:45 +0000 (20:46 +0200)
committerNikita Popov <nikic@php.net>
Wed, 9 Apr 2014 10:31:21 +0000 (12:31 +0200)
ext/mysql/php_mysql.c
ext/mysqli/mysqli.c
ext/mysqlnd/mysqlnd_reverse_api.c
ext/mysqlnd/php_mysqlnd.c
ext/pdo/pdo_dbh.c
ext/pdo/pdo_stmt.c
ext/pgsql/pgsql.c

index 3d092b2d6a167af92326eb697854c67c64ebb1ad..daf712cd0df3ccedddae84933f95e4d7bdaafb3b 100644 (file)
@@ -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;
index 0cea68a33f001c1453ef71d6eded5f1d57a09e76..c819b976ea5674c8108671c7c2921bf06e60344d 100644 (file)
@@ -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;
index cd490fa62cf8001e791c25d98f50d4a5a958e03e..b461b494273ac50df818240e65a2bd148a8851f7 100644 (file)
@@ -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);
 }
 /* }}} */
 
index 7712f1ecb8751aa6602864db36c5e966e585a2b8..1a4e67f5eb6e8d3fd19201f7f067f79e2af58e04 100644 (file)
@@ -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);
        }
 }
 /* }}} */
index d17867d1f9486fae753b185bbe165127f9f91fea..32e6e1bdd01e11683f72268986927e8d790aa1ea 100644 (file)
@@ -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);
index 2735aede41c087dc1047ac8228dd7640facb63a7..2593d02e96a5d7684691feddf8eaaa779be11d32 100644 (file)
@@ -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);
index f5e142a775fac142c911ee9dac5efbfd3b401ea5..d36901d8c1f5839239cb1e0ae09d8d748d6798b0 100644 (file)
@@ -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;