Skip to content
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

bpo-1635741: Refactor _threadmodule.c #23793

Merged
merged 3 commits into from Dec 16, 2020
Merged

bpo-1635741: Refactor _threadmodule.c #23793

merged 3 commits into from Dec 16, 2020

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Dec 16, 2020

  • Fix ExceptHookArgsType name: "_thread.ExceptHookArgs", instead of
    "_thread._ExceptHookArgs".
  • PyInit__thread() no longer intializes interp->num_threads to 0:
    it is already done in PyInterpreterState_New().
  • Use PyModule_AddType(), Py_NewRef() and Py_XNewRef().
  • Replace str_dict variable with _Py_IDENTIFIER(dict).
  • Remove assert(Py_IS_TYPE(obj, &Locktype)) from release_sentinel()
    to avoid having to retrive the type from this callback.

https://bugs.python.org/issue1635741

@vstinner
Copy link
Member Author

I chose to not convert static types to heap types in the same PR to keep the PR short enough for reviews.

cc @corona10 @shihai1991

@vstinner
Copy link
Member Author

I was not sure if it's a good idea to convert the module to multiphase init, but I wanted to do it to pass the lock type to newlockobject().

* Fix ExceptHookArgsType name: "_thread.ExceptHookArgs", instead of
  "_thread._ExceptHookArgs".
* PyInit__thread() no longer intializes interp->num_threads to 0:
  it is already done in PyInterpreterState_New().
* Use PyModule_AddType(), Py_NewRef() and Py_XNewRef().
* Replace str_dict variable with _Py_IDENTIFIER(__dict__).
* Remove assert(Py_IS_TYPE(obj, &Locktype)) from release_sentinel()
  to avoid having to retrive the type from this callback.
@vstinner
Copy link
Member Author

I was not sure if it's a good idea to convert the module to multiphase init, but I wanted to do it to pass the lock type to newlockobject().

I changed my mind. I reverted some changes to keep the legacy PyModule_Create() API. I removed the module state.

It's trivial to add a module state to migrate to PyModuleDef_Init(). But we may do that while static types are converted to heap types.

@vstinner vstinner changed the title bpo-1635741: Convert _thread to multiphase init bpo-1635741: Refactor _threadmodule.c Dec 16, 2020
@vstinner
Copy link
Member Author

The tricky part is to get localdummytype in local_new() and get localtype in local_getattro(). _PyType_GetModuleByDef() can be used for that.

* Rename t_bootstrap() to thread_run()
* bootstate structure: rename keyw member to kwargs
@vstinner vstinner merged commit 8203c73 into python:master Dec 16, 2020
@vstinner vstinner deleted the WIP_thread branch December 16, 2020 11:20
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 13, 2021
* Fix ExceptHookArgsType name: "_thread.ExceptHookArgs", instead of
  "_thread._ExceptHookArgs".
* PyInit__thread() no longer intializes interp->num_threads to 0:
  it is already done in PyInterpreterState_New().
* Use PyModule_AddType(), Py_NewRef() and Py_XNewRef().
* Replace str_dict variable with _Py_IDENTIFIER(__dict__).
* Remove assert(Py_IS_TYPE(obj, &Locktype)) from release_sentinel()
  to avoid having to retrive the type from this callback.
* Add thread_bootstate_free()
* Rename t_bootstrap() to thread_run()
* bootstate structure: rename keyw member to kwargs
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.

None yet

3 participants