diff --git a/CHANGES.current b/CHANGES.current index 345257e62..349b69707 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,10 @@ Version 1.3.39 (in progress) ============================ +2008-02-13: wsfulton + Add support for %extend and memberin typemaps. Previously the memberin typemaps were + ignored for member variables within a %extend block. + 2008-02-12: wsfulton Remove unnecessary temporary variable when wrapping return values that are references. Example of generated code for wrapping: diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 72a7ff496..38658ce9c 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -1422,36 +1422,39 @@ int Language::membervariableHandler(Node *n) { target = NewStringf("%s->%s", pname, name); Delete(pname); } - tm = Swig_typemap_lookup("memberin", n, target, 0); + } else { + target = NewStringf("$extendgetcall"); // member variable access expanded later } + tm = Swig_typemap_lookup("memberin", n, target, 0); int flags = Extend | SmartPointer | use_naturalvar_mode(n); if (is_non_virtual_protected_access(n)) flags = flags | CWRAP_ALL_PROTECTED_ACCESS; - Swig_MembersetToFunction(n, ClassType, flags); + String *call = 0; + Swig_MembersetToFunction(n, ClassType, flags, &call); Setattr(n, "memberset", "1"); - if (!Extend) { - /* Check for a member in typemap here */ - if (!tm) { - if (SwigType_isarray(type)) { - Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, "Unable to set variable of type %s.\n", SwigType_str(type, 0)); - make_set_wrapper = 0; - } - } else { - String *pname0 = Swig_cparm_name(0, 0); - String *pname1 = Swig_cparm_name(0, 1); - Replace(tm, "$source", pname1, DOH_REPLACE_ANY); - Replace(tm, "$target", target, DOH_REPLACE_ANY); - Replace(tm, "$input", pname1, DOH_REPLACE_ANY); - Replace(tm, "$self", pname0, DOH_REPLACE_ANY); - Setattr(n, "wrap:action", tm); - Delete(tm); - Delete(pname0); - Delete(pname1); + if (!tm) { + if (SwigType_isarray(type)) { + Swig_warning(WARN_TYPEMAP_VARIN_UNDEF, input_file, line_number, "Unable to set variable of type %s.\n", SwigType_str(type, 0)); + make_set_wrapper = 0; } - Delete(target); + } else { + String *pname0 = Swig_cparm_name(0, 0); + String *pname1 = Swig_cparm_name(0, 1); + Replace(tm, "$source", pname1, DOH_REPLACE_ANY); + Replace(tm, "$target", target, DOH_REPLACE_ANY); + Replace(tm, "$input", pname1, DOH_REPLACE_ANY); + Replace(tm, "$self", pname0, DOH_REPLACE_ANY); + Replace(tm, "$extendgetcall", call, DOH_REPLACE_ANY); + Setattr(n, "wrap:action", tm); + Delete(tm); + Delete(pname0); + Delete(pname1); } + Delete(call); + Delete(target); + if (make_set_wrapper) { Setattr(n, "sym:name", mrename_set); functionWrapper(n); diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index 3ed736f54..7c6837a2b 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -1203,7 +1203,7 @@ int Swig_DestructorToFunction(Node *n, String *classname, int cplus, int flags) * This function creates a C wrapper for setting a structure member. * ----------------------------------------------------------------------------- */ -int Swig_MembersetToFunction(Node *n, String *classname, int flags) { +int Swig_MembersetToFunction(Node *n, String *classname, int flags, String **call) { String *name; ParmList *parms; Parm *p; @@ -1251,23 +1251,21 @@ int Swig_MembersetToFunction(Node *n, String *classname, int flags) { Delete(p); if (flags & CWRAP_EXTEND) { - String *call; String *cres; String *code = Getattr(n, "code"); if (code) { /* I don't think this ever gets run - WSF */ Swig_add_extension_code(n, mangled, parms, void_type, code, cparse_cplusplus, "self"); } - call = Swig_cfunction_call(mangled, parms); - cres = NewStringf("%s;", call); + *call = Swig_cfunction_call(mangled, parms); + cres = NewStringf("%s;", *call); Setattr(n, "wrap:action", cres); - Delete(call); Delete(cres); } else { - String *call = Swig_cmemberset_call(name, type, self, varcref); - String *cres = NewStringf("%s;", call); + String *cres; + *call = Swig_cmemberset_call(name, type, self, varcref); + cres = NewStringf("%s;", *call); Setattr(n, "wrap:action", cres); - Delete(call); Delete(cres); } Setattr(n, "type", void_type); diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h index ade2d04c3..2b2c797c9 100644 --- a/Source/Swig/swig.h +++ b/Source/Swig/swig.h @@ -343,7 +343,7 @@ extern int ParmList_is_compactdefargs(ParmList *p); extern int Swig_MethodToFunction(Node *n, String *classname, int flags, SwigType *director_type, int is_director); extern int Swig_ConstructorToFunction(Node *n, String *classname, String *none_comparison, String *director_ctor, 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, String **call); extern int Swig_MembergetToFunction(Node *n, String *classname, int flags); extern int Swig_VargetToFunction(Node *n, int flags); extern int Swig_VarsetToFunction(Node *n, int flags);