Skip to content

Commit

Permalink
Fix directed method returning class without default ctor
Browse files Browse the repository at this point in the history
This wasn't working for Go, Ocaml, Octave, PHP, Python or Ruby.

Fixes #1145
  • Loading branch information
ojwb committed Jun 19, 2024
1 parent 1e2b0b8 commit 7424c0f
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Examples/test-suite/director_classes.i
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ bool PrintDebug = false;

struct DoubleHolder
{
DoubleHolder(double v = 0.0) : val(v) {}
DoubleHolder(double v) : val(v) {}
double val;
};

Expand Down
9 changes: 8 additions & 1 deletion Source/Modules/go.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4017,7 +4017,14 @@ class GO:public Language {
Wrapper_add_localv(w, "c_result", SwigType_lstr(result, "c_result"), "= 0", NIL);
}
} else {
String *cres = SwigType_lstr(result, "c_result");
String *cres;
SwigType *vt = cplus_value_type(result);
if (!vt) {
cres = SwigType_lstr(result, "c_result");
} else {
cres = SwigType_lstr(vt, "c_result");
Delete(vt);
}
Printf(w->code, "%s;\n", cres);
Delete(cres);
}
Expand Down
9 changes: 8 additions & 1 deletion Source/Modules/ocaml.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1450,7 +1450,14 @@ class OCAML:public Language {
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL);
}
} else {
String *cres = SwigType_lstr(returntype, "c_result");
String *cres;
SwigType *vt = cplus_value_type(returntype);
if (!vt) {
cres = SwigType_lstr(returntype, "c_result");
} else {
cres = SwigType_lstr(vt, "c_result");
Delete(vt);
}
Printf(w->code, "%s;\n", cres);
Delete(cres);
}
Expand Down
9 changes: 8 additions & 1 deletion Source/Modules/octave.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,14 @@ class OCTAVE:public Language {
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL);
}
} else {
String *cres = SwigType_lstr(returntype, "c_result");
String *cres;
SwigType *vt = cplus_value_type(returntype);
if (!vt) {
cres = SwigType_lstr(returntype, "c_result");
} else {
cres = SwigType_lstr(vt, "c_result");
Delete(vt);
}
Printf(w->code, "%s;\n", cres);
Delete(cres);
}
Expand Down
9 changes: 8 additions & 1 deletion Source/Modules/perl5.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2121,7 +2121,14 @@ class PERL5:public Language {
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL);
}
} else {
String *cres = SwigType_lstr(returntype, "c_result");
String *cres;
SwigType *vt = cplus_value_type(returntype);
if (!vt) {
cres = SwigType_lstr(returntype, "c_result");
} else {
cres = SwigType_lstr(vt, "c_result");
Delete(vt);
}
Printf(w->code, "%s;\n", cres);
Delete(cres);
}
Expand Down
9 changes: 8 additions & 1 deletion Source/Modules/php.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2327,7 +2327,14 @@ class PHP : public Language {
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL);
}
} else {
String *cres = SwigType_lstr(returntype, "c_result");
String *cres;
SwigType *vt = cplus_value_type(returntype);
if (!vt) {
cres = SwigType_lstr(returntype, "c_result");
} else {
cres = SwigType_lstr(vt, "c_result");
Delete(vt);
}
Printf(w->code, "%s;\n", cres);
Delete(cres);
}
Expand Down
9 changes: 8 additions & 1 deletion Source/Modules/python.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5403,7 +5403,14 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL);
}
} else {
String *cres = SwigType_lstr(returntype, "c_result");
String *cres;
SwigType *vt = cplus_value_type(returntype);
if (!vt) {
cres = SwigType_lstr(returntype, "c_result");
} else {
cres = SwigType_lstr(vt, "c_result");
Delete(vt);
}
Printf(w->code, "%s;\n", cres);
Delete(cres);
}
Expand Down
9 changes: 8 additions & 1 deletion Source/Modules/ruby.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3115,7 +3115,14 @@ class RUBY:public Language {
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL);
}
} else {
String *cres = SwigType_lstr(returntype, "c_result");
String *cres;
SwigType *vt = cplus_value_type(returntype);
if (!vt) {
cres = SwigType_lstr(returntype, "c_result");
} else {
cres = SwigType_lstr(vt, "c_result");
Delete(vt);
}
Printf(w->code, "%s;\n", cres);
Delete(cres);
}
Expand Down

0 comments on commit 7424c0f

Please sign in to comment.