Improve director unwrap detection for the return type

Resolve the return type to correctly determine if the type is a pointer or
reference to a director class.

SwigType_refptr_count_return() recently added as a simpler fix is no
longer needed.

The conventional approach of using the "type" rather than "decl" to
analyse the return type is used instead too.

Issue #1823
This commit is contained in:
William S Fulton 2022-10-10 08:27:44 +01:00
commit 2f55379687
10 changed files with 76 additions and 90 deletions

View file

@ -3150,25 +3150,9 @@ public:
Replaceall(tm, "$owner", "0");
}
}
// FIXME: this will not try to unwrap directors returned as non-director
// base class pointers!
/* New addition to unwrap director return values so that the original
* python object is returned instead.
*/
#if 1
int unwrap = 0;
String *decl = Getattr(n, "decl");
if (SwigType_refptr_count_return(decl) == 1) {
String *type = Getattr(n, "type");
//Node *classNode = Swig_methodclass(n);
//Node *module = Getattr(classNode, "module");
Node *module = Getattr(parent, "module");
Node *target = Swig_directormap(module, type);
if (target)
unwrap = 1;
}
if (unwrap) {
// Unwrap return values that are director classes so that the original Python object is returned instead.
if (!constructor && Swig_director_can_unwrap(n)) {
Wrapper_add_local(f, "director", "Swig::Director *director = 0");
Printf(f->code, "director = SWIG_DIRECTOR_CAST(%s);\n", Swig_cresult_name());
Append(f->code, "if (director) {\n");
@ -3180,9 +3164,7 @@ public:
} else {
Printf(f->code, "%s\n", tm);
}
#else
Printf(f->code, "%s\n", tm);
#endif
Delete(tm);
} else {
Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(d, 0), name);