Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP7 Support #48

Closed
wants to merge 75 commits into from
Closed
Show file tree
Hide file tree
Changes from 72 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
d3c7ca6
Mass replace smart_str -> smart_string
Sean-Der Apr 6, 2015
bb36411
Update PS_SERIALIZER_ENCODE_FUNC returns a zend_string instead of pas…
Sean-Der Apr 6, 2015
39a9afd
Update PS_SERIALIZER_DECODE_FUNC to use the new hash iteration API, p…
Sean-Der Apr 6, 2015
2a472e7
Update msgpack_var_add to use new hash API
Sean-Der Apr 6, 2015
805e4a2
zend_uint -> uint32_t
Sean-Der Apr 6, 2015
6f31cba
Update msgpack_serialize_zval. PHP_SET_CLASS_ATTRIBUTES now returns a…
Sean-Der Apr 7, 2015
e75fe8a
Update msgpack_serialize_object for new hashmap and zend_string API
Sean-Der Apr 7, 2015
83f6ec0
Rough version of msgpack_serialize_array, use new hash iteration API
Sean-Der Apr 7, 2015
8793909
Refactor msgpack_serialize_class to use new hash API and one level le…
Sean-Der Apr 10, 2015
fbc4e8e
Refactor msgpack_unserialize_class to drop one level of zval deferenc…
Sean-Der Apr 11, 2015
4f1e6e7
Remove unused macros from msgpack_unpack.c, update msgpack_var_push a…
Sean-Der Apr 11, 2015
8814fdd
Update msgpack_unserialize_map_item to handle zend_string inputs and …
Sean-Der Apr 11, 2015
41800b5
Replace MSGPACK_UNPACKER_OBJECT and MSGPACK_BASE_OBJECT macros with m…
Sean-Der Apr 11, 2015
51f7642
Update php_msgpack_base_t and php_msgpack_unpacker_t to use the new c…
Sean-Der Apr 12, 2015
01d6519
Cleanup last zval deref changes in msgpack_class.c
Sean-Der Apr 12, 2015
8e8e23c
Update msgpack_convert_long_to_properties to new hash table iteration…
Sean-Der Apr 13, 2015
67deff3
Update msgpack_convert_string_to_properties to use new zend_string API
Sean-Der Apr 13, 2015
e5ec207
Port msgpack_convert_array to the new hash iteration API
Sean-Der Apr 13, 2015
272eebd
Update ZEND_FUNCTION declaration of msgpack_unserialize to use new ze…
Sean-Der Apr 13, 2015
c52e1a7
Make sure to free returned smart_string in exposed ZEND_FUNCTION msgp…
Sean-Der Apr 14, 2015
ff23828
Update msgpack_check_ht_is_map to properly call zend_hash_add
Sean-Der Apr 15, 2015
3137c5b
Cleanup indentation, remove redundant casting
Sean-Der Apr 15, 2015
19e32ed
Port msgpack_convert_array to the new hash iteration API
Sean-Der Apr 16, 2015
a765bd8
Off by one when serializing a string during array serialization
Sean-Der Apr 16, 2015
f1388a6
msgpack_unserialize_map_item was incorrectly ported, MSGPACK_WARNING …
Sean-Der Apr 16, 2015
9d6d636
Add Z_TYPE_REF_AWARE_P macro since when packing we can are possibly p…
Sean-Der Apr 16, 2015
aaeee58
Z_LVAL_P -> zval_get_long in case where we could have refs
Sean-Der Apr 17, 2015
d9b6553
When packing make everything ref aware, before TYPE/VAL would fail
Sean-Der Apr 18, 2015
b37104b
FIXME update msgpack_serialize_zval to call Z_INDIRECT_P if the type …
Sean-Der Apr 20, 2015
f5b47f8
Cleanup msgpack_unserialize_class, fixing 012 test segment fault
Sean-Der Apr 21, 2015
774659c
FIXME add temporary version of ALLOC_INIT_ZVAL to msgpack_unpack, unt…
Sean-Der Apr 21, 2015
487f76d
msgpack_serialize_class expects a list of keys, not a map. Update msg…
Sean-Der Apr 22, 2015
85f58f4
Properly call __wakeup during unpacking
Sean-Der Apr 24, 2015
ea2d5be
Update var_push/stack_push to use a var_entries where data is a zval[…
Sean-Der May 3, 2015
76d5a8a
FIXME: Comment out the call_user_function_ex calls implemented via op…
Sean-Der May 5, 2015
c4baa8e
Add commented out loop over var_hash for freeing after serialization
Sean-Der May 5, 2015
4e19afa
Update msgpack_unserialize_class to use call_user_function_ex correctly
Sean-Der May 7, 2015
51960ae
Update ZEND_METHOD(msgpack_unpacker, feed) to use a zend_string for z…
Sean-Der May 7, 2015
3e67e92
When updating a class in msgpack_unserialize_map_item call zend_updat…
Sean-Der May 7, 2015
591b3b3
Update msgpack_unserialize_map_item to properly handle adding element…
Sean-Der May 9, 2015
0cd9aed
Update msgpack_var_add to return to the index of an already serialize…
Sean-Der May 9, 2015
12c8a02
Update msgpack_unserialize_map_item to unmangle the property key set …
Sean-Der May 10, 2015
70557c8
Update msgpack_var_access to use a zval** instead of a zval*** when f…
Sean-Der May 10, 2015
5306649
Start fixing the compile time errors in msgpack_convert.c
Sean-Der May 11, 2015
414f72b
Accidently disabled branch used to update classes in msgpack_unserial…
Sean-Der May 11, 2015
94d6f04
MSGPACK_UNPACK_CONTINUE returned from template_execute means we shoul…
Sean-Der May 12, 2015
60a3044
Bring back serializable interface support, was behind IFDEFs
Sean-Der May 12, 2015
308e918
msgpack_serialize_object is now ref aware
Sean-Der May 12, 2015
b265cd9
Bring back seperate stacks for dtor variables, still emalloc leaks
Sean-Der May 14, 2015
a40f0e7
Fix memory leak, don't make pointless dupe of zval string when updati…
Sean-Der May 15, 2015
1185dba
Fix memory leaks for non-dtor allocations
Sean-Der May 16, 2015
93ec0c7
Fix pack/unpack memory leaks for classes
Sean-Der May 16, 2015
351c29c
Fix zend_string memory leak in msgpack_serialize_class
Sean-Der May 16, 2015
2247ba1
Fix memory leak in msgpack_unserialize_map_item when executing __wakeup
Sean-Der May 16, 2015
210da3d
In msgpack_serialize_object allocate strings later, to make error han…
Sean-Der May 16, 2015
45d832a
Memory leaks in msgpack_unserialize_class
Sean-Der May 16, 2015
f1b108a
PS_SERIALIZER_ENCODE_FUNC would pass an null zval * as return_value t…
Sean-Der May 16, 2015
caa80cb
Use Z_OBJCE_P instead of Z_OBJ_P()->ce
Sean-Der May 17, 2015
3a75af1
Cleaner ref handling when unpacking a map item
Sean-Der May 18, 2015
676e6bd
Update msgpack_unserialize_map_item to remove accidently added Z_ISREF_P
Sean-Der May 20, 2015
6fbc26a
msgpack_unserialize_class now properly handles references, before it …
Sean-Der May 20, 2015
88217d0
msgpack_serialize_array was incorrectly ported to handle when php_onl…
Sean-Der May 20, 2015
f53f484
Remove MSGPACK_METHOD1 macro which created the necessary opcodes to c…
Sean-Der May 20, 2015
b1a2abc
Update MessagePackUnpacker to use new object API, fixing unpacker tests
Sean-Der May 22, 2015
3fb45c3
Z_LVAL_P on a boolean is no longer valid, msgpack->setOption incorrec…
Sean-Der May 22, 2015
3572938
Began converting msgpack_convert.c from using symtable_update to upda…
Sean-Der May 26, 2015
db405c4
Fix memory leak when serializing a class with a unserialize entry
Sean-Der May 26, 2015
3866934
Update msgpack_convert_long_to_properties to properly detect keys
Sean-Der May 27, 2015
fd19e23
Finish converting msgpack_convert_array
Sean-Der May 28, 2015
edcaeda
ZEND_HASH_FOREACH_KEY_VAL -> ZEND_HASH_FOREACH_STR_KEY_VAL ulong key …
Sean-Der May 29, 2015
c51a499
Fix unpacking code, we can't just reuse the stack anymore since the z…
Sean-Der May 30, 2015
0ecf768
Finish 'unpack of template convertor' test fails, memory leaks unfixed
Sean-Der May 31, 2015
138072b
Fixes from review by @zxcvdavid
Sean-Der Jun 3, 2015
94ad5fd
Update msgpack_convert_template tests to assert we can create create …
Sean-Der Jun 3, 2015
7bdfe4b
Cleaning up memory leaks in msgpack_convert.c
Sean-Der Jun 7, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 49 additions & 94 deletions msgpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,8 @@ static ZEND_MINIT_FUNCTION(msgpack)

msgpack_init_class();

#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 1)
REGISTER_LONG_CONSTANT(
"MESSAGEPACK_OPT_PHPONLY", MSGPACK_CLASS_OPT_PHPONLY,
CONST_CS | CONST_PERSISTENT);
#endif
REGISTER_LONG_CONSTANT("MESSAGEPACK_OPT_PHPONLY",
MSGPACK_CLASS_OPT_PHPONLY, CONST_CS | CONST_PERSISTENT);

return SUCCESS;
}
Expand All @@ -124,19 +121,15 @@ static ZEND_MINFO_FUNCTION(msgpack)
}

zend_module_entry msgpack_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
STANDARD_MODULE_HEADER,
#endif
"msgpack",
msgpack_functions,
ZEND_MINIT(msgpack),
ZEND_MSHUTDOWN(msgpack),
NULL,
NULL,
ZEND_MINFO(msgpack),
#if ZEND_MODULE_API_NO >= 20010901
PHP_MSGPACK_VERSION,
#endif
STANDARD_MODULE_PROPERTIES
};

Expand All @@ -147,91 +140,62 @@ ZEND_GET_MODULE(msgpack)
#if HAVE_PHP_SESSION
PS_SERIALIZER_ENCODE_FUNC(msgpack)
{
smart_str buf = {0};
smart_string buf = {0};
zend_string *z_string;
msgpack_serialize_data_t var_hash;

msgpack_serialize_var_init(&var_hash);

msgpack_serialize_zval(&buf, PS(http_session_vars), var_hash TSRMLS_CC);

if (newlen)
{
*newlen = buf.len;
}

smart_str_0(&buf);
*newstr = buf.c;

msgpack_serialize_zval(&buf, &PS(http_session_vars), var_hash);
msgpack_serialize_var_destroy(&var_hash);

return SUCCESS;
z_string = zend_string_init(buf.c, buf.len, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe msgpack_serialize_zval should use zend_str directly? then we can save a string duplication here

smart_string_free(&buf);

return z_string;
}

PS_SERIALIZER_DECODE_FUNC(msgpack)
{
int ret;
HashTable *tmp_hash;
HashPosition tmp_hash_pos;
char *key_str;
ulong key_long;
uint key_len;
zval *tmp;
zval **value;
zend_string *key_str;
zval tmp, *value;
size_t off = 0;
msgpack_unpack_t mp;
msgpack_unserialize_data_t var_hash;

ALLOC_INIT_ZVAL(tmp);

template_init(&mp);

msgpack_unserialize_var_init(&var_hash);

mp.user.retval = (zval *)tmp;
mp.user.var_hash = (msgpack_unserialize_data_t *)&var_hash;
mp.user.retval = &tmp;
mp.user.var_hash = &var_hash;

ret = template_execute(&mp, (char *)val, (size_t)vallen, &off);
ret = template_execute(&mp, val, vallen, &off);

if (ret == MSGPACK_UNPACK_EXTRA_BYTES || ret == MSGPACK_UNPACK_SUCCESS)
{
if (ret == MSGPACK_UNPACK_EXTRA_BYTES || ret == MSGPACK_UNPACK_SUCCESS) {
msgpack_unserialize_set_return_value(&var_hash, &tmp);
msgpack_unserialize_var_destroy(&var_hash, 0);

tmp_hash = HASH_OF(tmp);

zend_hash_internal_pointer_reset_ex(tmp_hash, &tmp_hash_pos);

while (zend_hash_get_current_data_ex(
tmp_hash, (void *)&value, &tmp_hash_pos) == SUCCESS)
{
ret = zend_hash_get_current_key_ex(
tmp_hash, &key_str, &key_len, &key_long, 0, &tmp_hash_pos);
switch (ret)
{
case HASH_KEY_IS_LONG:
/* ??? */
break;
case HASH_KEY_IS_STRING:
php_set_session_var(
key_str, key_len - 1, *value, NULL TSRMLS_CC);
php_add_session_var(key_str, key_len - 1 TSRMLS_CC);
break;
ZEND_HASH_FOREACH_STR_KEY_VAL(HASH_OF(&tmp), key_str, value) {
if (key_str) {
php_set_session_var(key_str, value, NULL);
php_add_session_var(key_str);
} else {
//unhandled non-string key
}
zend_hash_move_forward_ex(tmp_hash, &tmp_hash_pos);
}
}
else
{
} ZEND_HASH_FOREACH_END();
zval_ptr_dtor(&tmp);
} else {
msgpack_unserialize_var_destroy(&var_hash, 1);
}

zval_ptr_dtor(&tmp);

return SUCCESS;
}
#endif

PHP_MSGPACK_API void php_msgpack_serialize(smart_str *buf, zval *val TSRMLS_DC)
PHP_MSGPACK_API void php_msgpack_serialize(smart_string *buf, zval *val TSRMLS_DC)
{

msgpack_serialize_data_t var_hash;

msgpack_serialize_var_init(&var_hash);
Expand Down Expand Up @@ -259,13 +223,12 @@ PHP_MSGPACK_API void php_msgpack_unserialize(
msgpack_unserialize_var_init(&var_hash);

RETVAL_NULL();
mp.user.retval = (zval *)return_value;
mp.user.var_hash = (msgpack_unserialize_data_t *)&var_hash;
mp.user.retval = return_value;
mp.user.var_hash = &var_hash;

ret = template_execute(&mp, str, (size_t)str_len, &off);

switch (ret)
{
switch (ret) {
case MSGPACK_UNPACK_PARSE_ERROR:
zval_dtor(return_value);
ZVAL_FALSE(return_value);
Expand All @@ -274,15 +237,16 @@ PHP_MSGPACK_API void php_msgpack_unserialize(
break;
case MSGPACK_UNPACK_CONTINUE:
msgpack_unserialize_var_destroy(&var_hash, 0);
ZVAL_FALSE(return_value);
MSGPACK_WARNING(
"[msgpack] (%s) Insufficient data for unserializing",
__FUNCTION__);
break;
case MSGPACK_UNPACK_EXTRA_BYTES:
case MSGPACK_UNPACK_SUCCESS:
msgpack_unserialize_set_return_value(&var_hash, return_value);
msgpack_unserialize_var_destroy(&var_hash, 0);
if (off < (size_t)str_len)
{
if (off < str_len) {
MSGPACK_WARNING("[msgpack] (%s) Extra bytes", __FUNCTION__);
}
break;
Expand All @@ -298,52 +262,43 @@ PHP_MSGPACK_API void php_msgpack_unserialize(
static ZEND_FUNCTION(msgpack_serialize)
{
zval *parameter;
smart_str buf = {0};
smart_string buf = {0};

if (zend_parse_parameters(
ZEND_NUM_ARGS() TSRMLS_CC, "z", &parameter) == FAILURE)
{
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &parameter) == FAILURE) {
return;
}

php_msgpack_serialize(&buf, parameter TSRMLS_CC);
smart_str_0(&buf);
smart_string_0(&buf);

ZVAL_STRINGL(return_value, buf.c, buf.len, 0);
ZVAL_STRINGL(return_value, buf.c, buf.len);
smart_string_free(&buf);
}

static ZEND_FUNCTION(msgpack_unserialize)
{
char *str;
int str_len;
zend_string *str;
zval *object = NULL;

if (zend_parse_parameters(
ZEND_NUM_ARGS() TSRMLS_CC, "s|z",
&str, &str_len, &object) == FAILURE)
{
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|z", &str, &object) == FAILURE) {
return;
}

if (!str_len)
{
if (!str) {
RETURN_NULL();
}

if (object == NULL)
{
php_msgpack_unserialize(return_value, str, str_len TSRMLS_CC);
}
else
{
zval *zv;
if (object == NULL) {
php_msgpack_unserialize(return_value, str->val, str->len);
} else {
zval zv, *zv_p;
zv_p = &zv;

ALLOC_INIT_ZVAL(zv);
php_msgpack_unserialize(zv, str, str_len TSRMLS_CC);
php_msgpack_unserialize(&zv, str->val, str->len);

if (msgpack_convert_template(return_value, object, &zv) != SUCCESS)
{
if (msgpack_convert_template(return_value, object, &zv_p) != SUCCESS) {
RETURN_NULL();
}

}
}
Loading