Skip to content
Browse files

Allow get_current_key() not to return the key itself, instead of a du…

…plicate
  • Loading branch information...
1 parent 0fcce4a commit 36eaad252fc5fe292cd4f071f76e7879ce21130c @zsuraski zsuraski committed Dec 22, 2000
Showing with 13 additions and 13 deletions.
  1. +1 −2 Zend/zend.c
  2. +3 −3 Zend/zend_builtin_functions.c
  3. +1 −1 Zend/zend_execute.c
  4. +5 −4 Zend/zend_hash.c
  5. +3 −3 Zend/zend_hash.h
View
3 Zend/zend.c
@@ -94,10 +94,9 @@ static void print_hash(HashTable *ht, int indent)
ZEND_PUTS(" ");
}
ZEND_PUTS("[");
- switch (zend_hash_get_current_key_ex(ht, &string_key, &str_len, &num_key, &iterator)) {
+ switch (zend_hash_get_current_key_ex(ht, &string_key, &str_len, &num_key, 0, &iterator)) {
case HASH_KEY_IS_STRING:
ZEND_PUTS(string_key);
- efree(string_key);
break;
case HASH_KEY_IS_LONG:
zend_printf("%ld",num_key);
View
6 Zend/zend_builtin_functions.c
@@ -332,7 +332,7 @@ ZEND_FUNCTION(each)
entry->refcount++;
/* add the key elements */
- switch (zend_hash_get_current_key(target_hash, &string_key, &num_key)) {
+ switch (zend_hash_get_current_key(target_hash, &string_key, &num_key, 1)) {
case HASH_KEY_IS_STRING:
add_get_index_string(return_value,0,string_key,(void **) &inserted_pointer,0);
break;
@@ -589,7 +589,7 @@ ZEND_FUNCTION(get_class_methods)
efree(lcname);
array_init(return_value);
zend_hash_internal_pointer_reset(&ce->function_table);
- while ((key_type = zend_hash_get_current_key(&ce->function_table, &string_key, &num_key)) != HASH_KEY_NON_EXISTANT) {
+ while ((key_type = zend_hash_get_current_key(&ce->function_table, &string_key, &num_key, 1)) != HASH_KEY_NON_EXISTANT) {
if (key_type == HASH_KEY_IS_STRING) {
MAKE_STD_ZVAL(method_name);
ZVAL_STRING(method_name, string_key, 0);
@@ -731,7 +731,7 @@ ZEND_FUNCTION(get_included_files)
array_init(return_value);
zend_hash_internal_pointer_reset(&EG(included_files));
- while(zend_hash_get_current_key(&EG(included_files), &entry,NULL) == HASH_KEY_IS_STRING) {
+ while(zend_hash_get_current_key(&EG(included_files), &entry, NULL, 1) == HASH_KEY_IS_STRING) {
add_next_index_string(return_value,entry,0);
zend_hash_move_forward(&EG(included_files));
}
View
2 Zend/zend_execute.c
@@ -2221,7 +2221,7 @@ binary_assign_op_addr: {
ALLOC_ZVAL(key);
INIT_PZVAL(key);
- switch (zend_hash_get_current_key(fe_ht, &str_key, &int_key)) {
+ switch (zend_hash_get_current_key(fe_ht, &str_key, &int_key, 1)) {
case HASH_KEY_IS_STRING:
key->value.str.val = str_key;
key->value.str.len = strlen(str_key);
View
9 Zend/zend_hash.c
@@ -1019,7 +1019,7 @@ ZEND_API int zend_hash_move_backwards_ex(HashTable *ht, HashPosition *pos)
/* This function should be made binary safe */
-ZEND_API int zend_hash_get_current_key_ex(HashTable *ht, char **str_index, ulong *str_length, ulong *num_index, HashPosition *pos)
+ZEND_API int zend_hash_get_current_key_ex(HashTable *ht, char **str_index, ulong *str_length, ulong *num_index, zend_bool duplicate, HashPosition *pos)
{
Bucket *p;
@@ -1029,9 +1029,10 @@ ZEND_API int zend_hash_get_current_key_ex(HashTable *ht, char **str_index, ulong
if (p) {
if (p->nKeyLength) {
- *str_index = (char *) estrndup(p->arKey, p->nKeyLength);
- if (ht->persistent) {
- persist_alloc(*str_index);
+ if (duplicate) {
+ *str_index = estrndup(p->arKey, p->nKeyLength);
+ } else {
+ *str_index = p->arKey;
}
if (str_length) {
*str_length = p->nKeyLength;
View
6 Zend/zend_hash.h
@@ -146,7 +146,7 @@ ZEND_API ulong zend_hash_next_free_element(HashTable *ht);
/* traversing */
ZEND_API int zend_hash_move_forward_ex(HashTable *ht, HashPosition *pos);
ZEND_API int zend_hash_move_backwards_ex(HashTable *ht, HashPosition *pos);
-ZEND_API int zend_hash_get_current_key_ex(HashTable *ht, char **str_index, ulong *str_length, ulong *num_index, HashPosition *pos);
+ZEND_API int zend_hash_get_current_key_ex(HashTable *ht, char **str_index, ulong *str_length, ulong *num_index, zend_bool duplicate, HashPosition *pos);
ZEND_API int zend_hash_get_current_key_type_ex(HashTable *ht, HashPosition *pos);
ZEND_API int zend_hash_get_current_data_ex(HashTable *ht, void **pData, HashPosition *pos);
ZEND_API void zend_hash_internal_pointer_reset_ex(HashTable *ht, HashPosition *pos);
@@ -156,8 +156,8 @@ ZEND_API void zend_hash_internal_pointer_end_ex(HashTable *ht, HashPosition *pos
zend_hash_move_forward_ex(ht, NULL)
#define zend_hash_move_backwards(ht) \
zend_hash_move_backwards_ex(ht, NULL)
-#define zend_hash_get_current_key(ht, str_index, num_index) \
- zend_hash_get_current_key_ex(ht, str_index, NULL, num_index, NULL)
+#define zend_hash_get_current_key(ht, str_index, num_index, duplicate) \
+ zend_hash_get_current_key_ex(ht, str_index, NULL, num_index, duplicate, NULL)
#define zend_hash_get_current_key_type(ht) \
zend_hash_get_current_key_type_ex(ht, NULL)
#define zend_hash_get_current_data(ht, pData) \

0 comments on commit 36eaad2

Please sign in to comment.
Something went wrong with that request. Please try again.