From 7b929dce822d1a518c524e5e01e7b99200d51aa3 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sat, 22 Jan 2022 15:22:43 +1300 Subject: [PATCH] [php] Fix director upcall check This resolves an issue uncovered by adding a _runme.php for testcase director_alternating. --- .../test-suite/php/director_alternating_runme.php | 11 +++++++++++ Lib/php/director.swg | 9 ++------- Source/Modules/php.cxx | 9 +++++---- 3 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 Examples/test-suite/php/director_alternating_runme.php diff --git a/Examples/test-suite/php/director_alternating_runme.php b/Examples/test-suite/php/director_alternating_runme.php new file mode 100644 index 000000000..de33038be --- /dev/null +++ b/Examples/test-suite/php/director_alternating_runme.php @@ -0,0 +1,11 @@ +id(); +check::equal($id, director_alternating::idFromGetBar(), "idFromGetBar() failed"); diff --git a/Lib/php/director.swg b/Lib/php/director.swg index 68be6a3ba..55ffff516 100644 --- a/Lib/php/director.swg +++ b/Lib/php/director.swg @@ -99,6 +99,8 @@ namespace Swig { } } + zend_object *swig_get_self() const { return Z_OBJ(swig_self); } + void swig_disown() const { if (!swig_disown_flag) { swig_disown_flag = true; @@ -106,13 +108,6 @@ namespace Swig { } } - static bool swig_is_overridden_method(const char *cname, zval *z) { - zend_string * cname_str = zend_string_init(cname, strlen(cname), 0); - zend_class_entry *ce = zend_lookup_class(cname_str); - zend_string_release(cname_str); - return ce == Z_OBJCE_P(z); - } - template void swig_acquire_ownership(Type *vptr) const { if (vptr) { diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 357f6de3e..eda3f1fdc 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -1336,9 +1336,10 @@ public: } if (is_member_director(n)) { + Wrapper_add_local(f, "director", "Swig::Director *director = 0"); + Append(f->code, "director = SWIG_DIRECTOR_CAST(arg1);\n"); Wrapper_add_local(f, "upcall", "bool upcall = false"); - Printf(f->code, "upcall = !Swig::Director::swig_is_overridden_method(\"%s%s\", ZEND_THIS);\n", - prefix, Swig_class_name(Swig_methodclass(n))); + Printf(f->code, "upcall = (director && (director->swig_get_self()==Z_OBJ_P(ZEND_THIS)));\n"); } Swig_director_emit_dynamic_cast(n, f); @@ -1904,8 +1905,8 @@ public: Delete(director_ctor_code); director_ctor_code = NewStringEmpty(); director_prot_ctor_code = NewStringEmpty(); - Printf(director_ctor_code, "if (Swig::Director::swig_is_overridden_method(\"%s\", arg0)) { /* not subclassed */\n", class_name); - Printf(director_prot_ctor_code, "if (Swig::Director::swig_is_overridden_method(\"%s\", arg0)) { /* not subclassed */\n", class_name); + Printf(director_ctor_code, "if (Z_OBJCE_P(arg0) == SWIG_Php_ce_%s) { /* not subclassed */\n", class_name); + Printf(director_prot_ctor_code, "if (Z_OBJCE_P(arg0) == SWIG_Php_ce_%s) { /* not subclassed */\n", class_name); Printf(director_ctor_code, " %s = new %s(%s);\n", Swig_cresult_name(), ctype, args); Printf(director_prot_ctor_code, " zend_throw_exception(zend_ce_type_error, \"accessing abstract class or protected constructor\", 0);\n"