Skip to content

Commit

Permalink
Autotools: Sync configure options
Browse files Browse the repository at this point in the history
- AC_ARG_ENABLE replaced with PHP_ARG_ENABLE
- checks sorted
- AS_VAR_IF macros used
- For checking the Valgrind header, the AC_CHECK_HEADERS is used which
  defines the HAVE_VALGRIND_MEMCHECK_H preprocessor macro by default
- The APC_MMAP preprocessor macro is either undefined or defined to 1
  so the `#if` checks are also replaced with `#ifdef` to not cause
  possible -Wundef warnings emitted if such compiler configuration is
  set
  • Loading branch information
petk authored and nikic committed Sep 3, 2024
1 parent cf43c19 commit f7fe4cc
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 62 deletions.
2 changes: 1 addition & 1 deletion apc_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ PHP_APCU_API zend_bool apc_cache_info(zval *info, apc_cache_t *cache, zend_bool
add_assoc_long(info, "start_time", cache->header->stime);
array_add_double(info, apc_str_mem_size, (double) cache->header->mem_size);

#if APC_MMAP
#ifdef APC_MMAP
add_assoc_stringl(info, "memory_type", "mmap", sizeof("mmap")-1);
#else
add_assoc_stringl(info, "memory_type", "IPC shared", sizeof("IPC shared")-1);
Expand Down
2 changes: 1 addition & 1 deletion apc_globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ ZEND_BEGIN_MODULE_GLOBALS(apcu)
zend_long ttl; /* parameter to apc_cache_create */
zend_long smart; /* smart value */

#if APC_MMAP
#ifdef APC_MMAP
char *mmap_file_mask; /* mktemp-style file-mask to pass to mmap */
#endif

Expand Down
2 changes: 1 addition & 1 deletion apc_mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "apc_mmap.h"
#include "apc_lock.h"

#if APC_MMAP
#ifdef APC_MMAP

#include <fcntl.h>
#include <sys/types.h>
Expand Down
2 changes: 1 addition & 1 deletion apc_mmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

/* Wrapper functions for shared memory mapped files */

#if APC_MMAP
#ifdef APC_MMAP
apc_segment_t apc_mmap(char *file_mask, size_t size);
void apc_unmap(apc_segment_t* segment);
#endif
Expand Down
6 changes: 3 additions & 3 deletions apc_sma.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ PHP_APCU_API void apc_sma_init(apc_sma_t* sma, void** data, apc_sma_expunge_f ex
sma->expunge = expunge;
sma->data = data;

#if APC_MMAP
#ifdef APC_MMAP
/*
* I don't think multiple anonymous mmaps makes any sense
* so force sma_numseg to 1 in this case
Expand All @@ -324,7 +324,7 @@ PHP_APCU_API void apc_sma_init(apc_sma_t* sma, void** data, apc_sma_expunge_f ex
block_t *first, *empty, *last;
void* shmaddr;

#if APC_MMAP
#ifdef APC_MMAP
sma->segs[i] = apc_mmap(mask, sma->size);
if(sma->num != 1)
memcpy(&mask[strlen(mask)-6], "XXXXXX", 6);
Expand Down Expand Up @@ -388,7 +388,7 @@ PHP_APCU_API void apc_sma_detach(apc_sma_t* sma) {
sma->initialized = 0;

for (i = 0; i < sma->num; i++) {
#if APC_MMAP
#ifdef APC_MMAP
apc_unmap(&sma->segs[i]);
#else
apc_shm_detach(&sma->segs[i]);
Expand Down
94 changes: 43 additions & 51 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,26 @@ PHP_ARG_ENABLE([apcu-rwlocks],
[yes],
[no])

AC_MSG_CHECKING(if APCu should be built in debug mode)
AC_ARG_ENABLE([apcu-debug],
PHP_ARG_ENABLE([apcu-debug],
[if APCu should be built in debug mode],
[AS_HELP_STRING([--enable-apcu-debug],
[Enable APCu debugging])],
[PHP_APCU_DEBUG=$enableval],
[PHP_APCU_DEBUG=no])
AC_MSG_RESULT($PHP_APCU_DEBUG)
[no],
[no])

AC_MSG_CHECKING(if APCu should clear on SIGUSR1)
AC_ARG_ENABLE([apcu-clear-signal],
PHP_ARG_ENABLE([apcu-clear-signal],
[if APCu should clear on SIGUSR1],
[AS_HELP_STRING([--enable-apcu-clear-signal],
[Enable SIGUSR1 clearing handler])],
[
AC_DEFINE(APC_CLEAR_SIGNAL, 1, [ ])
AC_MSG_RESULT(yes)
],
[
AC_MSG_RESULT(no)
])

PHP_APCU_MMAP=yes
AC_MSG_CHECKING([if APCu will use mmap (or shm)])
AC_ARG_ENABLE([apcu-mmap],
[no],
[no])

PHP_ARG_ENABLE([apcu-mmap],
[if APCu should use mmap instead of shm],
[AS_HELP_STRING([--disable-apcu-mmap],
[Disable mmap, falls back on shm])],
[
if test "x$enableval" = "xno"; then
PHP_APCU_MMAP=no
else
PHP_APCU_MMAP=yes
fi
])
AC_MSG_RESULT($PHP_APCU_MMAP)
[yes],
[no])

PHP_ARG_ENABLE([apcu-spinlocks],
[if APCu should utilize spinlocks before flocks],
Expand All @@ -51,7 +38,37 @@ PHP_ARG_ENABLE([apcu-spinlocks],
[no],
[no])

PHP_ARG_ENABLE([valgrind-checks],
[whether to enable Valgrind-based memory checks],
[AS_HELP_STRING([--disable-valgrind-checks],
[Disable Valgrind-based memory checks])],
[yes],
[no])

PHP_ARG_ENABLE([coverage],
[whether to include code coverage symbols],
[AS_HELP_STRING([--enable-coverage],
[Include code coverage symbols (DEVELOPERS ONLY!!)])],
[no],
[no])

if test "$PHP_APCU" != "no"; then
AS_VAR_IF([PHP_APCU_DEBUG], [no], [],
[AC_DEFINE([APC_DEBUG], [1],
[Define to 1 if APCu debugging mode is enabled.])])

AS_VAR_IF([PHP_APCU_CLEAR_SIGNAL], [no], [],
[AC_DEFINE([APC_CLEAR_SIGNAL], [1],
[Define to 1 if SIGUSR1 clearing handler is enabled.])])

AS_VAR_IF([PHP_APCU_MMAP], [no], [],
[AC_DEFINE([APC_MMAP], [1],
[Define to 1 if APCu uses mmap instead of shm.])])

AS_VAR_IF([PHP_VALGRIND_CHECKS], [no], [],
[AC_CHECK_HEADERS([valgrind/memcheck.h], [],
[AC_MSG_NOTICE([Valgrind-based memory checks are disabled.])])])

AS_VAR_IF([PHP_APCU_RWLOCKS], [no], [], [
AC_CACHE_CHECK([whether the target compiler supports builtin atomics],
[PHP_cv_APCU_GCC_ATOMICS],
Expand All @@ -65,14 +82,6 @@ if test "$PHP_APCU" != "no"; then
[AC_MSG_FAILURE([Compiler does not support atomics])])
])

if test "$PHP_APCU_DEBUG" != "no"; then
AC_DEFINE(APC_DEBUG, 1, [ ])
fi

if test "$PHP_APCU_MMAP" != "no"; then
AC_DEFINE(APC_MMAP, 1, [ ])
fi

if test "$PHP_APCU_RWLOCKS" != "no"; then
orig_LIBS="$LIBS"
LIBS="$LIBS -lpthread"
Expand Down Expand Up @@ -192,16 +201,6 @@ if test "$PHP_APCU" != "no"; then

AC_CHECK_FUNCS(sigaction)

AC_ARG_ENABLE([valgrind-checks],
[AS_HELP_STRING([--disable-valgrind-checks],
[Disable Valgrind based memory checks])],
[PHP_APCU_VALGRIND=no],
[
PHP_APCU_VALGRIND=yes
AC_CHECK_HEADER(valgrind/memcheck.h,
[AC_DEFINE([HAVE_VALGRIND_MEMCHECK_H],1, [enable valgrind memchecks])])
])

for i in -Wall -Wextra -Wno-unused-parameter; do
AX_CHECK_COMPILE_FLAG([$i], [APCU_CFLAGS="$APCU_CFLAGS $i"])
done
Expand All @@ -225,13 +224,6 @@ if test "$PHP_APCU" != "no"; then
AC_DEFINE(HAVE_APCU, 1, [ ])
fi

PHP_ARG_ENABLE([coverage],
[whether to include code coverage symbols],
[AS_HELP_STRING([--enable-coverage],
[Include code coverage symbols (DEVELOPERS ONLY!!)])],
[no],
[no])

if test "$PHP_COVERAGE" = "yes"; then

if test "$GCC" != "yes"; then
Expand Down
8 changes: 4 additions & 4 deletions php_apc.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static void php_apc_init_globals(zend_apcu_globals* apcu_globals)
static PHP_INI_MH(OnUpdateShmSegments) /* {{{ */
{
zend_long shm_segments = ZEND_STRTOL(new_value->val, NULL, 10);
#if APC_MMAP
#ifdef APC_MMAP
if (shm_segments != 1) {
php_error_docref(NULL, E_WARNING, "apc.shm_segments setting ignored in MMAP mode");
}
Expand Down Expand Up @@ -139,7 +139,7 @@ STD_PHP_INI_ENTRY("apc.entries_hint", "4096", PHP_INI_SYSTEM, OnUpdateLong,
STD_PHP_INI_ENTRY("apc.gc_ttl", "3600", PHP_INI_SYSTEM, OnUpdateLong, gc_ttl, zend_apcu_globals, apcu_globals)
STD_PHP_INI_ENTRY("apc.ttl", "0", PHP_INI_SYSTEM, OnUpdateLong, ttl, zend_apcu_globals, apcu_globals)
STD_PHP_INI_ENTRY("apc.smart", "0", PHP_INI_SYSTEM, OnUpdateLong, smart, zend_apcu_globals, apcu_globals)
#if APC_MMAP
#ifdef APC_MMAP
STD_PHP_INI_ENTRY("apc.mmap_file_mask", NULL, PHP_INI_SYSTEM, OnUpdateString, mmap_file_mask, zend_apcu_globals, apcu_globals)
#endif
STD_PHP_INI_BOOLEAN("apc.enable_cli", "0", PHP_INI_SYSTEM, OnUpdateBool, enable_cli, zend_apcu_globals, apcu_globals)
Expand Down Expand Up @@ -168,7 +168,7 @@ static PHP_MINFO_FUNCTION(apcu)
#else
php_info_print_table_row(2, "APCu Debugging", "Disabled");
#endif
#if APC_MMAP
#ifdef APC_MMAP
php_info_print_table_row(2, "MMAP Support", "Enabled");
php_info_print_table_row(2, "MMAP File Mask", APCG(mmap_file_mask));
#else
Expand Down Expand Up @@ -235,7 +235,7 @@ static PHP_MINIT_FUNCTION(apcu)
if (APCG(enabled)) {

if (!APCG(initialized)) {
#if APC_MMAP
#ifdef APC_MMAP
char *mmap_file_mask = APCG(mmap_file_mask);
#else
char *mmap_file_mask = NULL;
Expand Down

0 comments on commit f7fe4cc

Please sign in to comment.