mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-112015: Implement ctypes.memoryview_at()
(GH-112018)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Petr Viktorin <encukou@gmail.com> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
This commit is contained in:
parent
f21af186bf
commit
b4f799b1e7
6 changed files with 120 additions and 1 deletions
|
@ -524,6 +524,7 @@ elif sizeof(c_ulonglong) == sizeof(c_void_p):
|
|||
# functions
|
||||
|
||||
from _ctypes import _memmove_addr, _memset_addr, _string_at_addr, _cast_addr
|
||||
from _ctypes import _memoryview_at_addr
|
||||
|
||||
## void *memmove(void *, const void *, size_t);
|
||||
memmove = CFUNCTYPE(c_void_p, c_void_p, c_void_p, c_size_t)(_memmove_addr)
|
||||
|
@ -549,6 +550,14 @@ def string_at(ptr, size=-1):
|
|||
Return the byte string at void *ptr."""
|
||||
return _string_at(ptr, size)
|
||||
|
||||
_memoryview_at = PYFUNCTYPE(
|
||||
py_object, c_void_p, c_ssize_t, c_int)(_memoryview_at_addr)
|
||||
def memoryview_at(ptr, size, readonly=False):
|
||||
"""memoryview_at(ptr, size[, readonly]) -> memoryview
|
||||
|
||||
Return a memoryview representing the memory at void *ptr."""
|
||||
return _memoryview_at(ptr, size, bool(readonly))
|
||||
|
||||
try:
|
||||
from _ctypes import _wstring_at_addr
|
||||
except ImportError:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue