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
|
|
@ -1,6 +1,12 @@
|
||||||
Version 1.3.22 (in progress)
|
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
|
5/24/2004: dancy
|
||||||
|
|
||||||
* Allegro CL module: Now using some macros (defined in
|
* Allegro CL module: Now using some macros (defined in
|
||||||
|
|
|
||||||
28
Examples/test-suite/file_test.i
Normal file
28
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 \
|
attributetest \
|
||||||
complextest \
|
complextest \
|
||||||
director_stl \
|
director_stl \
|
||||||
|
file_test \
|
||||||
implicittest \
|
implicittest \
|
||||||
inplaceadd \
|
inplaceadd \
|
||||||
lib_std_vectora \
|
lib_std_vectora \
|
||||||
|
|
|
||||||
9
Examples/test-suite/python/file_test_runme.py
Normal file
9
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
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