8000 Add docstrings for POINTER and pointer · python/cpython@e251a7d · GitHub
[go: up one dir, main page]

Skip to content

Commit e251a7d

Browse files
Add docstrings for POINTER and pointer
1 parent efd4961 commit e251a7d

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

Lib/ctypes/__init__.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,19 @@ class c_bool(_SimpleCData):
268268
from _ctypes import POINTER, pointer, _pointer_type_cache
269269

270270
def POINTER(cls):
271+
"""
272+
Create and return a new ctypes pointer type.
273+
274+
cls
275+
A ctypes type.
276+
277+
Pointer types are cached and reused internally,
278+
so calling this function repeatedly is cheap.
279+
280+
Pointer types for incomplete types are not cached,
281+
so calling this function repeatedly will give
282+
different types.
283+
"""
271284
if cls is None:
272285
return c_void_p
273286
try:
@@ -280,9 +293,16 @@ def POINTER(cls):
280293
return type(f'LP_{cls}', (_Pointer,), {})
281294
return type(f'LP_{cls.__name__}', (_Pointer,), {'_type_': cls})
282295

283-
def pointer(arg):
284-
typ = POINTER(type(arg))
285-
return typ(arg)
296+
def pointer(obj):
297+
"""
298+
Create a new pointer instance, pointing to 'obj'.
299+
300+
The returned object is of the type POINTER(type(obj)). Note that if you
301+
just want to pass a pointer to an object to a foreign function call, you
302+
should use byref(obj) which is much faster.
303+
"""
304+
typ = POINTER(type(obj))
305+
return typ(obj)
286306

287307
class c_wchar_p(_SimpleCData):
288308
_type_ = "Z"

0 commit comments

Comments
 (0)
0