Fix for 'self' being used as a parameter name
This commit is contained in:
parent
3855b96459
commit
6029b2f7d8
5 changed files with 19 additions and 12 deletions
|
|
@ -1,13 +1,15 @@
|
||||||
// Checks if collisions of argument names with target language keywords are
|
// Checks if collisions of argument names with target language keywords are
|
||||||
// resolved properly when directors are used (currently only »abstract« for
|
// resolved properly when directors are used
|
||||||
// C#, D and Java is checked).
|
|
||||||
%module(directors="1") director_keywords
|
%module(directors="1") director_keywords
|
||||||
|
|
||||||
|
%warnfilter(SWIGWARN_PARSE_KEYWORD);
|
||||||
|
|
||||||
%feature("director") Foo;
|
%feature("director") Foo;
|
||||||
|
|
||||||
%inline %{
|
%inline %{
|
||||||
struct Foo {
|
struct Foo {
|
||||||
virtual ~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
|
||||||
};
|
};
|
||||||
%}
|
%}
|
||||||
|
|
|
||||||
5
Examples/test-suite/python/director_keywords_runme.py
Normal file
5
Examples/test-suite/python/director_keywords_runme.py
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
from director_keywords import *
|
||||||
|
|
||||||
|
f = Foo()
|
||||||
|
f.check_self(20)
|
||||||
|
|
||||||
|
|
@ -130,7 +130,7 @@ PYTHONKW(None);
|
||||||
/*
|
/*
|
||||||
'self' is also a bad Name
|
'self' is also a bad Name
|
||||||
*/
|
*/
|
||||||
PYTHONBN(self);
|
PYTHONKW(self);
|
||||||
|
|
||||||
#undef PYTHONBN
|
#undef PYTHONBN
|
||||||
#undef PYTHONKW
|
#undef PYTHONKW
|
||||||
|
|
|
||||||
|
|
@ -2268,7 +2268,7 @@ public:
|
||||||
Printf(imcall, "swigCPtr");
|
Printf(imcall, "swigCPtr");
|
||||||
|
|
||||||
String *this_type = Copy(getClassType());
|
String *this_type = Copy(getClassType());
|
||||||
String *name = NewString("self");
|
String *name = NewString("jself");
|
||||||
String *qualifier = Getattr(n, "qualifier");
|
String *qualifier = Getattr(n, "qualifier");
|
||||||
if (qualifier)
|
if (qualifier)
|
||||||
SwigType_push(this_type, qualifier);
|
SwigType_push(this_type, qualifier);
|
||||||
|
|
@ -3734,7 +3734,7 @@ public:
|
||||||
/* Create the intermediate class wrapper */
|
/* Create the intermediate class wrapper */
|
||||||
tm = Swig_typemap_lookup("jtype", n, "", 0);
|
tm = Swig_typemap_lookup("jtype", n, "", 0);
|
||||||
if (tm) {
|
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 {
|
} else {
|
||||||
Swig_warning(WARN_JAVA_TYPEMAP_JTYPE_UNDEF, input_file, line_number, "No jtype typemap defined for %s\n", SwigType_str(returntype, 0));
|
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");
|
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);
|
Parm *tp = NewParmNode(c_classname, n);
|
||||||
String *jdesc;
|
String *jdesc;
|
||||||
|
|
||||||
|
|
@ -4062,7 +4062,7 @@ public:
|
||||||
|
|
||||||
/* Emit the intermediate class's upcall to the actual class */
|
/* 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
|
// Handle exception classes specified in the "except" feature's "throws" attribute
|
||||||
addThrows(n, "feature:except", n);
|
addThrows(n, "feature:except", n);
|
||||||
|
|
|
||||||
|
|
@ -2178,12 +2178,12 @@ public:
|
||||||
SwigType_add_pointer(ptype);
|
SwigType_add_pointer(ptype);
|
||||||
String *mangle = SwigType_manglestr(ptype);
|
String *mangle = SwigType_manglestr(ptype);
|
||||||
|
|
||||||
Wrapper_add_local(w, "self", "SV *self");
|
Wrapper_add_local(w, "swigself", "SV *swigself");
|
||||||
Printf(w->code, "self = SWIG_NewPointerObj(SWIG_as_voidptr(this), SWIGTYPE%s, SWIG_SHADOW);\n", mangle);
|
Printf(w->code, "swigself = 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");
|
Printf(w->code, "sv_bless(swigself, gv_stashpv(swig_get_class(), 0));\n");
|
||||||
Delete(mangle);
|
Delete(mangle);
|
||||||
Delete(ptype);
|
Delete(ptype);
|
||||||
Append(pstack, "XPUSHs(self);\n");
|
Append(pstack, "XPUSHs(swigself);\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
Parm *p;
|
Parm *p;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue