8000 gh-85283: Build resource extension with limited C API (#110989) · python/cpython@e37620e · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit e37620e

Browse files
authored
gh-85283: Build resource extension with limited C API (#110989)
* Replace PyStructSequence_SET_ITEM() with PyStructSequence_SetItem(). * Replace PyTuple_GET_SIZE() with PyTuple_Size(). * Replace PyTuple_GET_ITEM() with PyTuple_GetItem().
1 parent 2ba6f68 commit e37620e

File tree

4 files changed

+38
-36
lines changed

4 files changed

+38
-36
lines changed

Doc/whatsnew/3.13.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -932,9 +932,9 @@ Build Changes
932932
* Building CPython now requires a compiler with support for the C11 atomic
933933
library, GCC built-in atomic functions, or MSVC interlocked intrinsics.
934934

935-
* The ``errno``, ``md5``, ``winsound``, ``_ctypes_test``, ``_stat`` and
936-
``_testimportmultiple`` C extensions are now built with the :ref:`limited C
937-
API <limited-c-api>`.
935+
* The ``errno``, ``md5``, ``resource``, ``winsound``, ``_ctypes_test``,
936+
``_stat`` and ``_testimportmultiple`` C extensions are now built with the
937+
:ref:`limited C API <limited-c-api>`.
938938
(Contributed by Victor Stinner in :gh:`85283`.)
939939

940940

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The ``errno``, ``md5``, ``winsound``, ``_ctypes_test``, ``_stat`` and
2-
``_testimportmultiple`` C extensions are now built with the :ref:`limited C API
3-
<limited-c-api>`.
1+
The ``errno``, ``md5``, ``resource``, ``winsound``, ``_ctypes_test``, ``_stat``
2+
and ``_testimportmultiple`` C extensions are now built with the :ref:`limited C
3+
API <limited-c-api>`.
44
Patch by Victor Stinner.

Modules/clinic/resource.c.h

Lines changed: 11 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/resource.c

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
// clinic/resource.c.h uses internal pycore_modsupport.h API
2-
#ifndef Py_BUILD_CORE_BUILTIN
3-
# define Py_BUILD_CORE_MODULE 1
4-
#endif
1+
// Need limited C API version 3.13 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED
2+
#define Py_LIMITED_API 0x030d0000
53

64
#include "Python.h"
75
#include <errno.h> // errno
@@ -121,24 +119,24 @@ resource_getrusage_impl(PyObject *module, int who)
121119
if (!result)
122120
return NULL;
123121

124-
PyStructSequence_SET_ITEM(result, 0,
122+
PyStructSequence_SetItem(result, 0,
125123
PyFloat_FromDouble(doubletime(ru.ru_utime)));
126-
PyStructSequence_SET_ITEM(result, 1,
124+
PyStructSequence_SetItem(result, 1,
127125
PyFloat_FromDouble(doubletime(ru.ru_stime)));
128-
PyStructSequence_SET_ITEM(result, 2, PyLong_FromLong(ru.ru_maxrss));
129-
PyStructSequence_SET_ITEM(result, 3, PyLong_FromLong(ru.ru_ixrss));
130-
PyStructSequence_SET_ITEM(result, 4, PyLong_FromLong(ru.ru_idrss));
131-
PyStructSequence_SET_ITEM(result, 5, PyLong_FromLong(ru.ru_isrss));
132-
PyStructSequence_SET_ITEM(result, 6, PyLong_FromLong(ru.ru_minflt));
133-
PyStructSequence_SET_ITEM(result, 7, PyLong_FromLong(ru.ru_majflt));
134-
PyStructSequence_SET_ITEM(result, 8, PyLong_FromLong(ru.ru_nswap));
135-
PyStructSequence_SET_ITEM(result, 9, PyLong_FromLong(ru.ru_inblock));
136-
PyStructSequence_SET_ITEM(result, 10, PyLong_FromLong(ru.ru_oublock));
137-
PyStructSequence_SET_ITEM(result, 11, PyLong_FromLong(ru.ru_msgsnd));
138-
PyStructSequence_SET_ITEM(result, 12, PyLong_FromLong(ru.ru_msgrcv));
139-
PyStructSequence_SET_ITEM(result, 13, PyLong_FromLong(ru.ru_nsignals));
140-
PyStructSequence_SET_ITEM(result, 14, PyLong_FromLong(ru.ru_nvcsw));
141-
PyStructSequence_SET_ITEM(result, 15, PyLong_FromLong(ru.ru_nivcsw));
126+
PyStructSequence_SetItem(result, 2, PyLong_FromLong(ru.ru_maxrss));
127+
PyStructSequence_SetItem(result, 3, PyLong_FromLong(ru.ru_ixrss));
128+
PyStructSequence_SetItem(result, 4, PyLong_FromLong(ru.ru_idrss));
129+
PyStructSequence_SetItem(result, 5, PyLong_FromLong(ru.ru_isrss));
130+
PyStructSequence_SetItem(result, 6, PyLong_FromLong(ru.ru_minflt));
131+
PyStructSequence_SetItem(result, 7, PyLong_FromLong(ru.ru_majflt));
132+
PyStructSequence_SetItem(result, 8, PyLong_FromLong(ru.ru_nswap));
133+
PyStructSequence_SetItem(result, 9, PyLong_FromLong(ru.ru_inblock));
134+
PyStructSequence_SetItem(result, 10, PyLong_FromLong(ru.ru_oublock));
135+
PyStructSequence_SetItem(result, 11, PyLong_FromLong(ru.ru_msgsnd));
136+
PyStructSequence_SetItem(result, 12, PyLong_FromLong(ru.ru_msgrcv));
137+
PyStructSequence_SetItem(result, 13, PyLong_FromLong(ru.ru_nsignals));
138+
PyStructSequence_SetItem(result, 14, PyLong_FromLong(ru.ru_nvcsw));
139+
PyStructSequence_SetItem(result, 15, PyLong_FromLong(ru.ru_nivcsw));
142140

143141
if (PyErr_Occurred()) {
144142
Py_DECREF(result);
@@ -158,13 +156,13 @@ py2rlimit(PyObject *limits, struct rlimit *rl_out)
158156
/* Here limits is a borrowed reference */
159157
return -1;
160158

161-
if (PyTuple_GET_SIZE(limits) != 2) {
159+
if (PyTuple_Size(limits) != 2) {
162160
PyErr_SetString(PyExc_ValueError,
163161
"expected a tuple of 2 integers");
164162
goto error;
165163
}
166-
curobj = PyTuple_GET_ITEM(limits, 0);
167-
maxobj = PyTuple_GET_ITEM(limits, 1);
164+
curobj = PyTuple_GetItem(limits, 0); // borrowed
165+
maxobj = PyTuple_GetItem(limits, 1); // borrowed
168166
#if !defined(HAVE_LARGEFILE_SUPPORT)
169167
rl_out->rlim_cur = PyLong_AsLong(curobj);
170168
if (rl_out->rlim_cur == (rlim_t)-1 && PyErr_Occurred())

0 commit comments

Comments
 (0)
0