This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2021年06月29日 06:53 by JunyiXie, last changed 2022年04月11日 14:59 by admin.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 26949 | open | JunyiXie, 2021年06月29日 07:04 | |
| Messages (4) | |||
|---|---|---|---|
| msg396703 - (view) | Author: junyixie (JunyiXie) * | Date: 2021年06月29日 06:53 | |
In _PyStructSequence_InitType, it will check type is initialized.
but when we have multi subinterpreters, type may be initialized expected.
when type already been initialized, should return 0 rather than throw exception.
```c
/* PyTypeObject has already been initialized */
if (Py_REFCNT(type) != 0) {
return 0;
}
```
```c
int
_PyStructSequence_InitType(PyTypeObject *type, PyStructSequence_Desc *desc,
unsigned long tp_flags)
{
PyMemberDef *members;
Py_ssize_t n_members, n_unnamed_members;
#ifdef Py_TRACE_REFS
/* if the type object was chained, unchain it first
before overwriting its storage */
if (type->ob_base.ob_base._ob_next) {
_Py_ForgetReference((PyObject *)type);
}
#endif
/* PyTypeObject has already been initialized */
if (Py_REFCNT(type) != 0) {
PyErr_BadInternalCall();
return -1;
}
```
|
|||
| msg404490 - (view) | Author: Hai Shi (shihai1991) * (Python triager) | Date: 2021年10月20日 16:24 | |
> In _PyStructSequence_InitType, it will check type is initialized. It's a internal C API :) > when type already been initialized, should return 0 rather than throw exception. The another solution is to check the type status before calling _PyStructSequence_InitType(). |
|||
| msg406068 - (view) | Author: junyixie (JunyiXie) * | Date: 2021年11月10日 03:33 | |
Include/internal/pycore_structseq.h: 10 11 12: PyAPI_FUNC(int) _PyStructSequence_InitType( 13 PyTypeObject *type, 14 PyStructSequence_Desc *desc, Modules/_cursesmodule.c: 4794 /* ncurses_version */ 4795 if (NcursesVersionType.tp_name == NULL) { 4796: if (_PyStructSequence_InitType(&NcursesVersionType, 4797 &ncurses_version_desc, 4798 Py_TPFLAGS_DISALLOW_INSTANTIATION) < 0) { Objects/structseq.c: 463 464 int 465: _PyStructSequence_InitType(PyTypeObject *type, PyStructSequence_Desc *desc, 466 unsigned long tp_flags) 467 { ... 527 PyStructSequence_InitType2(PyTypeObject *type, PyStructSequence_Desc *desc) 528 { 529: return _PyStructSequence_InitType(type, desc, 0); 530 } 531 Python/sysmodule.c: 2813 /* version_info */ 2814 if (VersionInfoType.tp_name == NULL) { 2815: if (_PyStructSequence_InitType(&VersionInfoType, 2816 &version_info_desc, 2817 Py_TPFLAGS_DISALLOW_INSTANTIATION) < 0) { .... 2827 // sys.flags: updated in-place later by _PySys_UpdateConfig() 2828 if (FlagsType.tp_name == 0) { 2829: if (_PyStructSequence_InitType(&FlagsType, &flags_desc, 2830 Py_TPFLAGS_DISALLOW_INSTANTIATION) < 0) { 2831 goto type_init_failed; .... 2837 /* getwindowsversion */ 2838 if (WindowsVersionType.tp_name == 0) { 2839: if (_PyStructSequence_InitType(&WindowsVersionType, 2840 &windows_version_desc, 2841 Py_TPFLAGS_DISALLOW_INSTANTIATION) < 0) { |
|||
| msg406325 - (view) | Author: Hai Shi (shihai1991) * (Python triager) | Date: 2021年11月14日 17:05 | |
OK,thanks. If it's just only interal calling, I don't think throwing a exception would break anything. As your pasted code shows, the modules have judeged the tp_name is inited or not. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:59:47 | admin | set | github: 88698 |
| 2021年11月14日 17:05:16 | shihai1991 | set | messages: + msg406325 |
| 2021年11月10日 03:33:12 | JunyiXie | set | messages: + msg406068 |
| 2021年10月20日 16:24:43 | shihai1991 | set | nosy:
+ shihai1991 messages: + msg404490 |
| 2021年06月29日 07:04:58 | JunyiXie | set | keywords:
+ patch stage: patch review pull_requests: + pull_request25516 |
| 2021年06月29日 06:53:42 | JunyiXie | create | |