summaryrefslogtreecommitdiffstats
path: root/Modules/_io
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2023-11-01 15:34:42 (GMT)
committerGitHub <noreply@github.com>2023-11-01 15:34:42 (GMT)
commitd9b606b3d04fc56fb0bcc479d7d6c14562edb5e2 (patch)
tree14d10605507380e411d5f62e5bab28f74091129d /Modules/_io
parent97b3cd38d105fd891ba46dd27d08f03d1c6dd348 (diff)
downloadcpython-d9b606b3d04fc56fb0bcc479d7d6c14562edb5e2.zip
cpython-d9b606b3d04fc56fb0bcc479d7d6c14562edb5e2.tar.gz
cpython-d9b606b3d04fc56fb0bcc479d7d6c14562edb5e2.tar.bz2
gh-111089: Use PyUnicode_AsUTF8() in Argument Clinic (#111585)
Replace PyUnicode_AsUTF8AndSize() with PyUnicode_AsUTF8() to remove the explicit check for embedded null characters. The change avoids to have to include explicitly <string.h> to get the strlen() function when using a recent version of the limited C API.
Diffstat (limited to 'Modules/_io')
-rw-r--r--Modules/_io/clinic/_iomodule.c.h30
-rw-r--r--Modules/_io/clinic/fileio.c.h9
-rw-r--r--Modules/_io/clinic/textio.c.h23
-rw-r--r--Modules/_io/clinic/winconsoleio.c.h9
4 files changed, 13 insertions, 58 deletions
diff --git a/Modules/_io/clinic/_iomodule.c.h b/Modules/_io/clinic/_iomodule.c.h
index 112408a..68a8a20 100644
--- a/Modules/_io/clinic/_iomodule.c.h
+++ b/Modules/_io/clinic/_iomodule.c.h
@@ -188,15 +188,10 @@ _io_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
_PyArg_BadArgument("open", "argument 'mode'", "str", args[1]);
goto exit;
}
- Py_ssize_t mode_length;
- mode = PyUnicode_AsUTF8AndSize(args[1], &mode_length);
+ mode = PyUnicode_AsUTF8(args[1]);
if (mode == NULL) {
goto exit;
}
- if (strlen(mode) != (size_t)mode_length) {
- PyErr_SetString(PyExc_ValueError, "embedded null character");
- goto exit;
- }
if (!--noptargs) {
goto skip_optional_pos;
}
@@ -215,15 +210,10 @@ _io_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
encoding = NULL;
}
else if (PyUnicode_Check(args[3])) {
- Py_ssize_t encoding_length;
- encoding = PyUnicode_AsUTF8AndSize(args[3], &encoding_length);
+ encoding = PyUnicode_AsUTF8(args[3]);
if (encoding == NULL) {
goto exit;
}
- if (strlen(encoding) != (size_t)encoding_length) {
- PyErr_SetString(PyExc_ValueError, "embedded null character");
- goto exit;
- }
}
else {
_PyArg_BadArgument("open", "argument 'encoding'", "str or None", args[3]);
@@ -238,15 +228,10 @@ _io_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
errors = NULL;
}
else if (PyUnicode_Check(args[4])) {
- Py_ssize_t errors_length;
- errors = PyUnicode_AsUTF8AndSize(args[4], &errors_length);
+ errors = PyUnicode_AsUTF8(args[4]);
if (errors == NULL) {
goto exit;
}
- if (strlen(errors) != (size_t)errors_length) {
- PyErr_SetString(PyExc_ValueError, "embedded null character");
- goto exit;
- }
}
else {
_PyArg_BadArgument("open", "argument 'errors'", "str or None", args[4]);
@@ -261,15 +246,10 @@ _io_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
newline = NULL;
}
else if (PyUnicode_Check(args[5])) {
- Py_ssize_t newline_length;
- newline = PyUnicode_AsUTF8AndSize(args[5], &newline_length);
+ newline = PyUnicode_AsUTF8(args[5]);
if (newline == NULL) {
goto exit;
}
- if (strlen(newline) != (size_t)newline_length) {
- PyErr_SetString(PyExc_ValueError, "embedded null character");
- goto exit;
- }
}
else {
_PyArg_BadArgument("open", "argument 'newline'", "str or None", args[5]);
@@ -404,4 +384,4 @@ _io_open_code(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec
exit:
return return_value;
}
-/*[clinic end generated code: output=5d60f4e778a600a4 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=feb173d5f2bfb98a input=a9049054013a1b77]*/
diff --git a/Modules/_io/clinic/fileio.c.h b/Modules/_io/clinic/fileio.c.h
index cf3ba28..6f5d660 100644
--- a/Modules/_io/clinic/fileio.c.h
+++ b/Modules/_io/clinic/fileio.c.h
@@ -107,15 +107,10 @@ _io_FileIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
_PyArg_BadArgument("FileIO", "argument 'mode'", "str", fastargs[1]);
goto exit;
}
- Py_ssize_t mode_length;
- mode = PyUnicode_AsUTF8AndSize(fastargs[1], &mode_length);
+ mode = PyUnicode_AsUTF8(fastargs[1]);
if (mode == NULL) {
goto exit;
}
- if (strlen(mode) != (size_t)mode_length) {
- PyErr_SetString(PyExc_ValueError, "embedded null character");
- goto exit;
- }
if (!--noptargs) {
goto skip_optional_pos;
}
@@ -528,4 +523,4 @@ _io_FileIO_isatty(fileio *self, PyObject *Py_UNUSED(ignored))
#ifndef _IO_FILEIO_TRUNCATE_METHODDEF
#define _IO_FILEIO_TRUNCATE_METHODDEF
#endif /* !defined(_IO_FILEIO_TRUNCATE_METHODDEF) */
-/*[clinic end generated code: output=1c0f4a36f76b0c6a input=a9049054013a1b77]*/
+/*[clinic end generated code: output=27cff9d0a618edb6 input=a9049054013a1b77]*/
diff --git a/Modules/_io/clinic/textio.c.h b/Modules/_io/clinic/textio.c.h
index b24a166..25c301e 100644
--- a/Modules/_io/clinic/textio.c.h
+++ b/Modules/_io/clinic/textio.c.h
@@ -185,15 +185,10 @@ _io__TextIOBase_write(PyObject *self, PyTypeObject *cls, PyObject *const *args,
_PyArg_BadArgument("write", "argument 1", "str", args[0]);
goto exit;
}
- Py_ssize_t s_length;
- s = PyUnicode_AsUTF8AndSize(args[0], &s_length);
+ s = PyUnicode_AsUTF8(args[0]);
if (s == NULL) {
goto exit;
}
- if (strlen(s) != (size_t)s_length) {
- PyErr_SetString(PyExc_ValueError, "embedded null character");
- goto exit;
- }
return_value = _io__TextIOBase_write_impl(self, cls, s);
exit:
@@ -475,15 +470,10 @@ _io_TextIOWrapper___init__(PyObject *self, PyObject *args, PyObject *kwargs)
encoding = NULL;
}
else if (PyUnicode_Check(fastargs[1])) {
- Py_ssize_t encoding_length;
- encoding = PyUnicode_AsUTF8AndSize(fastargs[1], &encoding_length);
+ encoding = PyUnicode_AsUTF8(fastargs[1]);
if (encoding == NULL) {
goto exit;
}
- if (strlen(encoding) != (size_t)encoding_length) {
- PyErr_SetString(PyExc_ValueError, "embedded null character");
- goto exit;
- }
}
else {
_PyArg_BadArgument("TextIOWrapper", "argument 'encoding'", "str or None", fastargs[1]);
@@ -504,15 +494,10 @@ _io_TextIOWrapper___init__(PyObject *self, PyObject *args, PyObject *kwargs)
newline = NULL;
}
else if (PyUnicode_Check(fastargs[3])) {
- Py_ssize_t newline_length;
- newline = PyUnicode_AsUTF8AndSize(fastargs[3], &newline_length);
+ newline = PyUnicode_AsUTF8(fastargs[3]);
if (newline == NULL) {
goto exit;
}
- if (strlen(newline) != (size_t)newline_length) {
- PyErr_SetString(PyExc_ValueError, "embedded null character");
- goto exit;
- }
}
else {
_PyArg_BadArgument("TextIOWrapper", "argument 'newline'", "str or None", fastargs[3]);
@@ -980,4 +965,4 @@ _io_TextIOWrapper_close(textio *self, PyObject *Py_UNUSED(ignored))
{
return _io_TextIOWrapper_close_impl(self);
}
-/*[clinic end generated code: output=e58ce89b7354e77a input=a9049054013a1b77]*/
+/*[clinic end generated code: output=c9ffb48a5278cbd4 input=a9049054013a1b77]*/
diff --git a/Modules/_io/clinic/winconsoleio.c.h b/Modules/_io/clinic/winconsoleio.c.h
index 6cab295..8609fc9 100644
--- a/Modules/_io/clinic/winconsoleio.c.h
+++ b/Modules/_io/clinic/winconsoleio.c.h
@@ -106,15 +106,10 @@ _io__WindowsConsoleIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
_PyArg_BadArgument("_WindowsConsoleIO", "argument 'mode'", "str", fastargs[1]);
goto exit;
}
- Py_ssize_t mode_length;
- mode = PyUnicode_AsUTF8AndSize(fastargs[1], &mode_length);
+ mode = PyUnicode_AsUTF8(fastargs[1]);
if (mode == NULL) {
goto exit;
}
- if (strlen(mode) != (size_t)mode_length) {
- PyErr_SetString(PyExc_ValueError, "embedded null character");
- goto exit;
- }
if (!--noptargs) {
goto skip_optional_pos;
}
@@ -457,4 +452,4 @@ _io__WindowsConsoleIO_isatty(winconsoleio *self, PyObject *Py_UNUSED(ignored))
#ifndef _IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF
#define _IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF
#endif /* !defined(_IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF) */
-/*[clinic end generated code: output=04108fc26b187386 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=76408dd67894bc9c input=a9049054013a1b77]*/