Skip to content

Commit 0c1fea3

Browse files
committed
Start working on porting this to PHP7(not finish yet)
1 parent 7bdfe4b commit 0c1fea3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+664
-19719
lines changed

msgpack.c

+55-50
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,11 @@ static zend_function_entry msgpack_functions[] = {
5959
{NULL, NULL, NULL}
6060
};
6161

62-
static void msgpack_init_globals(zend_msgpack_globals *msgpack_globals)
62+
static void msgpack_init_globals(zend_msgpack_globals *msgpack_globals) /* {{{ */
6363
{
64-
TSRMLS_FETCH();
65-
66-
if (PG(display_errors))
67-
{
64+
if (PG(display_errors)) {
6865
msgpack_globals->error_display = 1;
69-
}
70-
else
71-
{
66+
} else {
7267
msgpack_globals->error_display = 0;
7368
}
7469

@@ -78,9 +73,9 @@ static void msgpack_init_globals(zend_msgpack_globals *msgpack_globals)
7873
msgpack_globals->serialize.var_hash = NULL;
7974
msgpack_globals->serialize.level = 0;
8075
}
76+
/* }}} */
8177

82-
static ZEND_MINIT_FUNCTION(msgpack)
83-
{
78+
static ZEND_MINIT_FUNCTION(msgpack) /* {{{ */ {
8479
ZEND_INIT_MODULE_GLOBALS(msgpack, msgpack_init_globals, NULL);
8580

8681
REGISTER_INI_ENTRIES();
@@ -98,16 +93,16 @@ static ZEND_MINIT_FUNCTION(msgpack)
9893

9994
return SUCCESS;
10095
}
96+
/* }}} */
10197

102-
static ZEND_MSHUTDOWN_FUNCTION(msgpack)
103-
{
98+
static ZEND_MSHUTDOWN_FUNCTION(msgpack) /* {{{ */ {
10499
UNREGISTER_INI_ENTRIES();
105100

106101
return SUCCESS;
107102
}
103+
/* }}} */
108104

109-
static ZEND_MINFO_FUNCTION(msgpack)
110-
{
105+
static ZEND_MINFO_FUNCTION(msgpack) /* {{{ */ {
111106
php_info_print_table_start();
112107
php_info_print_table_row(2, "MessagePack Support", "enabled");
113108
#if HAVE_PHP_SESSION
@@ -119,6 +114,7 @@ static ZEND_MINFO_FUNCTION(msgpack)
119114

120115
DISPLAY_INI_ENTRIES();
121116
}
117+
/* }}} */
122118

123119
zend_module_entry msgpack_module_entry = {
124120
STANDARD_MODULE_HEADER,
@@ -138,30 +134,29 @@ ZEND_GET_MODULE(msgpack)
138134
#endif
139135

140136
#if HAVE_PHP_SESSION
141-
PS_SERIALIZER_ENCODE_FUNC(msgpack)
137+
PS_SERIALIZER_ENCODE_FUNC(msgpack) /* {{{ */
142138
{
143-
smart_string buf = {0};
144-
zend_string *z_string;
139+
smart_str buf = {0};
145140
msgpack_serialize_data_t var_hash;
146141

147142
msgpack_serialize_var_init(&var_hash);
148-
msgpack_serialize_zval(&buf, &PS(http_session_vars), var_hash);
143+
msgpack_serialize_zval(&buf, &PS(http_session_vars), var_hash);
149144
msgpack_serialize_var_destroy(&var_hash);
150145

151-
z_string = zend_string_init(buf.c, buf.len, 0);
152-
smart_string_free(&buf);
146+
smart_str_0(&buf);
153147

154-
return z_string;
148+
return buf.s;
155149
}
156150

157-
PS_SERIALIZER_DECODE_FUNC(msgpack)
158-
{
151+
/* }}} */
152+
153+
PS_SERIALIZER_DECODE_FUNC(msgpack) /* {{{ */ {
159154
int ret;
160155
zend_string *key_str;
161156
zval tmp, *value;
162-
size_t off = 0;
163157
msgpack_unpack_t mp;
164158
msgpack_unserialize_data_t var_hash;
159+
size_t off = 0;
165160

166161
template_init(&mp);
167162

@@ -182,30 +177,28 @@ PS_SERIALIZER_DECODE_FUNC(msgpack)
182177
php_add_session_var(key_str);
183178
}
184179
} ZEND_HASH_FOREACH_END();
180+
185181
zval_ptr_dtor(&tmp);
186182
} else {
187183
msgpack_unserialize_var_destroy(&var_hash, 1);
188184
}
189185

190186
return SUCCESS;
191187
}
188+
/* }}} */
192189
#endif
193190

194-
PHP_MSGPACK_API void php_msgpack_serialize(smart_string *buf, zval *val TSRMLS_DC)
195-
{
191+
PHP_MSGPACK_API void php_msgpack_serialize(smart_str *buf, zval *val) /* {{{ */ {
196192

197193
msgpack_serialize_data_t var_hash;
198194

199195
msgpack_serialize_var_init(&var_hash);
200-
201-
msgpack_serialize_zval(buf, val, var_hash TSRMLS_CC);
202-
196+
msgpack_serialize_zval(buf, val, var_hash);
203197
msgpack_serialize_var_destroy(&var_hash);
204198
}
199+
/* }}} */
205200

206-
PHP_MSGPACK_API void php_msgpack_unserialize(
207-
zval *return_value, char *str, size_t str_len TSRMLS_DC)
208-
{
201+
PHP_MSGPACK_API void php_msgpack_unserialize( zval *return_value, char *str, size_t str_len) /* {{{ */ {
209202
int ret;
210203
size_t off = 0;
211204
msgpack_unpack_t mp;
@@ -234,8 +227,8 @@ PHP_MSGPACK_API void php_msgpack_unserialize(
234227
MSGPACK_WARNING("[msgpack] (%s) Parse error", __FUNCTION__);
235228
break;
236229
case MSGPACK_UNPACK_CONTINUE:
230+
msgpack_unserialize_set_return_value(&var_hash, return_value);
237231
msgpack_unserialize_var_destroy(&var_hash, 0);
238-
ZVAL_FALSE(return_value);
239232
MSGPACK_WARNING(
240233
"[msgpack] (%s) Insufficient data for unserializing",
241234
__FUNCTION__);
@@ -256,29 +249,33 @@ PHP_MSGPACK_API void php_msgpack_unserialize(
256249
break;
257250
}
258251
}
252+
/* }}} */
259253

260-
static ZEND_FUNCTION(msgpack_serialize)
261-
{
254+
static ZEND_FUNCTION(msgpack_serialize) /* {{{ */ {
262255
zval *parameter;
263-
smart_string buf = {0};
256+
smart_str buf = {0};
264257

265-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &parameter) == FAILURE) {
258+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &parameter) == FAILURE) {
266259
return;
267260
}
268261

269-
php_msgpack_serialize(&buf, parameter TSRMLS_CC);
270-
smart_string_0(&buf);
262+
php_msgpack_serialize(&buf, parameter);
263+
264+
if (buf.s) {
265+
smart_str_0(&buf);
266+
ZVAL_STR(return_value, buf.s);
267+
} else {
268+
RETURN_EMPTY_STRING();
269+
}
271270

272-
ZVAL_STRINGL(return_value, buf.c, buf.len);
273-
smart_string_free(&buf);
274271
}
272+
/* }}} */
275273

276-
static ZEND_FUNCTION(msgpack_unserialize)
277-
{
274+
static ZEND_FUNCTION(msgpack_unserialize) /* {{{ */ {
278275
zend_string *str;
279276
zval *object = NULL;
280277

281-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|z", &str, &object) == FAILURE) {
278+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|z", &str, &object) == FAILURE) {
282279
return;
283280
}
284281

@@ -289,14 +286,22 @@ static ZEND_FUNCTION(msgpack_unserialize)
289286
if (object == NULL) {
290287
php_msgpack_unserialize(return_value, str->val, str->len);
291288
} else {
292-
zval zv, *zv_p;
293-
zv_p = &zv;
294-
289+
zval zv;
295290
php_msgpack_unserialize(&zv, str->val, str->len);
296291

297-
if (msgpack_convert_template(return_value, object, &zv_p) != SUCCESS) {
298-
RETURN_NULL();
292+
if (msgpack_convert_template(return_value, object, &zv) != SUCCESS) {
293+
RETVAL_NULL();
299294
}
300-
295+
zval_ptr_dtor(&zv);
301296
}
302297
}
298+
/* }}} */
299+
300+
/*
301+
* Local variables:
302+
* tab-width: 4
303+
* c-basic-offset: 4
304+
* End:
305+
* vim600: noet sw=4 ts=4 fdm=marker
306+
* vim<600: noet sw=4 ts=4
307+
*/

msgpack/pack_template.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ msgpack_pack_inline_func(_false)(msgpack_pack_user x)
685685

686686
msgpack_pack_inline_func(_array)(msgpack_pack_user x, unsigned int n)
687687
{
688-
if(n < 16) {
688+
if (n < 16) {
689689
unsigned char d = 0x90 | n;
690690
msgpack_pack_append_buffer(x, &d, 1);
691691
} else if(n < 65536) {

0 commit comments

Comments
 (0)