Skip to content

Commit 899d5d0

Browse files
committed
missing changes for plain arrays re #142
1 parent 4432757 commit 899d5d0

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

msgpack_pack.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -319,26 +319,35 @@ static inline void msgpack_serialize_array(smart_str *buf, zval *val, HashTable
319319
} ZEND_HASH_FOREACH_END();
320320
} else {
321321
uint32_t i;
322-
zval *data, *data_noref;
323322

324323
for (i = 0; i < n; i++) {
325-
if ((data = zend_hash_index_find(ht, i)) == NULL || &data == &val || (Z_TYPE_P(data) == IS_ARRAY && Z_IS_RECURSIVE_P(data))) {
326-
msgpack_pack_nil(buf);
327-
} else if (Z_TYPE_P(data) == IS_REFERENCE && Z_TYPE_P(Z_REFVAL_P(data)) == IS_ARRAY && Z_IS_RECURSIVE_P(Z_REFVAL_P(data))) {
324+
zval *data_noref, *data = zend_hash_index_find(ht, i);
325+
326+
if (!data) {
327+
MSGPACK_WARNING("[msgpack (%s) array index %u is not set", __FUNCTION__, i);
328328
msgpack_pack_nil(buf);
329+
continue;
330+
}
331+
332+
if (Z_TYPE_P(data) == IS_REFERENCE) {
333+
data_noref = Z_REFVAL_P(data);
329334
} else {
330-
if (Z_TYPE_P(data) == IS_REFERENCE) {
331-
data_noref = Z_REFVAL_P(data);
335+
data_noref = data;
336+
}
337+
338+
if (Z_TYPE_P(data_noref) == IS_ARRAY && Z_IS_RECURSIVE_P(data_noref)) {
339+
if (MSGPACK_G(php_only)) {
340+
/* pack ref */
341+
msgpack_serialize_zval(buf, data, var_hash);
332342
} else {
333-
data_noref = data;
343+
/* you lose */
344+
msgpack_pack_nil(buf);
334345
}
335-
346+
} else {
336347
if (Z_TYPE_P(data_noref) == IS_ARRAY && Z_CAN_PROTECT_RECURSION_P(data_noref)) {
337348
Z_PROTECT_RECURSION_P(data_noref);
338349
}
339-
340350
msgpack_serialize_zval(buf, data, var_hash);
341-
342351
if (Z_TYPE_P(data_noref) == IS_ARRAY && Z_CAN_PROTECT_RECURSION_P(data_noref)) {
343352
Z_UNPROTECT_RECURSION_P(data_noref);
344353
}

0 commit comments

Comments
 (0)