logo       

Re: Supplying default OUTPUT values: msg#00147

programming.swig

Subject: Re: Supplying default OUTPUT values

Cory Omand wrote:

I am attempting to wrap a function which opens a log file for use with
Perl. The function signature is:

log_t *
log_open(int version, const char *path, int *err);

In my SWIG interface file, I've specified this as:

%include "typemap.i"

%apply int *OUTPUT { int *error };
extern log_t *
log_open(int, const char *, int *error);

When I compile the module and use this function as:

($ptr, $err) = log_open($version, $path);

I get a random value in $err if the operation was successful. When an
actual error occurs, $err is set properly.

Can I have SWIG assign a default value to *error, such that the value of
$err is either zero (preferred), or undef? Alternately, is there a way
to have SWIG override 'errno', such that $! in perl would behave as
expected (e.g. numeric value from *error, and string value set by
another wrapped function log_err())?


Supply a new "in" typemap with your default value...

%include "typemaps.i"
%typemap(in,numinputs=0) int *OUTPUT(int temp = -1) "$1 = &temp;";

William
_______________________________________________
Swig maillist - Swig@xxxxxxxxxxxxxxx
http://mailman.cs.uchicago.edu/mailman/listinfo/swig



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise