[issue27274] [ctypes] Allow from_pointer creation
Memeplex
report at bugs.python.org
Sat Jul 9 13:36:48 EDT 2016
Memeplex added the comment:
I have been happily using this helper function:
def c_array(*args):
if type(args[1]) is int:
ptr, size = args
return (ptr._type_ * size).from_address(ct.addressof(ptr.contents))
else:
c_type, buf = args
return (c_type * (len(buf) // ct.sizeof(c_type))).from_buffer_copy(buf)
For example:
c_array(ptr_obj, 10)
c_array(c_int, bytes_obj)
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27274>
_______________________________________
More information about the Python-bugs-list
mailing list