From 3f9ebb31b9ebb64809d4d944cbc67b81d92ce4e7 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 8 Feb 2019 18:09:52 +1300 Subject: [PATCH] [PHP] Don't generate code referencing undefined $r This could happen in overloaded methods which returned void and took at least one const std::string& parameter. --- CHANGES.current | 5 +++++ Examples/test-suite/li_std_string.i | 6 ++++++ Examples/test-suite/php/li_std_string_runme.php | 14 ++++++++++++++ Source/Modules/php.cxx | 2 +- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index 88dcb1c9a..7fdc7189d 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,11 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.0.0 (in progress) =========================== +2019-02-08: olly + [PHP] Don't generate code which references $r when $r hasn't been + defined. This could happen in overloaded methods which returned + void and took at least one const std::string& parameter. + 2019-02-08: olly [PHP] The generated code is now compatible with PHP 7.3, and the testsuite now runs cleanly with this version too. diff --git a/Examples/test-suite/li_std_string.i b/Examples/test-suite/li_std_string.i index 822368491..47a9090b7 100644 --- a/Examples/test-suite/li_std_string.i +++ b/Examples/test-suite/li_std_string.i @@ -22,6 +22,12 @@ const std::string& test_const_reference(const std::string &x) { return x; } +void test_const_reference_returning_void(const std::string &) { +} + +void test_const_reference_returning_void(const std::string &, int) { +} + void test_pointer(std::string *x) { } diff --git a/Examples/test-suite/php/li_std_string_runme.php b/Examples/test-suite/php/li_std_string_runme.php index ad62247e1..dbf0228df 100644 --- a/Examples/test-suite/php/li_std_string_runme.php +++ b/Examples/test-suite/php/li_std_string_runme.php @@ -3,6 +3,17 @@ require "tests.php"; require "li_std_string.php"; +function die_on_error($errno, $errstr, $file, $line) { + if ($file !== Null) { + print $file; + if ($line !== Null) print ":$line"; + print ": "; + } + print "$errstr\n"; + exit(1); +} +set_error_handler("die_on_error", -1); + // Global variables //$s="initial string"; //check::equal(GlobalString2_get() ,"global string 2", "GlobalString2 test 1"); @@ -27,5 +38,8 @@ check::equal(Structure::StaticMemberString2(), $s, "StaticMemberString2 test 2") // below broken ? //check::equal(Structure::ConstStaticMemberString(), "const static member string", "ConstStaticMemberString test"); +// This used to give "Undefined variable: r" +li_std_string::test_const_reference_returning_void("foo"); + check::done(); ?> diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index a3ea8003e..fd1dedad7 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -979,7 +979,7 @@ public: /* Insert argument output code */ bool hasargout = false; for (i = 0, p = l; p; i++) { - if ((tm = Getattr(p, "tmap:argout"))) { + if ((tm = Getattr(p, "tmap:argout")) && Len(tm)) { hasargout = true; Replaceall(tm, "$source", Getattr(p, "lname")); // Replaceall(tm,"$input",Getattr(p,"lname"));