Skip to content

Commit

Permalink
Fix compile error
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Jan 7, 2025
1 parent 18e2166 commit f466a22
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
32 changes: 32 additions & 0 deletions ext-src/php_swoole.cc
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,38 @@ SW_API zend_long php_swoole_parse_to_size(zval *zv) {
}
}

SW_API zend_string *php_swoole_serialize(zval *zdata) {
php_serialize_data_t var_hash;
smart_str serialized_data = {0};

PHP_VAR_SERIALIZE_INIT(var_hash);
php_var_serialize(&serialized_data, zdata, &var_hash);
PHP_VAR_SERIALIZE_DESTROY(var_hash);

zend_string *result = nullptr;
if (!EG(exception)) {
result = zend_string_init(serialized_data.s->val, serialized_data.s->len, 1);
}
smart_str_free(&serialized_data);
return result;
}

SW_API bool php_swoole_unserialize(zend_string *data, zval *zv) {
php_unserialize_data_t var_hash;
const char *p = ZSTR_VAL(data);
size_t l = ZSTR_LEN(data);

PHP_VAR_UNSERIALIZE_INIT(var_hash);
zend_bool unserialized = php_var_unserialize(zv, (const uchar **) &p, (const uchar *) (p + l), &var_hash);
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
if (!unserialized) {
swoole_warning("unserialize() failed, Error at offset " ZEND_LONG_FMT " of %zd bytes",
(zend_long) ((char *) p - ZSTR_VAL(data)),
l);
}
return unserialized;
}

static void fatal_error(int code, const char *format, ...) {
va_list args;
va_start(args, format);
Expand Down
2 changes: 2 additions & 0 deletions ext-src/php_swoole_cxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ static inline bool php_swoole_is_fatal_error() {

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

#ifdef SW_HAVE_ZLIB
#define php_swoole_websocket_frame_pack php_swoole_websocket_frame_pack_ex
Expand Down
2 changes: 0 additions & 2 deletions ext-src/php_swoole_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ extern zend_class_entry *swoole_thread_queue_ce;
void php_swoole_thread_start(zend_string *file, ZendArray *argv);
void php_swoole_thread_join(pthread_t ptid);
int php_swoole_thread_get_exit_status(pthread_t ptid);
zend_string *php_swoole_serialize(zval *zdata);
bool php_swoole_unserialize(zend_string *data, zval *zv);
void php_swoole_thread_bailout(void);

ThreadResource *php_swoole_thread_arraylist_cast(zval *zobject);
Expand Down
32 changes: 0 additions & 32 deletions ext-src/swoole_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -329,38 +329,6 @@ static PHP_METHOD(swoole_thread, getNativeId) {
RETURN_LONG((zend_long) swoole_thread_get_native_id());
}

zend_string *php_swoole_serialize(zval *zdata) {
php_serialize_data_t var_hash;
smart_str serialized_data = {0};

PHP_VAR_SERIALIZE_INIT(var_hash);
php_var_serialize(&serialized_data, zdata, &var_hash);
PHP_VAR_SERIALIZE_DESTROY(var_hash);

zend_string *result = nullptr;
if (!EG(exception)) {
result = zend_string_init(serialized_data.s->val, serialized_data.s->len, 1);
}
smart_str_free(&serialized_data);
return result;
}

bool php_swoole_unserialize(zend_string *data, zval *zv) {
php_unserialize_data_t var_hash;
const char *p = ZSTR_VAL(data);
size_t l = ZSTR_LEN(data);

PHP_VAR_UNSERIALIZE_INIT(var_hash);
zend_bool unserialized = php_var_unserialize(zv, (const uchar **) &p, (const uchar *) (p + l), &var_hash);
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
if (!unserialized) {
swoole_warning("unserialize() failed, Error at offset " ZEND_LONG_FMT " of %zd bytes",
(zend_long) ((char *) p - ZSTR_VAL(data)),
l);
}
return unserialized;
}

void php_swoole_thread_rinit() {
if (tsrm_is_main_thread()) {
if (SG(request_info).path_translated) {
Expand Down

0 comments on commit f466a22

Please sign in to comment.