https://github.com/python/cpython/commit/3cc5ae5c2c6e729ca2750ed490dad56faa7c342d
commit: 3cc5ae5c2c6e729ca2750ed490dad56faa7c342d
branch: main
author: Victor Stinner <vstin...@python.org>
committer: vstinner <vstin...@python.org>
date: 2024-03-12T00:46:53Z
summary:

gh-85283: Convert grp extension to the limited C API (#116611)

posixmodule.h: remove check on the limited C API, since these helpers
are not part of the public C API.

files:
M Include/internal/pycore_global_objects_fini_generated.h
M Include/internal/pycore_global_strings.h
M Include/internal/pycore_runtime_init_generated.h
M Include/internal/pycore_unicodeobject_generated.h
M Modules/clinic/grpmodule.c.h
M Modules/grpmodule.c
M Modules/posixmodule.h
M Tools/c-analyzer/cpython/ignored.tsv

diff --git a/Include/internal/pycore_global_objects_fini_generated.h 
b/Include/internal/pycore_global_objects_fini_generated.h
index e8b62bd0dcd369..d2287687181450 100644
--- a/Include/internal/pycore_global_objects_fini_generated.h
+++ b/Include/internal/pycore_global_objects_fini_generated.h
@@ -983,7 +983,6 @@ _PyStaticObjects_CheckRefcnt(PyInterpreterState *interp) {
     _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(hi));
     _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(hook));
     _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(hour));
-    _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(id));
     _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(ident));
     _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(identity_hint));
     _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(ignore));
diff --git a/Include/internal/pycore_global_strings.h 
b/Include/internal/pycore_global_strings.h
index b41f5c8952021e..fb9ec44d3f52aa 100644
--- a/Include/internal/pycore_global_strings.h
+++ b/Include/internal/pycore_global_strings.h
@@ -472,7 +472,6 @@ struct _Py_global_strings {
         STRUCT_FOR_ID(hi)
         STRUCT_FOR_ID(hook)
         STRUCT_FOR_ID(hour)
-        STRUCT_FOR_ID(id)
         STRUCT_FOR_ID(ident)
         STRUCT_FOR_ID(identity_hint)
         STRUCT_FOR_ID(ignore)
diff --git a/Include/internal/pycore_runtime_init_generated.h 
b/Include/internal/pycore_runtime_init_generated.h
index 016eae02a2103d..658bf8030f661d 100644
--- a/Include/internal/pycore_runtime_init_generated.h
+++ b/Include/internal/pycore_runtime_init_generated.h
@@ -981,7 +981,6 @@ extern "C" {
     INIT_ID(hi), \
     INIT_ID(hook), \
     INIT_ID(hour), \
-    INIT_ID(id), \
     INIT_ID(ident), \
     INIT_ID(identity_hint), \
     INIT_ID(ignore), \
diff --git a/Include/internal/pycore_unicodeobject_generated.h 
b/Include/internal/pycore_unicodeobject_generated.h
index 64c4cf8c077056..d72353d56eae60 100644
--- a/Include/internal/pycore_unicodeobject_generated.h
+++ b/Include/internal/pycore_unicodeobject_generated.h
@@ -1257,9 +1257,6 @@ _PyUnicode_InitStaticStrings(PyInterpreterState *interp) {
     string = &_Py_ID(hour);
     assert(_PyUnicode_CheckConsistency(string, 1));
     _PyUnicode_InternInPlace(interp, &string);
-    string = &_Py_ID(id);
-    assert(_PyUnicode_CheckConsistency(string, 1));
-    _PyUnicode_InternInPlace(interp, &string);
     string = &_Py_ID(ident);
     assert(_PyUnicode_CheckConsistency(string, 1));
     _PyUnicode_InternInPlace(interp, &string);
diff --git a/Modules/clinic/grpmodule.c.h b/Modules/clinic/grpmodule.c.h
index 1da061f3fd8eb1..cc0ad210f42743 100644
--- a/Modules/clinic/grpmodule.c.h
+++ b/Modules/clinic/grpmodule.c.h
@@ -2,12 +2,6 @@
 preserve
 [clinic start generated code]*/
 
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-#  include "pycore_gc.h"          // PyGC_Head
-#  include "pycore_runtime.h"     // _Py_ID()
-#endif
-#include "pycore_modsupport.h"    // _PyArg_UnpackKeywords()
-
 PyDoc_STRVAR(grp_getgrgid__doc__,
 "getgrgid($module, /, id)\n"
 "--\n"
@@ -17,48 +11,21 @@ PyDoc_STRVAR(grp_getgrgid__doc__,
 "If id is not valid, raise KeyError.");
 
 #define GRP_GETGRGID_METHODDEF    \
-    {"getgrgid", _PyCFunction_CAST(grp_getgrgid), METH_FASTCALL|METH_KEYWORDS, 
grp_getgrgid__doc__},
+    {"getgrgid", (PyCFunction)(void(*)(void))grp_getgrgid, 
METH_VARARGS|METH_KEYWORDS, grp_getgrgid__doc__},
 
 static PyObject *
 grp_getgrgid_impl(PyObject *module, PyObject *id);
 
 static PyObject *
-grp_getgrgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs, 
PyObject *kwnames)
+grp_getgrgid(PyObject *module, PyObject *args, PyObject *kwargs)
 {
     PyObject *return_value = NULL;
-    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-
-    #define NUM_KEYWORDS 1
-    static struct {
-        PyGC_Head _this_is_not_used;
-        PyObject_VAR_HEAD
-        PyObject *ob_item[NUM_KEYWORDS];
-    } _kwtuple = {
-        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
-        .ob_item = { &_Py_ID(id), },
-    };
-    #undef NUM_KEYWORDS
-    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
-
-    #else  // !Py_BUILD_CORE
-    #  define KWTUPLE NULL
-    #endif  // !Py_BUILD_CORE
-
-    static const char * const _keywords[] = {"id", NULL};
-    static _PyArg_Parser _parser = {
-        .keywords = _keywords,
-        .fname = "getgrgid",
-        .kwtuple = KWTUPLE,
-    };
-    #undef KWTUPLE
-    PyObject *argsbuf[1];
+    static char *_keywords[] = {"id", NULL};
     PyObject *id;
 
-    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 
0, argsbuf);
-    if (!args) {
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:getgrgid", _keywords,
+        &id))
         goto exit;
-    }
-    id = args[0];
     return_value = grp_getgrgid_impl(module, id);
 
 exit:
@@ -74,52 +41,21 @@ PyDoc_STRVAR(grp_getgrnam__doc__,
 "If name is not valid, raise KeyError.");
 
 #define GRP_GETGRNAM_METHODDEF    \
-    {"getgrnam", _PyCFunction_CAST(grp_getgrnam), METH_FASTCALL|METH_KEYWORDS, 
grp_getgrnam__doc__},
+    {"getgrnam", (PyCFunction)(void(*)(void))grp_getgrnam, 
METH_VARARGS|METH_KEYWORDS, grp_getgrnam__doc__},
 
 static PyObject *
 grp_getgrnam_impl(PyObject *module, PyObject *name);
 
 static PyObject *
-grp_getgrnam(PyObject *module, PyObject *const *args, Py_ssize_t nargs, 
PyObject *kwnames)
+grp_getgrnam(PyObject *module, PyObject *args, PyObject *kwargs)
 {
     PyObject *return_value = NULL;
-    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-
-    #define NUM_KEYWORDS 1
-    static struct {
-        PyGC_Head _this_is_not_used;
-        PyObject_VAR_HEAD
-        PyObject *ob_item[NUM_KEYWORDS];
-    } _kwtuple = {
-        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
-        .ob_item = { &_Py_ID(name), },
-    };
-    #undef NUM_KEYWORDS
-    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
-
-    #else  // !Py_BUILD_CORE
-    #  define KWTUPLE NULL
-    #endif  // !Py_BUILD_CORE
-
-    static const char * const _keywords[] = {"name", NULL};
-    static _PyArg_Parser _parser = {
-        .keywords = _keywords,
-        .fname = "getgrnam",
-        .kwtuple = KWTUPLE,
-    };
-    #undef KWTUPLE
-    PyObject *argsbuf[1];
+    static char *_keywords[] = {"name", NULL};
     PyObject *name;
 
-    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 
0, argsbuf);
-    if (!args) {
-        goto exit;
-    }
-    if (!PyUnicode_Check(args[0])) {
-        _PyArg_BadArgument("getgrnam", "argument 'name'", "str", args[0]);
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "U:getgrnam", _keywords,
+        &name))
         goto exit;
-    }
-    name = args[0];
     return_value = grp_getgrnam_impl(module, name);
 
 exit:
@@ -146,4 +82,4 @@ grp_getgrall(PyObject *module, PyObject *Py_UNUSED(ignored))
 {
     return grp_getgrall_impl(module);
 }
-/*[clinic end generated code: output=2f7011384604d38d input=a9049054013a1b77]*/
+/*[clinic end generated code: output=81f180beb67fc585 input=a9049054013a1b77]*/
diff --git a/Modules/grpmodule.c b/Modules/grpmodule.c
index 9756f1c2fb15b1..a1fa6cf20f71fd 100644
--- a/Modules/grpmodule.c
+++ b/Modules/grpmodule.c
@@ -1,15 +1,17 @@
-
 /* UNIX group file access module */
 
-// clinic/grpmodule.c.h uses internal pycore_modsupport.h API
-#ifndef Py_BUILD_CORE_BUILTIN
-#  define Py_BUILD_CORE_MODULE 1
+// 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 <grp.h>                  // getgrgid_r()
+#include <string.h>               // memcpy()
 #include <unistd.h>               // sysconf()
 
 #include "clinic/grpmodule.c.h"
@@ -88,7 +90,7 @@ mkgrent(PyObject *module, struct group *p)
         Py_DECREF(x);
     }
 
-#define SET(i,val) PyStructSequence_SET_ITEM(v, i, val)
+#define SET(i,val) PyStructSequence_SetItem(v, i, val)
     SET(setIndex++, PyUnicode_DecodeFSDefault(p->gr_name));
     if (p->gr_passwd)
             SET(setIndex++, PyUnicode_DecodeFSDefault(p->gr_passwd));
diff --git a/Modules/posixmodule.h b/Modules/posixmodule.h
index 8827ce153fed8c..be732db04faf94 100644
--- a/Modules/posixmodule.h
+++ b/Modules/posixmodule.h
@@ -2,7 +2,6 @@
 
 #ifndef Py_POSIXMODULE_H
 #define Py_POSIXMODULE_H
-#ifndef Py_LIMITED_API
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -34,5 +33,4 @@ extern int _Py_Sigset_Converter(PyObject *, void *);
 #ifdef __cplusplus
 }
 #endif
-#endif   // !Py_LIMITED_API
 #endif   // !Py_POSIXMODULE_H
diff --git a/Tools/c-analyzer/cpython/ignored.tsv 
b/Tools/c-analyzer/cpython/ignored.tsv
index 682dceaf8ae41e..0024e2683052c8 100644
--- a/Tools/c-analyzer/cpython/ignored.tsv
+++ b/Tools/c-analyzer/cpython/ignored.tsv
@@ -740,3 +740,5 @@ Modules/expat/xmlrole.c     -       error   -
 Modules/_io/_iomodule.c        -       _PyIO_Module    -
 Modules/_sqlite/module.c       -       _sqlite3module  -
 Modules/clinic/md5module.c.h   _md5_md5        _keywords       -
+Modules/clinic/grpmodule.c.h   grp_getgrgid    _keywords       -
+Modules/clinic/grpmodule.c.h   grp_getgrnam    _keywords       -

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to