Skip to content

Commit f466a22

Browse files
committed
Fix compile error
1 parent 18e2166 commit f466a22

File tree

4 files changed

+34
-34
lines changed

4 files changed

+34
-34
lines changed

ext-src/php_swoole.cc

+32
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,38 @@ SW_API zend_long php_swoole_parse_to_size(zval *zv) {
372372
}
373373
}
374374

375+
SW_API zend_string *php_swoole_serialize(zval *zdata) {
376+
php_serialize_data_t var_hash;
377+
smart_str serialized_data = {0};
378+
379+
PHP_VAR_SERIALIZE_INIT(var_hash);
380+
php_var_serialize(&serialized_data, zdata, &var_hash);
381+
PHP_VAR_SERIALIZE_DESTROY(var_hash);
382+
383+
zend_string *result = nullptr;
384+
if (!EG(exception)) {
385+
result = zend_string_init(serialized_data.s->val, serialized_data.s->len, 1);
386+
}
387+
smart_str_free(&serialized_data);
388+
return result;
389+
}
390+
391+
SW_API bool php_swoole_unserialize(zend_string *data, zval *zv) {
392+
php_unserialize_data_t var_hash;
393+
const char *p = ZSTR_VAL(data);
394+
size_t l = ZSTR_LEN(data);
395+
396+
PHP_VAR_UNSERIALIZE_INIT(var_hash);
397+
zend_bool unserialized = php_var_unserialize(zv, (const uchar **) &p, (const uchar *) (p + l), &var_hash);
398+
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
399+
if (!unserialized) {
400+
swoole_warning("unserialize() failed, Error at offset " ZEND_LONG_FMT " of %zd bytes",
401+
(zend_long) ((char *) p - ZSTR_VAL(data)),
402+
l);
403+
}
404+
return unserialized;
405+
}
406+
375407
static void fatal_error(int code, const char *format, ...) {
376408
va_list args;
377409
va_start(args, format);

ext-src/php_swoole_cxx.h

+2
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ static inline bool php_swoole_is_fatal_error() {
162162

163163
ssize_t php_swoole_length_func(const swoole::Protocol *, swoole::network::Socket *, swoole::PacketLength *);
164164
SW_API zend_long php_swoole_parse_to_size(zval *zv);
165+
SW_API zend_string *php_swoole_serialize(zval *zdata);
166+
SW_API bool php_swoole_unserialize(zend_string *data, zval *zv);
165167

166168
#ifdef SW_HAVE_ZLIB
167169
#define php_swoole_websocket_frame_pack php_swoole_websocket_frame_pack_ex

ext-src/php_swoole_thread.h

-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ extern zend_class_entry *swoole_thread_queue_ce;
4040
void php_swoole_thread_start(zend_string *file, ZendArray *argv);
4141
void php_swoole_thread_join(pthread_t ptid);
4242
int php_swoole_thread_get_exit_status(pthread_t ptid);
43-
zend_string *php_swoole_serialize(zval *zdata);
44-
bool php_swoole_unserialize(zend_string *data, zval *zv);
4543
void php_swoole_thread_bailout(void);
4644

4745
ThreadResource *php_swoole_thread_arraylist_cast(zval *zobject);

ext-src/swoole_thread.cc

-32
Original file line numberDiff line numberDiff line change
@@ -329,38 +329,6 @@ static PHP_METHOD(swoole_thread, getNativeId) {
329329
RETURN_LONG((zend_long) swoole_thread_get_native_id());
330330
}
331331

332-
zend_string *php_swoole_serialize(zval *zdata) {
333-
php_serialize_data_t var_hash;
334-
smart_str serialized_data = {0};
335-
336-
PHP_VAR_SERIALIZE_INIT(var_hash);
337-
php_var_serialize(&serialized_data, zdata, &var_hash);
338-
PHP_VAR_SERIALIZE_DESTROY(var_hash);
339-
340-
zend_string *result = nullptr;
341-
if (!EG(exception)) {
342-
result = zend_string_init(serialized_data.s->val, serialized_data.s->len, 1);
343-
}
344-
smart_str_free(&serialized_data);
345-
return result;
346-
}
347-
348-
bool php_swoole_unserialize(zend_string *data, zval *zv) {
349-
php_unserialize_data_t var_hash;
350-
const char *p = ZSTR_VAL(data);
351-
size_t l = ZSTR_LEN(data);
352-
353-
PHP_VAR_UNSERIALIZE_INIT(var_hash);
354-
zend_bool unserialized = php_var_unserialize(zv, (const uchar **) &p, (const uchar *) (p + l), &var_hash);
355-
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
356-
if (!unserialized) {
357-
swoole_warning("unserialize() failed, Error at offset " ZEND_LONG_FMT " of %zd bytes",
358-
(zend_long) ((char *) p - ZSTR_VAL(data)),
359-
l);
360-
}
361-
return unserialized;
362-
}
363-
364332
void php_swoole_thread_rinit() {
365333
if (tsrm_is_main_thread()) {
366334
if (SG(request_info).path_translated) {

0 commit comments

Comments
 (0)