Skip to content

Commit

Permalink
Remove Ci_TypeAttrRaisingCallback
Browse files Browse the repository at this point in the history
Summary:
Removes the `Ci_TypeAttrRaisingCallback` hook. We use the same dictionary watcher added in D60084797.

Unfortunately we can no longer fail the updates for overriding a final method or assigning a known incompatible type - instead we now just issue a warning.

Unlike the previous version we no longer need to worry about the update failing - we know now that the dictionary watcher event will be delivered only when it can succeed after D60182094.

Differential Revision: D60249517

fbshipit-source-id: 9881b83ce9bd044caf538195732d172b827d616e
  • Loading branch information
DinoV authored and facebook-github-bot committed Aug 5, 2024
1 parent b370f07 commit b6e1707
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 22 deletions.
3 changes: 0 additions & 3 deletions Include/cinder/hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ CiAPI_DATA(Ci_HookType_ShadowFrame_WalkAndPopulate)
Ci_hook_ShadowFrame_WalkAndPopulate;

/* Hooks for Static Python. */
typedef int(*Ci_TypeAttrRaisingCallback)(PyTypeObject *type, PyObject *name, PyObject *value);
CiAPI_DATA(Ci_TypeAttrRaisingCallback) Ci_hook_type_setattr;

typedef vectorcallfunc (*Ci_HookType_PyCMethod_New)(PyMethodDef *method);
CiAPI_DATA(Ci_HookType_PyCMethod_New) Ci_hook_PyCMethod_New;

Expand Down
18 changes: 0 additions & 18 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -4393,11 +4393,6 @@ type_setattro(PyTypeObject *type, PyObject *name, PyObject *value)
/* Will fail in _PyObject_GenericSetAttrWithDict. */
Py_INCREF(name);
}
PyObject *existing = NULL;
if (type->tp_dict) {
existing = PyDict_GetItem(type->tp_dict, name);
Py_XINCREF(existing);
}
res = _PyObject_GenericSetAttrWithDict((PyObject *)type, name, value, NULL);
if (res == 0) {
/* Clear the VALID_VERSION flag of 'type' and all its
Expand All @@ -4412,20 +4407,7 @@ type_setattro(PyTypeObject *type, PyObject *name, PyObject *value)
}
_PyType_ClearNoShadowingInstances(type, value);
assert(_PyType_CheckConsistency(type));
if (Ci_hook_type_setattr && existing != value) {
int slotupdate_res = Ci_hook_type_setattr(type, name, value);
if (slotupdate_res == -1) {
// We failed to update the slot, so restore the existing value
int revert_res = _PyObject_GenericSetAttrWithDict((PyObject *)type, name, existing, NULL);
if (revert_res == 0) {
PyType_Modified(type);
}
slotupdate_res = slotupdate_res || revert_res;
}
res = res || slotupdate_res;
}
}
Py_XDECREF(existing);
Py_DECREF(name);
return res;
}
Expand Down
1 change: 0 additions & 1 deletion Python/cinderhooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Ci_HookType_ShadowFrame_GetModuleName_JIT Ci_hook_ShadowFrame_GetModuleName_JIT
Ci_HookType_ShadowFrame_WalkAndPopulate Ci_hook_ShadowFrame_WalkAndPopulate = NULL;

/* Static Python. */
Ci_TypeAttrRaisingCallback Ci_hook_type_setattr = NULL;
Ci_HookType_PyCMethod_New Ci_hook_PyCMethod_New = NULL;
Ci_HookType_PyDescr_NewMethod Ci_hook_PyDescr_NewMethod = NULL;
Ci_HookType_type_dealloc Ci_hook_type_dealloc = NULL;
Expand Down

0 comments on commit b6e1707

Please sign in to comment.