Skip to content

Commit 26e2696

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Avoid dependency on "struct flock" fields order.
2 parents 8724f9b + 470f589 commit 26e2696

File tree

4 files changed

+56
-103
lines changed

4 files changed

+56
-103
lines changed

ext/opcache/ZendAccelerator.c

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,12 @@ static inline void accel_restart_enter(void)
238238
#ifdef ZEND_WIN32
239239
INCREMENT(restart_in);
240240
#else
241-
# ifdef _AIX
242-
static FLOCK_STRUCTURE(restart_in_progress, F_WRLCK, SEEK_SET, 2, 1);
243-
# else
244-
static const FLOCK_STRUCTURE(restart_in_progress, F_WRLCK, SEEK_SET, 2, 1);
245-
#endif
241+
struct flock restart_in_progress;
242+
243+
restart_in_progress.l_type = F_WRLCK;
244+
restart_in_progress.l_whence = SEEK_SET;
245+
restart_in_progress.l_start = 2;
246+
restart_in_progress.l_len = 1;
246247

247248
if (fcntl(lock_file, F_SETLK, &restart_in_progress) == -1) {
248249
zend_accel_error(ACCEL_LOG_DEBUG, "RestartC(+1): %s (%d)", strerror(errno), errno);
@@ -257,11 +258,12 @@ static inline void accel_restart_leave(void)
257258
ZCSG(restart_in_progress) = 0;
258259
DECREMENT(restart_in);
259260
#else
260-
# ifdef _AIX
261-
static FLOCK_STRUCTURE(restart_finished, F_UNLCK, SEEK_SET, 2, 1);
262-
# else
263-
static const FLOCK_STRUCTURE(restart_finished, F_UNLCK, SEEK_SET, 2, 1);
264-
# endif
261+
struct flock restart_finished;
262+
263+
restart_finished.l_type = F_UNLCK;
264+
restart_finished.l_whence = SEEK_SET;
265+
restart_finished.l_start = 2;
266+
restart_finished.l_len = 1;
265267

266268
ZCSG(restart_in_progress) = 0;
267269
if (fcntl(lock_file, F_SETLK, &restart_finished) == -1) {
@@ -274,7 +276,12 @@ static inline int accel_restart_is_active(void)
274276
{
275277
if (ZCSG(restart_in_progress)) {
276278
#ifndef ZEND_WIN32
277-
FLOCK_STRUCTURE(restart_check, F_WRLCK, SEEK_SET, 2, 1);
279+
struct flock restart_check;
280+
281+
restart_check.l_type = F_WRLCK;
282+
restart_check.l_whence = SEEK_SET;
283+
restart_check.l_start = 2;
284+
restart_check.l_len = 1;
278285

279286
if (fcntl(lock_file, F_GETLK, &restart_check) == -1) {
280287
zend_accel_error(ACCEL_LOG_DEBUG, "RestartC: %s (%d)", strerror(errno), errno);
@@ -299,11 +306,12 @@ static inline int accel_activate_add(void)
299306
#ifdef ZEND_WIN32
300307
INCREMENT(mem_usage);
301308
#else
302-
# ifdef _AIX
303-
static FLOCK_STRUCTURE(mem_usage_lock, F_RDLCK, SEEK_SET, 1, 1);
304-
# else
305-
static const FLOCK_STRUCTURE(mem_usage_lock, F_RDLCK, SEEK_SET, 1, 1);
306-
# endif
309+
struct flock mem_usage_lock;
310+
311+
mem_usage_lock.l_type = F_RDLCK;
312+
mem_usage_lock.l_whence = SEEK_SET;
313+
mem_usage_lock.l_start = 1;
314+
mem_usage_lock.l_len = 1;
307315

308316
if (fcntl(lock_file, F_SETLK, &mem_usage_lock) == -1) {
309317
zend_accel_error(ACCEL_LOG_DEBUG, "UpdateC(+1): %s (%d)", strerror(errno), errno);
@@ -322,11 +330,12 @@ static inline void accel_deactivate_sub(void)
322330
ZCG(counted) = 0;
323331
}
324332
#else
325-
# ifdef _AIX
326-
static FLOCK_STRUCTURE(mem_usage_unlock, F_UNLCK, SEEK_SET, 1, 1);
327-
# else
328-
static const FLOCK_STRUCTURE(mem_usage_unlock, F_UNLCK, SEEK_SET, 1, 1);
329-
# endif
333+
struct flock mem_usage_unlock;
334+
335+
mem_usage_unlock.l_type = F_UNLCK;
336+
mem_usage_unlock.l_whence = SEEK_SET;
337+
mem_usage_unlock.l_start = 1;
338+
mem_usage_unlock.l_len = 1;
330339

331340
if (fcntl(lock_file, F_SETLK, &mem_usage_unlock) == -1) {
332341
zend_accel_error(ACCEL_LOG_DEBUG, "UpdateC(-1): %s (%d)", strerror(errno), errno);
@@ -339,11 +348,12 @@ static inline void accel_unlock_all(void)
339348
#ifdef ZEND_WIN32
340349
accel_deactivate_sub();
341350
#else
342-
# ifdef _AIX
343-
static FLOCK_STRUCTURE(mem_usage_unlock_all, F_UNLCK, SEEK_SET, 0, 0);
344-
# else
345-
static const FLOCK_STRUCTURE(mem_usage_unlock_all, F_UNLCK, SEEK_SET, 0, 0);
346-
# endif
351+
struct flock mem_usage_unlock_all;
352+
353+
mem_usage_unlock_all.l_type = F_UNLCK;
354+
mem_usage_unlock_all.l_whence = SEEK_SET;
355+
mem_usage_unlock_all.l_start = 0;
356+
mem_usage_unlock_all.l_len = 0;
347357

348358
if (fcntl(lock_file, F_SETLK, &mem_usage_unlock_all) == -1) {
349359
zend_accel_error(ACCEL_LOG_DEBUG, "UnlockAll: %s (%d)", strerror(errno), errno);
@@ -812,8 +822,12 @@ static inline int accel_is_inactive(void)
812822
return SUCCESS;
813823
}
814824
#else
815-
FLOCK_STRUCTURE(mem_usage_check, F_WRLCK, SEEK_SET, 1, 1);
825+
struct flock mem_usage_check;
816826

827+
mem_usage_check.l_type = F_WRLCK;
828+
mem_usage_check.l_whence = SEEK_SET;
829+
mem_usage_check.l_start = 1;
830+
mem_usage_check.l_len = 1;
817831
mem_usage_check.l_pid = -1;
818832
if (fcntl(lock_file, F_GETLK, &mem_usage_check) == -1) {
819833
zend_accel_error(ACCEL_LOG_DEBUG, "UpdateC: %s (%d)", strerror(errno), errno);

ext/opcache/ZendAccelerator.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,6 @@
8989
/*** file locking ***/
9090
#ifndef ZEND_WIN32
9191
extern int lock_file;
92-
93-
# if defined(HAVE_FLOCK_AIX64)
94-
# define FLOCK_STRUCTURE(name, type, whence, start, len) \
95-
struct flock name = {type, whence, 0, 0, 0, start, len }
96-
# elif defined(HAVE_FLOCK_BSD)
97-
# define FLOCK_STRUCTURE(name, type, whence, start, len) \
98-
struct flock name = {start, len, -1, type, whence}
99-
# elif defined(HAVE_FLOCK_LINUX)
100-
# define FLOCK_STRUCTURE(name, type, whence, start, len) \
101-
struct flock name = {type, whence, start, len}
102-
# else
103-
# error "Don't know how to define struct flock"
104-
# endif
10592
#endif
10693

10794
#if defined(ZEND_WIN32)

ext/opcache/config.m4

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -334,63 +334,6 @@ int main() {
334334
msg=yes],[msg=no],[msg=no])
335335
AC_MSG_RESULT([$msg])
336336

337-
flock_type=unknown
338-
AC_MSG_CHECKING(for struct flock layout)
339-
340-
if test "$flock_type" = "unknown"; then
341-
AC_RUN_IFELSE([AC_LANG_SOURCE([[
342-
#include <fcntl.h>
343-
struct flock lock = { 1, 2, 3, 4, 5, 6, 7 };
344-
int main() {
345-
if(lock.l_type == 1 && lock.l_whence == 2 && lock.l_start == 6 && lock.l_len== 7) {
346-
return 0;
347-
}
348-
return 1;
349-
}
350-
]])], [
351-
flock_type=aix64
352-
AC_DEFINE([HAVE_FLOCK_AIX64], [], [Struct flock is 64-bit AIX-type])
353-
], [])
354-
fi
355-
356-
if test "$flock_type" = "unknown"; then
357-
AC_RUN_IFELSE([AC_LANG_SOURCE([[
358-
#include <fcntl.h>
359-
struct flock lock = { 1, 2, 3, 4, 5 };
360-
int main() {
361-
if(lock.l_type == 1 && lock.l_whence == 2 && lock.l_start == 3 && lock.l_len == 4) {
362-
return 0;
363-
}
364-
return 1;
365-
}
366-
]])], [
367-
flock_type=linux
368-
AC_DEFINE([HAVE_FLOCK_LINUX], [], [Struct flock is Linux-type])
369-
], [])
370-
fi
371-
372-
if test "$flock_type" = "unknown"; then
373-
AC_RUN_IFELSE([AC_LANG_SOURCE([[
374-
#include <fcntl.h>
375-
struct flock lock = { 1, 2, 3, 4, 5 };
376-
int main() {
377-
if(lock.l_start == 1 && lock.l_len == 2 && lock.l_type == 4 && lock.l_whence == 5) {
378-
return 0;
379-
}
380-
return 1;
381-
}
382-
]])], [
383-
flock_type=bsd
384-
AC_DEFINE([HAVE_FLOCK_BSD], [], [Struct flock is BSD-type])
385-
], [])
386-
fi
387-
388-
AC_MSG_RESULT([$flock_type])
389-
390-
if test "$flock_type" = "unknown"; then
391-
AC_MSG_ERROR([Don't know how to define struct flock on this system[,] set --enable-opcache=no])
392-
fi
393-
394337
PHP_NEW_EXTENSION(opcache,
395338
ZendAccelerator.c \
396339
zend_accelerator_blacklist.c \

ext/opcache/zend_shared_alloc.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -435,15 +435,15 @@ void zend_shared_alloc_safe_unlock(void)
435435
}
436436
}
437437

438-
#ifndef ZEND_WIN32
439-
/* name l_type l_whence l_start l_len */
440-
static FLOCK_STRUCTURE(mem_write_lock, F_WRLCK, SEEK_SET, 0, 1);
441-
static FLOCK_STRUCTURE(mem_write_unlock, F_UNLCK, SEEK_SET, 0, 1);
442-
#endif
443-
444438
void zend_shared_alloc_lock(void)
445439
{
446440
#ifndef ZEND_WIN32
441+
struct flock mem_write_lock;
442+
443+
mem_write_lock.l_type = F_WRLCK;
444+
mem_write_lock.l_whence = SEEK_SET;
445+
mem_write_lock.l_start = 0;
446+
mem_write_lock.l_len = 1;
447447

448448
#ifdef ZTS
449449
tsrm_mutex_lock(zts_lock);
@@ -474,6 +474,15 @@ void zend_shared_alloc_lock(void)
474474

475475
void zend_shared_alloc_unlock(void)
476476
{
477+
#ifndef ZEND_WIN32
478+
struct flock mem_write_unlock;
479+
480+
mem_write_unlock.l_type = F_UNLCK;
481+
mem_write_unlock.l_whence = SEEK_SET;
482+
mem_write_unlock.l_start = 0;
483+
mem_write_unlock.l_len = 1;
484+
#endif
485+
477486
ZCG(locked) = 0;
478487

479488
#ifndef ZEND_WIN32

0 commit comments

Comments
 (0)