Skip to content

Commit 60e71a1

Browse files
committed
fix(worker): reset ini and session: support PHP8.2
1 parent c66c0ad commit 60e71a1

1 file changed

Lines changed: 24 additions & 24 deletions

File tree

frankenphp.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,27 @@ __thread zval *os_environment = NULL;
7777
__thread HashTable *worker_ini_snapshot = NULL;
7878

7979
/* Session user handler names (same structure as PS(mod_user_names)).
80-
* ps_create_sid, ps_validate_sid, ps_update_timestamp added in PHP 8.3 */
80+
* In PHP 8.2, mod_user_names is a union with .name.ps_* access.
81+
* In PHP 8.3+, mod_user_names is a direct struct with .ps_* access. */
8182
typedef struct {
8283
zval ps_open;
8384
zval ps_close;
8485
zval ps_read;
8586
zval ps_write;
8687
zval ps_destroy;
8788
zval ps_gc;
88-
#if PHP_VERSION_ID >= 80300
8989
zval ps_create_sid;
9090
zval ps_validate_sid;
9191
zval ps_update_timestamp;
92-
#endif
9392
} session_user_handlers;
9493

94+
/* Macro to access PS(mod_user_names) handlers across PHP versions */
95+
#if PHP_VERSION_ID >= 80300
96+
#define PS_MOD_USER_NAMES(handler) PS(mod_user_names).handler
97+
#else
98+
#define PS_MOD_USER_NAMES(handler) PS(mod_user_names).name.handler
99+
#endif
100+
95101
__thread session_user_handlers *worker_session_handlers_snapshot = NULL;
96102

97103
void frankenphp_update_local_thread_context(bool is_worker) {
@@ -288,7 +294,7 @@ static void frankenphp_snapshot_session_handlers(void) {
288294
}
289295

290296
/* Check if user session handlers are defined */
291-
if (Z_ISUNDEF(PS(mod_user_names).ps_open)) {
297+
if (Z_ISUNDEF(PS_MOD_USER_NAMES(ps_open))) {
292298
return; /* No user handlers to snapshot */
293299
}
294300

@@ -298,12 +304,12 @@ static void frankenphp_snapshot_session_handlers(void) {
298304
}
299305

300306
/* Copy each handler zval with incremented reference count */
301-
#define SNAPSHOT_HANDLER(name) \
302-
if (!Z_ISUNDEF(PS(mod_user_names).name)) { \
303-
ZVAL_COPY(&worker_session_handlers_snapshot->name, \
304-
&PS(mod_user_names).name); \
307+
#define SNAPSHOT_HANDLER(handler) \
308+
if (!Z_ISUNDEF(PS_MOD_USER_NAMES(handler))) { \
309+
ZVAL_COPY(&worker_session_handlers_snapshot->handler, \
310+
&PS_MOD_USER_NAMES(handler)); \
305311
} else { \
306-
ZVAL_UNDEF(&worker_session_handlers_snapshot->name); \
312+
ZVAL_UNDEF(&worker_session_handlers_snapshot->handler); \
307313
}
308314

309315
SNAPSHOT_HANDLER(ps_open);
@@ -312,11 +318,9 @@ static void frankenphp_snapshot_session_handlers(void) {
312318
SNAPSHOT_HANDLER(ps_write);
313319
SNAPSHOT_HANDLER(ps_destroy);
314320
SNAPSHOT_HANDLER(ps_gc);
315-
#if PHP_VERSION_ID >= 80300
316321
SNAPSHOT_HANDLER(ps_create_sid);
317322
SNAPSHOT_HANDLER(ps_validate_sid);
318323
SNAPSHOT_HANDLER(ps_update_timestamp);
319-
#endif
320324

321325
#undef SNAPSHOT_HANDLER
322326
}
@@ -328,13 +332,13 @@ static void frankenphp_restore_session_handlers(void) {
328332
}
329333

330334
/* Restore each handler zval */
331-
#define RESTORE_HANDLER(name) \
332-
if (!Z_ISUNDEF(worker_session_handlers_snapshot->name)) { \
333-
if (!Z_ISUNDEF(PS(mod_user_names).name)) { \
334-
zval_ptr_dtor(&PS(mod_user_names).name); \
335+
#define RESTORE_HANDLER(handler) \
336+
if (!Z_ISUNDEF(worker_session_handlers_snapshot->handler)) { \
337+
if (!Z_ISUNDEF(PS_MOD_USER_NAMES(handler))) { \
338+
zval_ptr_dtor(&PS_MOD_USER_NAMES(handler)); \
335339
} \
336-
ZVAL_COPY(&PS(mod_user_names).name, \
337-
&worker_session_handlers_snapshot->name); \
340+
ZVAL_COPY(&PS_MOD_USER_NAMES(handler), \
341+
&worker_session_handlers_snapshot->handler); \
338342
}
339343

340344
RESTORE_HANDLER(ps_open);
@@ -343,11 +347,9 @@ static void frankenphp_restore_session_handlers(void) {
343347
RESTORE_HANDLER(ps_write);
344348
RESTORE_HANDLER(ps_destroy);
345349
RESTORE_HANDLER(ps_gc);
346-
#if PHP_VERSION_ID >= 80300
347350
RESTORE_HANDLER(ps_create_sid);
348351
RESTORE_HANDLER(ps_validate_sid);
349352
RESTORE_HANDLER(ps_update_timestamp);
350-
#endif
351353

352354
#undef RESTORE_HANDLER
353355
}
@@ -363,9 +365,9 @@ static void frankenphp_cleanup_worker_state(void) {
363365

364366
/* Free session handlers snapshot */
365367
if (worker_session_handlers_snapshot != NULL) {
366-
#define FREE_HANDLER(name) \
367-
if (!Z_ISUNDEF(worker_session_handlers_snapshot->name)) { \
368-
zval_ptr_dtor(&worker_session_handlers_snapshot->name); \
368+
#define FREE_HANDLER(handler) \
369+
if (!Z_ISUNDEF(worker_session_handlers_snapshot->handler)) { \
370+
zval_ptr_dtor(&worker_session_handlers_snapshot->handler); \
369371
}
370372

371373
FREE_HANDLER(ps_open);
@@ -374,11 +376,9 @@ static void frankenphp_cleanup_worker_state(void) {
374376
FREE_HANDLER(ps_write);
375377
FREE_HANDLER(ps_destroy);
376378
FREE_HANDLER(ps_gc);
377-
#if PHP_VERSION_ID >= 80300
378379
FREE_HANDLER(ps_create_sid);
379380
FREE_HANDLER(ps_validate_sid);
380381
FREE_HANDLER(ps_update_timestamp);
381-
#endif
382382

383383
#undef FREE_HANDLER
384384

0 commit comments

Comments
 (0)