mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
Issue #2616: Implement ctypes.pointer() and ctypes.POINTER() in C for
better performance.
This commit is contained in:
parent
da950eb01c
commit
046e6a43ff
5 changed files with 83 additions and 25 deletions
|
@ -242,27 +242,7 @@ _check_size(c_void_p)
|
|||
class c_bool(_SimpleCData):
|
||||
_type_ = "?"
|
||||
|
||||
# This cache maps types to pointers to them.
|
||||
_pointer_type_cache = {}
|
||||
|
||||
def POINTER(cls):
|
||||
try:
|
||||
return _pointer_type_cache[cls]
|
||||
except KeyError:
|
||||
pass
|
||||
if type(cls) is str:
|
||||
klass = type(_Pointer)("LP_%s" % cls,
|
||||
(_Pointer,),
|
||||
{})
|
||||
_pointer_type_cache[id(klass)] = klass
|
||||
return klass
|
||||
else:
|
||||
name = "LP_%s" % cls.__name__
|
||||
klass = type(_Pointer)(name,
|
||||
(_Pointer,),
|
||||
{'_type_': cls})
|
||||
_pointer_type_cache[cls] = klass
|
||||
return klass
|
||||
from _ctypes import POINTER, pointer, _pointer_type_cache
|
||||
|
||||
try:
|
||||
from _ctypes import set_conversion_mode
|
||||
|
@ -312,10 +292,6 @@ def SetPointerType(pointer, cls):
|
|||
_pointer_type_cache[cls] = pointer
|
||||
del _pointer_type_cache[id(pointer)]
|
||||
|
||||
|
||||
def pointer(inst):
|
||||
return POINTER(type(inst))(inst)
|
||||
|
||||
# XXX Deprecated
|
||||
def ARRAY(typ, len):
|
||||
return typ * len
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue