Passing a FILE* from Python into a MinGW/SWIG module

J

John Pye

Hi all

I understand that I can't hope to pass a FILE* from the Windows
version of Python into a SWIG module that I've built using MinGW gcc/g+
+, because apparently the FILE* structure are different and
incompatible.

Is there an official workaround for this? Presumably I need to
implement a mingw-compatible version of all the 'file' class in
Python, eg

import mingw
import myswigmodule

F1 = mingw.file("newfile.txt","rw")
F1.write("somestuff")
F1.seek(0)
F2 = mingw.tmpfile()
myswigmodule.dosomething(F1,F2)
F2.seek(0)
print F2.read()

Has anyone done this? Is there a better way that doesn't require users
of my module to adapt? Do I have to use the dreaded MSVS to compile my
SWIG module?

Cheers
JP
 
R

Ross Ridge

John Pye said:
Is there an official workaround for this? Presumably I need to
implement a mingw-compatible version of all the 'file' class in
Python, eg

I'm not familiar with SWIG, but why not pass Python's own file class?
Method calls on Python's file class will be dispatched to C code in
the Python interpreter and so will use the C runtime that Python was
linked with.

Ross Ridge
 
T

Tommy Nordgren

Hi all

I understand that I can't hope to pass a FILE* from the Windows
version of Python into a SWIG module that I've built using MinGW
gcc/g+
+, because apparently the FILE* structure are different and
incompatible.

Is there an official workaround for this? Presumably I need to
implement a mingw-compatible version of all the 'file' class in
Python, eg

import mingw
import myswigmodule

F1 = mingw.file("newfile.txt","rw")
F1.write("somestuff")
F1.seek(0)
F2 = mingw.tmpfile()
myswigmodule.dosomething(F1,F2)
F2.seek(0)
print F2.read()

Has anyone done this? Is there a better way that doesn't require users
of my module to adapt? Do I have to use the dreaded MSVS to compile my
SWIG module?

Cheers
JP
Can you get the file descriptor from the FILE *, and use that?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top