Skip to content

Commit

Permalink
Support object style callback parameters (#3888)
Browse files Browse the repository at this point in the history
* Support object style callback parameters

* Optimize code

* fix tests

* Optimize code [2]

* Remove duplicate codes

* fix typo

* fix tests

* Add StatusInfo, Refactor

* Compatibility with PHP8
  • Loading branch information
matyhtf authored Nov 28, 2020
1 parent 19bf1bf commit 6a2cafd
Show file tree
Hide file tree
Showing 21 changed files with 769 additions and 123 deletions.
29 changes: 17 additions & 12 deletions ext-src/php_swoole.h
Original file line number Diff line number Diff line change
Expand Up @@ -589,35 +589,40 @@ static sw_inline void add_assoc_ulong_safe(zval *arg, const char *key, zend_ulon

/* PHP 7 class declaration macros */

#define SW_INIT_CLASS_ENTRY_BASE(module, namespaceName, snake_name, shortName, methods, parent_ce) do { \
#define SW_INIT_CLASS_ENTRY_BASE(module, namespace_name, snake_name, short_name, methods, parent_ce) do { \
zend_class_entry _##module##_ce = {}; \
INIT_CLASS_ENTRY(_##module##_ce, namespaceName, methods); \
INIT_CLASS_ENTRY(_##module##_ce, namespace_name, methods); \
module##_ce = zend_register_internal_class_ex(&_##module##_ce, parent_ce); \
SW_CLASS_ALIAS(snake_name, module); \
SW_CLASS_ALIAS_SHORT_NAME(shortName, module); \
if (snake_name) SW_CLASS_ALIAS(snake_name, module); \
if (short_name) SW_CLASS_ALIAS_SHORT_NAME(short_name, module); \
} while (0)

#define SW_INIT_CLASS_ENTRY(module, namespaceName, snake_name, shortName, methods) \
SW_INIT_CLASS_ENTRY_BASE(module, namespaceName, snake_name, shortName, methods, NULL); \
#define SW_INIT_CLASS_ENTRY(module, namespace_name, snake_name, short_name, methods) \
SW_INIT_CLASS_ENTRY_BASE(module, namespace_name, snake_name, short_name, methods, NULL); \
memcpy(&module##_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers))

#define SW_INIT_CLASS_ENTRY_EX(module, namespaceName, snake_name, shortName, methods, parent_module) \
SW_INIT_CLASS_ENTRY_BASE(module, namespaceName, snake_name, shortName, methods, parent_module##_ce); \
#define SW_INIT_CLASS_ENTRY_EX(module, namespace_name, snake_name, short_name, methods, parent_module) \
SW_INIT_CLASS_ENTRY_BASE(module, namespace_name, snake_name, short_name, methods, parent_module##_ce); \
memcpy(&module##_handlers, &parent_module##_handlers, sizeof(zend_object_handlers))

#define SW_INIT_CLASS_ENTRY_EX2(module, namespaceName, snake_name, shortName, methods, parent_module_ce, parent_module_handlers) \
SW_INIT_CLASS_ENTRY_BASE(module, namespaceName, snake_name, shortName, methods, parent_module_ce); \
#define SW_INIT_CLASS_ENTRY_EX2(module, namespace_name, snake_name, short_name, methods, parent_module_ce, parent_module_handlers) \
SW_INIT_CLASS_ENTRY_BASE(module, namespace_name, snake_name, short_name, methods, parent_module_ce); \
memcpy(&module##_handlers, parent_module_handlers, sizeof(zend_object_handlers))

// Data Object: no methods, no parent
#define SW_INIT_CLASS_ENTRY_DATA_OBJECT(module, namespace_name) \
SW_INIT_CLASS_ENTRY_BASE(module, namespace_name, NULL, NULL, NULL, NULL); \
memcpy(&module##_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers))

#define SW_CLASS_ALIAS(name, module) do { \
if (name) { \
sw_zend_register_class_alias(ZEND_STRL(name), module##_ce); \
} \
} while (0)

#define SW_CLASS_ALIAS_SHORT_NAME(shortName, module) do { \
#define SW_CLASS_ALIAS_SHORT_NAME(short_name, module) do { \
if (SWOOLE_G(use_shortname)) { \
SW_CLASS_ALIAS(shortName, module); \
SW_CLASS_ALIAS(short_name, module); \
} \
} while (0)

Expand Down
6 changes: 4 additions & 2 deletions ext-src/php_swoole_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Generated by build-library.php, Please DO NOT modify!
*/

/* $Id: 138bd3ee518144ea6dccceb624d540627537a972 */
/* $Id: d8341036d6d7e97eb77dd2adf823fbb9bbd52e8c */

static const char* swoole_library_source_constants =
"\n"
Expand Down Expand Up @@ -6685,6 +6685,8 @@ static const char* swoole_library_source_core_server_helper =
" 'enable_delay_receive' => true,\n"
" 'enable_reuse_port' => true,\n"
" 'task_use_object' => true,\n"
" 'task_object' => true,\n"
" 'event_object' => true,\n"
" 'task_enable_coroutine' => true,\n"
" 'task_worker_num' => true,\n"
" 'task_ipc_mode' => true,\n"
Expand Down Expand Up @@ -6983,7 +6985,7 @@ static const char* swoole_library_source_functions =
"declare(strict_types=1);\n"
"\n"
"if (PHP_VERSION_ID < 70200) {\n"
" throw new RuntimeException(\"require PHP version 7.2 or later\");\n"
" throw new RuntimeException('require PHP version 7.2 or later');\n"
"}\n"
"\n"
"if (SWOOLE_USE_SHORTNAME) {\n"
Expand Down
2 changes: 1 addition & 1 deletion ext-src/swoole_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ static PHP_FUNCTION(swoole_event_rshutdown) {
if (!sw_reactor()) {
return;
}
php_swoole_fatal_error(E_DEPRECATED, "Do Event::wait() in shutdown function is deprecated");
php_swoole_fatal_error(E_DEPRECATED, "Event::wait() in shutdown function is deprecated");
php_swoole_event_wait();
}
zend_end_try();
Expand Down
Loading

0 comments on commit 6a2cafd

Please sign in to comment.