Open vmonteco opened 3 months ago
It's a mistake in the docs, but the source of the mistake is understandable. Instances of ctypes.CDLL
create a dynamic _FuncPtr
subclass of ctypes._CFuncPtr
, with a particular _restype_
and _flags_
. For example:
>>> lib = ctypes.CDLL(None)
>>> issubclass(lib._FuncPtr, ctypes._CFuncPtr)
True
>>> hasattr(ctypes._CFuncPtr, '_restype_')
False
>>> hasattr(ctypes._CFuncPtr, '_flags_')
False
>>> lib._FuncPtr._restype_
<class 'ctypes.c_int'>
>>> lib._FuncPtr._flags_ == ctypes._FUNCFLAG_CDECL
True
>>> lib2 = ctypes.CDLL(None, use_errno=True)
>>> lib2._FuncPtr._flags_ == ctypes._FUNCFLAG_CDECL | ctypes._FUNCFLAG_USE_ERRNO
True
It's a mistake in the docs, but the source of the mistake is understandable. Instances of
ctypes.CDLL
create a dynamic_FuncPtr
subclass ofctypes._CFuncPtr
, with a particular_restype_
and_flags_
. For example:>>> lib = ctypes.CDLL(None) >>> issubclass(lib._FuncPtr, ctypes._CFuncPtr) True >>> hasattr(ctypes._CFuncPtr, '_restype_') False >>> hasattr(ctypes._CFuncPtr, '_flags_') False >>> lib._FuncPtr._restype_ <class 'ctypes.c_int'> >>> lib._FuncPtr._flags_ == ctypes._FUNCFLAG_CDECL True >>> lib2 = ctypes.CDLL(None, use_errno=True) >>> lib2._FuncPtr._flags_ == ctypes._FUNCFLAG_CDECL | ctypes._FUNCFLAG_USE_ERRNO True
I see, thank you for the explanation.
Documentation
Module
ctypes
doesn't seem to provide_FuncPtr
when imported.However, it provides
_CFuncType
that really looks similar to_FuncPtr
as described by the documentation according tohelp()
.Could it be a typo in the documentation?
Linked PRs