54
54
55
55
*/
56
56
57
+ /*[clinic input]
58
+ module _ctypes
59
+ [clinic start generated code]*/
60
+ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=476a19c49b31a75c]*/
61
+
57
62
#ifndef Py_BUILD_CORE_BUILTIN
58
63
# define Py_BUILD_CORE_MODULE 1
59
64
#endif
98
103
99
104
#include "pycore_runtime.h" // _PyRuntime
100
105
#include "pycore_global_objects.h" // _Py_ID()
106
+ #include "clinic/callproc.c.h"
101
107
102
108
#define CTYPES_CAPSULE_NAME_PYMEM "_ctypes pymem"
103
109
@@ -1893,8 +1899,22 @@ unpickle(PyObject *self, PyObject *args)
1893
1899
return NULL ;
1894
1900
}
1895
1901
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
+
1896
1915
static PyObject *
1897
- POINTER (PyObject * self , PyObject * cls )
1916
+ create_pointer_type (PyObject * module , PyObject * cls )
1917
+ /*[clinic end generated code: output=98c3547ab6f4f40b input=3b81cff5ff9b9d5b]*/
1898
1918
{
1899
1919
PyObject * result ;
1900
1920
PyTypeObject * typ ;
@@ -1944,8 +1964,22 @@ POINTER(PyObject *self, PyObject *cls)
1944
1964
return result ;
1945
1965
}
1946
1966
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
+
1947
1980
static PyObject *
1948
- pointer (PyObject * self , PyObject * arg )
1981
+ create_pointer_inst (PyObject * module , PyObject * arg )
1982
+ /*[clinic end generated code: output=3b543bc9f0de2180 input=713685fdb4d9bc27]*/
1949
1983
{
1950
1984
PyObject * result ;
1951
1985
PyObject * typ ;
@@ -1957,7 +1991,7 @@ pointer(PyObject *self, PyObject *arg)
1957
1991
else if (PyErr_Occurred ()) {
1958
1992
return NULL ;
1959
1993
}
1960
- typ = POINTER (NULL , (PyObject * )Py_TYPE (arg ));
1994
+ typ = create_pointer_type (NULL , (PyObject * )Py_TYPE (arg ));
1961
1995
if (typ == NULL )
1962
1996
return NULL ;
1963
1997
result = PyObject_CallOneArg (typ , arg );
@@ -1997,8 +2031,8 @@ buffer_info(PyObject *self, PyObject *arg)
1997
2031
PyMethodDef _ctypes_module_methods [] = {
1998
2032
{"get_errno" , get_errno , METH_NOARGS },
1999
2033
{"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
2002
2036
{"_unpickle" , unpickle , METH_VARARGS },
2003
2037
{"buffer_info" , buffer_info , METH_O , "Return buffer interface information" },
2004
2038
{"resize" , resize , METH_VARARGS , "Resize the memory buffer of a ctypes instance" },
0 commit comments