From cf3b9fca8fad5a8e9d63b9995c443cb9d25641f5 Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Mon, 24 Jun 2024 19:37:07 +0200 Subject: [PATCH] Sync #if/ifdef/defined (-Wundef) (#14623) These are either define (to value 1) or undefined: - __GNUC__ - DBA_CDB_BUILTIN - DBA_GDBM - HAVE_FORK - HAVE_PUTENV - HAVE_SETENV - HAVE_SYS_SELECT_H - HAVE_SYS_SOCKET_H - HAVE_SYS_WAIT_H - HAVE_UNSETENV - RFC3678_API - ZEND_ENABLE_ZVAL_LONG64 - ZTS Follow-up of GH-5526 --- ext/dba/dba_cdb.c | 32 ++++++++++++++++---------------- ext/dba/dba_dbm.c | 2 +- ext/opcache/ZendAccelerator.c | 2 +- ext/sockets/multicast.c | 2 +- ext/sockets/php_sockets.h | 2 +- ext/standard/basic_functions.c | 2 +- ext/standard/file.c | 2 +- ext/standard/proc_open.c | 8 ++++---- ext/standard/proc_open.h | 2 +- sapi/cgi/cgi_main.c | 12 ++++++------ sapi/cli/php_cli_server.c | 6 +++--- sapi/litespeed/lsapilib.h | 2 +- scripts/phpize.m4 | 2 +- win32/signal.c | 2 +- 14 files changed, 39 insertions(+), 39 deletions(-) diff --git a/ext/dba/dba_cdb.c b/ext/dba/dba_cdb.c index d5af1b8cce2..ac6a2452671 100644 --- a/ext/dba/dba_cdb.c +++ b/ext/dba/dba_cdb.c @@ -30,7 +30,7 @@ #endif #include -#if DBA_CDB_BUILTIN +#ifdef DBA_CDB_BUILTIN # include "libcdb/cdb.h" # include "libcdb/cdb_make.h" # include "libcdb/uint32.h" @@ -45,7 +45,7 @@ typedef struct { struct cdb c; -#if DBA_CDB_BUILTIN +#ifdef DBA_CDB_BUILTIN struct cdb_make m; php_stream *file; int make; @@ -58,7 +58,7 @@ typedef struct { DBA_OPEN_FUNC(cdb) { -#if DBA_CDB_BUILTIN +#ifdef DBA_CDB_BUILTIN php_stream* file = 0; int make; #else @@ -69,7 +69,7 @@ DBA_OPEN_FUNC(cdb) switch (info->mode) { case DBA_READER: -#if DBA_CDB_BUILTIN +#ifdef DBA_CDB_BUILTIN make = 0; file = info->fp; #else @@ -80,7 +80,7 @@ DBA_OPEN_FUNC(cdb) } #endif break; -#if DBA_CDB_BUILTIN +#ifdef DBA_CDB_BUILTIN case DBA_TRUNC: make = 1; file = info->fp; @@ -98,7 +98,7 @@ DBA_OPEN_FUNC(cdb) cdb = pemalloc(sizeof(dba_cdb), info->flags&DBA_PERSISTENT); memset(cdb, 0, sizeof(dba_cdb)); -#if DBA_CDB_BUILTIN +#ifdef DBA_CDB_BUILTIN if (make) { cdb_make_start(&cdb->m, file); } else { @@ -119,7 +119,7 @@ DBA_CLOSE_FUNC(cdb) CDB_INFO; /* cdb_free does not close associated file */ -#if DBA_CDB_BUILTIN +#ifdef DBA_CDB_BUILTIN if (cdb->make) { cdb_make_finish(&cdb->m); } else { @@ -132,7 +132,7 @@ DBA_CLOSE_FUNC(cdb) pefree(cdb, info->flags&DBA_PERSISTENT); } -#if DBA_CDB_BUILTIN +#ifdef DBA_CDB_BUILTIN # define php_cdb_read(cdb, buf, len, pos) cdb_read(cdb, buf, len, pos) # define php_cdb_findnext(cdb, key, len) cdb_findnext(cdb, key, len) # define php_cdb_find(cdb, key, len) cdb_find(cdb, key, len) @@ -148,7 +148,7 @@ DBA_FETCH_FUNC(cdb) zend_string *fetched_val = NULL; unsigned int len; -#if DBA_CDB_BUILTIN +#ifdef DBA_CDB_BUILTIN if (cdb->make) return NULL; /* database was opened writeonly */ #endif @@ -173,7 +173,7 @@ DBA_FETCH_FUNC(cdb) DBA_UPDATE_FUNC(cdb) { -#if DBA_CDB_BUILTIN +#ifdef DBA_CDB_BUILTIN CDB_INFO; if (!cdb->make) @@ -190,7 +190,7 @@ DBA_EXISTS_FUNC(cdb) { CDB_INFO; -#if DBA_CDB_BUILTIN +#ifdef DBA_CDB_BUILTIN if (cdb->make) return FAILURE; /* database was opened writeonly */ #endif @@ -205,7 +205,7 @@ DBA_DELETE_FUNC(cdb) } /* {{{ cdb_file_read */ -#if DBA_CDB_BUILTIN +#ifdef DBA_CDB_BUILTIN # define cdb_file_read(fildes, buf, size) php_stream_read(fildes, buf, size) #else # define cdb_file_read(fildes, buf, size) read(fildes, buf, size) @@ -218,7 +218,7 @@ DBA_DELETE_FUNC(cdb) /* {{{ cdb_file_lseek php_stream_seek does not return actual position */ -#if DBA_CDB_BUILTIN +#ifdef DBA_CDB_BUILTIN zend_off_t cdb_file_lseek(php_stream *fp, zend_off_t offset, int whence) { php_stream_seek(fp, offset, whence); return php_stream_tell(fp); @@ -243,7 +243,7 @@ DBA_FIRSTKEY_FUNC(cdb) char buf[8]; zend_string *key; -#if DBA_CDB_BUILTIN +#ifdef DBA_CDB_BUILTIN if (cdb->make) return NULL; /* database was opened writeonly */ #endif @@ -283,7 +283,7 @@ DBA_NEXTKEY_FUNC(cdb) char buf[8]; zend_string *key; -#if DBA_CDB_BUILTIN +#ifdef DBA_CDB_BUILTIN if (cdb->make) return NULL; /* database was opened writeonly */ #endif @@ -319,7 +319,7 @@ DBA_SYNC_FUNC(cdb) DBA_INFO_FUNC(cdb) { -#if DBA_CDB_BUILTIN +#ifdef DBA_CDB_BUILTIN if (!strcmp(hnd->name, "cdb")) { return estrdup(cdb_version()); } else { diff --git a/ext/dba/dba_dbm.c b/ext/dba/dba_dbm.c index 88a89590827..044d9c156be 100644 --- a/ext/dba/dba_dbm.c +++ b/ext/dba/dba_dbm.c @@ -188,7 +188,7 @@ DBA_SYNC_FUNC(dbm) DBA_INFO_FUNC(dbm) { -#if DBA_GDBM +#ifdef DBA_GDBM if (!strcmp(DBM_VERSION, "GDBM")) { return dba_info_gdbm(hnd, info); diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index 8d45b2ae41b..a5a3f606082 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -2181,7 +2181,7 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type) ZCSG(hits)++; /* TBFixed: may lose one hit */ persistent_script->dynamic_members.hits++; /* see above */ #else -#if ZEND_ENABLE_ZVAL_LONG64 +#ifdef ZEND_ENABLE_ZVAL_LONG64 InterlockedIncrement64(&ZCSG(hits)); InterlockedIncrement64(&persistent_script->dynamic_members.hits); #else diff --git a/ext/sockets/multicast.c b/ext/sockets/multicast.c index 4eefb33b694..6af9a95f615 100644 --- a/ext/sockets/multicast.c +++ b/ext/sockets/multicast.c @@ -560,7 +560,7 @@ static int _php_mcast_source_op( #endif } -#if RFC3678_API +#ifdef RFC3678_API static int _php_source_op_to_rfc3678_op(enum source_op sop) { switch (sop) { diff --git a/ext/sockets/php_sockets.h b/ext/sockets/php_sockets.h index ca9f3babf36..89c613ba430 100644 --- a/ext/sockets/php_sockets.h +++ b/ext/sockets/php_sockets.h @@ -41,7 +41,7 @@ extern zend_module_entry sockets_module_entry; #ifdef PHP_WIN32 #include #else -#if HAVE_SYS_SOCKET_H +#ifdef HAVE_SYS_SOCKET_H #include #endif #endif diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 6e923d20ecb..fee800f7e02 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -122,7 +122,7 @@ typedef struct _user_tick_function_entry { bool calling; } user_tick_function_entry; -#if HAVE_PUTENV +#ifdef HAVE_PUTENV typedef struct { char *putenv_string; char *previous_value; diff --git a/ext/standard/file.c b/ext/standard/file.c index 1d28e5ddf7b..8a3decd5125 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -48,7 +48,7 @@ # ifdef HAVE_SYS_PARAM_H # include # endif -# if HAVE_SYS_SELECT_H +# ifdef HAVE_SYS_SELECT_H # include # endif # include diff --git a/ext/standard/proc_open.c b/ext/standard/proc_open.c index d935f9d216e..f55fbfef568 100644 --- a/ext/standard/proc_open.c +++ b/ext/standard/proc_open.c @@ -232,7 +232,7 @@ static void _php_free_envp(php_process_env env) } /* }}} */ -#if HAVE_SYS_WAIT_H +#ifdef HAVE_SYS_WAIT_H static pid_t waitpid_cached(php_process_handle *proc, int *wait_status, int options) { if (proc->has_cached_exit_wait_status) { @@ -544,7 +544,7 @@ static bool is_special_character_present(const zend_string *arg) return false; } -/* See https://docs.microsoft.com/en-us/cpp/cpp/parsing-cpp-command-line-arguments and +/* See https://docs.microsoft.com/en-us/cpp/cpp/parsing-cpp-command-line-arguments and * https://learn.microsoft.com/en-us/archive/blogs/twistylittlepassagesallalike/everyone-quotes-command-line-arguments-the-wrong-way */ static void append_win_escaped_arg(smart_str *str, zend_string *arg, bool is_cmd_argument) { @@ -1352,7 +1352,7 @@ PHP_FUNCTION(proc_open) php_error_docref(NULL, E_WARNING, "posix_spawn() failed: %s", strerror(r)); goto exit_fail; } -#elif HAVE_FORK +#elif defined(HAVE_FORK) /* the Unix way */ child = fork(); @@ -1414,7 +1414,7 @@ PHP_FUNCTION(proc_open) proc->childHandle = childHandle; #endif proc->env = env; -#if HAVE_SYS_WAIT_H +#ifdef HAVE_SYS_WAIT_H proc->has_cached_exit_wait_status = false; #endif diff --git a/ext/standard/proc_open.h b/ext/standard/proc_open.h index 411e7e3da8c..2dba712f995 100644 --- a/ext/standard/proc_open.h +++ b/ext/standard/proc_open.h @@ -43,7 +43,7 @@ typedef struct _php_process_handle { zend_resource **pipes; zend_string *command; php_process_env env; -#if HAVE_SYS_WAIT_H +#ifdef HAVE_SYS_WAIT_H /* We can only request the status once before it becomes unavailable. * Cache the result so we can request it multiple times. */ int cached_exit_wait_status_value; diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index af5d15f23b7..8901b16d05a 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -595,23 +595,23 @@ static char *sapi_fcgi_getenv(const char *name, size_t name_len) static char *_sapi_cgi_putenv(char *name, size_t name_len, char *value) { -#if !HAVE_SETENV || !HAVE_UNSETENV +#if !defined(HAVE_SETENV) || !defined(HAVE_UNSETENV) size_t len; char *buf; #endif -#if HAVE_SETENV +#ifdef HAVE_SETENV if (value) { setenv(name, value, 1); } #endif -#if HAVE_UNSETENV +#ifdef HAVE_UNSETENV if (!value) { unsetenv(name); } #endif -#if !HAVE_SETENV || !HAVE_UNSETENV +#if !defined(HAVE_SETENV) || !defined(HAVE_UNSETENV) /* if cgi, or fastcgi and not found in fcgi env check the regular environment this leaks, but it's only cgi anyway, we'll fix @@ -623,13 +623,13 @@ static char *_sapi_cgi_putenv(char *name, size_t name_len, char *value) return getenv(name); } #endif -#if !HAVE_SETENV +#if !defined(HAVE_SETENV) if (value) { len = slprintf(buf, len - 1, "%s=%s", name, value); putenv(buf); } #endif -#if !HAVE_UNSETENV +#if !defined(HAVE_UNSETENV) if (!value) { len = slprintf(buf, len - 1, "%s=", name); putenv(buf); diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c index d0b29c09ab6..274d7cd865b 100644 --- a/sapi/cli/php_cli_server.c +++ b/sapi/cli/php_cli_server.c @@ -110,7 +110,7 @@ #define OUTPUT_IS_TTY 1 #define OUTPUT_NOT_TTY 0 -#if HAVE_FORK +#ifdef HAVE_FORK # include static pid_t php_cli_server_master; static pid_t *php_cli_server_workers; @@ -2362,7 +2362,7 @@ static void php_cli_server_dtor(php_cli_server *server) /* {{{ */ if (server->router) { pefree(server->router, 1); } -#if HAVE_FORK +#ifdef HAVE_FORK if (php_cli_server_workers_max > 1 && php_cli_server_workers && getpid() == php_cli_server_master) { @@ -2484,7 +2484,7 @@ static void php_cli_server_startup_workers(void) { return; } -#if HAVE_FORK +#ifdef HAVE_FORK php_cli_server_workers_max = ZEND_ATOL(workers); if (php_cli_server_workers_max > 1) { zend_long php_cli_server_worker; diff --git a/sapi/litespeed/lsapilib.h b/sapi/litespeed/lsapilib.h index b17c92528ac..58850eadb17 100644 --- a/sapi/litespeed/lsapilib.h +++ b/sapi/litespeed/lsapilib.h @@ -418,7 +418,7 @@ int LSAPI_Postfork_Parent(LSAPI_Request * pReq); #define LSAPI_LOG_PID (0x10000) void LSAPI_Log(int flag, const char * fmt, ...) -#if __GNUC__ +#ifdef __GNUC__ __attribute__((format(printf, 2, 3))) #endif ; diff --git a/scripts/phpize.m4 b/scripts/phpize.m4 index 54fab5e01cb..a8b984d5adb 100644 --- a/scripts/phpize.m4 +++ b/scripts/phpize.m4 @@ -100,7 +100,7 @@ old_CPPFLAGS=$CPPFLAGS CPPFLAGS="-I$phpincludedir" AC_EGREP_CPP(php_zts_is_enabled,[ #include
-#if ZTS +#ifdef ZTS php_zts_is_enabled #endif ],[ diff --git a/win32/signal.c b/win32/signal.c index 1207fe1fc09..a2549a45415 100644 --- a/win32/signal.c +++ b/win32/signal.c @@ -97,7 +97,7 @@ PHP_FUNCTION(sapi_windows_set_ctrl_handler) RETURN_THROWS(); } -#if ZTS +#ifdef ZTS if (!tsrm_is_main_thread()) { zend_throw_error(NULL, "CTRL events can only be received on the main thread"); RETURN_THROWS();