ctypes shared object FILE*

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dog Walker

    ctypes shared object FILE*

    I need to call a function in a shared object with this signature:
    init_dialog(FIL E *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!
  • Aaron Brady

    #2
    Re: ctypes shared object FILE*

    On Nov 8, 6:34 pm, "Dog Walker" <thud...@gmail. comwrote:
    I need to call a function in a shared object with this signature:
    init_dialog(FIL E *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(P yObject *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.python api.PyFile_AsFi le.argtypes= [ ctypes.py_objec t ]
    >>ctypes.python api.PyFile_AsFi le.restype= ctypes.c_void_p
    >>ctypes.python api.PyFile_AsFi le( sys.stdin )
    2019259304
    >>ctypes.python api.PyFile_AsFi le( sys.stdout )
    2019259336

    But I'm confused why PyFile_AsFile didn't return a c_void_p as I
    asked.

    Comment

    Working...