Skip to content

Commit 3693ad2

Browse files
authored
Refactor union semun in ext/sysvsem (#13473)
The union semun is always defined in php-src code. Current systems require user to define it manually as done in the ext/sysvsem/sysvsem.c. The conditional checks for HAVE_SEMUN were unused. The PHP 3.0.12 AIX bug bugs.php.net/2149 was fixed by the removal of __GNU_LIBRARY__ check, so this now further simplifies the code. The Autoconf AC_CHECK_TYPES checks if system by any chance has the union semun, and by default defines the HAVE_UNION_SEMUN.
1 parent f75143c commit 3693ad2

File tree

2 files changed

+6
-53
lines changed

2 files changed

+6
-53
lines changed

ext/sysvsem/config.m4

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,9 @@ PHP_ARG_ENABLE([sysvsem],
44
[Enable System V semaphore support])])
55

66
if test "$PHP_SYSVSEM" != "no"; then
7-
PHP_NEW_EXTENSION(sysvsem, sysvsem.c, $ext_shared)
8-
AC_DEFINE(HAVE_SYSVSEM, 1, [ ])
9-
AC_CACHE_CHECK(for union semun,php_cv_semun,
10-
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
11-
#include <sys/types.h>
12-
#include <sys/ipc.h>
13-
#include <sys/sem.h>
14-
]], [[union semun x;]])],[
15-
php_cv_semun=yes
16-
],[
17-
php_cv_semun=no
18-
])
19-
)
20-
if test "$php_cv_semun" = "yes"; then
21-
AC_DEFINE(HAVE_SEMUN, 1, [ ])
22-
else
23-
AC_DEFINE(HAVE_SEMUN, 0, [ ])
24-
fi
7+
PHP_NEW_EXTENSION(sysvsem, sysvsem.c, $ext_shared)
8+
AC_DEFINE(HAVE_SYSVSEM, 1, [ ])
9+
AC_CHECK_TYPES([union semun],,,[#include <sys/types.h>
10+
#include <sys/ipc.h>
11+
#include <sys/sem.h>])
2512
fi

ext/sysvsem/sysvsem.c

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,13 @@
3232
#include "php_sysvsem.h"
3333
#include "ext/standard/info.h"
3434

35-
#if !HAVE_SEMUN
36-
35+
#ifndef HAVE_UNION_SEMUN
3736
union semun {
3837
int val; /* value for SETVAL */
3938
struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */
4039
unsigned short int *array; /* array for GETALL, SETALL */
4140
struct seminfo *__buf; /* buffer for IPC_INFO */
4241
};
43-
44-
#undef HAVE_SEMUN
45-
#define HAVE_SEMUN 1
46-
4742
#endif
4843

4944
/* {{{ sysvsem_module_entry */
@@ -173,12 +168,6 @@ PHP_MINFO_FUNCTION(sysvsem)
173168
}
174169
/* }}} */
175170

176-
#define SETVAL_WANTS_PTR
177-
178-
#if defined(_AIX)
179-
#undef SETVAL_WANTS_PTR
180-
#endif
181-
182171
/* {{{ Return an id for the semaphore with the given key, and allow max_acquire (default 1) processes to acquire it simultaneously */
183172
PHP_FUNCTION(sem_get)
184173
{
@@ -247,24 +236,11 @@ PHP_FUNCTION(sem_get)
247236
/* If we are the only user, then take this opportunity to set the max. */
248237

249238
if (count == 1) {
250-
#if HAVE_SEMUN
251-
/* This is correct for Linux which has union semun. */
252239
union semun semarg;
253240
semarg.val = max_acquire;
254241
if (semctl(semid, SYSVSEM_SEM, SETVAL, semarg) == -1) {
255242
php_error_docref(NULL, E_WARNING, "Failed for key 0x" ZEND_XLONG_FMT ": %s", key, strerror(errno));
256243
}
257-
#elif defined(SETVAL_WANTS_PTR)
258-
/* This is correct for Solaris 2.6 which does not have union semun. */
259-
if (semctl(semid, SYSVSEM_SEM, SETVAL, &max_acquire) == -1) {
260-
php_error_docref(NULL, E_WARNING, "Failed for key 0x%lx: %s", key, strerror(errno));
261-
}
262-
#else
263-
/* This works for i.e. AIX */
264-
if (semctl(semid, SYSVSEM_SEM, SETVAL, max_acquire) == -1) {
265-
php_error_docref(NULL, E_WARNING, "Failed for key 0x%lx: %s", key, strerror(errno));
266-
}
267-
#endif
268244
}
269245

270246
/* Set semaphore 1 back to zero. */
@@ -357,32 +333,22 @@ PHP_FUNCTION(sem_remove)
357333
{
358334
zval *arg_id;
359335
sysvsem_sem *sem_ptr;
360-
#if HAVE_SEMUN
361336
union semun un;
362337
struct semid_ds buf;
363-
#endif
364338

365339
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &arg_id, sysvsem_ce) == FAILURE) {
366340
RETURN_THROWS();
367341
}
368342

369343
sem_ptr = Z_SYSVSEM_P(arg_id);
370344

371-
#if HAVE_SEMUN
372345
un.buf = &buf;
373346
if (semctl(sem_ptr->semid, 0, IPC_STAT, un) < 0) {
374-
#else
375-
if (semctl(sem_ptr->semid, 0, IPC_STAT, NULL) < 0) {
376-
#endif
377347
php_error_docref(NULL, E_WARNING, "SysV semaphore for key 0x%x does not (any longer) exist", sem_ptr->key);
378348
RETURN_FALSE;
379349
}
380350

381-
#if HAVE_SEMUN
382351
if (semctl(sem_ptr->semid, 0, IPC_RMID, un) < 0) {
383-
#else
384-
if (semctl(sem_ptr->semid, 0, IPC_RMID, NULL) < 0) {
385-
#endif
386352
php_error_docref(NULL, E_WARNING, "Failed for SysV semaphore for key 0x%x: %s", sem_ptr->key, strerror(errno));
387353
RETURN_FALSE;
388354
}

0 commit comments

Comments
 (0)