op->func_annotations = NULL;
op->func_typeparams = NULL;
op->vectorcall = _PyFunction_Vectorcall;
- op->func_version = 0;
+ _PyFunction_SetVersion(op, 0);
_PyObject_GC_TRACK(op);
handle_func_event(PyFunction_EVENT_CREATE, op, NULL);
return op;
op->func_annotations = NULL;
op->func_typeparams = NULL;
op->vectorcall = _PyFunction_Vectorcall;
- op->func_version = 0;
+ _PyFunction_SetVersion(op, 0);
_PyObject_GC_TRACK(op);
handle_func_event(PyFunction_EVENT_CREATE, op, NULL);
return (PyObject *)op;
void
_PyFunction_SetVersion(PyFunctionObject *func, uint32_t version)
{
+ PyInterpreterState *interp = _PyInterpreterState_GET();
+ if (func->func_version != 0) {
+ PyFunctionObject **slot =
+ interp->func_state.func_version_cache
+ + (func->func_version % FUNC_VERSION_CACHE_SIZE);
+ if (*slot == func) {
+ *slot = NULL;
+ }
+ }
func->func_version = version;
if (version != 0) {
- PyInterpreterState *interp = _PyInterpreterState_GET();
interp->func_state.func_version_cache[
version % FUNC_VERSION_CACHE_SIZE] = func;
}
}
handle_func_event(PyFunction_EVENT_MODIFY_DEFAULTS,
(PyFunctionObject *) op, defaults);
- ((PyFunctionObject *)op)->func_version = 0;
+ _PyFunction_SetVersion((PyFunctionObject *)op, 0);
Py_XSETREF(((PyFunctionObject *)op)->func_defaults, defaults);
return 0;
}
PyFunction_SetVectorcall(PyFunctionObject *func, vectorcallfunc vectorcall)
{
assert(func != NULL);
- func->func_version = 0;
+ _PyFunction_SetVersion(func, 0);
func->vectorcall = vectorcall;
}
}
handle_func_event(PyFunction_EVENT_MODIFY_KWDEFAULTS,
(PyFunctionObject *) op, defaults);
- ((PyFunctionObject *)op)->func_version = 0;
+ _PyFunction_SetVersion((PyFunctionObject *)op, 0);
Py_XSETREF(((PyFunctionObject *)op)->func_kwdefaults, defaults);
return 0;
}
Py_TYPE(closure)->tp_name);
return -1;
}
- ((PyFunctionObject *)op)->func_version = 0;
+ _PyFunction_SetVersion((PyFunctionObject *)op, 0);
Py_XSETREF(((PyFunctionObject *)op)->func_closure, closure);
return 0;
}
"non-dict annotations");
return -1;
}
- ((PyFunctionObject *)op)->func_version = 0;
+ _PyFunction_SetVersion((PyFunctionObject *)op, 0);
Py_XSETREF(((PyFunctionObject *)op)->func_annotations, annotations);
return 0;
}
return -1;
}
handle_func_event(PyFunction_EVENT_MODIFY_CODE, op, value);
- op->func_version = 0;
+ _PyFunction_SetVersion(op, 0);
Py_XSETREF(op->func_code, Py_NewRef(value));
return 0;
}
}
handle_func_event(PyFunction_EVENT_MODIFY_DEFAULTS, op, value);
- op->func_version = 0;
+ _PyFunction_SetVersion(op, 0);
Py_XSETREF(op->func_defaults, Py_XNewRef(value));
return 0;
}
}
handle_func_event(PyFunction_EVENT_MODIFY_KWDEFAULTS, op, value);
- op->func_version = 0;
+ _PyFunction_SetVersion(op, 0);
Py_XSETREF(op->func_kwdefaults, Py_XNewRef(value));
return 0;
}
"__annotations__ must be set to a dict object");
return -1;
}
- op->func_version = 0;
+ _PyFunction_SetVersion(op, 0);
Py_XSETREF(op->func_annotations, Py_XNewRef(value));
return 0;
}
static int
func_clear(PyFunctionObject *op)
{
- op->func_version = 0;
+ _PyFunction_SetVersion(op, 0);
Py_CLEAR(op->func_globals);
Py_CLEAR(op->func_builtins);
Py_CLEAR(op->func_module);
if (op->func_weakreflist != NULL) {
PyObject_ClearWeakRefs((PyObject *) op);
}
- if (op->func_version != 0) {
- PyInterpreterState *interp = _PyInterpreterState_GET();
- PyFunctionObject **slot =
- interp->func_state.func_version_cache
- + (op->func_version % FUNC_VERSION_CACHE_SIZE);
- if (*slot == op) {
- *slot = NULL;
- }
- }
+ _PyFunction_SetVersion(op, 0);
(void)func_clear(op);
// These aren't cleared by func_clear().
Py_DECREF(op->func_code);