summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlly Betts <olly@survex.com>2022-09-28 19:01:01 +1300
committerOlly Betts <olly@survex.com>2022-09-28 19:01:01 +1300
commit246dd2d787ffe7fda72598415e0768482acf053e (patch)
tree1024d580b00553ad981c7fc885296c2b89478726
parent55c95d475cc0deebdc35564aa39875fe03d72c35 (diff)
downloadswig-246dd2d787ffe7fda72598415e0768482acf053e.tar.gz
[php] Workaround PHP 8.2 header problem
We need to include php.h before stdio.h (and probably before most other libc headers).
-rw-r--r--Lib/php/phprun.swg2
-rw-r--r--Source/Modules/php.cxx8
2 files changed, 8 insertions, 2 deletions
diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg
index a81baf001..538b7e165 100644
--- a/Lib/php/phprun.swg
+++ b/Lib/php/phprun.swg
@@ -10,8 +10,6 @@
extern "C" {
#endif
-#include "php.h"
-
#if PHP_MAJOR_VERSION < 7
# error These bindings need PHP 7 or later - to generate PHP5 bindings use: SWIG < 4.0.0 and swig -php5
#endif
diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx
index 37a58d752..a661a0a91 100644
--- a/Source/Modules/php.cxx
+++ b/Source/Modules/php.cxx
@@ -545,6 +545,14 @@ public:
Swig_banner(f_begin);
+ // We need to include php.h before string.h gets included, at least with
+ // PHP 8.2. Otherwise string.h is included without _GNU_SOURCE being
+ // included and memrchr() doesn't get declared, and then inline code in
+ // the PHP headers defines _GNU_SOURCE, includes string.h (which is a
+ // no op thanks to the include gaurds), then tries to use memrchr() and
+ // fails.
+ Append(f_runtime, "#include \"php.h\"\n\n");
+
Printf(f_runtime, "\n\n#ifndef SWIGPHP\n#define SWIGPHP\n#endif\n\n");
if (directorsEnabled()) {