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
This commit is contained in:
Art Yerkes 2003-03-08 03:25:09 +00:00
commit 636daff4e1
4 changed files with 24 additions and 5 deletions

View file

@ -201,6 +201,7 @@ int Dispatcher::namespaceDeclaration(Node *n) { return defaultHandler(n); }
Language::Language() { Language::Language() {
symbols = NewHash(); symbols = NewHash();
classtypes = NewHash(); classtypes = NewHash();
none_comparison = NewString("$arg != 0");
overloading = 0; overloading = 0;
multiinput = 0; multiinput = 0;
directors = 0; directors = 0;
@ -1759,7 +1760,8 @@ Language::constructorHandler(Node *n) {
mrename = Swig_name_construct(symname); mrename = Swig_name_construct(symname);
if (CPlusPlus) patch_parms(parms); 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); Setattr(n,"sym:name", mrename);
functionWrapper(n); functionWrapper(n);
Delete(mrename); Delete(mrename);
@ -1779,7 +1781,8 @@ Language::copyconstructorHandler(Node *n) {
Parm *parms = Getattr(n,"parms"); Parm *parms = Getattr(n,"parms");
if (CPlusPlus) patch_parms(parms); if (CPlusPlus) patch_parms(parms);
mrename = Swig_name_copyconstructor(symname); 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); Setattr(n,"sym:name", mrename);
functionWrapper(n); functionWrapper(n);
Delete(mrename); Delete(mrename);
@ -2149,3 +2152,7 @@ String * Language::getClassPrefix() const {
String * Language::getClassType() const { String * Language::getClassType() const {
return ClassType; return ClassType;
} }
void Language::SetNoneComparison( String *nc ) {
none_comparison = nc;
}

View file

@ -209,6 +209,8 @@ public:
/* Return true if directors are enabled */ /* Return true if directors are enabled */
int directorsEnabled() const; int directorsEnabled() const;
/* Set none comparison string */
void SetNoneComparison( String *s );
protected: protected:
/* Patch C++ pass-by-value */ /* Patch C++ pass-by-value */
@ -241,6 +243,7 @@ public:
private: private:
Hash *symbols; Hash *symbols;
Hash *classtypes; Hash *classtypes;
String *none_comparison;
int overloading; int overloading;
int multiinput; int multiinput;
int directors; int directors;

View file

@ -609,7 +609,8 @@ Swig_directormap(Node *module, String *type) {
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
int 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; ParmList *parms;
SwigType *type; SwigType *type;
@ -649,16 +650,22 @@ Swig_ConstructorToFunction(Node *n, String *classname, int cplus, int flags)
String *name = Getattr(parent, "sym:name"); String *name = Getattr(parent, "sym:name");
String* directorname = NewStringf("__DIRECTOR__%s", name); String* directorname = NewStringf("__DIRECTOR__%s", name);
String* action = NewString(""); 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. /* if Python class has been subclassed, create a director instance.
* otherwise, just create a normal 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)), Swig_cresult(type, "result", Swig_cppconstructor_director_call(directorname, parms)),
"} else {\n", "} else {\n",
Swig_cresult(type, "result", Swig_cppconstructor_nodirector_call(classname, parms)), Swig_cresult(type, "result", Swig_cppconstructor_nodirector_call(classname, parms)),
"}\n", "}\n",
NULL); NULL);
Setattr(n, "wrap:action", action); Setattr(n, "wrap:action", action);
Delete(tmp_none_comparison);
Delete(action); Delete(action);
Delete(directorname); Delete(directorname);
} else { } else {

View file

@ -436,7 +436,9 @@ extern String *Swig_cmemberget_call(String_or_char *name, SwigType *t, String
/* --- Transformations --- */ /* --- Transformations --- */
extern int Swig_MethodToFunction(Node *n, String *classname, int flags); 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_DestructorToFunction(Node *n, String *classname, int cplus, int flags);
extern int Swig_MembersetToFunction(Node *n, String *classname, int flags); extern int Swig_MembersetToFunction(Node *n, String *classname, int flags);
extern int Swig_MembergetToFunction(Node *n, String *classname, int flags); extern int Swig_MembergetToFunction(Node *n, String *classname, int flags);