I am using ctypes to wrap a C-library (which I have control over) with Python. I want to wrap a C-function with declaration:
int fread_int( FILE * stream );
Adapted from svplayer
import sys
from ctypes import POINTER, Structure, py_object, pythonapi
class File(Structure):
pass
if sys.version_info[0] > 2:
convert_file = pythonapi.PyObject_AsFileDescriptor
convert_file.restype = c_int
else:
convert_file = pythonapi.PyFile_AsFile
convert_file.restype = POINTER(File)
convert_file.argtypes = [py_object]
fp = open('path').fp
c_file = convert_file(fp)