Hi,

this diff allows me to build the php8 bindings for the upcoming
mapserver 8 release, cf
https://github.com/MapServer/MapServer/issues/6201 - patches taken from
upstream swig via fedora
(https://src.fedoraproject.org/rpms/swig/c/62dded8bacb09398b03d1352820636182d2494ab
, pointed out at by the debian mapserver maintainer) - with this i've
mapserver 8.0.0-beta1 ok building php bits.

tests in a bulk would be welcome as i have no idea what havoc enabling
php in swig could cause to consumers.

Landry
? 62dded8bacb09398b03d1352820636182d2494ab
? patch-Doc_Manual_Php_html
? patch-Doc_Manual_Preprocessor_html
? patch-Doc_Manual_SWIG_html
? patch-Examples_Makefile_in
? patch-Examples_test-suite_director_overload2_i
? patch-Examples_test-suite_director_overload_i
? patch-Examples_test-suite_overload_polymorphic_i
? patch-Examples_test-suite_php_director_overload_runme_php
? patch-Examples_test-suite_php_evil_diamond_prop_runme_php
? patch-Examples_test-suite_php_overload_polymorphic_runme_php
? patch-RELEASENOTES
? swig-4.0.2-Fix-char-typecheck-typemap-to-accept-Null.patch
? swig-4.0.2-Fix-overloaded-directed-methods-with-non-void-re.patch
? swig-4.0.2-Improve-PHP-object-creation.patch
? swig-4.0.2-Support-PHP8.patch
Index: Makefile
===================================================================
RCS file: /cvs/ports/devel/swig/Makefile,v
retrieving revision 1.76
diff -u -r1.76 Makefile
--- Makefile    5 May 2022 15:41:56 -0000       1.76
+++ Makefile    26 Jun 2022 20:23:31 -0000
@@ -2,7 +2,7 @@
 
 SUBST_VARS =   VERSION
 VERSION =      4.0.2
-REVISION =     1
+REVISION =     2
 
 DISTNAME =     swig-${VERSION}
 CATEGORIES =   devel
@@ -20,11 +20,13 @@
 
 MODULES =      lang/python \
                lang/ruby \
+               lang/php \
                lang/tcl
 
 MODRUBY_RUNDEP = No
 
 MODPY_RUNDEP = No
+MODPHP_BUILDDEP =      Yes
 
 BUILD_DEPENDS =        ${MODTCL_BUILD_DEPENDS} \
                lang/guile
@@ -36,9 +38,9 @@
                 --with-tcllib=${MODTCL_LIBDIR} \
                 --with-guilelib=${LOCALBASE}/lib \
                 --with-python=${MODPY_BIN} \
+                --with-php=${MODPHP_BIN} \
                 --with-ruby=${RUBY} \
                 --without-mzscheme \
-                --without-php \
                 --without-ocaml
 MODGNU_CONFIG_GUESS_DIRS = ${WRKSRC}/Tools/config
 
Index: patches/patch-Lib_cdata_i
===================================================================
RCS file: patches/patch-Lib_cdata_i
diff -N patches/patch-Lib_cdata_i
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-Lib_cdata_i   26 Jun 2022 20:23:31 -0000
@@ -0,0 +1,15 @@
+backport php 8 support from upstream via
+https://src.fedoraproject.org/rpms/swig/c/62dded8bacb09398b03d1352820636182d2494ab
+
+Index: Lib/cdata.i
+--- Lib/cdata.i.orig
++++ Lib/cdata.i
+@@ -21,7 +21,7 @@ typedef struct SWIGCDATA {
+ }
+ %typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH);
+ 
+-#elif SWIGPHP7
++#elif SWIGPHP
+ 
+ %typemap(out) SWIGCDATA {
+   ZVAL_STRINGL($result, $1.data, $1.len);
Index: patches/patch-Lib_exception_i
===================================================================
RCS file: patches/patch-Lib_exception_i
diff -N patches/patch-Lib_exception_i
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-Lib_exception_i       26 Jun 2022 20:23:31 -0000
@@ -0,0 +1,15 @@
+backport php 8 support from upstream via
+https://src.fedoraproject.org/rpms/swig/c/62dded8bacb09398b03d1352820636182d2494ab
+
+Index: Lib/exception.i
+--- Lib/exception.i.orig
++++ Lib/exception.i
+@@ -12,7 +12,7 @@
+ %insert("runtime") "swigerrors.swg"
+ 
+ 
+-#ifdef SWIGPHP7
++#ifdef SWIGPHP
+ %{
+ #include "zend_exceptions.h"
+ #define SWIG_exception(code, msg) do { zend_throw_exception(NULL, (char*)msg, 
code); goto thrown; } while (0)
Index: patches/patch-Lib_php_php_swg
===================================================================
RCS file: patches/patch-Lib_php_php_swg
diff -N patches/patch-Lib_php_php_swg
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-Lib_php_php_swg       26 Jun 2022 20:23:31 -0000
@@ -0,0 +1,18 @@
+backport php 8 support from upstream via
+https://src.fedoraproject.org/rpms/swig/c/62dded8bacb09398b03d1352820636182d2494ab
+
+Index: Lib/php/php.swg
+--- Lib/php/php.swg.orig
++++ Lib/php/php.swg
+@@ -465,7 +465,10 @@
+ %php_typecheck(double,SWIG_TYPECHECK_DOUBLE,IS_DOUBLE)
+ %php_typecheck(char,SWIG_TYPECHECK_CHAR,IS_STRING)
+ 
+-%typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) char *, char *&, char []
++%typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) char *, char *&
++ " $1 = (Z_TYPE($input) == IS_STRING || Z_TYPE($input) == IS_NULL); "
++
++%typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) char []
+  " $1 = (Z_TYPE($input) == IS_STRING); "
+ 
+ %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE
Index: patches/patch-Lib_php_phprun_swg
===================================================================
RCS file: patches/patch-Lib_php_phprun_swg
diff -N patches/patch-Lib_php_phprun_swg
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-Lib_php_phprun_swg    26 Jun 2022 20:23:31 -0000
@@ -0,0 +1,29 @@
+backport php 8 support from upstream via
+https://src.fedoraproject.org/rpms/swig/c/62dded8bacb09398b03d1352820636182d2494ab
+
+Index: Lib/php/phprun.swg
+--- Lib/php/phprun.swg.orig
++++ Lib/php/phprun.swg
+@@ -12,8 +12,8 @@ extern "C" {
+ #include "zend_exceptions.h"
+ #include "php.h"
+ 
+-#if PHP_MAJOR_VERSION != 7
+-# error These bindings need PHP7 - to generate PHP5 bindings use: SWIG < 
4.0.0 and swig -php5
++#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
+ 
+ #include "ext/standard/php_string.h"
+@@ -204,7 +204,11 @@ SWIG_ConvertPtr(zval *z, void **ptr, swig_type_info *t
+ 
+   switch (Z_TYPE_P(z)) {
+     case IS_OBJECT: {
++#if PHP_MAJOR_VERSION < 8
+       HashTable * ht = Z_OBJ_HT_P(z)->get_properties(z);
++#else
++      HashTable * ht = Z_OBJ_HT_P(z)->get_properties(Z_OBJ_P(z));
++#endif
+       if (ht) {
+         zval * _cPtr = zend_hash_str_find(ht, "_cPtr", sizeof("_cPtr") - 1);
+         if (_cPtr) {
Index: patches/patch-Source_Modules_php_cxx
===================================================================
RCS file: patches/patch-Source_Modules_php_cxx
diff -N patches/patch-Source_Modules_php_cxx
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-Source_Modules_php_cxx        26 Jun 2022 20:23:31 -0000
@@ -0,0 +1,93 @@
+backport php 8 support from upstream via
+https://src.fedoraproject.org/rpms/swig/c/62dded8bacb09398b03d1352820636182d2494ab
+
+Index: Source/Modules/php.cxx
+--- Source/Modules/php.cxx.orig
++++ Source/Modules/php.cxx
+@@ -473,6 +473,20 @@ class PHP : public Language { (public)
+     s_arginfo = NewString("/* arginfo subsection */\n");
+     arginfo_used = NewHash();
+ 
++    // Add arginfo we'll definitely need for *_alter_newobject and 
*_get_newobject.
++    SetFlag(arginfo_used, "1");
++    Append(s_arginfo,
++         "ZEND_BEGIN_ARG_INFO_EX(swig_arginfo_1, 0, 0, 0)\n"
++         " ZEND_ARG_INFO(0,arg1)\n"
++         "ZEND_END_ARG_INFO()\n");
++
++    SetFlag(arginfo_used, "2");
++    Append(s_arginfo,
++         "ZEND_BEGIN_ARG_INFO_EX(swig_arginfo_2, 0, 0, 0)\n"
++         " ZEND_ARG_INFO(0,arg1)\n"
++         " ZEND_ARG_INFO(0,arg2)\n"
++         "ZEND_END_ARG_INFO()\n");
++
+     /* start the function entry section */
+     s_entry = NewString("/* entry subsection */\n");
+ 
+@@ -653,8 +667,8 @@ class PHP : public Language { (public)
+     }
+     Printv(f_begin, s_vdecl, s_wrappers, NIL);
+     Printv(f_begin, all_cs_entry, "\n\n", s_arginfo, "\n\n", s_entry,
+-      " SWIG_ZEND_NAMED_FE(swig_", module, "_alter_newobject,_wrap_swig_", 
module, "_alter_newobject,NULL)\n"
+-      " SWIG_ZEND_NAMED_FE(swig_", module, "_get_newobject,_wrap_swig_", 
module, "_get_newobject,NULL)\n"
++      " SWIG_ZEND_NAMED_FE(swig_", module, "_alter_newobject,_wrap_swig_", 
module, "_alter_newobject,swig_arginfo_2)\n"
++      " SWIG_ZEND_NAMED_FE(swig_", module, "_get_newobject,_wrap_swig_", 
module, "_get_newobject,swig_arginfo_1)\n"
+       " ZEND_FE_END\n};\n\n", NIL);
+     Printv(f_begin, s_init, NIL);
+     Delete(s_header);
+@@ -689,25 +703,46 @@ class PHP : public Language { (public)
+ 
+     // We want to only emit each different arginfo once, as that reduces the
+     // size of both the generated source code and the compiled extension
+-    // module.  To do this, we name the arginfo to encode the number of
+-    // parameters and which (if any) are passed by reference by using a
+-    // sequence of 0s (for non-reference) and 1s (for by references).
++    // module.  The parameters at this level are just named arg1, arg2, etc
++    // so we generate an arginfo name with the number of parameters and a
++    // bitmap value saying which (if any) are passed by reference.
+     ParmList *l = Getattr(n, "parms");
+-    String * arginfo_code = NewStringEmpty();
++    unsigned long bitmap = 0, bit = 1;
++    int n_params = 0;
++    bool overflowed = false;
+     for (Parm *p = l; p; p = Getattr(p, "tmap:in:next")) {
+       /* Ignored parameters */
+       if (checkAttribute(p, "tmap:in:numinputs", "0")) {
+       continue;
+       }
+-      Append(arginfo_code, GetFlag(p, "tmap:in:byref") ? "1" : "0");
++      ++n_params;
++      if (GetFlag(p, "tmap:in:byref")) {
++        bitmap |= bit;
++        if (bit == 0) overflowed = true;
++      }
++      bit <<= 1;
+     }
++    String * arginfo_code;
++    if (overflowed) {
++      // We overflowed the bitmap so just generate a unique name - this only
++      // happens for a function with more parameters than bits in a long
++      // where a high numbered parameter is passed by reference, so should be
++      // rare in practice.
++      static int overflowed_counter = 0;
++      arginfo_code = NewStringf("z%d", ++overflowed_counter);
++    } else if (bitmap == 0) {
++      // No parameters passed by reference.
++      arginfo_code = NewStringf("%d", n_params);
++    } else {
++      arginfo_code = NewStringf("%d_%lx", n_params, bitmap);
++    }
+ 
+     if (!GetFlag(arginfo_used, arginfo_code)) {
+-      // Not had this one before, so emit it.
++      // Not had this one before so emit it.
+       SetFlag(arginfo_used, arginfo_code);
+       Printf(s_arginfo, "ZEND_BEGIN_ARG_INFO_EX(swig_arginfo_%s, 0, 0, 0)\n", 
arginfo_code);
+-      for (const char * p = Char(arginfo_code); *p; ++p) {
+-      Printf(s_arginfo, " ZEND_ARG_PASS_INFO(%c)\n", *p);
++      for (Parm *p = l; p; p = Getattr(p, "tmap:in:next")) {
++      Printf(s_arginfo, " ZEND_ARG_INFO(%d,%s)\n", GetFlag(p, 
"tmap:in:byref"), Getattr(p, "lname"));
+       }
+       Printf(s_arginfo, "ZEND_END_ARG_INFO()\n");
+     }
Index: patches/patch-configure
===================================================================
RCS file: patches/patch-configure
diff -N patches/patch-configure
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-configure     26 Jun 2022 20:23:31 -0000
@@ -0,0 +1,23 @@
+find our php-config-${PHP_VERSION}
+
+Index: configure
+--- configure.orig
++++ configure
+@@ -9924,14 +9924,14 @@ done
+       { $as_echo "$as_me:${as_lineno-$LINENO}: checking for PHP header files" 
>&5
+ $as_echo_n "checking for PHP header files... " >&6; }
+             case $PHP in
+-        *7.*)
+-          PHPCONFIG=`echo "$PHP"|sed 's/7\...*$/-config&/'` ;;
++        *8.*)
++          PHPCONFIG=`echo "$PHP"|sed 's/\(-8\..\)/-config\1/'` ;;
+         *)
+           PHPCONFIG=$PHP-config ;;
+       esac
+       php_version=`$PHPCONFIG --version 2>/dev/null`
+       case $php_version in
+-      7.*)
++      8.*)
+         PHPINC=`$PHPCONFIG --includes 2>/dev/null`
+         if test -n "$PHPINC"; then
+           { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PHPINC" >&5

Reply via email to