Skip to content

Commit bc630ad

Browse files
committed
Get rid of old HashTable iteration API (it doesn't work with constant arrays)
1 parent 8f968c5 commit bc630ad

File tree

2 files changed

+41
-38
lines changed

2 files changed

+41
-38
lines changed

ext/intl/dateformat/dateformat_format_object.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,28 +86,41 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object)
8686
//nothing
8787
} else if (Z_TYPE_P(format) == IS_ARRAY) {
8888
HashTable *ht = Z_ARRVAL_P(format);
89-
HashPosition pos = {0};
89+
uint32_t idx;
9090
zval *z;
91+
9192
if (zend_hash_num_elements(ht) != 2) {
9293
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
9394
"datefmt_format_object: bad format; if array, it must have "
9495
"two elements", 0);
9596
RETURN_FALSE;
9697
}
9798

98-
zend_hash_internal_pointer_reset_ex(ht, &pos);
99-
z = zend_hash_get_current_data_ex(ht, &pos);
100-
if (!valid_format(z)) {
99+
idx = 0;
100+
while (idx < ht->nNumUsed) {
101+
z = &ht->arData[idx].val;
102+
if (Z_TYPE_P(z) != IS_UNDEF) {
103+
break;
104+
}
105+
idx++;
106+
}
107+
if (idx >= ht->nNumUsed || !valid_format(z)) {
101108
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
102109
"datefmt_format_object: bad format; the date format (first "
103110
"element of the array) is not valid", 0);
104111
RETURN_FALSE;
105112
}
106113
dateStyle = (DateFormat::EStyle)Z_LVAL_P(z);
107114

108-
zend_hash_move_forward_ex(ht, &pos);
109-
z = zend_hash_get_current_data_ex(ht, &pos);
110-
if (!valid_format(z)) {
115+
idx++;
116+
while (idx < ht->nNumUsed) {
117+
z = &ht->arData[idx].val;
118+
if (Z_TYPE_P(z) != IS_UNDEF) {
119+
break;
120+
}
121+
idx++;
122+
}
123+
if (idx >= ht->nNumUsed || !valid_format(z)) {
111124
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
112125
"datefmt_format_object: bad format; the time format ("
113126
"second element of the array) is not valid", 0);

ext/snmp/snmp.c

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -964,41 +964,20 @@ static void php_snmp_internal(INTERNAL_FUNCTION_PARAMETERS, int st,
964964
static int php_snmp_parse_oid(zval *object, int st, struct objid_query *objid_query, zval *oid, zval *type, zval *value)
965965
{
966966
char *pptr;
967-
HashPosition pos_oid, pos_type, pos_value;
967+
uint32_t idx_type = 0, idx_value = 0;
968968
zval *tmp_oid, *tmp_type, *tmp_value;
969969

970970
if (Z_TYPE_P(oid) != IS_ARRAY) {
971-
/*
972-
if (Z_ISREF_PP(oid)) {
973-
SEPARATE_ZVAL(oid);
974-
}
975-
*/
976971
convert_to_string_ex(oid);
977-
} else if (Z_TYPE_P(oid) == IS_ARRAY) {
978-
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(oid), &pos_oid);
979972
}
980973

981974
if (st & SNMP_CMD_SET) {
982975
if (Z_TYPE_P(type) != IS_ARRAY) {
983-
/*
984-
if (Z_ISREF_PP(type)) {
985-
SEPARATE_ZVAL(type);
986-
}
987-
*/
988976
convert_to_string_ex(type);
989-
} else if (Z_TYPE_P(type) == IS_ARRAY) {
990-
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(type), &pos_type);
991977
}
992978

993979
if (Z_TYPE_P(value) != IS_ARRAY) {
994-
/*
995-
if (Z_ISREF_PP(value)) {
996-
SEPARATE_ZVAL(value);
997-
}
998-
*/
999980
convert_to_string_ex(value);
1000-
} else if (Z_TYPE_P(value) == IS_ARRAY) {
1001-
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(value), &pos_value);
1002981
}
1003982
}
1004983

@@ -1041,18 +1020,22 @@ static int php_snmp_parse_oid(zval *object, int st, struct objid_query *objid_qu
10411020
return FALSE;
10421021
}
10431022
objid_query->array_output = ( (st & SNMP_CMD_SET) ? FALSE : TRUE );
1044-
for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(oid), &pos_oid);
1045-
(tmp_oid = zend_hash_get_current_data_ex(Z_ARRVAL_P(oid), &pos_oid)) != NULL;
1046-
zend_hash_move_forward_ex(Z_ARRVAL_P(oid), &pos_oid) ) {
1047-
1023+
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(oid), tmp_oid) {
10481024
convert_to_string_ex(tmp_oid);
10491025
objid_query->vars[objid_query->count].oid = Z_STRVAL_P(tmp_oid);
10501026
if (st & SNMP_CMD_SET) {
10511027
if (Z_TYPE_P(type) == IS_STRING) {
10521028
pptr = Z_STRVAL_P(type);
10531029
objid_query->vars[objid_query->count].type = *pptr;
10541030
} else if (Z_TYPE_P(type) == IS_ARRAY) {
1055-
if ((tmp_type = zend_hash_get_current_data_ex(Z_ARRVAL_P(type), &pos_type)) != NULL) {
1031+
while (idx_type < Z_ARRVAL_P(type)->nNumUsed) {
1032+
tmp_type = &Z_ARRVAL_P(type)->arData[idx_type].val;
1033+
if (Z_TYPE_P(tmp_type) != IS_UNDEF) {
1034+
break;
1035+
}
1036+
idx_type++;
1037+
}
1038+
if (idx_type < Z_ARRVAL_P(type)->nNumUsed) {
10561039
convert_to_string_ex(tmp_type);
10571040
if (Z_STRLEN_P(tmp_type) != 1) {
10581041
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
10611044
}
10621045
pptr = Z_STRVAL_P(tmp_type);
10631046
objid_query->vars[objid_query->count].type = *pptr;
1064-
zend_hash_move_forward_ex(Z_ARRVAL_P(type), &pos_type);
1047+
idx_type++;
10651048
} else {
10661049
php_error_docref(NULL, E_WARNING, "'%s': no type set", Z_STRVAL_P(tmp_oid));
10671050
efree(objid_query->vars);
@@ -1072,10 +1055,17 @@ static int php_snmp_parse_oid(zval *object, int st, struct objid_query *objid_qu
10721055
if (Z_TYPE_P(value) == IS_STRING) {
10731056
objid_query->vars[objid_query->count].value = Z_STRVAL_P(value);
10741057
} else if (Z_TYPE_P(value) == IS_ARRAY) {
1075-
if ((tmp_value = zend_hash_get_current_data_ex(Z_ARRVAL_P(value), &pos_value)) != NULL) {
1058+
while (idx_value < Z_ARRVAL_P(value)->nNumUsed) {
1059+
tmp_value = &Z_ARRVAL_P(value)->arData[idx_value].val;
1060+
if (Z_TYPE_P(tmp_value) != IS_UNDEF) {
1061+
break;
1062+
}
1063+
idx_value++;
1064+
}
1065+
if (idx_value < Z_ARRVAL_P(value)->nNumUsed) {
10761066
convert_to_string_ex(tmp_value);
10771067
objid_query->vars[objid_query->count].value = Z_STRVAL_P(tmp_value);
1078-
zend_hash_move_forward_ex(Z_ARRVAL_P(value), &pos_value);
1068+
idx_value++;
10791069
} else {
10801070
php_error_docref(NULL, E_WARNING, "'%s': no value set", Z_STRVAL_P(tmp_oid));
10811071
efree(objid_query->vars);
@@ -1084,7 +1074,7 @@ static int php_snmp_parse_oid(zval *object, int st, struct objid_query *objid_qu
10841074
}
10851075
}
10861076
objid_query->count++;
1087-
}
1077+
} ZEND_HASH_FOREACH_END();
10881078
}
10891079

10901080
/* now parse all OIDs */

0 commit comments

Comments
 (0)