You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
3.0 KiB

From b7dedecfdd708c5323addc1b28e16cc727e01980 Mon Sep 17 00:00:00 2001
From: Olly Betts <olly@survex.com>
Date: Thu, 18 Mar 2021 10:53:58 +1300
Subject: [PATCH] php: Fix char* typecheck typemap to accept Null
The corresponding in typemap already does.
Fixes #1655, reported by CJSlominski.
---
CHANGES.current | 4 ++++
Examples/test-suite/overload_polymorphic.i | 3 +++
.../test-suite/php/overload_polymorphic_runme.php | 14 ++++++++++++++
Lib/php/php.swg | 5 ++++-
4 files changed, 25 insertions(+), 1 deletion(-)
create mode 100644 Examples/test-suite/php/overload_polymorphic_runme.php
#diff --git a/CHANGES.current b/CHANGES.current
#index 58fd05a56..f287e3d60 100644
#--- a/CHANGES.current
#+++ b/CHANGES.current
#@@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
# Version 4.1.0 (in progress)
# ===========================
#
#+2021-03-18: olly
#+ #1655 [PHP] Fix char* typecheck typemap to accept PHP Null like the
#+ corresponding in typemap does.
#+
# 2021-03-18: olly
# #1900, #1905 [PHP] Fix wrapping of overloaded directed methods with
# non-void return.
diff --git a/Examples/test-suite/overload_polymorphic.i b/Examples/test-suite/overload_polymorphic.i
index ac004f948..72aabd840 100644
--- a/Examples/test-suite/overload_polymorphic.i
+++ b/Examples/test-suite/overload_polymorphic.i
@@ -23,4 +23,7 @@ class Unknown;
int test2(Unknown* unknown) { return 0; }
int test2(Base* base) { return 1; }
+int test3(const char*, const Base* = 0, bool = false) { return 0; }
+int test3(Base&, const char* = 0, const Base* = 0, bool = false) { return 1; }
+
%}
diff --git a/Examples/test-suite/php/overload_polymorphic_runme.php b/Examples/test-suite/php/overload_polymorphic_runme.php
new file mode 100644
index 000000000..0afe16808
--- /dev/null
+++ b/Examples/test-suite/php/overload_polymorphic_runme.php
@@ -0,0 +1,14 @@
+<?php
+
+require "tests.php";
+require "overload_polymorphic.php";
+
+$t = new Derived();
+
+check::equal(overload_polymorphic::test($t), 0, "test(Derived)");
+check::equal(overload_polymorphic::test(1), 1, "test(1)");
+check::equal(overload_polymorphic::test2($t), 1, "test2(Derived)");
+check::equal(overload_polymorphic::test3($t, null, $t), 1, "test3(Derived, null, Derived)");
+
+check::done();
+?>
diff --git a/Lib/php/php.swg b/Lib/php/php.swg
index 4eba6be2a..ccfd371ab 100644
--- a/Lib/php/php.swg
+++ b/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
--
2.26.3