Skip to content

Commit faf5850

Browse files
committed
Fixing tests(not finish yet)
1 parent 693a223 commit faf5850

File tree

7 files changed

+55
-78
lines changed

7 files changed

+55
-78
lines changed

msgpack.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ static ZEND_MINIT_FUNCTION(msgpack) /* {{{ */ {
8181
REGISTER_INI_ENTRIES();
8282

8383
#if HAVE_PHP_SESSION
84-
php_session_register_serializer("msgpack",
85-
PS_SERIALIZER_ENCODE_NAME(msgpack),
86-
PS_SERIALIZER_DECODE_NAME(msgpack));
84+
php_session_register_serializer("msgpack", PS_SERIALIZER_ENCODE_NAME(msgpack), PS_SERIALIZER_DECODE_NAME(msgpack));
8785
#endif
8886

8987
msgpack_init_class();

msgpack_convert.c

Lines changed: 45 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ static inline int msgpack_convert_long_to_properties(HashTable *ht, zval *object
5151
return FAILURE;
5252
}
5353
default:
54-
zend_hash_move_forward_ex(props, prop_pos);
55-
zend_update_property(Z_OBJCE_P(object), object, prop_name, prop_len, val);
54+
zend_hash_move_forward_ex(props, prop_pos);
55+
zend_update_property(Z_OBJCE_P(object), object, prop_name, prop_len, val);
5656
return SUCCESS;
5757
}
5858
}
@@ -69,22 +69,22 @@ static inline int msgpack_convert_long_to_properties(HashTable *ht, zval *object
6969
}
7070
/* }}} */
7171

72-
static inline int msgpack_convert_string_to_properties(zval *object, char *key, uint key_len, zval *val, HashTable *var)/* {{{ */ {
72+
static inline int msgpack_convert_string_to_properties(zval *object, zend_string *key, zval *val, HashTable *var)/* {{{ */ {
7373
zend_class_entry *ce = Z_OBJCE_P(object);
7474
HashTable *propers = Z_OBJPROP_P(object);
7575
zend_string *prot_name, *priv_name;
7676
zval pub_name;
7777
int return_code;
7878

79-
ZVAL_STRINGL(&pub_name, key, key_len);
80-
priv_name = zend_mangle_property_name(ce->name->val, ce->name->len, key, key_len, 1);
81-
prot_name = zend_mangle_property_name("*", 1, key, key_len, 1);
79+
ZVAL_STR(&pub_name, key);
80+
priv_name = zend_mangle_property_name(ce->name->val, ce->name->len, key->val, key->len, 1);
81+
prot_name = zend_mangle_property_name("*", 1, key->val, key->len, 1);
8282

8383
if (zend_hash_find(propers, priv_name) != NULL) {
84-
zend_update_property(ce, object, key, key_len, val);
84+
zend_update_property_ex(ce, object, key, val);
8585
return_code = SUCCESS;
8686
} else if (zend_hash_find(propers, prot_name) != NULL) {
87-
zend_update_property(ce, object, key, key_len, val);
87+
zend_update_property_ex(ce, object, key, val);
8888
return_code = SUCCESS;
8989
} else {
9090
zend_std_write_property(object, &pub_name, val, NULL);
@@ -94,7 +94,6 @@ static inline int msgpack_convert_string_to_properties(zval *object, char *key,
9494

9595
zend_string_release(priv_name);
9696
zend_string_release(prot_name);
97-
zval_ptr_dtor(&pub_name);
9897

9998
return return_code;
10099
}
@@ -104,8 +103,7 @@ int msgpack_convert_array(zval *return_value, zval *tpl, zval *value) /* {{{ */
104103
zend_string *key;
105104
int key_type;
106105
ulong key_index;
107-
zval *data, *arydata;
108-
HashPosition pos, valpos;
106+
zval *data;
109107
HashTable *ht, *htval;
110108

111109
if (Z_TYPE_P(tpl) != IS_ARRAY) {
@@ -127,6 +125,8 @@ int msgpack_convert_array(zval *return_value, zval *tpl, zval *value) /* {{{ */
127125

128126
/* string */
129127
if (ht->nNumOfElements != ht->nNextFreeElement) {
128+
HashPosition valpos;
129+
130130
htval = HASH_OF(value);
131131

132132
if (!htval) {
@@ -137,9 +137,8 @@ int msgpack_convert_array(zval *return_value, zval *tpl, zval *value) /* {{{ */
137137
zend_hash_internal_pointer_reset_ex(htval, &valpos);
138138
ZEND_HASH_FOREACH_KEY_VAL(ht, key_index, key, data) {
139139
if (key) {
140-
int (*convert_function)(zval *, zval *, zval *) = NULL;
141140
zval *dataval;
142-
141+
int (*convert_function)(zval *, zval *, zval *) = NULL;
143142
switch (Z_TYPE_P(data)) {
144143
case IS_ARRAY:
145144
convert_function = msgpack_convert_array;
@@ -157,13 +156,16 @@ int msgpack_convert_array(zval *return_value, zval *tpl, zval *value) /* {{{ */
157156
return FAILURE;
158157
}
159158

159+
if (Z_TYPE_P(dataval) == IS_INDIRECT) {
160+
dataval = Z_INDIRECT_P(dataval);
161+
}
162+
160163
if (convert_function) {
161164
zval rv;
162165
if (convert_function(&rv, data, dataval) != SUCCESS) {
163166
return FAILURE;
164167
}
165-
Z_TRY_ADDREF_P(dataval);
166-
zend_symtable_update(Z_ARRVAL_P(return_value), key, dataval);
168+
zend_symtable_update(Z_ARRVAL_P(return_value), key, &rv);
167169
} else {
168170
Z_TRY_ADDREF_P(dataval);
169171
zend_symtable_update(Z_ARRVAL_P(return_value), key, dataval);
@@ -175,6 +177,8 @@ int msgpack_convert_array(zval *return_value, zval *tpl, zval *value) /* {{{ */
175177
return SUCCESS;
176178
} else {
177179
/* index */
180+
zval *arydata;
181+
HashPosition pos;
178182
int (*convert_function)(zval *, zval *, zval *) = NULL;
179183

180184
if (Z_TYPE_P(value) != IS_ARRAY) {
@@ -184,7 +188,6 @@ int msgpack_convert_array(zval *return_value, zval *tpl, zval *value) /* {{{ */
184188

185189
zend_hash_internal_pointer_reset_ex(ht, &pos);
186190
key_type = zend_hash_get_current_key_ex(ht, &key, &key_index, &pos);
187-
188191
if (key_type == HASH_KEY_NON_EXISTENT) {
189192
MSGPACK_WARNING(
190193
"[msgpack] (%s) first element in template array is empty",
@@ -215,46 +218,28 @@ int msgpack_convert_array(zval *return_value, zval *tpl, zval *value) /* {{{ */
215218
return FAILURE;
216219
}
217220

218-
zend_hash_internal_pointer_reset_ex(htval, &valpos);
219-
for (;; zend_hash_move_forward_ex(htval, &valpos)) {
220-
key_type = zend_hash_get_current_key_ex(htval, &key, &key_index, &valpos);
221-
222-
if (key_type == HASH_KEY_NON_EXISTENT) {
223-
break;
224-
}
225-
226-
if ((arydata = zend_hash_get_current_data_ex(htval, &valpos)) == NULL) {
227-
MSGPACK_WARNING( "[msgpack] (%s) can't get next data in indexed array", __FUNCTION__);
228-
continue;
229-
}
230-
231-
switch (key_type) {
232-
case HASH_KEY_IS_LONG: {
233-
zval rv;
234-
if (convert_function) {
235-
if (convert_function(&rv, data, arydata) != SUCCESS) {
236-
MSGPACK_WARNING(
237-
"[msgpack] (%s) "
238-
"convert failure in HASH_KEY_IS_LONG "
239-
"in indexed array",
240-
__FUNCTION__);
241-
return FAILURE;
242-
}
243-
add_next_index_zval(return_value, &rv);
244-
} else {
245-
Z_TRY_ADDREF_P(arydata);
246-
add_next_index_zval(return_value, arydata);
221+
ZEND_HASH_FOREACH_KEY_VAL_IND(htval, key_index, key, arydata) {
222+
if (key) {
223+
MSGPACK_WARNING("[msgpack] (%s) key is string", __FUNCTION__);
224+
return FAILURE;
225+
} else {
226+
zval rv;
227+
if (convert_function) {
228+
if (convert_function(&rv, data, arydata) != SUCCESS) {
229+
MSGPACK_WARNING(
230+
"[msgpack] (%s) "
231+
"convert failure in HASH_KEY_IS_LONG "
232+
"in indexed array",
233+
__FUNCTION__);
234+
return FAILURE;
247235
}
248-
break;
236+
add_next_index_zval(return_value, &rv);
237+
} else {
238+
Z_TRY_ADDREF_P(arydata);
239+
add_next_index_zval(return_value, arydata);
249240
}
250-
case HASH_KEY_IS_STRING:
251-
MSGPACK_WARNING("[msgpack] (%s) key is string", __FUNCTION__);
252-
return FAILURE;
253-
default:
254-
MSGPACK_WARNING("[msgpack] (%s) key is not string nor array", __FUNCTION__);
255-
return FAILURE;
256-
}
257-
}
241+
}
242+
} ZEND_HASH_FOREACH_END();
258243
return SUCCESS;
259244
}
260245

@@ -283,6 +268,10 @@ int msgpack_convert_object(zval *return_value, zval *tpl, zval *value) /* {{{ */
283268
return FAILURE;
284269
}
285270

271+
if (Z_TYPE_P(value) == IS_INDIRECT) {
272+
value = Z_INDIRECT_P(value);
273+
}
274+
286275
if (Z_TYPE_P(value) == IS_OBJECT) {
287276
zend_class_entry *vce = Z_OBJCE_P(value);
288277
if (zend_string_equals(ce->name, vce->name)) {
@@ -327,8 +316,8 @@ int msgpack_convert_object(zval *return_value, zval *tpl, zval *value) /* {{{ */
327316
switch (Z_TYPE_P(value)) {
328317
case IS_ARRAY:
329318
{
330-
HashTable *ht, *ret, *var = NULL;
331319
int num;
320+
HashTable *ht, *ret, *var = NULL;
332321
zend_string *str_key;
333322
zval *data;
334323
ulong num_key;
@@ -351,7 +340,7 @@ int msgpack_convert_object(zval *return_value, zval *tpl, zval *value) /* {{{ */
351340

352341
ZEND_HASH_FOREACH_STR_KEY_VAL(ht, str_key, data) {
353342
if (str_key) {
354-
if (msgpack_convert_string_to_properties(return_value, str_key->val, str_key->len, data, var) != SUCCESS) {
343+
if (msgpack_convert_string_to_properties(return_value, str_key, data, var) != SUCCESS) {
355344
MSGPACK_WARNING("[msgpack] (%s) "
356345
"illegal offset type, skip this decoding",
357346
__FUNCTION__);

msgpack_unpack.c

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -447,16 +447,12 @@ int msgpack_unserialize_map_item(msgpack_unserialize_data *unpack, zval **contai
447447
}
448448
} else if (Z_TYPE_P(val) == IS_STRING) {
449449
ce = msgpack_unserialize_class(container, Z_STR_P(val), 1);
450-
451450
if (ce == NULL) {
452451
MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val);
453-
454452
return 0;
455453
}
456454
}
457-
458455
MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val);
459-
460456
return 0;
461457
} else {
462458
switch (unpack->type) {
@@ -466,10 +462,8 @@ int msgpack_unserialize_map_item(msgpack_unserialize_data *unpack, zval **contai
466462
ce = msgpack_unserialize_class(container, Z_STR_P(key), 0);
467463
if (ce == NULL) {
468464
MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val);
469-
470465
return 0;
471466
}
472-
473467
/* implementing Serializable */
474468
if (ce->unserialize == NULL) {
475469
MSGPACK_WARNING(
@@ -506,18 +500,14 @@ int msgpack_unserialize_map_item(msgpack_unserialize_data *unpack, zval **contai
506500
zval_ptr_dtor(*container);
507501
}
508502

509-
*container = rval;
503+
ZVAL_COPY_VALUE(*container, rval);
510504
if (type == MSGPACK_SERIALIZE_TYPE_OBJECT_REFERENCE) {
511505
ZVAL_MAKE_REF(*container);
512506
}
513507

514-
if (Z_REFCOUNTED_P(*container)) {
515-
Z_ADDREF_P(*container);
516-
}
517-
508+
Z_TRY_ADDREF_P(*container);
518509

519510
MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val);
520-
521511
return 0;
522512
}
523513
}
@@ -540,11 +530,11 @@ int msgpack_unserialize_map_item(msgpack_unserialize_data *unpack, zval **contai
540530

541531
zend_string_release(key_zstring);
542532
zval_ptr_dtor(key);
543-
zval_ptr_dtor(val);
533+
zval_ptr_dtor(val);
544534
} else {
545535
switch (Z_TYPE_P(key)) {
546536
case IS_LONG:
547-
if ((val = zend_hash_index_update(HASH_OF(container_val), Z_LVAL_P(key), val)) == NULL) {
537+
if (zend_hash_index_update(HASH_OF(container_val), Z_LVAL_P(key), val) == NULL) {
548538
zval_ptr_dtor(val);
549539
MSGPACK_WARNING(
550540
"[msgpack] (%s) illegal offset type, skip this decoding",
@@ -553,7 +543,7 @@ int msgpack_unserialize_map_item(msgpack_unserialize_data *unpack, zval **contai
553543
zval_ptr_dtor(key);
554544
break;
555545
case IS_STRING:
556-
if ((val = zend_hash_update(HASH_OF(container_val), Z_STR(*key), val)) == NULL) {
546+
if (zend_hash_update(HASH_OF(container_val), Z_STR(*key), val) == NULL) {
557547
zval_ptr_dtor(val);
558548
MSGPACK_WARNING(
559549
"[msgpack] (%s) illegal offset type, skip this decoding",

tests/060.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ array(1) {
240240
[0]=>
241241
&array(1) {
242242
[0]=>
243-
&array(1) {
243+
array(1) {
244244
[0]=>
245245
*RECURSION*
246246
}

tests/061.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ array(1) {
245245
[0]=>
246246
&array(1) {
247247
[0]=>
248-
&array(1) {
248+
array(1) {
249249
[0]=>
250250
*RECURSION*
251251
}

tests/064.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ array(1) {
242242
[0]=>
243243
&array(1) {
244244
[0]=>
245-
&array(1) {
245+
array(1) {
246246
[0]=>
247247
*RECURSION*
248248
}

tests/065.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ array(1) {
247247
[0]=>
248248
&array(1) {
249249
[0]=>
250-
&array(1) {
250+
array(1) {
251251
[0]=>
252252
*RECURSION*
253253
}

0 commit comments

Comments
 (0)