From: Dmitry Stogov Date: Fri, 13 Feb 2015 17:18:29 +0000 (+0300) Subject: Get rid of old HashTable iteration API (it doesn't work with constant arrays) X-Git-Tag: PRE_PHP7_EREG_MYSQL_REMOVALS~155 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bc630ad6da0c6d7cf2d224dba8972499d5691c6b;p=php Get rid of old HashTable iteration API (it doesn't work with constant arrays) --- diff --git a/ext/intl/dateformat/dateformat_format_object.cpp b/ext/intl/dateformat/dateformat_format_object.cpp index 1df6cc9612..7246778486 100644 --- a/ext/intl/dateformat/dateformat_format_object.cpp +++ b/ext/intl/dateformat/dateformat_format_object.cpp @@ -86,8 +86,9 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object) //nothing } else if (Z_TYPE_P(format) == IS_ARRAY) { HashTable *ht = Z_ARRVAL_P(format); - HashPosition pos = {0}; + uint32_t idx; zval *z; + if (zend_hash_num_elements(ht) != 2) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_format_object: bad format; if array, it must have " @@ -95,9 +96,15 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object) RETURN_FALSE; } - zend_hash_internal_pointer_reset_ex(ht, &pos); - z = zend_hash_get_current_data_ex(ht, &pos); - if (!valid_format(z)) { + idx = 0; + while (idx < ht->nNumUsed) { + z = &ht->arData[idx].val; + if (Z_TYPE_P(z) != IS_UNDEF) { + break; + } + idx++; + } + if (idx >= ht->nNumUsed || !valid_format(z)) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_format_object: bad format; the date format (first " "element of the array) is not valid", 0); @@ -105,9 +112,15 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object) } dateStyle = (DateFormat::EStyle)Z_LVAL_P(z); - zend_hash_move_forward_ex(ht, &pos); - z = zend_hash_get_current_data_ex(ht, &pos); - if (!valid_format(z)) { + idx++; + while (idx < ht->nNumUsed) { + z = &ht->arData[idx].val; + if (Z_TYPE_P(z) != IS_UNDEF) { + break; + } + idx++; + } + if (idx >= ht->nNumUsed || !valid_format(z)) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_format_object: bad format; the time format (" "second element of the array) is not valid", 0); diff --git a/ext/snmp/snmp.c b/ext/snmp/snmp.c index 930affa041..e7cb87096e 100644 --- a/ext/snmp/snmp.c +++ b/ext/snmp/snmp.c @@ -964,41 +964,20 @@ retry: static int php_snmp_parse_oid(zval *object, int st, struct objid_query *objid_query, zval *oid, zval *type, zval *value) { char *pptr; - HashPosition pos_oid, pos_type, pos_value; + uint32_t idx_type = 0, idx_value = 0; zval *tmp_oid, *tmp_type, *tmp_value; if (Z_TYPE_P(oid) != IS_ARRAY) { - /* - if (Z_ISREF_PP(oid)) { - SEPARATE_ZVAL(oid); - } - */ convert_to_string_ex(oid); - } else if (Z_TYPE_P(oid) == IS_ARRAY) { - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(oid), &pos_oid); } if (st & SNMP_CMD_SET) { if (Z_TYPE_P(type) != IS_ARRAY) { - /* - if (Z_ISREF_PP(type)) { - SEPARATE_ZVAL(type); - } - */ convert_to_string_ex(type); - } else if (Z_TYPE_P(type) == IS_ARRAY) { - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(type), &pos_type); } if (Z_TYPE_P(value) != IS_ARRAY) { - /* - if (Z_ISREF_PP(value)) { - SEPARATE_ZVAL(value); - } - */ convert_to_string_ex(value); - } else if (Z_TYPE_P(value) == IS_ARRAY) { - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(value), &pos_value); } } @@ -1041,10 +1020,7 @@ static int php_snmp_parse_oid(zval *object, int st, struct objid_query *objid_qu return FALSE; } objid_query->array_output = ( (st & SNMP_CMD_SET) ? FALSE : TRUE ); - for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(oid), &pos_oid); - (tmp_oid = zend_hash_get_current_data_ex(Z_ARRVAL_P(oid), &pos_oid)) != NULL; - zend_hash_move_forward_ex(Z_ARRVAL_P(oid), &pos_oid) ) { - + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(oid), tmp_oid) { convert_to_string_ex(tmp_oid); objid_query->vars[objid_query->count].oid = Z_STRVAL_P(tmp_oid); if (st & SNMP_CMD_SET) { @@ -1052,7 +1028,14 @@ static int php_snmp_parse_oid(zval *object, int st, struct objid_query *objid_qu pptr = Z_STRVAL_P(type); objid_query->vars[objid_query->count].type = *pptr; } else if (Z_TYPE_P(type) == IS_ARRAY) { - if ((tmp_type = zend_hash_get_current_data_ex(Z_ARRVAL_P(type), &pos_type)) != NULL) { + while (idx_type < Z_ARRVAL_P(type)->nNumUsed) { + tmp_type = &Z_ARRVAL_P(type)->arData[idx_type].val; + if (Z_TYPE_P(tmp_type) != IS_UNDEF) { + break; + } + idx_type++; + } + if (idx_type < Z_ARRVAL_P(type)->nNumUsed) { convert_to_string_ex(tmp_type); if (Z_STRLEN_P(tmp_type) != 1) { php_error_docref(NULL, E_WARNING, "'%s': bogus type '%s', should be single char, got %u", Z_STRVAL_P(tmp_oid), Z_STRVAL_P(tmp_type), Z_STRLEN_P(tmp_type)); @@ -1061,7 +1044,7 @@ static int php_snmp_parse_oid(zval *object, int st, struct objid_query *objid_qu } pptr = Z_STRVAL_P(tmp_type); objid_query->vars[objid_query->count].type = *pptr; - zend_hash_move_forward_ex(Z_ARRVAL_P(type), &pos_type); + idx_type++; } else { php_error_docref(NULL, E_WARNING, "'%s': no type set", Z_STRVAL_P(tmp_oid)); efree(objid_query->vars); @@ -1072,10 +1055,17 @@ static int php_snmp_parse_oid(zval *object, int st, struct objid_query *objid_qu if (Z_TYPE_P(value) == IS_STRING) { objid_query->vars[objid_query->count].value = Z_STRVAL_P(value); } else if (Z_TYPE_P(value) == IS_ARRAY) { - if ((tmp_value = zend_hash_get_current_data_ex(Z_ARRVAL_P(value), &pos_value)) != NULL) { + while (idx_value < Z_ARRVAL_P(value)->nNumUsed) { + tmp_value = &Z_ARRVAL_P(value)->arData[idx_value].val; + if (Z_TYPE_P(tmp_value) != IS_UNDEF) { + break; + } + idx_value++; + } + if (idx_value < Z_ARRVAL_P(value)->nNumUsed) { convert_to_string_ex(tmp_value); objid_query->vars[objid_query->count].value = Z_STRVAL_P(tmp_value); - zend_hash_move_forward_ex(Z_ARRVAL_P(value), &pos_value); + idx_value++; } else { php_error_docref(NULL, E_WARNING, "'%s': no value set", Z_STRVAL_P(tmp_oid)); efree(objid_query->vars); @@ -1084,7 +1074,7 @@ static int php_snmp_parse_oid(zval *object, int st, struct objid_query *objid_qu } } objid_query->count++; - } + } ZEND_HASH_FOREACH_END(); } /* now parse all OIDs */