Skip to content

Commit e414c39

Browse files
committed
fix appending an array to another
1 parent 5fa7cff commit e414c39

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

bdict.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,10 @@ zval * bdict::search(const std::string &needle, const long &mode, const std::str
329329

330330
if (class_name == "bdict") {
331331
zval *next_result = (zend_container::bdict_fetch_object(Z_OBJ_P(value)))->bdict_data->search(needle, mode, current_path);
332-
zend_hash_merge(Z_ARRVAL_P(zv), Z_ARRVAL_P(next_result), (copy_ctor_func_t) zval_add_ref, false);
332+
zend_hash_append_strings(Z_ARRVAL_P(zv), Z_ARRVAL_P(next_result));
333333
} else if (class_name == "blist") {
334334
zval *next_result = (zend_container::blist_fetch_object(Z_OBJ_P(value)))->blist_data->search(needle, mode, current_path);
335-
zend_hash_merge(Z_ARRVAL_P(zv), Z_ARRVAL_P(next_result), (copy_ctor_func_t) zval_add_ref, false);
335+
zend_hash_append_strings(Z_ARRVAL_P(zv), Z_ARRVAL_P(next_result));
336336
} else if (modev && class_name == "bstr") {
337337
if ((zend_container::bstr_fetch_object(Z_OBJ_P(value)))->bstr_data->_value.find(needle) != std::string::npos)
338338
add_next_index_string(zv, current_path.c_str());

bitem.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ bool bitem::is_ll(const std::string &s) {
6262
return (*p == 0);
6363
}
6464

65+
void bitem::zend_hash_append_strings(HashTable *target, HashTable *source) {
66+
for(zend_hash_internal_pointer_reset(source);
67+
zend_hash_has_more_elements(source) == SUCCESS;
68+
zend_hash_move_forward(source)) {
69+
zend_string *_str_index;
70+
zend_ulong num_index;
71+
zend_hash_get_current_key(source, &_str_index, &num_index);
72+
zval *value = zend_hash_get_current_data(source);
73+
zend_hash_next_index_insert(target, value);
74+
}
75+
}
76+
6577
std::string bitem::get_type() const {
6678
return "bitem";
6779
}

bitem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class bitem {
1818
static std::string escape_key(const std::string &key);
1919
static bool is_ull(const std::string &s);
2020
static bool is_ll(const std::string &s);
21+
static void zend_hash_append_strings(HashTable *target, HashTable *source);
2122

2223
public:
2324
bitem() {}

blist.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,10 @@ zval * blist::search(const std::string &needle, const long &mode, const std::str
344344

345345
if (class_name == "bdict") {
346346
zval *next_result = (zend_container::bdict_fetch_object(Z_OBJ_P(value)))->bdict_data->search(needle, mode, current_path);
347-
zend_hash_merge(Z_ARRVAL_P(zv), Z_ARRVAL_P(next_result), (copy_ctor_func_t) zval_add_ref, false);
347+
zend_hash_append_strings(Z_ARRVAL_P(zv), Z_ARRVAL_P(next_result));
348348
} else if (class_name == "blist") {
349349
zval *next_result = (zend_container::blist_fetch_object(Z_OBJ_P(value)))->blist_data->search(needle, mode, current_path);
350-
zend_hash_merge(Z_ARRVAL_P(zv), Z_ARRVAL_P(next_result), (copy_ctor_func_t) zval_add_ref, false);
350+
zend_hash_append_strings(Z_ARRVAL_P(zv), Z_ARRVAL_P(next_result));
351351
} else if (modev && class_name == "bstr") {
352352
if ((zend_container::bstr_fetch_object(Z_OBJ_P(value)))->bstr_data->_value.find(needle) != std::string::npos)
353353
add_next_index_string(zv, current_path.c_str());

0 commit comments

Comments
 (0)