Skip to content

bpo-46417: Cleanup typeobject.c code - #30795

Merged
vstinner merged 1 commit into
python:mainfrom
vstinner:cleanup_typeobject
Jan 22, 2022
Merged

bpo-46417: Cleanup typeobject.c code#30795
vstinner merged 1 commit into
python:mainfrom
vstinner:cleanup_typeobject

Conversation

@vstinner

@vstinnervstinner commented Jan 22, 2022

Copy link
Copy Markdown
Member
  • Add comment to recurse_down_subclasses() explaining why it's safe
    to use a borrowed reference to tp_subclasses.
  • remove_all_subclasses() no longer accept NULL cases
  • type_set_bases() now relies on the fact that new_bases is not NULL.
  • type_dealloc_common() avoids PyErr_Fetch/PyErr_Restore if tp_bases
    is NULL.
  • remove_all_subclasses() makes sure that no exception is raised.
  • Don't test at runtime if tp_mro only contains types: rely on
    _PyType_CAST() assertion for that.
  • _PyStaticType_Dealloc() no longer clears tp_subclasses which is
    already NULL.
  • mro_hierarchy() avoids calling _PyType_GetSubclasses() if
    tp_subclasses is NULL.

Coding style:

  • Use Py_NewRef().
  • Add braces and move variable declarations to the first variable
    assignement.
  • Rename a few variables and parameters to use better names.

https://bugs.python.org/issue46417

* Add comment to recurse_down_subclasses() explaining why it's safe
to use a borrowed reference to tp_subclasses.
* remove_all_subclasses() no longer accept NULL cases
* type_set_bases() now relies on the fact that new_bases is not NULL.
* type_dealloc_common() avoids PyErr_Fetch/PyErr_Restore if tp_bases
is NULL.
* remove_all_subclasses() makes sure that no exception is raised.
* Don't test at runtime if tp_mro only contains types: rely on
_PyType_CAST() assertion for that.
* _PyStaticType_Dealloc() no longer clears tp_subclasses which is
already NULL.
* mro_hierarchy() avoids calling _PyType_GetSubclasses() if
tp_subclasses is NULL.
Coding style:
* Use Py_NewRef().
* Add braces and move variable declarations to the first variable
assignement.
* Rename a few variables and parameters to use better names.
@vstinner

Copy link
Copy Markdown
MemberAuthor

test_concurrent_futures timed out on Address sanitizer and had to be re-run:

1 re-run test:
test_concurrent_futures
10 slowest tests:
- test_concurrent_futures: 25 min
- test_peg_generator: 9 min 46 sec
- test_tools: 4 min 45 sec
- test_asyncio: 2 7min 18 sec
- test_weakref: 1 min 26 sec
- test_venv: 1 min 24 sec
- test_subprocess: 1 min 6 sec
- test_lib2to3: 1 min 1 sec
- test_pickle: 59.4 sec
- test_gdb: 58.5 sec

@vstinner
vstinner merged commit 3a4c15b into python:mainJan 22, 2022
@vstinner
vstinner deleted the cleanup_typeobject branch January 22, 2022 17:56
@encukou

Copy link
Copy Markdown
Member

In PyType_GetModuleByDef, the comment & assert is now out of date:

 // mro_invoke() ensures that the type MRO cannot be empty, so we don't have
// to check i < PyTuple_GET_SIZE(mro) at the first loop iteration.
assert(PyTuple_GET_SIZE(mro) >= 1);

With a for loop, the i < PyTuple_GET_SIZE(mro) check is done before each iteration.

@vstinner

Copy link
Copy Markdown
MemberAuthor

Two years later, I don't recall why I replaced the while() loop with a for() loop. You can restore the while if you prefer.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@vstinner@encukou@the-knights-who-say-ni@bedevere-bot