|
Re: Re: using stdout/stderr with python: msg#00155programming.swig
Luigi: Could you add the attached files to CVS? file.i -> Lib/python file_test.i, file_test_runme.py -> Examples/test-suite/python I still don't know how to make the new CVS rep. work for me. Anyway, the file.i should be used as usual %module mymodule ... %include file.i ... int myfunc(FILE *file); ... and it will provide the proper 'in' typemaps. Then you can call: import sys import mymodule .... mymodule.myfunc(sys.stdout) See the file_test_runme.py for more examples. Marcelo Luigi Ballabio wrote: On 2004.05.25 17:48, Kevin Smith wrote: /* Typemaps for FILE* From the ideas of Luigi luigi.ballabio@xxxxxxxxxxxxx */ %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*); %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; } %} import sys import file_test file_test.nfile(sys.stdout) cstdout = file_test.GetStdOut() file_test.nfile(cstdout) file_test.nfile("test.dat") |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | RE: SWIG and autotools - some solutions (corrected further): 00155, Craig N. Scott |
|---|---|
| Next by Date: | Re: mh, it's acting up.: 00155, Marcelo Matus |
| Previous by Thread: | Re: Re: using stdout/stderr with pythoni: 00155, Luigi Ballabio |
| Next by Thread: | Re: Re: using stdout/stderr with python: 00155, Martin F Krafft |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |