Python typemap for FILE* (in behalf of Marcelo)
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5929 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
e465a6ae6a
commit
d062b8cce8
5 changed files with 92 additions and 0 deletions
48
Lib/python/file.i
Normal file
48
Lib/python/file.i
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
Typemaps for FILE*
|
||||
|
||||
From the ideas of Luigi
|
||||
luigi.ballabio@fastwebnet.it
|
||||
*/
|
||||
|
||||
%types(FILE *);
|
||||
|
||||
/* defining basic methods */
|
||||
%fragment("SWIG_AsValFilePtr","header") {
|
||||
SWIGSTATICINLINE(int)
|
||||
SWIG_AsValFilePtr(PyObject *obj, FILE **val) {
|
||||
static swig_type_info* desc = 0;
|
||||
FILE *ptr = 0;
|
||||
if (!desc) desc = SWIG_TypeQuery("FILE *");
|
||||
if ((SWIG_ConvertPtr(obj,(void **)(&ptr), desc, 0)) != -1) {
|
||||
if (val) *val = ptr;
|
||||
return 1;
|
||||
}
|
||||
if (PyFile_Check(obj)) {
|
||||
if (val) *val = PyFile_AsFile(obj);
|
||||
return 1;
|
||||
}
|
||||
if (val) PyErr_SetString(PyExc_TypeError, "a FILE* is expected");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment("SWIG_AsFilePtr","header",fragment="SWIG_AsValFilePtr") {
|
||||
SWIGSTATICINLINE(FILE*)
|
||||
SWIG_AsFilePtr(PyObject *obj) {
|
||||
FILE *val = 0;
|
||||
SWIG_AsValFilePtr(obj, &val);
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment("SWIG_CheckFilePtr","header",fragment="SWIG_AsValFilePtr") {
|
||||
SWIGSTATICINLINE(int)
|
||||
SWIG_CheckFilePtr(PyObject *obj) {
|
||||
return SWIG_AsValFilePtr(obj, (FILE **)(0));
|
||||
}
|
||||
}
|
||||
|
||||
/* defining the typemaps */
|
||||
%typemap_ascheck(SWIG_CCode(POINTER), SWIG_AsFilePtr, SWIG_CheckFilePtr,
|
||||
"SWIG_AsFilePtr", "SWIG_CheckFilePtr", FILE*);
|
||||
Loading…
Add table
Add a link
Reference in a new issue