Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

_testcapi has invalid usage of PyType_GetName #136288

Copy link
Copy link
@ZeroIntensity

Description

@ZeroIntensity
Issue body actions

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:

return PyErr_Format(
PyExc_TypeError,
"expected %s instance",
PyType_GetName(type));

return PyErr_Format(
PyExc_TypeError,
"type %s has no vectorcall offset",
PyType_GetName(type));

There are two problems:

  1. PyType_GetName returns a PyObject *, not a string (so the %s conversion is invalid).
  2. 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

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.