https://github.com/python/cpython/commit/d7f107a767e5768da4c7f9f5c4e112b12be101b1
commit: d7f107a767e5768da4c7f9f5c4e112b12be101b1
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2026-09-02T17:57:31+02:00
summary:
gh-155742: Use PyBytesWriter in xml.etree (#155749)
Replace soft deprecated PyBytes_FromStringAndSize() with
PyBytesWriter.
files:
M Modules/_elementtree.c
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index fa178f53e9b3ff..18bbbb618c2b18 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -3165,7 +3165,6 @@ makeuniversal(XMLParserObject* self, const char* string)
necessary */
PyObject* tag;
- char* p;
Py_ssize_t i;
/* look for namespace separator */
@@ -3174,22 +3173,28 @@ makeuniversal(XMLParserObject* self, const char* string)
break;
if (i != size) {
/* convert to universal name */
- tag = PyBytes_FromStringAndSize(NULL, size+1);
- if (tag == NULL) {
+ PyBytesWriter *writer = PyBytesWriter_Create(1 + size);
+ if (writer == NULL) {
Py_DECREF(key);
return NULL;
}
- p = PyBytes_AS_STRING(tag);
+ char *p = PyBytesWriter_GetData(writer);
p[0] = '{';
memcpy(p+1, string, size);
size++;
+
+ tag = PyBytesWriter_Finish(writer);
+ if (tag == NULL) {
+ Py_DECREF(key);
+ return NULL;
+ }
} else {
/* plain name; use key as tag */
tag = Py_NewRef(key);
}
/* decode universal name */
- p = PyBytes_AS_STRING(tag);
+ const char *p = PyBytes_AS_STRING(tag);
value = PyUnicode_DecodeUTF8(p, size, "strict");
Py_DECREF(tag);
if (!value) {
_______________________________________________
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]