diff --git a/Examples/test-suite/director_keywords.i b/Examples/test-suite/director_keywords.i index 473786c00..53f124772 100644 --- a/Examples/test-suite/director_keywords.i +++ b/Examples/test-suite/director_keywords.i @@ -1,13 +1,15 @@ // Checks if collisions of argument names with target language keywords are -// resolved properly when directors are used (currently only »abstract« for -// C#, D and Java is checked). +// resolved properly when directors are used %module(directors="1") director_keywords +%warnfilter(SWIGWARN_PARSE_KEYWORD); + %feature("director") Foo; %inline %{ struct Foo { virtual ~Foo() {} - virtual void bar(int abstract) {} + virtual void check_abstract(int abstract) {} // for Java, C#, D... + virtual void check_self(int self) {} // self for Python }; %} diff --git a/Examples/test-suite/python/director_keywords_runme.py b/Examples/test-suite/python/director_keywords_runme.py new file mode 100644 index 000000000..03a50206a --- /dev/null +++ b/Examples/test-suite/python/director_keywords_runme.py @@ -0,0 +1,5 @@ +from director_keywords import * + +f = Foo() +f.check_self(20) + diff --git a/Lib/python/pythonkw.swg b/Lib/python/pythonkw.swg index 8ad0ef11b..2f76a664a 100644 --- a/Lib/python/pythonkw.swg +++ b/Lib/python/pythonkw.swg @@ -130,7 +130,7 @@ PYTHONKW(None); /* 'self' is also a bad Name */ -PYTHONBN(self); +PYTHONKW(self); #undef PYTHONBN #undef PYTHONKW diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index 72924fac2..2d07c55c4 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -2268,7 +2268,7 @@ public: Printf(imcall, "swigCPtr"); String *this_type = Copy(getClassType()); - String *name = NewString("self"); + String *name = NewString("jself"); String *qualifier = Getattr(n, "qualifier"); if (qualifier) SwigType_push(this_type, qualifier); @@ -3734,7 +3734,7 @@ public: /* Create the intermediate class wrapper */ tm = Swig_typemap_lookup("jtype", n, "", 0); if (tm) { - Printf(callback_def, " public static %s %s(%s self", tm, imclass_dmethod, qualified_classname); + Printf(callback_def, " public static %s %s(%s jself", tm, imclass_dmethod, qualified_classname); } else { Swig_warning(WARN_JAVA_TYPEMAP_JTYPE_UNDEF, input_file, line_number, "No jtype typemap defined for %s\n", SwigType_str(returntype, 0)); } @@ -3851,7 +3851,7 @@ public: Printf(w->code, "if (swigjobj && jenv->IsSameObject(swigjobj, NULL) == JNI_FALSE) {\n"); } - /* Start the Java field descriptor for the intermediate class's upcall (insert self object) */ + /* Start the Java field descriptor for the intermediate class's upcall (insert jself object) */ Parm *tp = NewParmNode(c_classname, n); String *jdesc; @@ -4062,7 +4062,7 @@ public: /* Emit the intermediate class's upcall to the actual class */ - String *upcall = NewStringf("self.%s(%s)", symname, imcall_args); + String *upcall = NewStringf("jself.%s(%s)", symname, imcall_args); // Handle exception classes specified in the "except" feature's "throws" attribute addThrows(n, "feature:except", n); diff --git a/Source/Modules/perl5.cxx b/Source/Modules/perl5.cxx index c67ba554a..224c4852e 100644 --- a/Source/Modules/perl5.cxx +++ b/Source/Modules/perl5.cxx @@ -2178,12 +2178,12 @@ public: SwigType_add_pointer(ptype); String *mangle = SwigType_manglestr(ptype); - Wrapper_add_local(w, "self", "SV *self"); - Printf(w->code, "self = SWIG_NewPointerObj(SWIG_as_voidptr(this), SWIGTYPE%s, SWIG_SHADOW);\n", mangle); - Printf(w->code, "sv_bless(self, gv_stashpv(swig_get_class(), 0));\n"); + Wrapper_add_local(w, "swigself", "SV *swigself"); + Printf(w->code, "swigself = SWIG_NewPointerObj(SWIG_as_voidptr(this), SWIGTYPE%s, SWIG_SHADOW);\n", mangle); + Printf(w->code, "sv_bless(swigself, gv_stashpv(swig_get_class(), 0));\n"); Delete(mangle); Delete(ptype); - Append(pstack, "XPUSHs(self);\n"); + Append(pstack, "XPUSHs(swigself);\n"); } Parm *p;