The typemap for FILE * in ports.i now also accepts a regular FILE *
pointer object. Also a bug with Scheme file ports that are open for input and output has been fixed. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5889 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
959ab00630
commit
eab20219ec
1 changed files with 17 additions and 7 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
/* ports.i --- Guile typemaps for handling ports -*- c -*-
|
/* ports.i --- Guile typemaps for handling ports -*- c -*-
|
||||||
Copyright (C) 2000 Matthias Koeppe <mkoeppe@mail.math.uni-magdeburg.de>
|
Copyright (C) 2000, 2004 Matthias Koeppe <mkoeppe@mail.math.uni-magdeburg.de>
|
||||||
|
|
||||||
$Header$
|
$Header$
|
||||||
*/
|
*/
|
||||||
|
|
@ -14,11 +14,19 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
%}
|
%}
|
||||||
|
|
||||||
/* Feed temporary FILE * arguments from file ports */
|
/* This typemap for FILE * accepts
|
||||||
|
(1) FILE * pointer objects,
|
||||||
|
(2) Scheme file ports. In this case, it creates a temporary C stream
|
||||||
|
which reads or writes from a dup'ed file descriptor.
|
||||||
|
*/
|
||||||
|
|
||||||
%typemap(in, doc="$NAME is a port") FILE *
|
%typemap(in, doc="$NAME is a file port or a FILE * pointer") FILE *
|
||||||
|
( int closep )
|
||||||
{
|
{
|
||||||
if(!(SCM_FPORTP($input)))
|
if (SWIG_ConvertPtr($input, (void**) &($1), $1_descriptor, 0) == 0) {
|
||||||
|
closep = 0;
|
||||||
|
}
|
||||||
|
else if(!(SCM_FPORTP($input)))
|
||||||
scm_wrong_type_arg("$name", $argnum, $input);
|
scm_wrong_type_arg("$name", $argnum, $input);
|
||||||
else {
|
else {
|
||||||
int fd;
|
int fd;
|
||||||
|
|
@ -30,14 +38,16 @@
|
||||||
$1=fdopen(fd,
|
$1=fdopen(fd,
|
||||||
SCM_OUTPUT_PORT_P($input)
|
SCM_OUTPUT_PORT_P($input)
|
||||||
? (SCM_INPUT_PORT_P($input)
|
? (SCM_INPUT_PORT_P($input)
|
||||||
? "rw" : "w")
|
? "r+" : "w")
|
||||||
: "r");
|
: "r");
|
||||||
if($1==NULL)
|
if($1==NULL)
|
||||||
scm_misc_error("$name", strerror(errno), SCM_EOL);
|
scm_misc_error("$name", strerror(errno), SCM_EOL);
|
||||||
|
closep = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap(freearg) FILE* {
|
%typemap(freearg) FILE* {
|
||||||
|
if (closep$argnum)
|
||||||
fclose($1);
|
fclose($1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue