[New-bugs-announce] [issue45315] `PyType_FromSpec` does not copy the name

Sebastian Berg report at bugs.python.org
Tue Sep 28 16:45:06 EDT 2021

New submission from Sebastian Berg <sebastian at sipsolutions.net>:

As noted in the issue: https://bugs.python.org/issue15870#msg402800 `PyType_FromSpec` assumes that the `name` passed is persistent for the program lifetime.  This seems wrong/unnecessary: We are creating a heap-type, a heap-type's name is stored as a unicode object anyway!

So, there is no reason to require the string be persistent, and a program that decides to build a custom name dynamically (for whatever reasons) would run into a crash when the name is accessed.

The code:


Should be modified to point to to the `ht_name` (utf8) data instead.  My guess is, the simplest solution is calling `type_set_name`, even if that runs some unnecessary checks.

I understand that the FromSpec API is mostly designed to replace the static type definition rather than extend it, but it seems an unintentional/strange requirement.

components: Interpreter Core
messages: 402804
nosy: seberg
priority: normal
severity: normal
status: open
title: `PyType_FromSpec` does not copy the name
type: crash
versions: Python 3.11

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list