https://github.com/python/cpython/commit/90d40027f75cb096ac9abf85f3fb6a2a13b21824
commit: 90d40027f75cb096ac9abf85f3fb6a2a13b21824
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2026-09-29T13:56:02+02:00
summary:

gh-156939: Fix Modules/_testcapi/bytes.c: remove double Py_DECREF (#158400)

Remove a spurious Py_DECREF(writer_type) in _PyTestCapi_Init_Bytes()
that over-decremented the reference after it was already released.
Also fix writer_discard method flags (METH_VARARGS -> METH_NOARGS),
a typo, and PEP 7 spacing in for-loop initializers.

Co-authored-by: Claude Opus 4.6 <[email protected]>

files:
M Modules/_testcapi/bytes.c

diff --git a/Modules/_testcapi/bytes.c b/Modules/_testcapi/bytes.c
index a5b904dc2f90bc..7382fe2227b8b6 100644
--- a/Modules/_testcapi/bytes.c
+++ b/Modules/_testcapi/bytes.c
@@ -339,7 +339,7 @@ static PyMethodDef writer_methods[] = {
     {"get_size", _PyCFunction_CAST(writer_get_size), METH_NOARGS},
     {"finish", _PyCFunction_CAST(writer_finish), METH_NOARGS},
     {"finish_with_size", _PyCFunction_CAST(writer_finish_with_size), 
METH_VARARGS},
-    {"discard", _PyCFunction_CAST(writer_discard), METH_VARARGS},
+    {"discard", _PyCFunction_CAST(writer_discard), METH_NOARGS},
     {NULL,              NULL}           /* sentinel */
 };
 
@@ -470,7 +470,7 @@ test_byteswriter_ptr(PyObject *Py_UNUSED(module), PyObject 
*Py_UNUSED(args))
     memset(str, 'x', 100);
     str += 100;
 
-    // make sure that the test switchs to a bytes object
+    // make sure that the test switches to a bytes object
     assert((100 + 200) > pybyteswriter_small_buffer_size());
     char *old_str = str;
     str = PyBytesWriter_GrowAndUpdatePointer(writer, 200, str);
@@ -489,10 +489,10 @@ test_byteswriter_ptr(PyObject *Py_UNUSED(module), 
PyObject *Py_UNUSED(args))
     }
     assert(PyBytes_GET_SIZE(result) == 300);
     str = PyBytes_AS_STRING(result);
-    for (Py_ssize_t i=0; i < 100; i++) {
+    for (Py_ssize_t i = 0; i < 100; i++) {
         assert(str[i] == 'x');
     }
-    for (Py_ssize_t i=0; i < 200; i++) {
+    for (Py_ssize_t i = 0; i < 200; i++) {
         assert(str[100 + i] == 'y');
     }
     Py_DECREF(result);
@@ -615,7 +615,6 @@ _PyTestCapi_Init_Bytes(PyObject *m)
     // PyBytesWriter.obj is the second member, small_buffer is the first member
     long size = (long)pybyteswriter_small_buffer_size();
     if (PyModule_AddIntConstant(m, "PyBytesWriter_small_buffer", size) < 0) {
-        Py_DECREF(writer_type);
         return -1;
     }
 

_______________________________________________
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]

Reply via email to