@@ -179,8 +179,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_swoole_mime_type_read, 0, 0, 1)
179
179
ZEND_ARG_INFO(0 , filename)
180
180
ZEND_END_ARG_INFO()
181
181
182
- const zend_function_entry swoole_functions[] =
183
- {
182
+ const zend_function_entry swoole_functions[] = {
184
183
PHP_FE (swoole_version, arginfo_swoole_void)
185
184
PHP_FE (swoole_cpu_num, arginfo_swoole_void)
186
185
PHP_FE (swoole_last_error, arginfo_swoole_void)
@@ -218,33 +217,24 @@ const zend_function_entry swoole_functions[] =
218
217
PHP_FE (swoole_internal_call_user_shutdown_begin, arginfo_swoole_void)
219
218
PHP_FE_END /* Must be the last line in swoole_functions[] */
220
219
};
221
- // clang-format on
222
-
223
- zend_class_entry *swoole_exception_ce;
224
- zend_object_handlers swoole_exception_handlers;
225
-
226
- zend_class_entry *swoole_error_ce;
227
- zend_object_handlers swoole_error_handlers;
228
220
229
221
static const zend_module_dep swoole_deps[] = {
230
222
#ifdef SW_USE_JSON
231
- ZEND_MOD_REQUIRED (" json" )
223
+ ZEND_MOD_REQUIRED (" json" )
232
224
#endif
233
225
#ifdef SW_USE_MYSQLND
234
- ZEND_MOD_REQUIRED (" mysqlnd" )
226
+ ZEND_MOD_REQUIRED (" mysqlnd" )
235
227
#endif
236
228
#ifdef SW_SOCKETS
237
- ZEND_MOD_REQUIRED (" sockets" )
229
+ ZEND_MOD_REQUIRED (" sockets" )
238
230
#endif
239
231
#ifdef SW_USE_CURL
240
- ZEND_MOD_REQUIRED (" curl" )
232
+ ZEND_MOD_REQUIRED (" curl" )
241
233
#endif
242
- ZEND_MOD_END
234
+ ZEND_MOD_END
243
235
};
244
236
245
- // clang-format off
246
- zend_module_entry swoole_module_entry =
247
- {
237
+ zend_module_entry swoole_module_entry = {
248
238
STANDARD_MODULE_HEADER_EX,
249
239
nullptr ,
250
240
swoole_deps,
@@ -260,6 +250,12 @@ zend_module_entry swoole_module_entry =
260
250
};
261
251
// clang-format on
262
252
253
+ zend_class_entry *swoole_exception_ce;
254
+ zend_object_handlers swoole_exception_handlers;
255
+
256
+ zend_class_entry *swoole_error_ce;
257
+ zend_object_handlers swoole_error_handlers;
258
+
263
259
#ifdef COMPILE_DL_SWOOLE
264
260
ZEND_GET_MODULE (swoole)
265
261
#endif
@@ -304,6 +300,14 @@ static void php_swoole_init_globals(zend_swoole_globals *swoole_globals) {
304
300
305
301
void php_swoole_register_shutdown_function (const char *function) {
306
302
php_shutdown_function_entry shutdown_function_entry;
303
+ #if PHP_VERSION_ID >= 80100
304
+ zval function_name;
305
+ ZVAL_STRING (&function_name, function);
306
+ zend_fcall_info_init (
307
+ &function_name, 0 , &shutdown_function_entry.fci , &shutdown_function_entry.fci_cache , NULL , NULL );
308
+ register_user_shutdown_function (Z_STRVAL (function_name), Z_STRLEN (function_name), &shutdown_function_entry);
309
+ zval_ptr_dtor (&function_name);
310
+ #else
307
311
zval *function_name;
308
312
#if PHP_VERSION_ID >= 80000
309
313
shutdown_function_entry.arg_count = 0 ;
@@ -315,8 +319,8 @@ void php_swoole_register_shutdown_function(const char *function) {
315
319
function_name = &shutdown_function_entry.arguments [0 ];
316
320
#endif
317
321
ZVAL_STRING (function_name, function);
318
- register_user_shutdown_function (
319
- Z_STRVAL_P (function_name), Z_STRLEN_P (function_name), &shutdown_function_entry);
322
+ register_user_shutdown_function (Z_STRVAL_P (function_name), Z_STRLEN_P (function_name), &shutdown_function_entry);
323
+ # endif
320
324
}
321
325
322
326
void php_swoole_set_global_option (HashTable *vht) {
@@ -398,14 +402,17 @@ SW_API bool php_swoole_is_enable_coroutine() {
398
402
static void fatal_error (int code, const char *format, ...) {
399
403
va_list args;
400
404
va_start (args, format);
401
- zend_object *exception = zend_throw_exception (swoole_error_ce, swoole::std_string::vformat (format, args).c_str (), code);
405
+ zend_object *exception =
406
+ zend_throw_exception (swoole_error_ce, swoole::std_string::vformat (format, args).c_str (), code);
402
407
va_end (args);
403
408
404
409
zend_try {
405
410
zend_exception_error (exception, E_ERROR);
406
- } zend_catch {
411
+ }
412
+ zend_catch {
407
413
exit (255 );
408
- } zend_end_try ();
414
+ }
415
+ zend_end_try ();
409
416
}
410
417
411
418
/* {{{ PHP_MINIT_FUNCTION
@@ -967,14 +974,14 @@ static void _sw_zend_string_free(void *address) {
967
974
zend_string_free (zend::fetch_zend_string_by_val (address));
968
975
}
969
976
970
- static swoole::Allocator php_allocator {
977
+ static swoole::Allocator php_allocator{
971
978
_sw_emalloc,
972
979
_sw_ecalloc,
973
980
_sw_erealloc,
974
981
_sw_efree,
975
982
};
976
983
977
- static swoole::Allocator zend_string_allocator {
984
+ static swoole::Allocator zend_string_allocator{
978
985
_sw_zend_string_malloc,
979
986
_sw_zend_string_calloc,
980
987
_sw_zend_string_realloc,
@@ -1335,17 +1342,17 @@ static PHP_FUNCTION(swoole_internal_call_user_shutdown_begin) {
1335
1342
1336
1343
static PHP_FUNCTION (swoole_substr_unserialize) {
1337
1344
zend_long offset, length = 0 ;
1338
- char *buf = NULL ;
1339
- size_t buf_len;
1345
+ char *buf = NULL ;
1346
+ size_t buf_len;
1340
1347
zval *options = NULL ;
1341
1348
1342
- ZEND_PARSE_PARAMETERS_START (2 , 4 )
1349
+ ZEND_PARSE_PARAMETERS_START (2 , 4 )
1343
1350
Z_PARAM_STRING (buf, buf_len)
1344
1351
Z_PARAM_LONG (offset)
1345
1352
Z_PARAM_OPTIONAL
1346
1353
Z_PARAM_LONG (length)
1347
1354
Z_PARAM_ARRAY (options)
1348
- ZEND_PARSE_PARAMETERS_END ();
1355
+ ZEND_PARSE_PARAMETERS_END ();
1349
1356
1350
1357
if (buf_len == 0 ) {
1351
1358
RETURN_FALSE;
@@ -1366,21 +1373,21 @@ static PHP_FUNCTION(swoole_substr_unserialize) {
1366
1373
static PHP_FUNCTION (swoole_substr_json_decode) {
1367
1374
zend_long offset, length = 0 ;
1368
1375
char *str;
1369
- size_t str_len;
1370
- zend_bool assoc = 0 ; /* return JS objects as PHP objects by default */
1371
- zend_bool assoc_null = 1 ;
1372
- zend_long depth = PHP_JSON_PARSER_DEFAULT_DEPTH;
1373
- zend_long options = 0 ;
1376
+ size_t str_len;
1377
+ zend_bool assoc = 0 ; /* return JS objects as PHP objects by default */
1378
+ zend_bool assoc_null = 1 ;
1379
+ zend_long depth = PHP_JSON_PARSER_DEFAULT_DEPTH;
1380
+ zend_long options = 0 ;
1374
1381
1375
- ZEND_PARSE_PARAMETERS_START (2 , 6 )
1382
+ ZEND_PARSE_PARAMETERS_START (2 , 6 )
1376
1383
Z_PARAM_STRING (str, str_len)
1377
1384
Z_PARAM_LONG (offset)
1378
1385
Z_PARAM_OPTIONAL
1379
1386
Z_PARAM_LONG (length)
1380
1387
Z_PARAM_BOOL_EX (assoc, assoc_null, 1 , 0 )
1381
1388
Z_PARAM_LONG (depth)
1382
1389
Z_PARAM_LONG (options)
1383
- ZEND_PARSE_PARAMETERS_END ();
1390
+ ZEND_PARSE_PARAMETERS_END ();
1384
1391
1385
1392
if (str_len == 0 ) {
1386
1393
RETURN_FALSE;
@@ -1397,12 +1404,11 @@ static PHP_FUNCTION(swoole_substr_json_decode) {
1397
1404
/* For BC reasons, the bool $assoc overrides the long $options bit for PHP_JSON_OBJECT_AS_ARRAY */
1398
1405
if (!assoc_null) {
1399
1406
if (assoc) {
1400
- options |= PHP_JSON_OBJECT_AS_ARRAY;
1407
+ options |= PHP_JSON_OBJECT_AS_ARRAY;
1401
1408
} else {
1402
1409
options &= ~PHP_JSON_OBJECT_AS_ARRAY;
1403
1410
}
1404
1411
}
1405
1412
zend::json_decode (return_value, str + offset, length, options, depth);
1406
1413
}
1407
1414
#endif
1408
-
0 commit comments