1 Star 0 Fork 3

rockerzhu/swig

forked from OpenCloudOS Stream/swig 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
swig-4.0.2-Fix-overloaded-directed-methods-with-non-void-re.patch 3.47 KB
一键复制 编辑 原始数据 按行查看 历史
nilusyi 提交于 2023-03-09 15:19 . OCS package init
From 2e7da86b2ced479e48741cc8713479dee426be61 Mon Sep 17 00:00:00 2001
From: Olly Betts <olly@survex.com>
Date: Wed, 9 Dec 2020 09:48:55 +1300
Subject: [PATCH] php: Fix overloaded directed methods with non-void return
We were treating such methods like constructors and assigning to the
internal _cPtr, which just seems bizarrely wrong.
Fixes #1900
---
CHANGES.current | 4 ++++
Examples/test-suite/director_overload.i | 11 ++++++++++-
.../test-suite/php/director_overload_runme.php | 18 ++++++++++++++++++
Source/Modules/php.cxx | 4 ++--
4 files changed, 34 insertions(+), 3 deletions(-)
create mode 100644 Examples/test-suite/php/director_overload_runme.php
#diff --git a/CHANGES.current b/CHANGES.current
#index acaea3aea..58fd05a56 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
#+ #1900, #1905 [PHP] Fix wrapping of overloaded directed methods with
#+ non-void return.
#+
# 2021-03-11: murillo128
# #1498 [Javascript] Support type conversion.
#
diff --git a/Examples/test-suite/director_overload.i b/Examples/test-suite/director_overload.i
index 604ffe5ca..d6feb122b 100644
--- a/Examples/test-suite/director_overload.i
+++ b/Examples/test-suite/director_overload.i
@@ -47,5 +47,14 @@ public:
virtual void notover(int *p) const {}
};
-%}
+class OverloadedGetSet
+{
+ int v;
+public:
+ OverloadedGetSet() : v(42) { }
+ virtual ~OverloadedGetSet() { }
+ virtual int rw() const { return v; }
+ virtual void rw(int new_v) { v = new_v; }
+};
+%}
diff --git a/Examples/test-suite/php/director_overload_runme.php b/Examples/test-suite/php/director_overload_runme.php
new file mode 100644
index 000000000..f5fc56b65
--- /dev/null
+++ b/Examples/test-suite/php/director_overload_runme.php
@@ -0,0 +1,18 @@
+
+<?php
+
+require "tests.php";
+require "director_overload.php";
+
+check::functions(array('new_overloadedClass','new_overloadedPointers','new_overloadedGetSet','overloadedclass_method1','overloadedclass_method3','overloadedclass_method2','overloadedpointers_method','overloadedpointers_notover','overloadedgetset_rw'));
+
+check::classes(array('OverloadedClass','OverloadedPointers','OverloadedGetSet'));
+check::globals(array());
+
+$o = new OverloadedGetSet;
+check::equal($o->rw(), 42, "get_set() initial value not 42");
+check::equal($o->rw(7), null, "get_set() failed to set");
+check::equal($o->rw(), 7, "get_set() didn't return back set value");
+
+check::done();
+?>
diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx
index 1edbd874c..eaae32d63 100644
--- a/Source/Modules/php.cxx
+++ b/Source/Modules/php.cxx
@@ -1566,7 +1566,7 @@ public:
Printf(prepare, "case %d: ", ++last_handled_i);
}
if (non_void_return) {
- if ((!directorsEnabled() || !Swig_directorclass(n)) && !constructor) {
+ if (!constructor) {
Append(prepare, "$r=");
} else if (wrapperType == staticmemberfn || wrapperType == staticmembervar) {
Append(prepare, "$r=");
@@ -1590,7 +1590,7 @@ public:
if (had_a_case)
Printf(prepare, "default: ");
if (non_void_return) {
- if ((!directorsEnabled() || !Swig_directorclass(n)) && !constructor) {
+ if (!constructor) {
Append(prepare, "$r=");
} else if (wrapperType == staticmemberfn || wrapperType == staticmembervar) {
Append(prepare, "$r=");
--
2.26.3
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/rockerzhu/swig.git
git@gitee.com:rockerzhu/swig.git
rockerzhu
swig
swig
master

搜索帮助