Skip to content

Sync #if/ifdef/defined (-Wundef) #14623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions ext/dba/dba_cdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#endif
#include <fcntl.h>

#if DBA_CDB_BUILTIN
#ifdef DBA_CDB_BUILTIN
# include "libcdb/cdb.h"
# include "libcdb/cdb_make.h"
# include "libcdb/uint32.h"
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion ext/dba/dba_dbm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/ZendAccelerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ext/sockets/multicast.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion ext/sockets/php_sockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extern zend_module_entry sockets_module_entry;
#ifdef PHP_WIN32
#include <Winsock2.h>
#else
#if HAVE_SYS_SOCKET_H
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#endif
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/basic_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
# ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
# endif
# if HAVE_SYS_SELECT_H
# ifdef HAVE_SYS_SELECT_H
# include <sys/select.h>
# endif
# include <sys/socket.h>
Expand Down
8 changes: 4 additions & 4 deletions ext/standard/proc_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion ext/standard/proc_open.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions sapi/cgi/cgi_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions sapi/cli/php_cli_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
#define OUTPUT_IS_TTY 1
#define OUTPUT_NOT_TTY 0

#if HAVE_FORK
#ifdef HAVE_FORK
# include <sys/wait.h>
static pid_t php_cli_server_master;
static pid_t *php_cli_server_workers;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 2 additions & 6 deletions sapi/litespeed/lsapilib.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ extern "C" {
#endif

#include "lsapidef.h"
#include "zend_portability.h"

#include <stddef.h>
#include <sys/time.h>
Expand Down Expand Up @@ -417,12 +418,7 @@ int LSAPI_Postfork_Parent(LSAPI_Request * pReq);

#define LSAPI_LOG_PID (0x10000)

void LSAPI_Log(int flag, const char * fmt, ...)
#if __GNUC__
__attribute__((format(printf, 2, 3)))
#endif
;

void LSAPI_Log(int flag, const char * fmt, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be isolated from Zend, I think I prefer what you had before so we don't have unnecessary dependency on Zend if not needed.

Copy link
Member Author

@petk petk Jun 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, added back as it was with only ifdef changed.

I was already thinking about these __attribute__ items and how to improve it. It might fit a bit better together once we add a minimum compiler requirement in the future to rely on __has_attribute feature that comes with GCC 5 and later and clang 2.9 and later (I think). With some other adjustments for some almost obsolete platforms. Because now PHP doesn't have this resolved optimally yet.


#if defined (c_plusplus) || defined (__cplusplus)
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/phpize.m4
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ old_CPPFLAGS=$CPPFLAGS
CPPFLAGS="-I$phpincludedir"
AC_EGREP_CPP(php_zts_is_enabled,[
#include <main/php_config.h>
#if ZTS
#ifdef ZTS
php_zts_is_enabled
#endif
],[
Expand Down
2 changes: 1 addition & 1 deletion win32/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading