From 246dd2d787ffe7fda72598415e0768482acf053e Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 28 Sep 2022 19:01:01 +1300 Subject: [PATCH] [php] Workaround PHP 8.2 header problem We need to include php.h before stdio.h (and probably before most other libc headers). --- Lib/php/phprun.swg | 2 -- Source/Modules/php.cxx | 8 ++++++++ 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()) {