Skip to content

Commit 07bd293

Browse files
alexmalyshevmeta-codesync[bot]
authored andcommitted
Move enable_patching global into ModuleState
Summary: Move the `enable_patching` file-scope global variable from `_cinderx-lib.cpp` into the `ModuleState` class. This is part of a broader effort to consolidate CinderX global state into the ModuleState singleton to improve modularity and support proper multi-phase initialization. Reviewed By: yoney Differential Revision: D96480469 fbshipit-source-id: 68ceb303d569cd49b323b1e5a40bc43310358155
1 parent 2ab3c3b commit 07bd293

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

cinderx/_cinderx-lib.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -856,10 +856,6 @@ int cinderx_type_watcher(PyTypeObject* type) {
856856
return 0;
857857
}
858858

859-
#if PY_VERSION_HEX >= 0x030C0000
860-
bool enable_patching = 0;
861-
#endif
862-
863859
static PyObject* cinderx_freeze_type(PyObject*, PyObject* o) {
864860
if (!PyType_Check(o)) {
865861
PyErr_Format(
@@ -876,7 +872,7 @@ static PyObject* cinderx_freeze_type(PyObject*, PyObject* o) {
876872
((PyTypeObject*)o)->tp_flags |= Ci_Py_TPFLAGS_FROZEN;
877873
}
878874
#else
879-
if (!enable_patching) {
875+
if (!cinderx::getModuleState()->enable_patching) {
880876
((PyTypeObject*)o)->tp_flags |= Py_TPFLAGS_IMMUTABLETYPE;
881877
}
882878
#endif
@@ -1495,7 +1491,7 @@ int _cinderx_exec_impl(PyObject* m) {
14951491

14961492
#if PY_VERSION_HEX >= 0x030C0000
14971493
char* patching = getenv("PYTHONENABLEPATCHING");
1498-
enable_patching = patching != nullptr && strcmp(patching, "1") == 0;
1494+
state->enable_patching = patching != nullptr && strcmp(patching, "1") == 0;
14991495

15001496
#ifdef ENABLE_INTERPRETER_LOOP
15011497
Ci_InitOpcodes();

cinderx/module_state.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ struct ModuleState {
9494

9595
// Callback invoked when a compilation unit is deleted during preloading.
9696
std::function<void(BorrowedRef<>)> unit_deleted_during_preload;
97+
98+
// Whether runtime modification of Strict Module types is allowed.
99+
bool enable_patching{false};
97100
};
98101

99102
// Get the global ModuleState singleton.

0 commit comments

Comments
 (0)