ctypes shared object FILE*

Discussion in 'Python' started by Dog Walker, Nov 9, 2008.

  1. Dog Walker

    Dog Walker Guest

    I need to call a function in a shared object with this signature:
    init_dialog(FILE *input, FILE *output)
    The FILE*'s are to stdin and stdout.

    The call from python is libdialog.init_dialog( x, y)
    I need to define x and y so that they will have the structure of
    sys.stdin and sys.stdout; the called function (init_dialog) is using a
    (std?) function fileno to extract the fileno from the FILE* describing
    stdin and stdout.
    How can I do this?

    --
    I have seen the future and I'm not in it!
     
    Dog Walker, Nov 9, 2008
    #1
    1. Advertising

  2. Dog Walker

    Aaron Brady Guest

    On Nov 8, 6:34 pm, "Dog Walker" <> wrote:
    > I need to call a function in a shared object with this signature:
    > init_dialog(FILE *input, FILE *output)
    > The FILE*'s are to stdin and stdout.
    >
    > The call from python is libdialog.init_dialog( x, y)
    > I need to define x and y so that they will have the structure of
    > sys.stdin and sys.stdout; the called function (init_dialog) is using a
    > (std?) function fileno to extract the fileno from the FILE* describing
    > stdin and stdout.
    > How can I do this?
    >
    > --
    > I have seen the future and I'm not in it!


    sys.stdin and sys.stdout have a 'fileno' method, which returns an
    integer.

    FILE* PyFile_AsFile(PyObject *p)
    Return the file object associated with p as a FILE*.

    This might be what you want. You need to inform the function of what
    types to expect and return.

    >>> import sys
    >>> import ctypes
    >>> ctypes.pythonapi.PyFile_AsFile.argtypes= [ ctypes.py_object ]
    >>> ctypes.pythonapi.PyFile_AsFile.restype= ctypes.c_void_p
    >>> ctypes.pythonapi.PyFile_AsFile( sys.stdin )

    2019259304
    >>> ctypes.pythonapi.PyFile_AsFile( sys.stdout )

    2019259336

    But I'm confused why PyFile_AsFile didn't return a c_void_p as I
    asked.
     
    Aaron Brady, Nov 9, 2008
    #2
    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. Douglass Turner
    Replies:
    2
    Views:
    2,100
    Manfred Bartz
    Sep 4, 2003
  2. Henk Punt
    Replies:
    0
    Views:
    424
    Henk Punt
    Jul 23, 2004
  3. Srijit Kumar Bhadra

    Shared Memory Example (Python, ctypes, VC++)

    Srijit Kumar Bhadra, Mar 19, 2005, in forum: Python
    Replies:
    2
    Views:
    6,875
    jlchereau
    Nov 16, 2008
  4. Srijit Kumar Bhadra
    Replies:
    0
    Views:
    872
    Srijit Kumar Bhadra
    Apr 2, 2005
  5. Replies:
    0
    Views:
    535
Loading...

Share This Page