Skip to content

Improve hack used in debug_options #39093

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 5 commits into from
Feb 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/sage/structure/debug_options.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ cdef class DebugOptions_class:

cdef DebugOptions_class debug = DebugOptions_class()

# Since "debug" is declared with a type, it can only be cimported at
# Since "debug" is declared with cdef, it can only be cimported at
# the Cython level, not imported in plain Python. So we add it to the
# globals manually. We need to hack into Cython internals for this
# since Sage is compiled with the old_style_globals option.
from cpython.object cimport PyObject
cdef extern from *:
PyObject* __pyx_d

(<object>__pyx_d)["debug"] = debug
# globals manually. However this will make the variable out of sync
# if some user modifies the object, which is inevitable.
# See https://github.com/cython/cython/issues/3959#issuecomment-753455240
# and https://github.com/cython/cython/issues/656
# Note that ``_this_module`` could not be ``globals()``
# because Sage is compiled with the old_style_globals option.
import sage.structure.debug_options as _this_module
_this_module.debug = debug
del _this_module
Loading