Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > ctypes shared object FILE*

Reply
Thread Tools

ctypes shared object FILE*

 
 
Dog Walker
Guest
Posts: n/a
 
      11-09-2008
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!
 
Reply With Quote
 
 
 
 
Aaron Brady
Guest
Posts: n/a
 
      11-09-2008
On Nov 8, 6:34*pm, "Dog Walker" <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shared Memory Example (Python, ctypes, VC++) Srijit Kumar Bhadra Python 2 11-16-2008 09:35 AM
WindowsXP/ CTypes - How to convert ctypes array to a string? dudeja.rajat@gmail.com Python 0 08-19-2008 10:20 AM
Working with C object of python object (pycairo,ctypes) AngelBlaZe Python 1 02-27-2007 09:37 AM
RE: [ctypes-users] [Ann] ctypes 0.9.0 released Henk Punt Python 0 07-23-2004 10:34 PM
built with --enable-shared but get error: libpython2.3.so.1.0: can't open shared object file Douglass Turner Python 2 09-04-2003 01:56 PM



Advertisments