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

Fix enum_type_object type on Python 3.11 #385

Merged
merged 1 commit into from
Apr 26, 2022
Merged

Fix enum_type_object type on Python 3.11 #385

merged 1 commit into from
Apr 26, 2022

Conversation

vstinner
Copy link
Contributor

The enum_type_object type inherits from PyLong_Type which is not tracked
by the GC. Instances doesn't have to be tracked by the GC: remove the
Py_TPFLAGS_HAVE_GC flag.

The Python C API documentation says:

"To create a container type, the tp_flags field of the type object
must include the Py_TPFLAGS_HAVE_GC and provide an implementation of
the tp_traverse handler."

https://docs.python.org/dev/c-api/gcsupport.html

The new exception was introduced in Python 3.11 by:
python/cpython#88429

The enum_type_object type inherits from PyLong_Type which is not tracked
by the GC. Instances doesn't have to be tracked by the GC: remove the
Py_TPFLAGS_HAVE_GC flag.

The Python C API documentation says:

    "To create a container type, the tp_flags field of the type object
    must include the Py_TPFLAGS_HAVE_GC and provide an implementation of
    the tp_traverse handler."

https://docs.python.org/dev/c-api/gcsupport.html

The new exception was introduced in Python 3.11 by:
python/cpython#88429
@vstinner
Copy link
Contributor Author

A Boost Python enum also has a name, but a name type is a Python str string which is not tracked by the GC. Example (in Python 3.11):

>>> import gc
>>> my_str="hello"
>>> gc.is_tracked(my_str)
False

So it's fine to no track Boost Python enums by the Python GC. Only objects which contain other objects must be tracked by the GC, like containers (list, dict, ...).

Reference documentation about the Python GC: https://devguide.python.org/garbage_collector/

@vstinner
Copy link
Contributor Author

The "deploy documentation / deploy (pull_request)" CI job failed with:

Push the commit or tag
  /usr/bin/git push origin gh-pages
  remote: Permission to boostorg/python.git denied to github-actions[bot].
  fatal: unable to access 'https://github.com/boostorg/python.git/': The requested URL returned error: 403
  Error: Action failed with "The process '/usr/bin/git' failed with exit code 128"

It doesn't seem to be related to my change.

@vstinner
Copy link
Contributor Author

Test Windows / build (3.7) (pull_request) Failing after 32s

It seems to be unrelated to my change:

Could not find MSBuild version with C++ support. VS2015, VS2017, or VS2019 (with C++) needs to be installed.

@vstinner
Copy link
Contributor Author

imath test suite pass with this change, it has been tested in a Fedora COPR for Python 3.11 with this change, and imath package built successfully: https://copr.fedorainfracloud.org/coprs/g/python/python3.11/builds/

4334582 | imath | 3.1.5-1.fc37 | an hour ago | 15 minutes | succeeded

Without this change, imath raises a SystemError "type Boost.Python.enum has the Py_TPFLAGS_HAVE_GC flag but has no traverse function" on Python 3.11: AcademySoftwareFoundation/Imath#253

Fedora issues about Boost Python on Python 3.11:

@stefanseefeld
Copy link
Member

Thanks @vstinner for this PR. I confirm that the CI build failure is unrelated (and is in fact a misconfiguration in the CI workflow logic, as PRs from other repos lack permission to push doc updates).

@stefanseefeld stefanseefeld merged commit a218bab into boostorg:develop Apr 26, 2022
@vstinner vstinner deleted the py311_enum_gc branch April 26, 2022 13:50
jcarpent added a commit to jcarpent/boost-feedstock that referenced this pull request Oct 28, 2022
jcarpent added a commit to jcarpent/boost-feedstock that referenced this pull request Oct 28, 2022
@afh afh mentioned this pull request Apr 19, 2023
12 tasks
Dettorer added a commit to Dettorer/nixpkgs that referenced this pull request May 13, 2023
The import checks didn't pass because of a boost binding problem solved
by boostorg/python#385.
Dettorer added a commit to Dettorer/nixpkgs that referenced this pull request May 13, 2023
The import checks didn't pass because of a boost binding problem solved
by boostorg/python#385.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants