Skip to content

Commit c1101a4

Browse files
committed
Don't include system headers in php_config.h
Configuration headers (config.h, etc.), as their name implies, are supposed to contain macro definitions to avoid having them to pass on the command line[1]. It seems fine if they include other configuration headers when needed. In any way, they are supposed to be included very early in compilation units which require them. Doing more than defining simple macros, possibly guarded by defines set during compile time (such as a compiler or platform identification), can lead to subtle issues, which may go unnoticed such as the fallback definitions in the hard-coded (!) fpm_config.h, which may actually be used unconditionally, because the appropriate system headers have not already been included. [1] <https://www.gnu.org/software/autoconf/manual/autoconf-2.72/html_node/Configuration-Headers.html>
1 parent 4ef1c5f commit c1101a4

File tree

6 files changed

+48
-28
lines changed

6 files changed

+48
-28
lines changed

TSRM/TSRM.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,27 @@
1616
#if !defined(__CYGWIN__) && defined(_WIN32)
1717
# define TSRM_WIN32
1818
# include <Zend/zend_config.w32.h>
19+
# define _CRTDBG_MAP_ALLOC
20+
# include <malloc.h>
21+
# include <stdlib.h>
22+
# include <crtdbg.h>
23+
# include <string.h>
24+
# ifndef ZEND_INCLUDE_FULL_WINDOWS_HEADERS
25+
# define WIN32_LEAN_AND_MEAN
26+
# endif
27+
# include <winsock2.h>
28+
# include <windows.h>
29+
# include <float.h>
1930
#else
2031
# include <main/php_config.h>
32+
# include <stdlib.h>
33+
# ifdef HAVE_SYS_TYPES_H
34+
# include <sys/types.h>
35+
# endif
36+
# ifdef HAVE_SYS_SELECT_H
37+
# include <sys/select.h>
38+
# endif
39+
# include <string.h>
2140
#endif
2241

2342
#include <stdint.h>

Zend/zend.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,32 @@
2424

2525
#define ZEND_ENGINE_3
2626

27+
#if !defined(__CYGWIN__) && defined(_WIN32)
28+
# define TSRM_WIN32
29+
# include <Zend/zend_config.w32.h>
30+
# define _CRTDBG_MAP_ALLOC
31+
# include <malloc.h>
32+
# include <stdlib.h>
33+
# include <crtdbg.h>
34+
# include <string.h>
35+
# ifndef ZEND_INCLUDE_FULL_WINDOWS_HEADERS
36+
# define WIN32_LEAN_AND_MEAN
37+
# endif
38+
# include <winsock2.h>
39+
# include <windows.h>
40+
# include <float.h>
41+
#else
42+
# include <main/php_config.h>
43+
# include <stdlib.h>
44+
# ifdef HAVE_SYS_TYPES_H
45+
# include <sys/types.h>
46+
# endif
47+
# ifdef HAVE_SYS_SELECT_H
48+
# include <sys/select.h>
49+
# endif
50+
# include <string.h>
51+
#endif
52+
2753
#include "zend_types.h"
2854
#include "zend_map_ptr.h"
2955
#include "zend_errors.h"

Zend/zend_config.w32.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,6 @@
2222

2323
#include <../main/config.w32.h>
2424

25-
#define _CRTDBG_MAP_ALLOC
26-
27-
#include <malloc.h>
28-
#include <stdlib.h>
29-
#include <crtdbg.h>
30-
31-
#include <string.h>
32-
33-
#ifndef ZEND_INCLUDE_FULL_WINDOWS_HEADERS
34-
#define WIN32_LEAN_AND_MEAN
35-
#endif
36-
#include <winsock2.h>
37-
#include <windows.h>
38-
39-
#include <float.h>
40-
4125
#if _MSC_VER < 1900
4226
#define snprintf _snprintf
4327
#endif

configure.ac

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,6 @@ AH_TOP([
4343
#define ZEND_DLIMPORT
4444
])
4545
AH_BOTTOM([
46-
#include <stdlib.h>
47-
48-
#ifdef HAVE_SYS_TYPES_H
49-
# include <sys/types.h>
50-
#endif
51-
52-
#ifdef HAVE_SYS_SELECT_H
53-
#include <sys/select.h>
54-
#endif
55-
56-
#include <string.h>
57-
5846
#endif /* PHP_CONFIG_H */
5947
])
6048

sapi/fpm/fpm/fpm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#ifndef FPM_H
44
#define FPM_H 1
55

6+
#include <zend.h>
67
#include <unistd.h>
78

89
#ifdef HAVE_SYSEXITS_H

sapi/fpm/fpm/fpm_events.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#ifndef FPM_EVENTS_H
44
#define FPM_EVENTS_H 1
55

6+
#include <zend.h>
7+
68
#define FPM_EV_TIMEOUT (1 << 0)
79
#define FPM_EV_READ (1 << 1)
810
#define FPM_EV_PERSIST (1 << 2)

0 commit comments

Comments
 (0)