[3.14] Revert "gh-112068: C API: Add support of nullable arguments in PyArg_Parse (GH-121303)" (GH-136991) (#137006)

This commit is contained in:
Serhiy Storchaka 2025-07-22 19:16:31 +03:00 committed by GitHub
parent c328d140eb
commit 805daa2edb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 144 additions and 322 deletions

View file

@ -23,6 +23,7 @@
#endif
#include <Python.h>
#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t()
#include "pycore_bytesobject.h" // _PyBytes_Find()
#include "pycore_fileutils.h" // _Py_stat_struct
#include "pycore_weakref.h" // FT_CLEAR_WEAKREFS()
@ -515,7 +516,7 @@ mmap_read_method(PyObject *op, PyObject *args)
mmap_object *self = mmap_object_CAST(op);
CHECK_VALID(NULL);
if (!PyArg_ParseTuple(args, "|n?:read", &num_bytes))
if (!PyArg_ParseTuple(args, "|O&:read", _Py_convert_optional_to_ssize_t, &num_bytes))
return NULL;
CHECK_VALID(NULL);
@ -1709,7 +1710,7 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
DWORD off_lo; /* lower 32 bits of offset */
DWORD size_hi; /* upper 32 bits of size */
DWORD size_lo; /* lower 32 bits of size */
PyObject *tagname = NULL;
PyObject *tagname = Py_None;
DWORD dwErr = 0;
int fileno;
HANDLE fh = 0;
@ -1719,7 +1720,7 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
"tagname",
"access", "offset", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwdict, "in|U?iL", keywords,
if (!PyArg_ParseTupleAndKeywords(args, kwdict, "in|OiL", keywords,
&fileno, &map_size,
&tagname, &access, &offset)) {
return NULL;
@ -1852,7 +1853,13 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
m_obj->weakreflist = NULL;
m_obj->exports = 0;
/* set the tag name */
if (tagname != NULL) {
if (!Py_IsNone(tagname)) {
if (!PyUnicode_Check(tagname)) {
Py_DECREF(m_obj);
return PyErr_Format(PyExc_TypeError, "expected str or None for "
"'tagname', not %.200s",
Py_TYPE(tagname)->tp_name);
}
m_obj->tagname = PyUnicode_AsWideCharString(tagname, NULL);
if (m_obj->tagname == NULL) {
Py_DECREF(m_obj);