8000 gh-117482: Fix Builtin Types Slot Wrappers When Embedded by ericsnowcurrently · Pull Request #121636 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-117482: Fix Builtin Types Slot Wrappers When Embedded #121636

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

Next Next commit
Restore the finalization code.
  • Loading branch information
ericsnowcurrently committed Jul 11, 2024
commit 99c57468d9bdbcb3a7dffcb6cbfcf782bbb4ca56
22 changes: 20 additions & 2 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,15 @@ managed_static_type_state_init(PyInterpreterState *interp, PyTypeObject *self,

/* Reset the type's per-interpreter state.
This basically undoes what managed_static_type_state_init() did. */
static void
static PyTypeObject *
managed_static_type_state_clear(PyInterpreterState *interp, PyTypeObject *self,
int isbuiltin, int final)
{
size_t index = managed_static_type_index_get(self);
size_t full_index = isbuiltin
? index
: index + _Py_MAX_MANAGED_STATIC_BUILTIN_TYPES;
PyTypeObject *def = &_PyRuntime.types.managed_static.types[full_index].def;

managed_static_type_state *state = isbuiltin
? &(interp->types.builtins.initialized[index])
Expand Down Expand Up @@ -312,6 +313,8 @@ managed_static_type_state_clear(PyInterpreterState *interp, PyTypeObject *self,
}
PyMutex_Unlock(&interp->types.mutex);
}

return def;
}

static PyTypeObject *
Expand Down Expand Up @@ -5849,7 +5852,15 @@ fini_static_type(PyInterpreterState *interp, PyTypeObject *type,
}

_PyStaticType_ClearWeakRefs(interp, type);
managed_static_type_state_clear(interp, type, isbuiltin, final);
PyTypeObject *def =
managed_static_type_state_clear(interp, type, isbuiltin, final);
/* For now we exclude extension module types. */
if (final && isbuiltin) {
/* Restore the static type to it's (mostly) original values. */
destructor dealloc = type->tp_dealloc;
memcpy(type, def, sizeof(PyTypeObject));
type->tp_dealloc = dealloc;
}
}

void
Expand Down Expand Up @@ -8481,6 +8492,9 @@ init_static_type(PyInterpreterState *interp, PyTypeObject *self,
PyTypeObject *def = managed_static_type_get_def(self, isbuiltin);
if (initial) {
memcpy(def, self, sizeof(PyTypeObject));
/* For now we do not worry about preserving the index
at finalization. */
managed_static_type_index_clear(def);
}

int res;
Expand All @@ -8492,6 +8506,10 @@ init_static_type(PyInterpreterState *interp, PyTypeObject *self,
managed_static_type_state_clear(interp, self, isbuiltin, initial);
}

if (initial) {
Py_SET_TYPE(def, Py_TYPE(self));
}

return res;
}

Expand Down
0