Skip to content

Commit 6184d5c

Browse files
committed
Remove PHP 8.0 compatible code
1 parent 88c19c6 commit 6184d5c

9 files changed

+6
-106
lines changed

ext-src/php_swoole.cc

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -284,19 +284,12 @@ void php_swoole_register_shutdown_function(const char *function) {
284284
shutdown_function_entry.param_count = 0;
285285
register_user_shutdown_function(Z_STRVAL(function_name), Z_STRLEN(function_name), &shutdown_function_entry);
286286
zval_ptr_dtor(&function_name);
287-
#elif PHP_VERSION_ID >= 80100
287+
#else
288288
zval function_name;
289289
ZVAL_STRING(&function_name, function);
290290
zend_fcall_info_init(
291291
&function_name, 0, &shutdown_function_entry.fci, &shutdown_function_entry.fci_cache, NULL, NULL);
292292
register_user_shutdown_function(Z_STRVAL(function_name), Z_STRLEN(function_name), &shutdown_function_entry);
293-
#else
294-
zval *function_name;
295-
shutdown_function_entry.arg_count = 0;
296-
shutdown_function_entry.arguments = NULL;
297-
function_name = &shutdown_function_entry.function_name;
298-
ZVAL_STRING(function_name, function);
299-
register_user_shutdown_function(Z_STRVAL_P(function_name), Z_STRLEN_P(function_name), &shutdown_function_entry);
300293
#endif
301294
}
302295

ext-src/php_swoole_coroutine.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,8 @@
2525
#include "zend_vm.h"
2626
#include "zend_closures.h"
2727

28-
#if PHP_VERSION_ID >= 80100
29-
#define SWOOLE_COROUTINE_MOCK_FIBER_CONTEXT 1
3028
#include "zend_fibers.h"
3129
#include "zend_observer.h"
32-
#endif
3330

3431
#include <stack>
3532
#include <thread>
@@ -64,10 +61,6 @@ struct PHPContext {
6461
zend_class_entry *exception_class;
6562
zend_object *exception;
6663
zend_output_globals *output_ptr;
67-
#if PHP_VERSION_ID < 80100
68-
/* for array_walk non-reentrancy */
69-
zend::Function *array_walk_fci;
70-
#endif
7164
/* for error control `@` */
7265
bool in_silence;
7366
bool enable_scheduler;
@@ -77,10 +70,8 @@ struct PHPContext {
7770
zend_fcall_info fci;
7871
zend_fcall_info_cache fci_cache;
7972
zval return_value;
80-
#ifdef SWOOLE_COROUTINE_MOCK_FIBER_CONTEXT
8173
zend_fiber_context *fiber_context;
8274
bool fiber_init_notified;
83-
#endif
8475
#ifdef ZEND_CHECK_STACK_LIMIT
8576
void *stack_base;
8677
void *stack_limit;
@@ -253,10 +244,8 @@ class PHPCoroutine {
253244

254245
static inline void init_main_context() {
255246
main_context.co = nullptr;
256-
#ifdef SWOOLE_COROUTINE_MOCK_FIBER_CONTEXT
257247
main_context.fiber_context = EG(main_fiber_context);
258248
main_context.fiber_init_notified = true;
259-
#endif
260249
save_context(&main_context);
261250
}
262251

@@ -288,15 +277,13 @@ class PHPCoroutine {
288277
static void on_resume(void *arg);
289278
static void on_close(void *arg);
290279
static void main_func(void *arg);
291-
#ifdef SWOOLE_COROUTINE_MOCK_FIBER_CONTEXT
292280
static zend_fiber_status get_fiber_status(PHPContext *ctx);
293281
static void fiber_context_init(PHPContext *ctx);
294282
static void fiber_context_try_init(PHPContext *ctx);
295283
static void fiber_context_destroy(PHPContext *ctx);
296284
static void fiber_context_try_destroy(PHPContext *ctx);
297285
static void fiber_context_switch_notify(PHPContext *from, PHPContext *to);
298286
static void fiber_context_switch_try_notify(PHPContext *from, PHPContext *to);
299-
#endif
300287
#ifdef ZEND_CHECK_STACK_LIMIT
301288
static void* stack_limit(PHPContext *ctx);
302289
static void* stack_base(PHPContext *ctx);

ext-src/php_swoole_odbc.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ BEGIN_EXTERN_C()
2424

2525
#include "ext/pdo/php_pdo_driver.h"
2626

27-
#if PHP_VERSION_ID >= 80000 && PHP_VERSION_ID < 80100
28-
#include "thirdparty/php80/pdo_odbc/php_pdo_odbc_int.h"
29-
#elif PHP_VERSION_ID >= 80100 && PHP_VERSION_ID < 80200
27+
#if PHP_VERSION_ID < 80200
3028
#include "thirdparty/php81/pdo_odbc/php_pdo_odbc_int.h"
3129
#elif PHP_VERSION_ID >= 80200 && PHP_VERSION_ID < 80300
3230
#include "thirdparty/php81/pdo_odbc/php_pdo_odbc_int.h"

ext-src/php_swoole_pgsql.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ BEGIN_EXTERN_C()
2525

2626
#include "ext/pdo/php_pdo_driver.h"
2727

28-
#if PHP_VERSION_ID >= 80000 && PHP_VERSION_ID < 80100
29-
#include "thirdparty/php80/pdo_pgsql/php_pdo_pgsql_int.h"
30-
#elif PHP_VERSION_ID >= 80100 && PHP_VERSION_ID < 80200
28+
#if PHP_VERSION_ID < 80200
3129
#include "thirdparty/php81/pdo_pgsql/php_pdo_pgsql_int.h"
3230
#elif PHP_VERSION_ID >= 80200 && PHP_VERSION_ID < 80300
3331
#include "thirdparty/php81/pdo_pgsql/php_pdo_pgsql_int.h"

ext-src/php_swoole_private.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -668,13 +668,7 @@ static sw_inline void add_assoc_ulong_safe(zval *arg, const char *key, zend_ulon
668668
} \
669669
} while (0)
670670

671-
#if PHP_VERSION_ID < 80100
672-
#define SW_SET_CLASS_NOT_SERIALIZABLE(module) \
673-
module##_ce->serialize = zend_class_serialize_deny; \
674-
module##_ce->unserialize = zend_class_unserialize_deny;
675-
#else
676671
#define SW_SET_CLASS_NOT_SERIALIZABLE(module) module##_ce->ce_flags |= ZEND_ACC_NOT_SERIALIZABLE;
677-
#endif
678672

679673
#define sw_zend_class_clone_deny NULL
680674
#define SW_SET_CLASS_CLONEABLE(module, _clone_obj) module##_handlers.clone_obj = _clone_obj
@@ -1013,11 +1007,7 @@ static sw_inline void sw_zend_fci_cache_discard(zend_fcall_info_cache *fci_cache
10131007
}
10141008
}
10151009

1016-
#if PHP_VERSION_ID >= 80100
10171010
#define sw_php_spl_object_hash(o) php_spl_object_hash(Z_OBJ_P(o))
1018-
#else
1019-
#define sw_php_spl_object_hash(o) php_spl_object_hash(o)
1020-
#endif
10211011

10221012
//----------------------------------Misc API------------------------------------
10231013

@@ -1073,11 +1063,7 @@ static inline const char *php_swoole_get_last_error_message() {
10731063
}
10741064

10751065
static inline const char *php_swoole_get_last_error_file() {
1076-
#if PHP_VERSION_ID >= 80100
10771066
return PG(last_error_file) ? PG(last_error_file)->val : "-";
1078-
#else
1079-
return PG(last_error_file) ? PG(last_error_file) : "-";
1080-
#endif
10811067
}
10821068

10831069
END_EXTERN_C()

ext-src/php_swoole_sqlite.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ BEGIN_EXTERN_C()
2525

2626
#include "ext/pdo/php_pdo_driver.h"
2727

28-
#if PHP_VERSION_ID >= 80000 && PHP_VERSION_ID < 80100
29-
#include "thirdparty/php80/pdo_sqlite/php_pdo_sqlite_int.h"
30-
#elif PHP_VERSION_ID >= 80100 && PHP_VERSION_ID < 80200
28+
#if PHP_VERSION_ID < 80200
3129
#include "thirdparty/php81/pdo_sqlite/php_pdo_sqlite_int.h"
3230
#elif PHP_VERSION_ID >= 80200 && PHP_VERSION_ID < 80300
3331
#include "thirdparty/php81/pdo_sqlite/php_pdo_sqlite_int.h"

ext-src/swoole_coroutine.cc

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
#include "zend_builtin_functions.h"
2828
#include "ext/spl/spl_array.h"
2929

30-
#ifdef SWOOLE_COROUTINE_MOCK_FIBER_CONTEXT
3130
#include "zend_observer.h"
32-
#endif
3331

3432
#include <unordered_map>
3533
#include <chrono>
@@ -45,17 +43,6 @@ using swoole::PHPCoroutine;
4543
using swoole::coroutine::Socket;
4644
using swoole::coroutine::System;
4745

48-
#if PHP_VERSION_ID < 80100
49-
static zend_always_inline zend_vm_stack zend_vm_stack_new_page(size_t size, zend_vm_stack prev) {
50-
zend_vm_stack page = (zend_vm_stack) emalloc(size);
51-
52-
page->top = ZEND_VM_STACK_ELEMENTS(page);
53-
page->end = (zval *) ((char *) page + size);
54-
page->prev = prev;
55-
return page;
56-
}
57-
#endif
58-
5946
enum sw_exit_flags { SW_EXIT_IN_COROUTINE = 1 << 1, SW_EXIT_IN_SERVER = 1 << 2 };
6047

6148
SW_THREAD_LOCAL bool PHPCoroutine::activated = false;
@@ -302,9 +289,6 @@ static void coro_interrupt_function(zend_execute_data *execute_data) {
302289
PHPContext *PHPCoroutine::create_context(Args *args) {
303290
PHPContext *ctx = (PHPContext *) emalloc(sizeof(PHPContext));
304291
ctx->output_ptr = nullptr;
305-
#if PHP_VERSION_ID < 80100
306-
ctx->array_walk_fci = nullptr;
307-
#endif
308292
ctx->in_silence = false;
309293

310294
ctx->co = Coroutine::get_current();
@@ -317,10 +301,8 @@ PHPContext *PHPCoroutine::create_context(Args *args) {
317301
ctx->on_close = nullptr;
318302
ctx->enable_scheduler = true;
319303

320-
#ifdef SWOOLE_COROUTINE_MOCK_FIBER_CONTEXT
321304
fiber_context_try_init(ctx);
322305
ctx->fiber_init_notified = false;
323-
#endif
324306

325307
EG(vm_stack) = zend_vm_stack_new_page(SW_DEFAULT_PHP_STACK_PAGE_SIZE, nullptr);
326308
EG(vm_stack_top) = EG(vm_stack)->top + ZEND_CALL_FRAME_SLOT;
@@ -522,15 +504,6 @@ inline void PHPCoroutine::save_vm_stack(PHPContext *ctx) {
522504
ctx->error_handling = EG(error_handling);
523505
ctx->exception_class = EG(exception_class);
524506
ctx->exception = EG(exception);
525-
#if PHP_VERSION_ID < 80100
526-
if (UNEXPECTED(BG(array_walk_fci).size != 0)) {
527-
if (!ctx->array_walk_fci) {
528-
ctx->array_walk_fci = (zend::Function *) emalloc(sizeof(*ctx->array_walk_fci));
529-
}
530-
memcpy(ctx->array_walk_fci, &BG(array_walk_fci), sizeof(*ctx->array_walk_fci));
531-
memset(&BG(array_walk_fci), 0, sizeof(*ctx->array_walk_fci));
532-
}
533-
#endif
534507
if (UNEXPECTED(ctx->in_silence)) {
535508
ctx->tmp_error_reporting = EG(error_reporting);
536509
EG(error_reporting) = ctx->ori_error_reporting;
@@ -552,12 +525,6 @@ inline void PHPCoroutine::restore_vm_stack(PHPContext *ctx) {
552525
EG(error_handling) = ctx->error_handling;
553526
EG(exception_class) = ctx->exception_class;
554527
EG(exception) = ctx->exception;
555-
#if PHP_VERSION_ID < 80100
556-
if (UNEXPECTED(ctx->array_walk_fci && ctx->array_walk_fci->fci.size != 0)) {
557-
memcpy(&BG(array_walk_fci), ctx->array_walk_fci, sizeof(*ctx->array_walk_fci));
558-
ctx->array_walk_fci->fci.size = 0;
559-
}
560-
#endif
561528
if (UNEXPECTED(ctx->in_silence)) {
562529
EG(error_reporting) = ctx->tmp_error_reporting;
563530
}
@@ -614,9 +581,7 @@ void PHPCoroutine::on_yield(void *arg) {
614581
PHPContext *ctx = (PHPContext *) arg;
615582
PHPContext *origin_ctx = get_origin_context(ctx);
616583

617-
#ifdef SWOOLE_COROUTINE_MOCK_FIBER_CONTEXT
618584
fiber_context_switch_try_notify(ctx, origin_ctx);
619-
#endif
620585
save_context(ctx);
621586
restore_context(origin_ctx);
622587

@@ -631,9 +596,7 @@ void PHPCoroutine::on_resume(void *arg) {
631596
PHPContext *ctx = (PHPContext *) arg;
632597
PHPContext *current_ctx = get_context();
633598

634-
#ifdef SWOOLE_COROUTINE_MOCK_FIBER_CONTEXT
635599
fiber_context_switch_try_notify(current_ctx, ctx);
636-
#endif
637600
save_context(current_ctx);
638601
restore_context(ctx);
639602
record_last_msec(ctx);
@@ -676,11 +639,6 @@ void PHPCoroutine::destroy_context(PHPContext *ctx) {
676639
php_output_activate();
677640
SG(request_info).no_headers = no_headers;
678641
}
679-
#if PHP_VERSION_ID < 80100
680-
if (ctx->array_walk_fci) {
681-
efree(ctx->array_walk_fci);
682-
}
683-
#endif
684642

685643
if (ctx->defer_tasks) {
686644
while (!ctx->defer_tasks->empty()) {
@@ -706,10 +664,8 @@ void PHPCoroutine::destroy_context(PHPContext *ctx) {
706664

707665
Z_TRY_DELREF(ctx->return_value);
708666

709-
#ifdef SWOOLE_COROUTINE_MOCK_FIBER_CONTEXT
710667
fiber_context_switch_try_notify(ctx, origin_ctx);
711668
fiber_context_try_destroy(ctx);
712-
#endif
713669

714670
swoole_trace_log(SW_TRACE_COROUTINE,
715671
"coro close cid=%ld and resume to %ld, %zu remained. usage size: %zu. malloc size: %zu",
@@ -740,8 +696,7 @@ void PHPCoroutine::main_func(void *_args) {
740696
swoole_call_hook(SW_GLOBAL_HOOK_ON_CORO_START, ctx);
741697
}
742698

743-
#ifdef SWOOLE_COROUTINE_MOCK_FIBER_CONTEXT
744-
if (EXPECTED(SWOOLE_G(enable_fiber_mock) && ctx->fci_cache.function_handler->type == ZEND_USER_FUNCTION)) {
699+
if (UNEXPECTED(SWOOLE_G(enable_fiber_mock) && ctx->fci_cache.function_handler->type == ZEND_USER_FUNCTION)) {
745700
zend_execute_data *tmp = EG(current_execute_data);
746701
zend_execute_data call = {};
747702
EG(current_execute_data) = &call;
@@ -750,7 +705,7 @@ void PHPCoroutine::main_func(void *_args) {
750705
fiber_context_switch_try_notify(get_origin_context(ctx), ctx);
751706
EG(current_execute_data) = tmp;
752707
}
753-
#endif
708+
754709
zend_call_function(&ctx->fci, &ctx->fci_cache);
755710

756711
// Catch exception in main function of the coroutine
@@ -828,8 +783,6 @@ void PHPCoroutine::defer(zend::Function *fci) {
828783
ctx->defer_tasks->push(fci);
829784
}
830785

831-
#ifdef SWOOLE_COROUTINE_MOCK_FIBER_CONTEXT
832-
833786
void PHPCoroutine::fiber_context_init(PHPContext *ctx) {
834787
zend_fiber_context *fiber_context = (zend_fiber_context *) emalloc(sizeof(*fiber_context));
835788
fiber_context->handle = (void *) -1;
@@ -907,7 +860,6 @@ void PHPCoroutine::fiber_context_switch_try_notify(PHPContext *from, PHPContext
907860
}
908861
fiber_context_switch_notify(from, to);
909862
}
910-
#endif /* SWOOLE_COROUTINE_MOCK_FIBER_CONTEXT */
911863

912864
#ifdef ZEND_CHECK_STACK_LIMIT
913865
void *PHPCoroutine::stack_limit(PHPContext *ctx) {

ext-src/swoole_runtime.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,9 +1976,7 @@ static PHP_FUNCTION(swoole_stream_select) {
19761976
zval *r_array, *w_array, *e_array;
19771977
zend_long sec, usec = 0;
19781978
zend_bool secnull;
1979-
#if PHP_VERSION_ID >= 80100
19801979
bool usecnull = true;
1981-
#endif
19821980
int retval = 0;
19831981

19841982
ZEND_PARSE_PARAMETERS_START(4, 5)
@@ -1987,21 +1985,15 @@ static PHP_FUNCTION(swoole_stream_select) {
19871985
Z_PARAM_ARRAY_EX2(e_array, 1, 1, 1)
19881986
Z_PARAM_LONG_OR_NULL(sec, secnull)
19891987
Z_PARAM_OPTIONAL
1990-
#if PHP_VERSION_ID >= 80100
19911988
Z_PARAM_LONG_OR_NULL(usec, usecnull)
1992-
#else
1993-
Z_PARAM_LONG(usec)
1994-
#endif
19951989
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
19961990

1997-
#if PHP_VERSION_ID >= 80100
19981991
if (secnull && !usecnull) {
19991992
if (usec != 0) {
20001993
zend_argument_value_error(5, "must be null when argument #4 ($seconds) is null");
20011994
RETURN_THROWS();
20021995
}
20031996
}
2004-
#endif
20051997

20061998
double timeout = -1;
20071999
if (!secnull) {

ext-src/swoole_thread.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,7 @@ void php_swoole_thread_start(std::shared_ptr<Thread> thread, zend_string *file,
421421

422422
PG(expose_php) = false;
423423
PG(auto_globals_jit) = true;
424-
#if PHP_VERSION_ID >= 80100
425424
PG(enable_dl) = false;
426-
#else
427-
PG(enable_dl) = 0;
428-
#endif
429425

430426
swoole_thread_init(false);
431427

0 commit comments

Comments
 (0)