zend.h breaks system headers on OSX in PHP 5.3

php.internals

Wez Furlong

18 years ago
The system headers on OSX use __attribute__((always_inline)) and zend.h defines always_inline to something else, breaking the build when the compiler tries to resolve that attribute name. A solution is to prefix the defines used in the engine with zend or ZEND or other similar namespacing token, which I thought was our standard practice, considering everything else in there has a prefix. If there have been other similar changes elsewhere, they should also be fixed --Wez. Index: zend.h =================================================================== RCS file: /repository/ZendEngine2/zend.h,v retrieving revision 1.293.2.11.2.9.2.9 diff -u -p -r1.293.2.11.2.9.2.9 zend.h --- zend.h 2 Nov 2007 19:40:37 -0000 1.293.2.11.2.9.2.9 +++ zend.h 7 Nov 2007 04:36:01 -0000 @@ -324,42 +324,42 @@ struct _zval_struct { #define Z_SET_ISREF_TO(z, isref) Z_SET_ISREF_TO_P(&(z), isref) #if defined(__GNUC__) -#define always_inline inline __attribute__((always_inline)) +#define zend_always_inline inline __attribute__((always_inline)) #elif defined(_MSC_VER) -#define always_inline __forceinline +#define zend_always_inline __forceinline #else -#define always_inline inline +#define zend_always_inline inline #endif -static always_inline zend_uint zval_refcount_p(zval* pz) { +static zend_always_inline zend_uint zval_refcount_p(zval* pz) { return pz->refcount__gc; } -static always_inline zend_uint zval_set_refcount_p(zval* pz, zend_uint rc) { +static zend_always_inline zend_uint zval_set_refcount_p(zval* pz, zend_uint rc) { return pz->refcount__gc = rc; } -static always_inline zend_uint zval_addref_p(zval* pz) { +static zend_always_inline zend_uint zval_addref_p(zval* pz) { return ++pz->refcount__gc; } -static always_inline zend_uint zval_delref_p(zval* pz) { +static zend_always_inline zend_uint zval_delref_p(zval* pz) { return --pz->refcount__gc; } -static always_inline zend_bool zval_isref_p(zval* pz) { +static zend_always_inline zend_bool zval_isref_p(zval* pz) { return pz->is_ref__gc; } -static always_inline zend_bool zval_set_isref_p(zval* pz) { +static zend_always_inline zend_bool zval_set_isref_p(zval* pz) { return pz->is_ref__gc = 1; } -static always_inline zend_bool zval_unset_isref_p(zval* pz) { +static zend_always_inline zend_bool zval_unset_isref_p(zval* pz) { return pz->is_ref__gc = 0; } -static always_inline zend_bool zval_set_isref_to_p(zval* pz, zend_bool isref) { +static zend_always_inline zend_bool zval_set_isref_to_p(zval* pz, zend_bool isref) { return pz->is_ref__gc = isref; }

Dmitry Stogov

18 years ago
May be it is better to just define always_inline as inline on OSX. Something like: #if defined(__GNUC__) && !defined(OSX) ... Thanks. Dmitry.

Wez Furlong

18 years ago
This is not an OSX specific issue, it's a symbol leakage issue that can break potentially any library that uses that feature of gcc. I just happened to notice it on OSX. Better to rename our symbols to avoid conflict. --Wez. On Nov 7, 2007, at 2:48 AM, Dmitry Stogov wrote:

Dmitry Stogov

18 years ago
Hi Wez, Could you please give me more info about the issue. What is your GCC version? Does it related to GCC version? What error do you have? Is this problem described somewhere? Thanks. Dmitry.

Wez Furlong

18 years ago
If I instead apply the following patch to zend.h: Index: zend.h =================================================================== RCS file: /repository/ZendEngine2/zend.h,v retrieving revision 1.293.2.11.2.9.2.9 diff -u -p -r1.293.2.11.2.9.2.9 zend.h --- zend.h 2 Nov 2007 19:40:37 -0000 1.293.2.11.2.9.2.9 +++ zend.h 8 Nov 2007 09:00:25 -0000 @@ -331,6 +331,10 @@ struct _zval_struct { #define always_inline inline #endif +static __attribute__((always_inline)) int example(void) { + return 0; +} + static always_inline zend_uint zval_refcount_p(zval* pz) { return pz->refcount__gc; } I get this error when compiling PHP: /bin/sh /Users/wez/code/php/php5.3/libtool --silent --preserve-dup- deps --mode=compile /opt/local/bin/ccache cc -Iext/standard/ -I/Users/ wez/code/php/php5.3/ext/standard/ -DPHP_ATOM_INC -I/Users/wez/code/php/ php5.3/include -I/Users/wez/code/php/php5.3/main -I/Users/wez/code/php/ php5.3 -I/Users/wez/code/php/php5.3/ext/ereg/regex -I/usr/include/ libxml2 -I/Users/wez/code/php/php5.3/ext/date/lib -I/Users/wez/code/ php/php5.3/TSRM -I/Users/wez/code/php/php5.3/Zend -no-cpp-precomp -I/ usr/include -g -O2 -c /Users/wez/code/php/php5.3/ext/standard/info.c - o ext/standard/info.lo In file included from /Users/wez/code/php/php5.3/main/php.h:35, from /Users/wez/code/php/php5.3/ext/standard/info.c: 24: /Users/wez/code/php/php5.3/Zend/zend.h:334: error: syntax error before '__attribute__' /Users/wez/code/php/php5.3/Zend/zend.h:334: error: syntax error before ')' token make: *** [ext/standard/info.lo] Error 1 If I move the example function above the problematic define, the compile error goes away. In other words, that define is breaking the always_inline attribute by redefining it. My compiler: % gcc -v Using built-in specs. Target: i686-apple-darwin9 Configured with: /var/tmp/gcc/gcc-5465~16/src/configure --disable- checking -enable-werror --prefix=/usr --mandir=/share/man --enable- languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/ $/-4.0/ --with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/usr/ lib --build=i686-apple-darwin9 --with-arch=apple --with-tune=generic -- host=i686-apple-darwin9 --target=i686-apple-darwin9 Thread model: posix gcc version 4.0.1 (Apple Inc. build 5465) --Wez On Nov 8, 2007, at 3:11 AM, Dmitry Stogov wrote:

Dmitry Stogov

18 years ago
OK. I agree with your original patch. Could you commit it. Thanks. Dmitry.