Skip to content

Commit 470f589

Browse files
committed
Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2: Avoid dependency on "struct flock" fields order.
2 parents b71146b + 9222702 commit 470f589

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
@@ -236,11 +236,12 @@ static inline void accel_restart_enter(void)
236236
#ifdef ZEND_WIN32
237237
INCREMENT(restart_in);
238238
#else
239-
# ifdef _AIX
240-
static FLOCK_STRUCTURE(restart_in_progress, F_WRLCK, SEEK_SET, 2, 1);
241-
# else
242-
static const FLOCK_STRUCTURE(restart_in_progress, F_WRLCK, SEEK_SET, 2, 1);
243-
#endif
239+
struct flock restart_in_progress;
240+
241+
restart_in_progress.l_type = F_WRLCK;
242+
restart_in_progress.l_whence = SEEK_SET;
243+
restart_in_progress.l_start = 2;
244+
restart_in_progress.l_len = 1;
244245

245246
if (fcntl(lock_file, F_SETLK, &restart_in_progress) == -1) {
246247
zend_accel_error(ACCEL_LOG_DEBUG, "RestartC(+1): %s (%d)", strerror(errno), errno);
@@ -255,11 +256,12 @@ static inline void accel_restart_leave(void)
255256
ZCSG(restart_in_progress) = 0;
256257
DECREMENT(restart_in);
257258
#else
258-
# ifdef _AIX
259-
static FLOCK_STRUCTURE(restart_finished, F_UNLCK, SEEK_SET, 2, 1);
260-
# else
261-
static const FLOCK_STRUCTURE(restart_finished, F_UNLCK, SEEK_SET, 2, 1);
262-
# endif
259+
struct flock restart_finished;
260+
261+
restart_finished.l_type = F_UNLCK;
262+
restart_finished.l_whence = SEEK_SET;
263+
restart_finished.l_start = 2;
264+
restart_finished.l_len = 1;
263265

264266
ZCSG(restart_in_progress) = 0;
265267
if (fcntl(lock_file, F_SETLK, &restart_finished) == -1) {
@@ -272,7 +274,12 @@ static inline int accel_restart_is_active(void)
272274
{
273275
if (ZCSG(restart_in_progress)) {
274276
#ifndef ZEND_WIN32
275-
FLOCK_STRUCTURE(restart_check, F_WRLCK, SEEK_SET, 2, 1);
277+
struct flock restart_check;
278+
279+
restart_check.l_type = F_WRLCK;
280+
restart_check.l_whence = SEEK_SET;
281+
restart_check.l_start = 2;
282+
restart_check.l_len = 1;
276283

277284
if (fcntl(lock_file, F_GETLK, &restart_check) == -1) {
278285
zend_accel_error(ACCEL_LOG_DEBUG, "RestartC: %s (%d)", strerror(errno), errno);
@@ -297,11 +304,12 @@ static inline int accel_activate_add(void)
297304
#ifdef ZEND_WIN32
298305
INCREMENT(mem_usage);
299306
#else
300-
# ifdef _AIX
301-
static FLOCK_STRUCTURE(mem_usage_lock, F_RDLCK, SEEK_SET, 1, 1);
302-
# else
303-
static const FLOCK_STRUCTURE(mem_usage_lock, F_RDLCK, SEEK_SET, 1, 1);
304-
# endif
307+
struct flock mem_usage_lock;
308+
309+
mem_usage_lock.l_type = F_RDLCK;
310+
mem_usage_lock.l_whence = SEEK_SET;
311+
mem_usage_lock.l_start = 1;
312+
mem_usage_lock.l_len = 1;
305313

306314
if (fcntl(lock_file, F_SETLK, &mem_usage_lock) == -1) {
307315
zend_accel_error(ACCEL_LOG_DEBUG, "UpdateC(+1): %s (%d)", strerror(errno), errno);
@@ -320,11 +328,12 @@ static inline void accel_deactivate_sub(void)
320328
ZCG(counted) = 0;
321329
}
322330
#else
323-
# ifdef _AIX
324-
static FLOCK_STRUCTURE(mem_usage_unlock, F_UNLCK, SEEK_SET, 1, 1);
325-
# else
326-
static const FLOCK_STRUCTURE(mem_usage_unlock, F_UNLCK, SEEK_SET, 1, 1);
327-
# endif
331+
struct flock mem_usage_unlock;
332+
333+
mem_usage_unlock.l_type = F_UNLCK;
334+
mem_usage_unlock.l_whence = SEEK_SET;
335+
mem_usage_unlock.l_start = 1;
336+
mem_usage_unlock.l_len = 1;
328337

329338
if (fcntl(lock_file, F_SETLK, &mem_usage_unlock) == -1) {
330339
zend_accel_error(ACCEL_LOG_DEBUG, "UpdateC(-1): %s (%d)", strerror(errno), errno);
@@ -337,11 +346,12 @@ static inline void accel_unlock_all(void)
337346
#ifdef ZEND_WIN32
338347
accel_deactivate_sub();
339348
#else
340-
# ifdef _AIX
341-
static FLOCK_STRUCTURE(mem_usage_unlock_all, F_UNLCK, SEEK_SET, 0, 0);
342-
# else
343-
static const FLOCK_STRUCTURE(mem_usage_unlock_all, F_UNLCK, SEEK_SET, 0, 0);
344-
# endif
349+
struct flock mem_usage_unlock_all;
350+
351+
mem_usage_unlock_all.l_type = F_UNLCK;
352+
mem_usage_unlock_all.l_whence = SEEK_SET;
353+
mem_usage_unlock_all.l_start = 0;
354+
mem_usage_unlock_all.l_len = 0;
345355

346356
if (fcntl(lock_file, F_SETLK, &mem_usage_unlock_all) == -1) {
347357
zend_accel_error(ACCEL_LOG_DEBUG, "UnlockAll: %s (%d)", strerror(errno), errno);
@@ -830,8 +840,12 @@ static inline int accel_is_inactive(void)
830840
return SUCCESS;
831841
}
832842
#else
833-
FLOCK_STRUCTURE(mem_usage_check, F_WRLCK, SEEK_SET, 1, 1);
843+
struct flock mem_usage_check;
834844

845+
mem_usage_check.l_type = F_WRLCK;
846+
mem_usage_check.l_whence = SEEK_SET;
847+
mem_usage_check.l_start = 1;
848+
mem_usage_check.l_len = 1;
835849
mem_usage_check.l_pid = -1;
836850
if (fcntl(lock_file, F_GETLK, &mem_usage_check) == -1) {
837851
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(HAVE_OPCACHE_FILE_CACHE) && defined(ZEND_WIN32)

ext/opcache/config.m4

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

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

ext/opcache/zend_shared_alloc.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -375,15 +375,15 @@ void zend_shared_alloc_safe_unlock(void)
375375
}
376376
}
377377

378-
#ifndef ZEND_WIN32
379-
/* name l_type l_whence l_start l_len */
380-
static FLOCK_STRUCTURE(mem_write_lock, F_WRLCK, SEEK_SET, 0, 1);
381-
static FLOCK_STRUCTURE(mem_write_unlock, F_UNLCK, SEEK_SET, 0, 1);
382-
#endif
383-
384378
void zend_shared_alloc_lock(void)
385379
{
386380
#ifndef ZEND_WIN32
381+
struct flock mem_write_lock;
382+
383+
mem_write_lock.l_type = F_WRLCK;
384+
mem_write_lock.l_whence = SEEK_SET;
385+
mem_write_lock.l_start = 0;
386+
mem_write_lock.l_len = 1;
387387

388388
#ifdef ZTS
389389
tsrm_mutex_lock(zts_lock);
@@ -414,6 +414,15 @@ void zend_shared_alloc_lock(void)
414414

415415
void zend_shared_alloc_unlock(void)
416416
{
417+
#ifndef ZEND_WIN32
418+
struct flock mem_write_unlock;
419+
420+
mem_write_unlock.l_type = F_UNLCK;
421+
mem_write_unlock.l_whence = SEEK_SET;
422+
mem_write_unlock.l_start = 0;
423+
mem_write_unlock.l_len = 1;
424+
#endif
425+
417426
ZCG(locked) = 0;
418427

419428
#ifndef ZEND_WIN32

0 commit comments

Comments
 (0)