Message402800
| Author |
haberman2 |
| Recipients |
Alexander.Belopolsky, Arfrever, Christian.Tismer, Robin.Schreiber, amaury.forgeotdarc, belopolsky, haberman2, jcea, jhaberman, lekma, loewis, mattip, petr.viktorin, pitrou, seberg, steve.dower |
| Date |
2021年09月28日.19:11:53 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1632856313.7.0.644032533887.issue15870@roundup.psfhosted.org> |
| In-reply-to |
| Content |
> Everything is copied by `_FromSpec` after all.
One thing I noticed isn't copied is the string pointed to by tp_name: https://github.com/python/cpython/blob/0c50b8c0b8274d54d6b71ed7bd21057d3642f138/Objects/typeobject.c#L3427
This isn't an issue if tp_name is initialized from a string literal. But if tp_name is created dynamically, it could lead to a dangling pointer. If the general message is that "everything is copied by _FromSpec", it might make sense to copy the tp_name string too.
> However, I suppose that would replace a safe-by-design API with a "best practice" to never define the spec/slots statically (a best practice that is probably not generally followed or even advertised currently, I guess).
Yes that seems reasonable. I generally prefer static declarations, since they will end up in .data instead of .text and will avoid a copy to the stack at runtime. But these are very minor differences, especially for code that only runs once at startup, and a safe-by-default recommendation of always initializing PyType_* on the stack makes sense. |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2021年09月28日 19:11:53 | haberman2 | set | recipients:
+ haberman2, loewis, jcea, amaury.forgeotdarc, belopolsky, pitrou, Arfrever, petr.viktorin, lekma, Alexander.Belopolsky, mattip, Robin.Schreiber, steve.dower, seberg, Christian.Tismer, jhaberman |
| 2021年09月28日 19:11:53 | haberman2 | set | messageid: <1632856313.7.0.644032533887.issue15870@roundup.psfhosted.org> |
| 2021年09月28日 19:11:53 | haberman2 | link | issue15870 messages |
| 2021年09月28日 19:11:53 | haberman2 | create |
|