|
|
b7795d |
From 2e7da86b2ced479e48741cc8713479dee426be61 Mon Sep 17 00:00:00 2001
|
|
|
b7795d |
From: Olly Betts <olly@survex.com>
|
|
|
b7795d |
Date: Wed, 9 Dec 2020 09:48:55 +1300
|
|
|
b7795d |
Subject: [PATCH] php: Fix overloaded directed methods with non-void return
|
|
|
b7795d |
|
|
|
b7795d |
We were treating such methods like constructors and assigning to the
|
|
|
b7795d |
internal _cPtr, which just seems bizarrely wrong.
|
|
|
b7795d |
|
|
|
b7795d |
Fixes #1900
|
|
|
b7795d |
---
|
|
|
b7795d |
CHANGES.current | 4 ++++
|
|
|
b7795d |
Examples/test-suite/director_overload.i | 11 ++++++++++-
|
|
|
b7795d |
.../test-suite/php/director_overload_runme.php | 18 ++++++++++++++++++
|
|
|
b7795d |
Source/Modules/php.cxx | 4 ++--
|
|
|
b7795d |
4 files changed, 34 insertions(+), 3 deletions(-)
|
|
|
b7795d |
create mode 100644 Examples/test-suite/php/director_overload_runme.php
|
|
|
b7795d |
|
|
|
b7795d |
#diff --git a/CHANGES.current b/CHANGES.current
|
|
|
b7795d |
#index acaea3aea..58fd05a56 100644
|
|
|
b7795d |
#--- a/CHANGES.current
|
|
|
b7795d |
#+++ b/CHANGES.current
|
|
|
b7795d |
#@@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
|
|
|
b7795d |
# Version 4.1.0 (in progress)
|
|
|
b7795d |
# ===========================
|
|
|
b7795d |
#
|
|
|
b7795d |
#+2021-03-18: olly
|
|
|
b7795d |
#+ #1900, #1905 [PHP] Fix wrapping of overloaded directed methods with
|
|
|
b7795d |
#+ non-void return.
|
|
|
b7795d |
#+
|
|
|
b7795d |
# 2021-03-11: murillo128
|
|
|
b7795d |
# #1498 [Javascript] Support type conversion.
|
|
|
b7795d |
#
|
|
|
b7795d |
diff --git a/Examples/test-suite/director_overload.i b/Examples/test-suite/director_overload.i
|
|
|
b7795d |
index 604ffe5ca..d6feb122b 100644
|
|
|
b7795d |
--- a/Examples/test-suite/director_overload.i
|
|
|
b7795d |
+++ b/Examples/test-suite/director_overload.i
|
|
|
b7795d |
@@ -47,5 +47,14 @@ public:
|
|
|
b7795d |
virtual void notover(int *p) const {}
|
|
|
b7795d |
};
|
|
|
b7795d |
|
|
|
b7795d |
-%}
|
|
|
b7795d |
+class OverloadedGetSet
|
|
|
b7795d |
+{
|
|
|
b7795d |
+ int v;
|
|
|
b7795d |
+public:
|
|
|
b7795d |
+ OverloadedGetSet() : v(42) { }
|
|
|
b7795d |
+ virtual ~OverloadedGetSet() { }
|
|
|
b7795d |
+ virtual int rw() const { return v; }
|
|
|
b7795d |
+ virtual void rw(int new_v) { v = new_v; }
|
|
|
b7795d |
+};
|
|
|
b7795d |
|
|
|
b7795d |
+%}
|
|
|
b7795d |
diff --git a/Examples/test-suite/php/director_overload_runme.php b/Examples/test-suite/php/director_overload_runme.php
|
|
|
b7795d |
new file mode 100644
|
|
|
b7795d |
index 000000000..f5fc56b65
|
|
|
b7795d |
--- /dev/null
|
|
|
b7795d |
+++ b/Examples/test-suite/php/director_overload_runme.php
|
|
|
b7795d |
@@ -0,0 +1,18 @@
|
|
|
b7795d |
+
|
|
|
b7795d |
+
|
|
|
b7795d |
+
|
|
|
b7795d |
+require "tests.php";
|
|
|
b7795d |
+require "director_overload.php";
|
|
|
b7795d |
+
|
|
|
b7795d |
+check::functions(array('new_overloadedClass','new_overloadedPointers','new_overloadedGetSet','overloadedclass_method1','overloadedclass_method3','overloadedclass_method2','overloadedpointers_method','overloadedpointers_notover','overloadedgetset_rw'));
|
|
|
b7795d |
+
|
|
|
b7795d |
+check::classes(array('OverloadedClass','OverloadedPointers','OverloadedGetSet'));
|
|
|
b7795d |
+check::globals(array());
|
|
|
b7795d |
+
|
|
|
b7795d |
+$o = new OverloadedGetSet;
|
|
|
b7795d |
+check::equal($o->rw(), 42, "get_set() initial value not 42");
|
|
|
b7795d |
+check::equal($o->rw(7), null, "get_set() failed to set");
|
|
|
b7795d |
+check::equal($o->rw(), 7, "get_set() didn't return back set value");
|
|
|
b7795d |
+
|
|
|
b7795d |
+check::done();
|
|
|
b7795d |
+?>
|
|
|
b7795d |
diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx
|
|
|
b7795d |
index 1edbd874c..eaae32d63 100644
|
|
|
b7795d |
--- a/Source/Modules/php.cxx
|
|
|
b7795d |
+++ b/Source/Modules/php.cxx
|
|
|
b7795d |
@@ -1566,7 +1566,7 @@ public:
|
|
|
b7795d |
Printf(prepare, "case %d: ", ++last_handled_i);
|
|
|
b7795d |
}
|
|
|
b7795d |
if (non_void_return) {
|
|
|
b7795d |
- if ((!directorsEnabled() || !Swig_directorclass(n)) && !constructor) {
|
|
|
b7795d |
+ if (!constructor) {
|
|
|
b7795d |
Append(prepare, "$r=");
|
|
|
b7795d |
} else if (wrapperType == staticmemberfn || wrapperType == staticmembervar) {
|
|
|
b7795d |
Append(prepare, "$r=");
|
|
|
b7795d |
@@ -1590,7 +1590,7 @@ public:
|
|
|
b7795d |
if (had_a_case)
|
|
|
b7795d |
Printf(prepare, "default: ");
|
|
|
b7795d |
if (non_void_return) {
|
|
|
b7795d |
- if ((!directorsEnabled() || !Swig_directorclass(n)) && !constructor) {
|
|
|
b7795d |
+ if (!constructor) {
|
|
|
b7795d |
Append(prepare, "$r=");
|
|
|
b7795d |
} else if (wrapperType == staticmemberfn || wrapperType == staticmembervar) {
|
|
|
b7795d |
Append(prepare, "$r=");
|
|
|
b7795d |
--
|
|
|
b7795d |
2.26.3
|
|
|
b7795d |
|