Python typemap for FILE* (in behalf of Marcelo)
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5929 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
9edaaf5a7d
commit
95a6fa8edb
5 changed files with 92 additions and 0 deletions
|
|
@ -1,6 +1,12 @@
|
|||
Version 1.3.22 (in progress)
|
||||
==================================
|
||||
|
||||
05/26/2004: lballabio (Luigi Ballabio)
|
||||
Committed on behalf of Marcelo (who still has problems with
|
||||
the SourceForge CVS.)
|
||||
|
||||
Added Python typemaps for FILE* with (Python-only) test.
|
||||
|
||||
5/24/2004: dancy
|
||||
|
||||
* Allegro CL module: Now using some macros (defined in
|
||||
|
|
|
|||
28
SWIG/Examples/test-suite/file_test.i
Normal file
28
SWIG/Examples/test-suite/file_test.i
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
%module file_test
|
||||
|
||||
%include file.i
|
||||
|
||||
|
||||
%inline
|
||||
%{
|
||||
int nfile(FILE *file) {
|
||||
printf("hello %p\n", (void*)file);
|
||||
if (file) {
|
||||
// fprintf(file,"hello\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nfile(const char *filename) {
|
||||
FILE *file = fopen(filename,"w");
|
||||
nfile(file);
|
||||
fclose(file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
FILE* GetStdOut() {
|
||||
return stdout;
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
|
|
@ -14,6 +14,7 @@ CPP_TEST_CASES += \
|
|||
attributetest \
|
||||
complextest \
|
||||
director_stl \
|
||||
file_test \
|
||||
implicittest \
|
||||
inplaceadd \
|
||||
lib_std_vectora \
|
||||
|
|
|
|||
9
SWIG/Examples/test-suite/python/file_test_runme.py
Normal file
9
SWIG/Examples/test-suite/python/file_test_runme.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import sys
|
||||
import file_test
|
||||
|
||||
file_test.nfile(sys.stdout)
|
||||
|
||||
cstdout = file_test.GetStdOut()
|
||||
|
||||
file_test.nfile(cstdout)
|
||||
file_test.nfile("test.dat")
|
||||
48
SWIG/Lib/python/file.i
Normal file
48
SWIG/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