Skip to content

bpo-46417: Cleanup typeobject.c code #30795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 22, 2022
Merged

bpo-46417: Cleanup typeobject.c code #30795

merged 1 commit into from
Jan 22, 2022

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Jan 22, 2022

  • 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
Member Author

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:main Jan 22, 2022
@vstinner vstinner deleted the cleanup_typeobject branch January 22, 2022 17:56
@encukou
Copy link
Member

encukou commented Apr 8, 2024

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
Member Author

vstinner commented Apr 8, 2024

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 free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants