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

Discussion in 'Python' started by John Pye, Mar 14, 2007.

  1. John Pye

    John Pye Guest

    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
     
    John Pye, Mar 14, 2007
    #1
    1. Advertising

  2. John Pye

    Ross Ridge Guest

    John Pye <> wrote:
    >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

    --
    l/ // Ross Ridge -- The Great HTMU
    [oo][oo]
    -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/
    db //
     
    Ross Ridge, Mar 15, 2007
    #2
    1. Advertising

  3. On 14 mar 2007, at 11.57, John Pye wrote:

    > 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?

    -------------------------------------
    This sig is dedicated to the advancement of Nuclear Power
    Tommy Nordgren
     
    Tommy Nordgren, Mar 15, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sam Smith
    Replies:
    0
    Views:
    1,187
    Sam Smith
    Oct 18, 2004
  2. Phil Schmidt

    SWIG, MinGW, and Python 2.3 problem

    Phil Schmidt, Sep 10, 2003, in forum: Python
    Replies:
    0
    Views:
    544
    Phil Schmidt
    Sep 10, 2003
  3. John Pye
    Replies:
    0
    Views:
    453
    John Pye
    Mar 21, 2007
  4. Carl Douglas
    Replies:
    11
    Views:
    518
    Robert Kern
    Mar 23, 2007
  5. xeno fears
    Replies:
    1
    Views:
    502
    Martin v. Löwis
    Oct 4, 2009
Loading...

Share This Page