Fix for 'self' being used as a parameter name

This commit is contained in:
William S Fulton 2014-10-30 07:22:59 +00:00
parent 3855b96459
commit 6029b2f7d8
5 changed files with 19 additions and 12 deletions

View File

@ -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
};
%}

View File

@ -0,0 +1,5 @@
from director_keywords import *
f = Foo()
f.check_self(20)

View File

@ -130,7 +130,7 @@ PYTHONKW(None);
/*
'self' is also a bad Name
*/
PYTHONBN(self);
PYTHONKW(self);
#undef PYTHONBN
#undef PYTHONKW

View File

@ -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);

View File

@ -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;