diff --git a/Source/Modules/overload.cxx b/Source/Modules/overload.cxx index 511e550..f0bc3bd 100644 --- a/Source/Modules/overload.cxx +++ b/Source/Modules/overload.cxx @@ -718,6 +718,10 @@ String *Swig_overload_dispatch(Node *n, const_String_or_char_ptr fmt, int *maxar Parm *pi = Getattr(ni, "wrap:parms"); int num_required = emit_num_required(pi); int num_arguments = emit_num_arguments(pi); + if (checkAttribute(n, "wrap:this", "1")) { + num_required++; + num_arguments++; + } if (num_arguments > *maxargs) *maxargs = num_arguments; int varargs = emit_isvarargs(pi); @@ -751,7 +755,7 @@ String *Swig_overload_dispatch(Node *n, const_String_or_char_ptr fmt, int *maxar Printf(f, "}\n"); Delete(lfmt); } - if (print_typecheck(f, j, pj)) { + if (print_typecheck(f, (checkAttribute(n, "wrap:this", "1") ? j + 1 : j), pj)) { Printf(f, "if (_v) {\n"); num_braces++; } diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx index 5113a10..4fc8c69 100644 --- a/Source/Modules/php.cxx +++ b/Source/Modules/php.cxx @@ -673,6 +673,10 @@ public: int maxargs; String *tmp = NewStringEmpty(); + if (Swig_directorclass(n) && wrapperType == directorconstructor) { + /* We have an extra 'this' parameter. */ + Setattr(n, "wrap:this", "1"); + } String *dispatch = Swig_overload_dispatch(n, "return %s(INTERNAL_FUNCTION_PARAM_PASSTHRU);", &maxargs); /* Generate a dispatch wrapper for all overloaded functions */ @@ -686,25 +690,6 @@ public: Wrapper_add_local(f, "argc", "int argc"); - if (Swig_directorclass(n) && wrapperType == directorconstructor) { - /* - * We have an extra 'this' parameter. - * TODO: isn't there a better way to handle this? - */ - maxargs++; - for (int i = maxargs; i; i--) { - String *fro = NewStringf(" %d", i-1); - String *to = NewStringf(" %d", i); - Replaceall(dispatch, fro, to); - Delete(fro); - Delete(to); - fro = NewStringf("[%d]", i-1); - to = NewStringf("[%d]", i); - Replaceall(dispatch, fro, to); - Delete(fro); - Delete(to); - } - } Printf(tmp, "zval **argv[%d]", maxargs); Wrapper_add_local(f, "argv", tmp);