8000 gh-107659: ctypes: Add docstrings for `ctypes.pointer` and `ctypes.POINTER` by tomasr8 · Pull Request #107660 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-107659: ctypes: Add docstrings for ctypes.pointer and ctypes.POINTER #107660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension 8000

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add docstrings for :func:`ctypes.pointer` and :func:`ctypes.POINTER`.
44 changes: 39 additions & 5 deletions Modules/_ctypes/callproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@

*/

/*[clinic input]
module _ctypes
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=476a19c49b31a75c]*/

#ifndef Py_BUILD_CORE_BUILTIN
# define Py_BUILD_CORE_MODULE 1
#endif
Expand Down Expand Up @@ -98,6 +103,7 @@

#include "pycore_runtime.h" // _PyRuntime
#include "pycore_global_objects.h" // _Py_ID()
#include "clinic/callproc.c.h"

#define CTYPES_CAPSULE_NAME_PYMEM "_ctypes pymem"

Expand Down Expand Up @@ -1893,8 +1899,22 @@ unpickle(PyObject *self, PyObject *args)
return NULL;
}

/*[clinic input]
_ctypes.POINTER as create_pointer_type

type as cls: object
A ctypes type.
/

Create and return a new ctypes pointer type.

Pointer types are cached and reused internally,
so calling this function repeatedly is cheap.
[clinic start generated code]*/

static PyObject *
POINTER(PyObject *self, PyObject *cls)
create_pointer_type(PyObject *module, PyObject *cls)
/*[clinic end generated code: output=98c3547ab6f4f40b input=3b81cff5ff9b9d5b]*/
{
PyObject *result;
PyTypeObject *typ;
Expand Down Expand Up @@ -1944,8 +1964,22 @@ POINTER(PyObject *self, PyObject *cls)
return result;
}

/*[clinic input]
_ctypes.pointer as create_pointer_inst

obj as arg: object
/

Create a new pointer instance, pointing to 'obj'.

The returned object is of the type POINTER(type(obj)). Note that if you
just want to pass a pointer to an object to a foreign function call, you
should use byref(obj) which is much faster.
[clinic start generated code]*/

static PyObject *
pointer(PyObject *self, PyObject *arg)
create_pointer_inst(PyObject *module, PyObject *arg)
/*[clinic end generated code: output=3b543bc9f0de2180 input=713685fdb4d9bc27]*/
{
PyObject *result;
PyObject *typ;
Expand All @@ -1957,7 +1991,7 @@ pointer(PyObject *self, PyObject *arg)
else if (PyErr_Occurred()) {
return NULL;
}
typ = POINTER(NULL, (PyObject *)Py_TYPE(arg));
typ = create_pointer_type(NULL, (PyObject *)Py_TYPE(arg));
if (typ == NULL)
return NULL;
result = PyObject_CallOneArg(typ, arg);
Expand Down Expand Up @@ -1997,8 +2031,8 @@ buffer_info(PyObject *self, PyObject *arg)
PyMethodDef _ctypes_module_methods[] = {
{"get_errno", get_errno, METH_NOARGS},
{"set_errno", set_errno, METH_VARARGS},
{"POINTER", POINTER, METH_O },
{"pointer", pointer, METH_O },
CREATE_POINTER_TYPE_METHODDEF
CREATE_POINTER_INST_METHODDEF
{"_unpickle", unpickle, METH_VARARGS },
{"buffer_info", buffer_info, METH_O, "Return buffer interface information"},
{"resize", resize, METH_VARARGS, "Resize the memory buffer of a ctypes instance"},
Expand Down
38 changes: 38 additions & 0 deletions Modules/_ctypes/clinic/callproc.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0