From 636daff4e19e78e084739b9972f9182aaa9f94a8 Mon Sep 17 00:00:00 2001 From: Art Yerkes Date: Sat, 8 Mar 2003 03:25:09 +0000 Subject: [PATCH] Removed a Py_None from cwrap.c. Added SetNoneComparison in lang.cxx, which allows the language module to specify how to determine whether the empty argument was given for the 'self' pointer. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@4473 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- SWIG/Source/Modules/lang.cxx | 11 +++++++++-- SWIG/Source/Modules/swigmod.h | 3 +++ SWIG/Source/Swig/cwrap.c | 11 +++++++++-- SWIG/Source/Swig/swig.h | 4 +++- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/SWIG/Source/Modules/lang.cxx b/SWIG/Source/Modules/lang.cxx index de78f27f5..4b90f04d7 100644 --- a/SWIG/Source/Modules/lang.cxx +++ b/SWIG/Source/Modules/lang.cxx @@ -201,6 +201,7 @@ int Dispatcher::namespaceDeclaration(Node *n) { return defaultHandler(n); } Language::Language() { symbols = NewHash(); classtypes = NewHash(); + none_comparison = NewString("$arg != 0"); overloading = 0; multiinput = 0; directors = 0; @@ -1759,7 +1760,8 @@ Language::constructorHandler(Node *n) { mrename = Swig_name_construct(symname); if (CPlusPlus) patch_parms(parms); - Swig_ConstructorToFunction(n,ClassType,CPlusPlus,Getattr(n,"template") ? 0 :Extend); + Swig_ConstructorToFunction(n,ClassType,none_comparison, + CPlusPlus,Getattr(n,"template") ? 0 :Extend); Setattr(n,"sym:name", mrename); functionWrapper(n); Delete(mrename); @@ -1779,7 +1781,8 @@ Language::copyconstructorHandler(Node *n) { Parm *parms = Getattr(n,"parms"); if (CPlusPlus) patch_parms(parms); mrename = Swig_name_copyconstructor(symname); - Swig_ConstructorToFunction(n,ClassType, CPlusPlus, Getattr(n,"template") ? 0 : Extend); + Swig_ConstructorToFunction(n,ClassType, none_comparison, + CPlusPlus, Getattr(n,"template") ? 0 : Extend); Setattr(n,"sym:name", mrename); functionWrapper(n); Delete(mrename); @@ -2149,3 +2152,7 @@ String * Language::getClassPrefix() const { String * Language::getClassType() const { return ClassType; } + +void Language::SetNoneComparison( String *nc ) { + none_comparison = nc; +} diff --git a/SWIG/Source/Modules/swigmod.h b/SWIG/Source/Modules/swigmod.h index 610a4321a..66252d9d8 100644 --- a/SWIG/Source/Modules/swigmod.h +++ b/SWIG/Source/Modules/swigmod.h @@ -209,6 +209,8 @@ public: /* Return true if directors are enabled */ int directorsEnabled() const; + /* Set none comparison string */ + void SetNoneComparison( String *s ); protected: /* Patch C++ pass-by-value */ @@ -241,6 +243,7 @@ public: private: Hash *symbols; Hash *classtypes; + String *none_comparison; int overloading; int multiinput; int directors; diff --git a/SWIG/Source/Swig/cwrap.c b/SWIG/Source/Swig/cwrap.c index 6bc50cc12..64095847b 100644 --- a/SWIG/Source/Swig/cwrap.c +++ b/SWIG/Source/Swig/cwrap.c @@ -609,7 +609,8 @@ Swig_directormap(Node *module, String *type) { * ----------------------------------------------------------------------------- */ int -Swig_ConstructorToFunction(Node *n, String *classname, int cplus, int flags) +Swig_ConstructorToFunction(Node *n, String *classname, + String *none_comparison, int cplus, int flags) { ParmList *parms; SwigType *type; @@ -649,16 +650,22 @@ Swig_ConstructorToFunction(Node *n, String *classname, int cplus, int flags) String *name = Getattr(parent, "sym:name"); String* directorname = NewStringf("__DIRECTOR__%s", name); String* action = NewString(""); + String* tmp_none_comparison = Copy(none_comparison); + + Replaceall( tmp_none_comparison, "$arg", "arg1" ); + /* if Python class has been subclassed, create a director instance. * otherwise, just create a normal instance. */ - Printv(action, "if (arg1 != Py_None) { // subclassed\n", + // arty: arg1 != Py_None => tmp_none_comparison + Printv(action, "if (",tmp_none_comparison,") { // subclassed\n", Swig_cresult(type, "result", Swig_cppconstructor_director_call(directorname, parms)), "} else {\n", Swig_cresult(type, "result", Swig_cppconstructor_nodirector_call(classname, parms)), "}\n", NULL); Setattr(n, "wrap:action", action); + Delete(tmp_none_comparison); Delete(action); Delete(directorname); } else { diff --git a/SWIG/Source/Swig/swig.h b/SWIG/Source/Swig/swig.h index 58a58a92b..3a1e524b8 100644 --- a/SWIG/Source/Swig/swig.h +++ b/SWIG/Source/Swig/swig.h @@ -436,7 +436,9 @@ extern String *Swig_cmemberget_call(String_or_char *name, SwigType *t, String /* --- Transformations --- */ extern int Swig_MethodToFunction(Node *n, String *classname, int flags); -extern int Swig_ConstructorToFunction(Node *n, String *classname, int cplus, int flags); +extern int Swig_ConstructorToFunction(Node *n, String *classname, + String *none_comparison, + int cplus, int flags); extern int Swig_DestructorToFunction(Node *n, String *classname, int cplus, int flags); extern int Swig_MembersetToFunction(Node *n, String *classname, int flags); extern int Swig_MembergetToFunction(Node *n, String *classname, int flags);