logo       

Re: Re: using stdout/stderr with python: msg#00138

programming.swig

Subject: Re: Re: using stdout/stderr with python

On 2004.05.25 17:48, Kevin Smith wrote:
Martin F Krafft wrote:
Some of my functions take a FILE*. I understand how one can
provide wrappers or a typemap to deal with that, but what if
I want to pass stdout and stderr into these functions as the FILE*
arguments? I could not find a way to do this.

One way would be to create C functions like GetStdin and GetStdout, and wrap them. This way, from Python, you could get access to FILE* versions of those streams. Then, you can pass those values back into your other functions.

This wouldn't help when next he wants to pass a Python file handle created with open(). From a quick look at the Python/C API (see
http://www.python.org/doc/2.3.3/api/fileObjects.html) the following might work:

%typemap(in) FILE* {
if (PyFile_Check($input)) {
$1 = PyFile_AsFile($input);
} else {
SWIG_exception(SWIG_TypeError, "file expected"),
}
}

but I haven't tested it, so I don't guarantee that it won't cause scripts to crash horribly.

Hope this helps,
Luigi
_______________________________________________
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