5454
5555 */
5656
57+ /*[clinic input]
58+ module _ctypes
59+ [clinic start generated code]*/
60+ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=476a19c49b31a75c]*/
61+
5762#ifndef Py_BUILD_CORE_BUILTIN
5863# define Py_BUILD_CORE_MODULE 1
5964#endif
98103
99104#include "pycore_runtime.h" // _PyRuntime
100105#include "pycore_global_objects.h" // _Py_ID()
106+ #include "clinic/callproc.c.h"
101107
102108#define CTYPES_CAPSULE_NAME_PYMEM "_ctypes pymem"
103109
@@ -1893,8 +1899,22 @@ unpickle(PyObject *self, PyObject *args)
18931899 return NULL ;
18941900}
18951901
1902+ /*[clinic input]
1903+ _ctypes.POINTER as create_pointer_type
1904+
1905+ type as cls: object
1906+ A ctypes type.
1907+ /
1908+
1909+ Create and return a new ctypes pointer type.
1910+
1911+ Pointer types are cached and reused internally,
1912+ so calling this function repeatedly is cheap.
1913+ [clinic start generated code]*/
1914+
18961915static PyObject *
1897- POINTER (PyObject * self , PyObject * cls )
1916+ create_pointer_type (PyObject * module , PyObject * cls )
1917+ /*[clinic end generated code: output=98c3547ab6f4f40b input=3b81cff5ff9b9d5b]*/
18981918{
18991919 PyObject * result ;
19001920 PyTypeObject * typ ;
@@ -1944,8 +1964,22 @@ POINTER(PyObject *self, PyObject *cls)
19441964 return result ;
19451965}
19461966
1967+ /*[clinic input]
1968+ _ctypes.pointer as create_pointer_inst
1969+
1970+ obj as arg: object
1971+ /
1972+
1973+ Create a new pointer instance, pointing to 'obj'.
1974+
1975+ The returned object is of the type POINTER(type(obj)). Note that if you
1976+ just want to pass a pointer to an object to a foreign function call, you
1977+ should use byref(obj) which is much faster.
1978+ [clinic start generated code]*/
1979+
19471980static PyObject *
1948- pointer (PyObject * self , PyObject * arg )
1981+ create_pointer_inst (PyObject * module , PyObject * arg )
1982+ /*[clinic end generated code: output=3b543bc9f0de2180 input=713685fdb4d9bc27]*/
19491983{
19501984 PyObject * result ;
19511985 PyObject * typ ;
@@ -1957,7 +1991,7 @@ pointer(PyObject *self, PyObject *arg)
19571991 else if (PyErr_Occurred ()) {
19581992 return NULL ;
19591993 }
1960- typ = POINTER (NULL , (PyObject * )Py_TYPE (arg ));
1994+ typ = create_pointer_type (NULL , (PyObject * )Py_TYPE (arg ));
19611995 if (typ == NULL )
19621996 return NULL ;
19631997 result = PyObject_CallOneArg (typ , arg );
@@ -1997,8 +2031,8 @@ buffer_info(PyObject *self, PyObject *arg)
19972031PyMethodDef _ctypes_module_methods [] = {
19982032 {"get_errno" , get_errno , METH_NOARGS },
19992033 {"set_errno" , set_errno , METH_VARARGS },
2000- { "POINTER" , POINTER , METH_O },
2001- { "pointer" , pointer , METH_O },
2034+ CREATE_POINTER_TYPE_METHODDEF
2035+ CREATE_POINTER_INST_METHODDEF
20022036 {"_unpickle" , unpickle , METH_VARARGS },
20032037 {"buffer_info" , buffer_info , METH_O , "Return buffer interface information" },
20042038 {"resize" , resize , METH_VARARGS , "Resize the memory buffer of a ctypes instance" },
0 commit comments