@@ -245,6 +245,7 @@ static PyObject* pop(PyObject* s){
245245
246246
247247
248+ // Artifact[Implementation]: Explanation how a stack is used to implement the DFS based SCC algorithm
248249/**
249250 * The DFS walk for SCC calculations needs to perform actions on both
250251 * the pre-order and post-order visits to an object. To achieve this
@@ -290,6 +291,7 @@ static bool is_c_wrapper(PyObject* obj){
290291 return PyCFunction_Check (obj ) || Py_IS_TYPE (obj , & _PyMethodWrapper_Type ) || Py_IS_TYPE (obj , & PyWrapperDescr_Type );
291292}
292293
294+ // Artifact[Implementation]: The state used to track a single freeze call and construct SCCs
293295/**
294296 * Used to track the state of an in progress freeze operation.
295297 *
@@ -1468,8 +1470,8 @@ static int check_freezable(struct _Py_immutability_state *state, PyObject* obj,
14681470 }
14691471 goto error ;
14701472 case _Py_FREEZABLE_PROXY :
1471- // Reserved for future use — fall through to existing checks.
1472- break ;
1473+ assert ( PyModule_Check ( obj ) || obj == _PyObject_CAST ( & PyModule_Type ));
1474+ return 0 ;
14731475 }
14741476 }
14751477
@@ -2015,6 +2017,7 @@ static void make_weakrefs_safe(struct FreezeState* freeze_state)
20152017
20162018/* This undoes a freeze belonging to the given state */
20172019static void undo_freeze (struct FreezeState * state ) {
2020+ // Artifact[Implementation]: The function that rolls back immutability on failure
20182021 debug ("Unfreezing all frozen objects belonging to %p\n" , state );
20192022
20202023 // Clear dfs stack
@@ -2237,6 +2240,15 @@ late_init(struct _Py_immutability_state *state)
22372240static int
22382241freeze_impl (PyObject * const * objs , Py_ssize_t nobjs )
22392242{
2243+ // Artifact[Implementation]: The entry point to the `freeze()` function in C
2244+ //
2245+ // This is the central function to the freeze algorithm that handles
2246+ // DFS traversal and calls into other functions to:
2247+ // - Checking freezability
2248+ // - Checking and calling the pre-freeze hook
2249+ // - Construct SCCs
2250+ // - Handle failures
2251+ // - Remove objects from the GC list
22402252 struct _Py_immutability_state * imm_state = NULL ;
22412253 int result = 0 ;
22422254 TRACE_MERMAID_START ();
0 commit comments