Fix unnecessary and inconsistent null pointer checks
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13912 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
7299392ebb
commit
e0967f3e13
3 changed files with 238 additions and 249 deletions
|
|
@ -3472,7 +3472,7 @@ public:
|
|||
Wrapper *w = NewWrapper();
|
||||
ParmList *l = Getattr(n, "parms");
|
||||
bool is_void = !(Cmp(returntype, "void"));
|
||||
String *qualified_return = NewString("");
|
||||
String *qualified_return = 0;
|
||||
bool pure_virtual = (!(Cmp(storage, "virtual")) && !(Cmp(value, "0")));
|
||||
int status = SWIG_OK;
|
||||
bool output_director = true;
|
||||
|
|
@ -3496,90 +3496,86 @@ public:
|
|||
|
||||
imclass_dmethod = NewStringf("SwigDirector_%s", Swig_name_member(getNSpace(), classname, overloaded_name));
|
||||
|
||||
if (returntype) {
|
||||
qualified_return = SwigType_rcaststr(returntype, "c_result");
|
||||
|
||||
Delete(qualified_return);
|
||||
qualified_return = SwigType_rcaststr(returntype, "c_result");
|
||||
|
||||
if (!is_void && !ignored_method) {
|
||||
if (!SwigType_isclass(returntype)) {
|
||||
if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) {
|
||||
String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0));
|
||||
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL);
|
||||
Delete(construct_result);
|
||||
} else {
|
||||
String *base_typename = SwigType_base(returntype);
|
||||
String *resolved_typename = SwigType_typedef_resolve_all(base_typename);
|
||||
Symtab *symtab = Getattr(n, "sym:symtab");
|
||||
Node *typenode = Swig_symbol_clookup(resolved_typename, symtab);
|
||||
|
||||
if (SwigType_ispointer(returntype) || (typenode && Getattr(typenode, "abstract"))) {
|
||||
/* initialize pointers to something sane. Same for abstract
|
||||
classes when a reference is returned. */
|
||||
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL);
|
||||
} else {
|
||||
/* If returning a reference, initialize the pointer to a sane
|
||||
default - if a C# exception occurs, then the pointer returns
|
||||
something other than a NULL-initialized reference. */
|
||||
String *non_ref_type = Copy(returntype);
|
||||
|
||||
/* Remove reference and const qualifiers */
|
||||
Replaceall(non_ref_type, "r.", "");
|
||||
Replaceall(non_ref_type, "q(const).", "");
|
||||
Wrapper_add_localv(w, "result_default", "static", SwigType_str(non_ref_type, "result_default"), "=", SwigType_str(non_ref_type, "()"), NIL);
|
||||
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= &result_default", NIL);
|
||||
|
||||
Delete(non_ref_type);
|
||||
}
|
||||
|
||||
Delete(base_typename);
|
||||
Delete(resolved_typename);
|
||||
}
|
||||
if (!is_void && !ignored_method) {
|
||||
if (!SwigType_isclass(returntype)) {
|
||||
if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) {
|
||||
String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0));
|
||||
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL);
|
||||
Delete(construct_result);
|
||||
} else {
|
||||
SwigType *vt;
|
||||
String *base_typename = SwigType_base(returntype);
|
||||
String *resolved_typename = SwigType_typedef_resolve_all(base_typename);
|
||||
Symtab *symtab = Getattr(n, "sym:symtab");
|
||||
Node *typenode = Swig_symbol_clookup(resolved_typename, symtab);
|
||||
|
||||
vt = cplus_value_type(returntype);
|
||||
if (!vt) {
|
||||
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL);
|
||||
if (SwigType_ispointer(returntype) || (typenode && Getattr(typenode, "abstract"))) {
|
||||
/* initialize pointers to something sane. Same for abstract
|
||||
classes when a reference is returned. */
|
||||
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL);
|
||||
} else {
|
||||
Wrapper_add_localv(w, "c_result", SwigType_lstr(vt, "c_result"), NIL);
|
||||
Delete(vt);
|
||||
/* If returning a reference, initialize the pointer to a sane
|
||||
default - if a C# exception occurs, then the pointer returns
|
||||
something other than a NULL-initialized reference. */
|
||||
String *non_ref_type = Copy(returntype);
|
||||
|
||||
/* Remove reference and const qualifiers */
|
||||
Replaceall(non_ref_type, "r.", "");
|
||||
Replaceall(non_ref_type, "q(const).", "");
|
||||
Wrapper_add_localv(w, "result_default", "static", SwigType_str(non_ref_type, "result_default"), "=", SwigType_str(non_ref_type, "()"), NIL);
|
||||
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= &result_default", NIL);
|
||||
|
||||
Delete(non_ref_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Create the intermediate class wrapper */
|
||||
tm = Swig_typemap_lookup("imtype", n, "", 0);
|
||||
if (tm) {
|
||||
String *imtypeout = Getattr(n, "tmap:imtype:out"); // the type in the imtype typemap's out attribute overrides the type in the typemap
|
||||
if (imtypeout)
|
||||
tm = imtypeout;
|
||||
const String *im_directoroutattributes = Getattr(n, "tmap:imtype:directoroutattributes");
|
||||
if (im_directoroutattributes) {
|
||||
Printf(callback_def, " %s\n", im_directoroutattributes);
|
||||
Printf(director_delegate_definitions, " %s\n", im_directoroutattributes);
|
||||
}
|
||||
|
||||
Printf(callback_def, " private %s SwigDirector%s(", tm, overloaded_name);
|
||||
if (!ignored_method)
|
||||
Printf(director_delegate_definitions, " public delegate %s", tm);
|
||||
} else {
|
||||
Swig_warning(WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF, input_file, line_number, "No imtype typemap defined for %s\n", SwigType_str(returntype, 0));
|
||||
}
|
||||
|
||||
if ((c_ret_type = Swig_typemap_lookup("ctype", n, "", 0))) {
|
||||
if (!is_void && !ignored_method) {
|
||||
String *jretval_decl = NewStringf("%s jresult", c_ret_type);
|
||||
Wrapper_add_localv(w, "jresult", jretval_decl, "= 0", NIL);
|
||||
Delete(jretval_decl);
|
||||
Delete(base_typename);
|
||||
Delete(resolved_typename);
|
||||
}
|
||||
} else {
|
||||
Swig_warning(WARN_CSHARP_TYPEMAP_CTYPE_UNDEF, input_file, line_number, "No ctype typemap defined for %s for use in %s::%s (skipping director method)\n",
|
||||
SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
|
||||
output_director = false;
|
||||
SwigType *vt;
|
||||
|
||||
vt = cplus_value_type(returntype);
|
||||
if (!vt) {
|
||||
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL);
|
||||
} else {
|
||||
Wrapper_add_localv(w, "c_result", SwigType_lstr(vt, "c_result"), NIL);
|
||||
Delete(vt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Create the intermediate class wrapper */
|
||||
tm = Swig_typemap_lookup("imtype", n, "", 0);
|
||||
if (tm) {
|
||||
String *imtypeout = Getattr(n, "tmap:imtype:out"); // the type in the imtype typemap's out attribute overrides the type in the typemap
|
||||
if (imtypeout)
|
||||
tm = imtypeout;
|
||||
const String *im_directoroutattributes = Getattr(n, "tmap:imtype:directoroutattributes");
|
||||
if (im_directoroutattributes) {
|
||||
Printf(callback_def, " %s\n", im_directoroutattributes);
|
||||
Printf(director_delegate_definitions, " %s\n", im_directoroutattributes);
|
||||
}
|
||||
|
||||
Printf(callback_def, " private %s SwigDirector%s(", tm, overloaded_name);
|
||||
if (!ignored_method)
|
||||
Printf(director_delegate_definitions, " public delegate %s", tm);
|
||||
} else {
|
||||
Swig_warning(WARN_CSHARP_TYPEMAP_CSTYPE_UNDEF, input_file, line_number, "No imtype typemap defined for %s\n", SwigType_str(returntype, 0));
|
||||
}
|
||||
|
||||
if ((c_ret_type = Swig_typemap_lookup("ctype", n, "", 0))) {
|
||||
if (!is_void && !ignored_method) {
|
||||
String *jretval_decl = NewStringf("%s jresult", c_ret_type);
|
||||
Wrapper_add_localv(w, "jresult", jretval_decl, "= 0", NIL);
|
||||
Delete(jretval_decl);
|
||||
}
|
||||
} else {
|
||||
Swig_warning(WARN_CSHARP_TYPEMAP_CTYPE_UNDEF, input_file, line_number, "No ctype typemap defined for %s for use in %s::%s (skipping director method)\n",
|
||||
SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
|
||||
output_director = false;
|
||||
}
|
||||
|
||||
Swig_director_parms_fixup(l);
|
||||
|
||||
/* Attach the standard typemaps */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue