Package: swig
Version: 4.5.1-2
Severity: important
Tags: ftbfs patch
Control: tags -1 + fixed-upstream
Control: affects -1 + src:mapserver
Control: block 1149581 by -1

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Hi,

the PHP wrapper code that swig 4.5.1-2 generates does not compile with
PHP 8.6, which is in experimental and becomes the default in unstable
with the php8.6 transition (#1149581).  The generated code uses names
that PHP 8.6 removed: XtOffsetOf(), WRONG_PARAM_COUNT, ZEND_RESULT_CODE
and zval_is_true().

mapserver (php-mapscript-ng) fails to build because of it:

  mapscriptPHP7_wrap.c:960:48: error: implicit declaration of function 
'XtOffsetOf'; did you mean 'offsetof'?
  mapscriptPHP7_wrap.c:5014:5: error: 'WRONG_PARAM_COUNT' undeclared (first use 
in this function)
  mapscriptPHP7_wrap.c:57505:8: error: unknown type name 'ZEND_RESULT_CODE'; 
did you mean 'ZEND_USER_CODE'?

Upstream fixed the code generator after 4.5.1, in two commits that are
not in a release yet:

  https://github.com/swig/swig/commit/3a390b63aa71e567e062980e13cae079af8eadb4
    [PHP] Update generated code for PHP 8.6
  https://github.com/swig/swig/commit/788dabc1561374369585b93362bcf8a8f774b97d
    [PHP] Add missing block in generated code

The attached patch is both commits with a DEP-3 header, without the
CHANGES.current hunk.  They apply to 4.5.1 unchanged.  What they switch
to exists in PHP 8.0 and later, so the generated code still compiles
with PHP 8.4.

Tested in sbuild chroots:

  * swig 4.5.1-2 with the patch builds with php8.6 8.6.0-3 and
    php-defaults 108~exp2 from experimental.

  * SWIG's PHP test suite (make check-php-test-suite), run in that
    chroot with PHP 8.6.0: 732 of 739 cases pass.  None of the 7 failures
    is about the generated code.  Six need boost/shared_ptr.hpp, which
    was not installed, and li_constraints fails because its test script
    calls doubleval(), which PHP 8.6 deprecates.

  * mapserver 8.6.6-1, unchanged, builds against the patched swig with
    PHP 8.6, and with php8.4 8.4.28-3 in unstable.  mapserver has no PHP
    tests, so I ran a small script against the built module in both
    (load it, build and draw a map, wrong argument counts and types): all
    18 checks pass.

Once swig is fixed, mapserver only needs a rebuild.


- -- System Information:
Debian Release: 13.8
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable-security'), (500, 
'stable-debug'), (500, 'proposed-updates'), (500, 'stable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 6.12.117+deb13-amd64 (SMP w/12 CPU threads; PREEMPT)
Locale: LANG=en_IE.UTF-8, LC_CTYPE=en_IE.UTF-8 (charmap=UTF-8), 
LANGUAGE=en_IE:en
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)

-----BEGIN PGP SIGNATURE-----

iQKTBAEBCgB9FiEEw2Gx4wKVQ+vGJel9g3Kkd++uWcIFAmsKtgxfFIAAAAAALgAo
aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldEMz
NjFCMUUzMDI5NTQzRUJDNjI1RTk3RDgzNzJBNDc3RUZBRTU5QzIACgkQg3Kkd++u
WcJAMhAAp63Qp9a0iW1dcVHX4qt5x30FMRA2ItgZcEyVjIvaQYrKn2ppmSIfbJKN
inGk53xaQygzgOa4PyzBnD2BjyNEgTU/2bKP4CBY01ncDm0TjZhSOhXu9iNpykPM
0+GXqJ000Y1Jh5xYAyyH/4RhzfLfhRh0DxO0zDSKU4/PxQbfOpua8pmkK2rrx+Sl
KaJcwo9Yy+pYOEZp4VWGBfW/1vISVBnpzZHONnldo4fd/HskLKiegHFKMqtSjkHQ
MWDI0T3as2UO3mA0Ji9jCy8XINE8bXx5cJy2I4t7w2tvYgzOSn809TqZDmdfKJpY
VYWNGk7USmkAWn19Iyz1Jx7BArE9iKSR2UG8GWWqbo28qN7Q5MAFqBQz1nGqjKkN
I78hvXDpJ+IasD+m8zT0BDHU2DtLL+bJq57GNYaaDHIAJVbSRoQlphf+FDqDt7fN
92vbqua6yZi0NiGw797Fqx4cq5CeeRyh0qw7d4pOlC2fIxwL2+kBOJK24Jl6IEuz
0DwQs1Nso3atVwk0MdEKuioz0Jd0ufeXZAQ6EDISdh3rKcXQ3UlZembmoSSam6bL
nDd3N4kSd6m38hfGYjwtODzb1SHLTWA/NVZrLmGoggJsHbtUMO84f1zDcLpl8vlu
B9lvWVuJOqsmeIhifNkFR+XxTJjyeco5UL8bNZnSIYEMFssKmdg=
=XQF0
-----END PGP SIGNATURE-----
Description: [PHP] Update generated code for PHP 8.6
 PHP 8.6 removed the XtOffsetOf(), WRONG_PARAM_COUNT, ZEND_RESULT_CODE and
 zval_is_true() compatibility names, which the code SWIG generates for PHP
 still used.  Every PHP extension wrapped with SWIG 4.5.1 therefore fails to
 compile against PHP 8.6, for example mapserver (php-mapscript-ng):
 .
   mapscriptPHP7_wrap.c: error: implicit declaration of function 'XtOffsetOf'
   mapscriptPHP7_wrap.c: error: unknown type name 'ZEND_RESULT_CODE'
   mapscriptPHP7_wrap.c: error: 'WRONG_PARAM_COUNT' undeclared
 .
 This is upstream commit 3a390b63aa71 ("[PHP] Update generated code for PHP
 8.6") together with its follow-up 788dabc15613 ("[PHP] Add missing block in
 generated code",
 https://github.com/swig/swig/commit/788dabc1561374369585b93362bcf8a8f774b97d),
 which adds the braces the first commit left out around one of the
 two-statement replacements of WRONG_PARAM_COUNT.  The CHANGES.current hunk
 is left out.  The replacements (offsetof, zend_result, zend_is_true,
 zend_wrong_param_count() + RETURN_THROWS()) exist in every PHP version from
 8.0 on, so the generated code keeps compiling against PHP 8.4.
Origin: upstream, 
https://github.com/swig/swig/commit/3a390b63aa71e567e062980e13cae079af8eadb4
Forwarded: not-needed
Applied-Upstream: commits 3a390b63aa71 and 788dabc15613, to be released in 4.6.0
Last-Update: 2026-11-28

--- a/Lib/php/phprun.swg
+++ b/Lib/php/phprun.swg
@@ -66,7 +66,7 @@
 
 static inline
 swig_object_wrapper * swig_php_fetch_object(zend_object *obj) {
-  return (swig_object_wrapper *)((char *)obj - XtOffsetOf(swig_object_wrapper, 
std));
+  return (swig_object_wrapper *)((char *)obj - offsetof(swig_object_wrapper, 
std));
 }
 
 #define SWIG_as_voidptr(a) const_cast< void * >(static_cast< const void * >(a))
--- a/Lib/php/utils.i
+++ b/Lib/php/utils.i
@@ -1,6 +1,6 @@
 
 %define CONVERT_BOOL_IN(lvar,t,invar)
-  lvar = (t) zval_is_true(&invar);
+  lvar = (t) zend_is_true(&invar);
 %enddef
 
 %define CONVERT_INT_IN(lvar,t,invar)
--- a/Source/Modules/php.cxx
+++ b/Source/Modules/php.cxx
@@ -148,7 +148,7 @@
 
   Printf(s_wrappers, "/* Implement __toString equivalent, since that worked 
for the old-style resource wrapped pointers. */\n");
   Append(s_wrappers, "#if PHP_MAJOR_VERSION > 8 || PHP_MINOR_VERSION >= 2\n");
-  Printf(s_wrappers, "static ZEND_RESULT_CODE swig_ptr_cast_object(zend_object 
*zobj, zval *retval, int type) {\n");
+  Printf(s_wrappers, "static zend_result swig_ptr_cast_object(zend_object 
*zobj, zval *retval, int type) {\n");
   Append(s_wrappers, "#else\n");
   Printf(s_wrappers, "static int swig_ptr_cast_object(zend_object *zobj, zval 
*retval, int type) {\n");
   Append(s_wrappers, "#endif\n");
@@ -162,7 +162,7 @@
 
   Printf(s_oinit, "\n  /* Register classes to represent non-class pointer 
types */\n");
   Printf(s_oinit, "  swig_ptr_object_handlers = 
*zend_get_std_object_handlers();\n");
-  Printf(s_oinit, "  swig_ptr_object_handlers.offset = 
XtOffsetOf(swig_object_wrapper, std);\n");
+  Printf(s_oinit, "  swig_ptr_object_handlers.offset = 
offsetof(swig_object_wrapper, std);\n");
   Printf(s_oinit, "  swig_ptr_object_handlers.cast_object = 
swig_ptr_cast_object;\n");
 
   while (ki.key) {
@@ -1122,7 +1122,8 @@
     Printf(f->code, "  swig_object_wrapper *arg = 
SWIG_Z_FETCH_OBJ_P(ZEND_THIS);\n");
     Printf(f->code, "  zval args[2];\n  zend_string *arg2 = 0;\n\n");
     Printf(f->code, "  if(ZEND_NUM_ARGS() != 2 || 
zend_get_parameters_array_ex(2, args) != SUCCESS) {\n");
-    Printf(f->code, "\tWRONG_PARAM_COUNT;\n}\n\n");
+    Printf(f->code, "\tzend_wrong_param_count();\n");
+    Printf(f->code, "\tRETURN_THROWS();\n}\n\n");
     Printf(f->code, "  if (!arg) {\n");
     Printf(f->code, "    zend_throw_exception(zend_ce_type_error, \"this 
pointer is NULL\", 0);\n");
     Printf(f->code, "    return;\n");
@@ -1163,7 +1164,8 @@
     Printf(f->code, "  swig_object_wrapper *arg = 
SWIG_Z_FETCH_OBJ_P(ZEND_THIS);\n");
     Printf(f->code, "  zval args[1];\n  zend_string *arg2 = 0;\n\n");
     Printf(f->code, "  if(ZEND_NUM_ARGS() != 1 || 
zend_get_parameters_array_ex(1, args) != SUCCESS) {\n");
-    Printf(f->code, "\tWRONG_PARAM_COUNT;\n}\n\n");
+    Printf(f->code, "\tzend_wrong_param_count();\n");
+    Printf(f->code, "\tRETURN_THROWS();\n}\n\n");
     Printf(f->code, "  if (!arg) {\n");
     Printf(f->code, "    zend_throw_exception(zend_ce_type_error, \"this 
pointer is NULL\", 0);\n");
     Printf(f->code, "    return;\n");
@@ -1195,7 +1197,8 @@
     Printf(f->code, "  swig_object_wrapper *arg = 
SWIG_Z_FETCH_OBJ_P(ZEND_THIS);\n");
     Printf(f->code, "  zval args[1];\n  zend_string *arg2 = 0;\n\n");
     Printf(f->code, "  if(ZEND_NUM_ARGS() != 1 || 
zend_get_parameters_array_ex(1, args) != SUCCESS) {\n");
-    Printf(f->code, "\tWRONG_PARAM_COUNT;\n}\n\n");
+    Printf(f->code, "\tzend_wrong_param_count();\n");
+    Printf(f->code, "\tRETURN_THROWS();\n}\n\n");
     Printf(f->code, "  if(!arg) {\n");
     Printf(f->code, "    zend_throw_exception(zend_ce_type_error, \"this 
pointer is NULL\", 0);\n");
     Printf(f->code, "    return;\n");
@@ -1458,8 +1461,9 @@
       Wrapper_add_local(f, "arg_count", "int arg_count");
       Printf(f->code, "arg_count = ZEND_NUM_ARGS();\n");
       Printf(f->code, "if(arg_count<%d || arg_count>%d ||\n", num_required, 
num_arguments);
-      Printf(f->code, "   
zend_get_parameters_array_ex(arg_count,args)!=SUCCESS)\n");
-      Printf(f->code, "\tWRONG_PARAM_COUNT;\n\n");
+      Printf(f->code, "   
zend_get_parameters_array_ex(arg_count,args)!=SUCCESS) {\n");
+      Printf(f->code, "\tzend_wrong_param_count();\n");
+      Printf(f->code, "\tRETURN_THROWS();\n}\n\n");
     } else if (static_setter || static_getter) {
       if (num_arguments == 0) {
         Printf(f->code, "if(ZEND_NUM_ARGS() == 0) {\n");
@@ -1472,7 +1476,8 @@
       } else {
         Printf(f->code, "if(ZEND_NUM_ARGS() != %d || 
zend_get_parameters_array_ex(%d, args) != SUCCESS) {\n", num_arguments, 
num_arguments);
       }
-      Printf(f->code, "WRONG_PARAM_COUNT;\n}\n\n");
+      Printf(f->code, "zend_wrong_param_count();\n");
+      Printf(f->code, "RETURN_THROWS();\n}\n\n");
     }
 
     /* Now convert from PHP to C variables */
@@ -1983,7 +1988,7 @@
       // for classes without a destructor, and copy as the basis for other
       // classes.
       Printf(s_oinit, "  Swig_Php_base_object_handlers = 
*zend_get_std_object_handlers();\n");
-      Printf(s_oinit, "  Swig_Php_base_object_handlers.offset = 
XtOffsetOf(swig_object_wrapper, std);\n");
+      Printf(s_oinit, "  Swig_Php_base_object_handlers.offset = 
offsetof(swig_object_wrapper, std);\n");
       Printf(s_oinit, "  Swig_Php_base_object_handlers.clone_obj = NULL;\n");
       emitted_base_object_handlers = true;
     }

Reply via email to