Permalink
Browse files

php: supported 5.4.x version

  • Loading branch information...
1 parent 3399148 commit 9dd0a6eb86536c367b1903c83fb3f693c6d7f64e @advect advect committed Apr 20, 2012
Showing with 210 additions and 94 deletions.
  1. +4 −0 php/ChangeLog
  2. +19 −6 php/msgpack.c
  3. +18 −6 php/msgpack_class.c
  4. +104 −64 php/msgpack_pack.c
  5. +7 −1 php/msgpack_pack.h
  6. +50 −13 php/msgpack_unpack.c
  7. +5 −3 php/msgpack_unpack.h
  8. +2 −1 php/php_msgpack.h
  9. +1 −0 php/tests/029.phpt
View
@@ -1,5 +1,9 @@
msgpack extension changelog
+Version 0.5.2
+-------------
+ * Support PHP 5.4.x version.
+
Version 0.5.1
-------------
* Fixed include path for version check.
View
@@ -40,6 +40,9 @@ STD_PHP_INI_BOOLEAN(
STD_PHP_INI_BOOLEAN(
"msgpack.php_only", "1", PHP_INI_ALL, OnUpdateBool,
php_only, zend_msgpack_globals, msgpack_globals)
+STD_PHP_INI_BOOLEAN(
+ "msgpack.illegal_key_insert", "0", PHP_INI_ALL, OnUpdateBool,
+ illegal_key_insert, zend_msgpack_globals, msgpack_globals)
PHP_INI_END()
PS_SERIALIZER_FUNCS(msgpack);
@@ -66,6 +69,8 @@ static void msgpack_init_globals(zend_msgpack_globals *msgpack_globals)
}
msgpack_globals->php_only = 1;
+
+ msgpack_globals->illegal_key_insert = 0;
}
static ZEND_MINIT_FUNCTION(msgpack)
@@ -136,11 +141,15 @@ ZEND_GET_MODULE(msgpack)
PS_SERIALIZER_ENCODE_FUNC(msgpack)
{
smart_str buf = {0};
- php_serialize_data_t var_hash;
+ msgpack_serialize_data_t var_hash;
PHP_VAR_SERIALIZE_INIT(var_hash);
+#if PHP_API_VERSION < 20100412
msgpack_serialize_zval(&buf, PS(http_session_vars), &var_hash TSRMLS_CC);
+#else
+ msgpack_serialize_zval(&buf, PS(http_session_vars), var_hash TSRMLS_CC);
+#endif
if (newlen)
{
@@ -167,7 +176,7 @@ PS_SERIALIZER_DECODE_FUNC(msgpack)
zval **value;
size_t off = 0;
msgpack_unpack_t mp;
- php_unserialize_data_t var_hash;
+ msgpack_unserialize_data_t var_hash;
ALLOC_INIT_ZVAL(tmp);
@@ -176,7 +185,7 @@ PS_SERIALIZER_DECODE_FUNC(msgpack)
msgpack_unserialize_var_init(&var_hash);
mp.user.retval = (zval *)tmp;
- mp.user.var_hash = (php_unserialize_data_t *)&var_hash;
+ mp.user.var_hash = (msgpack_unserialize_data_t *)&var_hash;
ret = template_execute(&mp, (char *)val, (size_t)vallen, &off);
@@ -219,11 +228,15 @@ PS_SERIALIZER_DECODE_FUNC(msgpack)
PHP_MSGPACK_API void php_msgpack_serialize(smart_str *buf, zval *val TSRMLS_DC)
{
- php_serialize_data_t var_hash;
+ msgpack_serialize_data_t var_hash;
PHP_VAR_SERIALIZE_INIT(var_hash);
+#if PHP_API_VERSION < 20100412
msgpack_serialize_zval(buf, val, &var_hash TSRMLS_CC);
+#else
+ msgpack_serialize_zval(buf, val, var_hash TSRMLS_CC);
+#endif
PHP_VAR_SERIALIZE_DESTROY(var_hash);
}
@@ -234,7 +247,7 @@ PHP_MSGPACK_API void php_msgpack_unserialize(
int ret;
size_t off = 0;
msgpack_unpack_t mp;
- php_unserialize_data_t var_hash;
+ msgpack_unserialize_data_t var_hash;
if (str_len <= 0)
{
@@ -246,7 +259,7 @@ PHP_MSGPACK_API void php_msgpack_unserialize(
msgpack_unserialize_var_init(&var_hash);
mp.user.retval = (zval *)return_value;
- mp.user.var_hash = (php_unserialize_data_t *)&var_hash;
+ mp.user.var_hash = (msgpack_unserialize_data_t *)&var_hash;
ret = template_execute(&mp, str, (size_t)str_len, &off);
View
@@ -19,7 +19,7 @@ typedef struct {
zval *retval;
long offset;
msgpack_unpack_t mp;
- php_unserialize_data_t var_hash;
+ msgpack_unserialize_data_t var_hash;
long php_only;
zend_bool finished;
int error;
@@ -188,8 +188,10 @@ static void php_msgpack_base_free(php_msgpack_base_t *base TSRMLS_DC)
static zend_object_value php_msgpack_base_new(zend_class_entry *ce TSRMLS_DC)
{
zend_object_value retval;
- zval *tmp;
php_msgpack_base_t *base;
+#if PHP_API_VERSION < 20100412
+ zval *tmp;
+#endif
base = emalloc(sizeof(php_msgpack_base_t));
@@ -201,9 +203,13 @@ static zend_object_value php_msgpack_base_new(zend_class_entry *ce TSRMLS_DC)
base->object.ce = ce;
#endif
+#if PHP_API_VERSION < 20100412
zend_hash_copy(
base->object.properties, &ce->default_properties,
(copy_ctor_func_t)zval_add_ref, (void *)&tmp, sizeof(zval *));
+#else
+ object_properties_init(&base->object, ce);
+#endif
retval.handle = zend_objects_store_put(
base, (zend_objects_store_dtor_t)zend_objects_destroy_object,
@@ -233,8 +239,10 @@ static zend_object_value php_msgpack_unpacker_new(
zend_class_entry *ce TSRMLS_DC)
{
zend_object_value retval;
- zval *tmp;
php_msgpack_unpacker_t *unpacker;
+#if PHP_API_VERSION < 20100412
+ zval *tmp;
+#endif
unpacker = emalloc(sizeof(php_msgpack_unpacker_t));
@@ -246,9 +254,13 @@ static zend_object_value php_msgpack_unpacker_new(
unpacker->object.ce = ce;
#endif
+#if PHP_API_VERSION < 20100412
zend_hash_copy(
unpacker->object.properties, &ce->default_properties,
(copy_ctor_func_t)zval_add_ref, (void *)&tmp, sizeof(zval *));
+#else
+ object_properties_init(&unpacker->object, ce);
+#endif
retval.handle = zend_objects_store_put(
unpacker, (zend_objects_store_dtor_t)zend_objects_destroy_object,
@@ -410,7 +422,7 @@ static ZEND_METHOD(msgpack_unpacker, __construct)
msgpack_unserialize_var_init(&unpacker->var_hash);
(&unpacker->mp)->user.var_hash =
- (php_unserialize_data_t *)&unpacker->var_hash;
+ (msgpack_unserialize_data_t *)&unpacker->var_hash;
}
static ZEND_METHOD(msgpack_unpacker, __destruct)
@@ -533,7 +545,7 @@ static ZEND_METHOD(msgpack_unpacker, execute)
msgpack_unserialize_var_init(&unpacker->var_hash);
(&unpacker->mp)->user.var_hash =
- (php_unserialize_data_t *)&unpacker->var_hash;
+ (msgpack_unserialize_data_t *)&unpacker->var_hash;
}
(&unpacker->mp)->user.retval = (zval *)unpacker->retval;
@@ -649,7 +661,7 @@ static ZEND_METHOD(msgpack_unpacker, reset)
msgpack_unserialize_var_init(&unpacker->var_hash);
(&unpacker->mp)->user.var_hash =
- (php_unserialize_data_t *)&unpacker->var_hash;
+ (msgpack_unserialize_data_t *)&unpacker->var_hash;
}
void msgpack_init_class()
View
@@ -255,27 +255,34 @@ inline static void msgpack_serialize_array(
if (object)
{
- if (MSGPACK_G(php_only))
+ if (n == 0)
{
- if (Z_ISREF_P(val))
+ msgpack_pack_map(buf, n);
+ }
+ else
+ {
+ if (MSGPACK_G(php_only))
{
- msgpack_pack_map(buf, n + 2);
+ if (Z_ISREF_P(val))
+ {
+ msgpack_pack_map(buf, n + 2);
+ msgpack_pack_nil(buf);
+ msgpack_pack_long(buf, MSGPACK_SERIALIZE_TYPE_REFERENCE);
+ }
+ else
+ {
+ msgpack_pack_map(buf, n + 1);
+ }
+
msgpack_pack_nil(buf);
- msgpack_pack_long(buf, MSGPACK_SERIALIZE_TYPE_REFERENCE);
+
+ msgpack_serialize_string(buf, class_name, name_len);
}
else
{
- msgpack_pack_map(buf, n + 1);
+ msgpack_pack_array(buf, n);
+ hash = 0;
}
-
- msgpack_pack_nil(buf);
-
- msgpack_serialize_string(buf, class_name, name_len);
- }
- else
- {
- msgpack_pack_array(buf, n);
- hash = 0;
}
}
else if (n == 0)
@@ -301,67 +308,100 @@ inline static void msgpack_serialize_array(
if (n > 0)
{
- char *key;
- uint key_len;
- int key_type;
- ulong key_index;
- zval **data;
- HashPosition pos;
-
- zend_hash_internal_pointer_reset_ex(ht, &pos);
- for (;; zend_hash_move_forward_ex(ht, &pos))
+ if (object || hash)
{
- key_type = zend_hash_get_current_key_ex(
- ht, &key, &key_len, &key_index, 0, &pos);
-
- if (key_type == HASH_KEY_NON_EXISTANT)
+ char *key;
+ uint key_len;
+ int key_type;
+ ulong key_index;
+ zval **data;
+ HashPosition pos;
+
+ zend_hash_internal_pointer_reset_ex(ht, &pos);
+ for (;; zend_hash_move_forward_ex(ht, &pos))
{
- break;
- }
- if (incomplete_class && strcmp(key, MAGIC_MEMBER) == 0)
- {
- continue;
- }
+ key_type = zend_hash_get_current_key_ex(
+ ht, &key, &key_len, &key_index, 0, &pos);
- if (hash)
- {
- switch (key_type)
+ if (key_type == HASH_KEY_NON_EXISTANT)
{
- case HASH_KEY_IS_LONG:
- msgpack_pack_long(buf, key_index);
- break;
- case HASH_KEY_IS_STRING:
- msgpack_serialize_string(buf, key, key_len - 1);
- break;
- default:
- msgpack_serialize_string(buf, "", sizeof(""));
- MSGPACK_WARNING(
- "[msgpack] (%s) key is not string nor array",
- __FUNCTION__);
- break;
+ break;
+ }
+ if (incomplete_class && strcmp(key, MAGIC_MEMBER) == 0)
+ {
+ continue;
}
- }
- if (zend_hash_get_current_data_ex(
- ht, (void *)&data, &pos) != SUCCESS ||
- !data || data == &val ||
- (Z_TYPE_PP(data) == IS_ARRAY &&
- Z_ARRVAL_PP(data)->nApplyCount > 1))
- {
- msgpack_pack_nil(buf);
+ if (hash)
+ {
+ switch (key_type)
+ {
+ case HASH_KEY_IS_LONG:
+ msgpack_pack_long(buf, key_index);
+ break;
+ case HASH_KEY_IS_STRING:
+ msgpack_serialize_string(buf, key, key_len - 1);
+ break;
+ default:
+ msgpack_serialize_string(buf, "", sizeof(""));
+ MSGPACK_WARNING(
+ "[msgpack] (%s) key is not string nor array",
+ __FUNCTION__);
+ break;
+ }
+ }
+
+ if (zend_hash_get_current_data_ex(
+ ht, (void *)&data, &pos) != SUCCESS ||
+ !data || data == &val ||
+ (Z_TYPE_PP(data) == IS_ARRAY &&
+ Z_ARRVAL_PP(data)->nApplyCount > 1))
+ {
+ msgpack_pack_nil(buf);
+ }
+ else
+ {
+ if (Z_TYPE_PP(data) == IS_ARRAY)
+ {
+ Z_ARRVAL_PP(data)->nApplyCount++;
+ }
+
+ msgpack_serialize_zval(buf, *data, var_hash TSRMLS_CC);
+
+ if (Z_TYPE_PP(data) == IS_ARRAY)
+ {
+ Z_ARRVAL_PP(data)->nApplyCount--;
+ }
+ }
}
- else
+ }
+ else
+ {
+ zval **data;
+ uint i;
+
+ for (i = 0; i < n; i++)
{
- if (Z_TYPE_PP(data) == IS_ARRAY)
+ if (zend_hash_index_find(ht, i, (void *)&data) != SUCCESS ||
+ !data || data == &val ||
+ (Z_TYPE_PP(data) == IS_ARRAY &&
+ Z_ARRVAL_PP(data)->nApplyCount > 1))
{
- Z_ARRVAL_PP(data)->nApplyCount++;
+ msgpack_pack_nil(buf);
}
+ else
+ {
+ if (Z_TYPE_PP(data) == IS_ARRAY)
+ {
+ Z_ARRVAL_PP(data)->nApplyCount++;
+ }
- msgpack_serialize_zval(buf, *data, var_hash TSRMLS_CC);
+ msgpack_serialize_zval(buf, *data, var_hash TSRMLS_CC);
- if (Z_TYPE_PP(data) == IS_ARRAY)
- {
- Z_ARRVAL_PP(data)->nApplyCount--;
+ if (Z_TYPE_PP(data) == IS_ARRAY)
+ {
+ Z_ARRVAL_PP(data)->nApplyCount--;
+ }
}
}
}
@@ -399,7 +439,7 @@ inline static void msgpack_serialize_object(
msgpack_pack_nil(buf);
msgpack_pack_long(buf, MSGPACK_SERIALIZE_TYPE_CUSTOM_OBJECT);
- msgpack_serialize_string(buf, ce->name, ce->name_length);
+ msgpack_serialize_string(buf, (char *)ce->name, ce->name_length);
msgpack_pack_raw(buf, serialized_length);
msgpack_pack_raw_body(buf, serialized_data, serialized_length);
}
Oops, something went wrong.

0 comments on commit 9dd0a6e

Please sign in to comment.