Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
236657b
Implement `ctypes.buffer_at()`
rianhunter Nov 13, 2023
55d7690
Fix typo
rianhunter Nov 13, 2023
00e3c23
Apply suggestions from code review
rianhunter Jan 18, 2024
df0f992
Make size argument a Py_ssize_t, per @serhiy-storchaka suggestion
rianhunter Jan 19, 2024
eaa2d13
Add what's new entry
rianhunter Jan 19, 2024
db3a26a
Rename buffer_at to memoryview_at
rianhunter Jan 19, 2024
d7e2f25
Make mutable objects the default
rianhunter Jan 19, 2024
097a41c
Add test for ctypes.memoryview_at
rianhunter Jan 19, 2024
4fe9b44
Merge in the main branch; move What's New entry
encukou Sep 18, 2024
e2c2609
TMP
encukou Sep 18, 2024
d39bb42
Merge in the main branch
encukou Nov 29, 2024
3a6b559
Revert to calling through `ctypes` to get `c_void_p` conversion seman…
encukou Nov 29, 2024
375081a
Test read-only memoryview
encukou Nov 29, 2024
b9e8572
Use c_ssize_t for the size
encukou Nov 29, 2024
1a33fe3
Test size overflow
encukou Nov 29, 2024
0198c89
Doc fixups. Don't imply that *readonly* makes the memory immutable.
encukou Nov 29, 2024
6b0a8ae
Fixups
encukou Nov 29, 2024
e4af54f
Merge branch 'main' into ctypes-buffer-at
encukou Dec 12, 2024
5600cef
Apply suggestions from code review
encukou Dec 19, 2024
c3c9e17
Avoid extra variable
encukou Dec 19, 2024
d1ca15d
Merge in the main branch
encukou Dec 19, 2024
d41a201
Remove unneeded line
encukou Dec 20, 2024
f3b1987
Merge in the main branch
encukou Dec 20, 2024
82a6659
Merge in the main branch
encukou Jan 2, 2025
400a62d
Remove unneeded line
encukou Jan 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixups
  • Loading branch information
encukou committed Nov 29, 2024
commit 6b0a8ae6429dbe2f41985dfc04e79e29494ab0e1
2 changes: 1 addition & 1 deletion Doc/library/ctypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2181,7 +2181,7 @@ Utility functions
(While :meth:`~_CData.from_address` only takes integers, *ptr* can also
be given as a :class:`ctypes.POINTER` or a :func:`~ctypes.byref` object.)

.. audit-event:: ctypes.memoryview_at address,size,readonly ctypes.buffer_at
.. audit-event:: ctypes.memoryview_at address,size,readonly

.. versionadded:: next

Comment thread
rianhunter marked this conversation as resolved.
Expand Down
4 changes: 3 additions & 1 deletion Lib/ctypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,8 @@ 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)
_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]) -> memoryview
Comment thread
encukou marked this conversation as resolved.
Outdated

Expand All @@ -569,6 +570,7 @@ def wstring_at(ptr, size=-1):
Return the wide-character string at void *ptr."""
return _wstring_at(ptr, size)


if _os.name == "nt": # COM stuff
def DllGetClassObject(rclsid, riid, ppv):
try:
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_ctypes/test_memfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_memoryview_at(self):
b,
cast(b, c_void_p),
byref(b),
addressof(b)
addressof(b),
):
with self.subTest(foreign_ptr=type(foreign_ptr).__name__):
b[:] = b"initialval"
Expand Down Expand Up @@ -122,7 +122,7 @@ def test_memoryview_at_readonly(self):
b,
cast(b, c_void_p),
byref(b),
addressof(b)
addressof(b),
):
with self.subTest(foreign_ptr=type(foreign_ptr).__name__):
b[:] = b"initialval"
Expand Down
1 change: 0 additions & 1 deletion Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -5934,7 +5934,6 @@ _ctypes_mod_exec(PyObject *mod)
if (_ctypes_add_objects(mod) < 0) {
return -1;
}

return 0;
}

Expand Down