https://github.com/python/cpython/commit/8fc8fbb43a8bb46c04ab55f96049039de243afb0
commit: 8fc8fbb43a8bb46c04ab55f96049039de243afb0
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2024-03-15T08:49:58+01:00
summary:
gh-85283: Build pwd extension with the limited C API (#116841)
Argument Clinic now uses the PEP 737 "%T" format to format type name
for the limited C API.
files:
M Doc/whatsnew/3.13.rst
M Misc/NEWS.d/next/C API/2024-03-14-10-33-58.gh-issue-85283.LOgmdU.rst
M Modules/clinic/pwdmodule.c.h
M Modules/pwdmodule.c
M Tools/clinic/libclinic/converter.py
diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst
index 856c6ee1d6e3f0..03ae6018905380 100644
--- a/Doc/whatsnew/3.13.rst
+++ b/Doc/whatsnew/3.13.rst
@@ -1469,7 +1469,7 @@ 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``, ``fcntl``, ``grp``, ``md5``, ``resource``, ``winsound``,
+* The ``errno``, ``fcntl``, ``grp``, ``md5``, ``pwd``, ``resource``,
``winsound``,
``_ctypes_test``, ``_multiprocessing.posixshmem``, ``_scproxy``, ``_stat``,
``_testimportmultiple`` and ``_uuid`` C extensions are now built with the
:ref:`limited C API <limited-c-api>`.
diff --git a/Misc/NEWS.d/next/C
API/2024-03-14-10-33-58.gh-issue-85283.LOgmdU.rst b/Misc/NEWS.d/next/C
API/2024-03-14-10-33-58.gh-issue-85283.LOgmdU.rst
index a02b8a8210f9bd..8a3185a8649d7d 100644
--- a/Misc/NEWS.d/next/C API/2024-03-14-10-33-58.gh-issue-85283.LOgmdU.rst
+++ b/Misc/NEWS.d/next/C API/2024-03-14-10-33-58.gh-issue-85283.LOgmdU.rst
@@ -1,2 +1,2 @@
-The ``fcntl`` and ``grp`` C extensions are now built with the :ref:`limited
+The ``fcntl``, ``grp`` and ``pwd`` C extensions are now built with the
:ref:`limited
C API <limited-c-api>`. (Contributed by Victor Stinner in :gh:`85283`.)
diff --git a/Modules/clinic/pwdmodule.c.h b/Modules/clinic/pwdmodule.c.h
index 43d4825031c7e6..365d99aab1dd22 100644
--- a/Modules/clinic/pwdmodule.c.h
+++ b/Modules/clinic/pwdmodule.c.h
@@ -2,8 +2,6 @@
preserve
[clinic start generated code]*/
-#include "pycore_modsupport.h" // _PyArg_BadArgument()
-
PyDoc_STRVAR(pwd_getpwuid__doc__,
"getpwuid($module, uidobj, /)\n"
"--\n"
@@ -36,7 +34,7 @@ pwd_getpwnam(PyObject *module, PyObject *arg)
PyObject *name;
if (!PyUnicode_Check(arg)) {
- _PyArg_BadArgument("getpwnam", "argument", "str", arg);
+ PyErr_Format(PyExc_TypeError, "getpwnam() argument must be str, not
%T", arg);
goto exit;
}
name = arg;
@@ -73,4 +71,4 @@ pwd_getpwall(PyObject *module, PyObject *Py_UNUSED(ignored))
#ifndef PWD_GETPWALL_METHODDEF
#define PWD_GETPWALL_METHODDEF
#endif /* !defined(PWD_GETPWALL_METHODDEF) */
-/*[clinic end generated code: output=5a8fb12939ff4ea3 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=dac88d500f6d6f49 input=a9049054013a1b77]*/
diff --git a/Modules/pwdmodule.c b/Modules/pwdmodule.c
index c59a8e41aa292a..f58735aff99799 100644
--- a/Modules/pwdmodule.c
+++ b/Modules/pwdmodule.c
@@ -1,9 +1,16 @@
/* UNIX password file access module */
+// Need limited C API version 3.13 for PyMem_RawRealloc()
+#include "pyconfig.h" // Py_GIL_DISABLED
+#ifndef Py_GIL_DISABLED
+# define Py_LIMITED_API 0x030d0000
+#endif
+
#include "Python.h"
#include "posixmodule.h"
+#include <errno.h> // ERANGE
#include <pwd.h> // getpwuid()
#include <unistd.h> // sysconf()
@@ -83,7 +90,7 @@ mkpwent(PyObject *module, struct passwd *p)
if (item == NULL) { \
goto error; \
} \
- PyStructSequence_SET_ITEM(v, setIndex++, item); \
+ PyStructSequence_SetItem(v, setIndex++, item); \
} while(0)
SET_STRING(p->pw_name);
diff --git a/Tools/clinic/libclinic/converter.py
b/Tools/clinic/libclinic/converter.py
index da28ba56a346a1..744d03c2c1fea4 100644
--- a/Tools/clinic/libclinic/converter.py
+++ b/Tools/clinic/libclinic/converter.py
@@ -426,13 +426,12 @@ def bad_argument(self, displayname: str, expected: str,
*, limited_capi: bool, e
if limited_capi:
if expected_literal:
return (f'PyErr_Format(PyExc_TypeError, '
- f'"{{{{name}}}}() {displayname} must be {expected},
not %.50s", '
- f'{{argname}} == Py_None ? "None" :
Py_TYPE({{argname}})->tp_name);')
+ f'"{{{{name}}}}() {displayname} must be {expected},
not %T", '
+ f'{{argname}});')
else:
return (f'PyErr_Format(PyExc_TypeError, '
- f'"{{{{name}}}}() {displayname} must be %.50s, not
%.50s", '
- f'"{expected}", '
- f'{{argname}} == Py_None ? "None" :
Py_TYPE({{argname}})->tp_name);')
+ f'"{{{{name}}}}() {displayname} must be %s, not %T", '
+ f'"{expected}", {{argname}});')
else:
if expected_literal:
expected = f'"{expected}"'
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]