472,117 Members | 2,667 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,117 software developers and data experts.

ctypes shared object FILE*

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!
Nov 9 '08 #1
1 3395
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(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.
Nov 9 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Thomas Heller | last post: by
19 posts views Thread by Thomas Heller | last post: by
1 post views Thread by Srijit Kumar Bhadra | last post: by
reply views Thread by Srijit Kumar Bhadra | last post: by
3 posts views Thread by Paddy | last post: by
2 posts views Thread by Sells, Fred | last post: by
reply views Thread by member thudfoo | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.