Skip to content

Commit 0728e54

Browse files
vstinnerclaude
andcommitted
gh-156939: Fix _testcapi/bytes.c: remove double Py_DECREF
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 <noreply@anthropic.com>
1 parent 969af80 commit 0728e54

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

‎Modules/_testcapi/bytes.c‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ static PyMethodDef writer_methods[] = {
339339
{"get_size", _PyCFunction_CAST(writer_get_size), METH_NOARGS},
340340
{"finish", _PyCFunction_CAST(writer_finish), METH_NOARGS},
341341
{"finish_with_size", _PyCFunction_CAST(writer_finish_with_size), METH_VARARGS},
342-
{"discard", _PyCFunction_CAST(writer_discard), METH_VARARGS},
342+
{"discard", _PyCFunction_CAST(writer_discard), METH_NOARGS},
343343
{NULL, NULL} /* sentinel */
344344
};
345345

@@ -470,7 +470,7 @@ test_byteswriter_ptr(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
470470
memset(str, 'x', 100);
471471
str += 100;
472472

473-
// make sure that the test switchs to a bytes object
473+
// make sure that the test switches to a bytes object
474474
assert((100 + 200) > pybyteswriter_small_buffer_size());
475475
char *old_str = str;
476476
str = PyBytesWriter_GrowAndUpdatePointer(writer, 200, str);
@@ -489,10 +489,10 @@ test_byteswriter_ptr(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
489489
}
490490
assert(PyBytes_GET_SIZE(result) == 300);
491491
str = PyBytes_AS_STRING(result);
492-
for (Py_ssize_t i=0; i < 100; i++) {
492+
for (Py_ssize_t i = 0; i < 100; i++) {
493493
assert(str[i] == 'x');
494494
}
495-
for (Py_ssize_t i=0; i < 200; i++) {
495+
for (Py_ssize_t i = 0; i < 200; i++) {
496496
assert(str[100 + i] == 'y');
497497
}
498498
Py_DECREF(result);
@@ -615,7 +615,6 @@ _PyTestCapi_Init_Bytes(PyObject *m)
615615
// PyBytesWriter.obj is the second member, small_buffer is the first member
616616
long size = (long)pybyteswriter_small_buffer_size();
617617
if (PyModule_AddIntConstant(m, "PyBytesWriter_small_buffer", size) < 0) {
618-
Py_DECREF(writer_type);
619618
return -1;
620619
}
621620

0 commit comments

Comments
 (0)