-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Closed
Labels
testsTests in the Lib/test dirTests in the Lib/test dirtopic-C-APItype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
Spotted by @wsfulton in GH-136258. I'm making an issue so I can attach it to his PR.
PyType_GetName
is used incorrectly in two places:
cpython/Modules/_testcapi/vectorcall.c
Lines 180 to 183 in 93263d4
return PyErr_Format( | |
PyExc_TypeError, | |
"expected %s instance", | |
PyType_GetName(type)); |
cpython/Modules/_testcapi/vectorcall.c
Lines 186 to 189 in 93263d4
return PyErr_Format( | |
PyExc_TypeError, | |
"type %s has no vectorcall offset", | |
PyType_GetName(type)); |
There are two problems:
PyType_GetName
returns aPyObject *
, not a string (so the%s
conversion is invalid).- It also returns a strong reference, which isn't consumed by
PyErr_Format
and thus is leaked.
Fixes to tests generally don't matter, but I think that this one is worth fixing. People look to the source for examples, and considering this is one of our only examples using it, I'd rather not leave people to think that PyType_GetName
returns a string or borrowed reference.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
Metadata
Metadata
Assignees
Labels
testsTests in the Lib/test dirTests in the Lib/test dirtopic-C-APItype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error