FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-85283: Build resource extension with limited C API by vstinner · Pull Request #110989 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .h  (1) .rst  (2) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
6 changes: 3 additions & 3 deletions Doc/whatsnew/3.13.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -932,9 +932,9 @@ Build Changes
* Building CPython now requires a compiler with support for the C11 atomic
library, GCC built-in atomic functions, or MSVC interlocked intrinsics.

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


Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
The ``errno``, ``md5``, ``winsound``, ``_ctypes_test``, ``_stat`` and
``_testimportmultiple`` C extensions are now built with the :ref:`limited C API
<limited-c-api>`.
The ``errno``, ``md5``, ``resource``, ``winsound``, ``_ctypes_test``, ``_stat``
and ``_testimportmultiple`` C extensions are now built with the :ref:`limited C
API <limited-c-api>`.
Patch by Victor Stinner.
18 changes: 11 additions & 7 deletions Modules/clinic/resource.c.h

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

44 changes: 21 additions & 23 deletions Modules/resource.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// clinic/resource.c.h uses internal pycore_modsupport.h API
#ifndef Py_BUILD_CORE_BUILTIN
# define Py_BUILD_CORE_MODULE 1
#endif
// Need limited C API version 3.13 for Py_MOD_PER_INTERPRETER_GIL_SUPPORTED
#define Py_LIMITED_API 0x030d0000

#include "Python.h"
#include <errno.h> // errno
Expand Down Expand Up @@ -121,24 +119,24 @@ resource_getrusage_impl(PyObject *module, int who)
if (!result)
return NULL;

PyStructSequence_SET_ITEM(result, 0,
PyStructSequence_SetItem(result, 0,
PyFloat_FromDouble(doubletime(ru.ru_utime)));
PyStructSequence_SET_ITEM(result, 1,
PyStructSequence_SetItem(result, 1,
PyFloat_FromDouble(doubletime(ru.ru_stime)));
PyStructSequence_SET_ITEM(result, 2, PyLong_FromLong(ru.ru_maxrss));
PyStructSequence_SET_ITEM(result, 3, PyLong_FromLong(ru.ru_ixrss));
PyStructSequence_SET_ITEM(result, 4, PyLong_FromLong(ru.ru_idrss));
PyStructSequence_SET_ITEM(result, 5, PyLong_FromLong(ru.ru_isrss));
PyStructSequence_SET_ITEM(result, 6, PyLong_FromLong(ru.ru_minflt));
PyStructSequence_SET_ITEM(result, 7, PyLong_FromLong(ru.ru_majflt));
PyStructSequence_SET_ITEM(result, 8, PyLong_FromLong(ru.ru_nswap));
PyStructSequence_SET_ITEM(result, 9, PyLong_FromLong(ru.ru_inblock));
PyStructSequence_SET_ITEM(result, 10, PyLong_FromLong(ru.ru_oublock));
PyStructSequence_SET_ITEM(result, 11, PyLong_FromLong(ru.ru_msgsnd));
PyStructSequence_SET_ITEM(result, 12, PyLong_FromLong(ru.ru_msgrcv));
PyStructSequence_SET_ITEM(result, 13, PyLong_FromLong(ru.ru_nsignals));
PyStructSequence_SET_ITEM(result, 14, PyLong_FromLong(ru.ru_nvcsw));
PyStructSequence_SET_ITEM(result, 15, PyLong_FromLong(ru.ru_nivcsw));
PyStructSequence_SetItem(result, 2, PyLong_FromLong(ru.ru_maxrss));
PyStructSequence_SetItem(result, 3, PyLong_FromLong(ru.ru_ixrss));
PyStructSequence_SetItem(result, 4, PyLong_FromLong(ru.ru_idrss));
PyStructSequence_SetItem(result, 5, PyLong_FromLong(ru.ru_isrss));
PyStructSequence_SetItem(result, 6, PyLong_FromLong(ru.ru_minflt));
PyStructSequence_SetItem(result, 7, PyLong_FromLong(ru.ru_majflt));
PyStructSequence_SetItem(result, 8, PyLong_FromLong(ru.ru_nswap));
PyStructSequence_SetItem(result, 9, PyLong_FromLong(ru.ru_inblock));
PyStructSequence_SetItem(result, 10, PyLong_FromLong(ru.ru_oublock));
PyStructSequence_SetItem(result, 11, PyLong_FromLong(ru.ru_msgsnd));
PyStructSequence_SetItem(result, 12, PyLong_FromLong(ru.ru_msgrcv));
PyStructSequence_SetItem(result, 13, PyLong_FromLong(ru.ru_nsignals));
PyStructSequence_SetItem(result, 14, PyLong_FromLong(ru.ru_nvcsw));
PyStructSequence_SetItem(result, 15, PyLong_FromLong(ru.ru_nivcsw));

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

if (PyTuple_GET_SIZE(limits) != 2) {
if (PyTuple_Size(limits) != 2) {
PyErr_SetString(PyExc_ValueError,
"expected a tuple of 2 integers");
goto error;
}
curobj = PyTuple_GET_ITEM(limits, 0);
maxobj = PyTuple_GET_ITEM(limits, 1);
curobj = PyTuple_GetItem(limits, 0); // borrowed
maxobj = PyTuple_GetItem(limits, 1); // borrowed
#if !defined(HAVE_LARGEFILE_SUPPORT)
rl_out->rlim_cur = PyLong_AsLong(curobj);
if (rl_out->rlim_cur == (rlim_t)-1 && PyErr_Occurred())
Expand Down

Back | FazBrowse Home | New Git URL