jaeandersson / swig

SWIG is a software development tool that connects programs written in C and C++ with a variety of high-level programming languages.
http://www.swig.org
Other
23 stars 19 forks source link

STL Container improvements & changes to output argument syntax #63

Closed dcb210 closed 8 years ago

jaeandersson commented 8 years ago

About varargout - I'm not quite sure I understand the logic above. It looks very complicated. I also don't understand when the current design won't work.

The MATLAB user expects to get an "ans" output, so it's quite central.

That being said, the current rule is a bit unclear. A cleaner solution would maybe be to have:

A completely other approach is move the whole logic to the MEX. If I'm not mistaken, if you have a mex signature such as:

void fcn(int resc, mxArray *resv[], int argc, const mxArray *argv[])

you can assign to resv[0] even if resc is 0. That is, the ans output. This way, we can get an 'ans' output only for the specific overloads which have one output. No need to have all overloads behave the same way.

dcb210 commented 8 years ago

I’m not sure why the varargout was created. I just know that the original implementation does not work if a 'typemap(argout) Type “”;’ exists. I think it’s needed for the case where there are no outputs at all, not when an output exists but is not assigned by the user. varargout{1:nargout} handles the no output at all case correctly.

On Sep 23, 2015, at 4:02 PM, Joel Andersson notifications@github.com wrote:

About varargout - I'm not quite sure I understand the logic above. It looks very complicated. I also don't understand when the current design won't work.

The MATLAB user expects to get an "ans" output, so it's quite central.

That being said, the current rule is a bit unclear. A cleaner solution would maybe be to have:

No varargout at all when there is no output for any overload That is, varargout{1} when there is exactly one output for all overloads varargout{:} or varargout{1:max(1,nargout)} depending on whether some feature has been set. A completely other approach is move the whole logic to the MEX. If I'm not mistaken, if you have a mex signature such as:

void fcn(int resc, mxArray resv[], int argc, const mxArray argv[]) you can assign to resv[0] even if resc is 0. That is, the ans output. This way, we can get an 'ans' output only for the specific overloads which have one output. No need to have all overloads behave the same way.

— Reply to this email directly or view it on GitHub https://github.com/jaeandersson/swig/pull/63#issuecomment-142712840.

jaeandersson commented 8 years ago

I think we might be doing things way to complicated. Have a look at a3388cd45b11f32390a24f58566ae810bcedd2ae (committed to a separate branch). For me it appears to work fine, but I didn't do extensive testing.

jaeandersson commented 8 years ago

I posted a question at MATLAB answers for this:

http://www.mathworks.com/matlabcentral/answers/244970-wrapping-a-mex-function-which-has-with-ans-output-in-some-cases

Would be good to get a proper solution to this.

jaeandersson commented 8 years ago

Please have a look at https://github.com/jaeandersson/swig/pull/64. I'm quite sure that is the proper solution. The other commit (c47df74) looks fine though.

jaeandersson commented 8 years ago

Cherry-picked 490d28a3d18da594cc83bc4626319db142c9f9df and committed e80dc0acb7f9933b0ab101674f0fb0c87bc2bce8, which replaces fbb673d.