mirror of
https://github.com/python/cpython.git
synced 2025-11-20 10:57:44 +00:00
#2989: add PyType_Modified().
This commit is contained in:
parent
88eeef35d7
commit
74a1deaab3
4 changed files with 23 additions and 12 deletions
|
|
@ -37,7 +37,16 @@ Type Objects
|
||||||
|
|
||||||
.. cfunction:: unsigned int PyType_ClearCache(void)
|
.. cfunction:: unsigned int PyType_ClearCache(void)
|
||||||
|
|
||||||
Clears the internal lookup cache. Return the current version tag.
|
Clear the internal lookup cache. Return the current version tag.
|
||||||
|
|
||||||
|
.. versionadded:: 2.6
|
||||||
|
|
||||||
|
|
||||||
|
.. cfunction:: void PyType_Modified(PyTypeObject *type)
|
||||||
|
|
||||||
|
Invalidate the internal lookup cache for the type and all of its
|
||||||
|
subtypes. This function must be called after any manual
|
||||||
|
modification of the attributes or base classes of the type.
|
||||||
|
|
||||||
.. versionadded:: 2.6
|
.. versionadded:: 2.6
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -460,6 +460,7 @@ PyAPI_FUNC(PyObject *) PyType_GenericNew(PyTypeObject *,
|
||||||
PyObject *, PyObject *);
|
PyObject *, PyObject *);
|
||||||
PyAPI_FUNC(PyObject *) _PyType_Lookup(PyTypeObject *, PyObject *);
|
PyAPI_FUNC(PyObject *) _PyType_Lookup(PyTypeObject *, PyObject *);
|
||||||
PyAPI_FUNC(unsigned int) PyType_ClearCache(void);
|
PyAPI_FUNC(unsigned int) PyType_ClearCache(void);
|
||||||
|
PyAPI_FUNC(void) PyType_Modified(PyTypeObject *);
|
||||||
|
|
||||||
/* Generic operations on objects */
|
/* Generic operations on objects */
|
||||||
PyAPI_FUNC(int) PyObject_Print(PyObject *, FILE *, int);
|
PyAPI_FUNC(int) PyObject_Print(PyObject *, FILE *, int);
|
||||||
|
|
|
||||||
|
|
@ -239,7 +239,9 @@ Build
|
||||||
C API
|
C API
|
||||||
-----
|
-----
|
||||||
|
|
||||||
- The PyBytes functions have been renamed to PyByteArray
|
- Add ``PyType_Modified()`` as a public API to clear the type cache.
|
||||||
|
|
||||||
|
- The PyBytes functions have been renamed to PyByteArray.
|
||||||
|
|
||||||
- The PyString functions have been renamed to PyBytes. A batch of
|
- The PyString functions have been renamed to PyBytes. A batch of
|
||||||
defines were added so that the linker still sees the original
|
defines were added so that the linker still sees the original
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,6 @@ struct method_cache_entry {
|
||||||
|
|
||||||
static struct method_cache_entry method_cache[1 << MCACHE_SIZE_EXP];
|
static struct method_cache_entry method_cache[1 << MCACHE_SIZE_EXP];
|
||||||
static unsigned int next_version_tag = 0;
|
static unsigned int next_version_tag = 0;
|
||||||
static void type_modified(PyTypeObject *);
|
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
PyType_ClearCache(void)
|
PyType_ClearCache(void)
|
||||||
|
|
@ -47,12 +46,12 @@ PyType_ClearCache(void)
|
||||||
}
|
}
|
||||||
next_version_tag = 0;
|
next_version_tag = 0;
|
||||||
/* mark all version tags as invalid */
|
/* mark all version tags as invalid */
|
||||||
type_modified(&PyBaseObject_Type);
|
PyType_Modified(&PyBaseObject_Type);
|
||||||
return cur_version_tag;
|
return cur_version_tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
void
|
||||||
type_modified(PyTypeObject *type)
|
PyType_Modified(PyTypeObject *type)
|
||||||
{
|
{
|
||||||
/* Invalidate any cached data for the specified type and all
|
/* Invalidate any cached data for the specified type and all
|
||||||
subclasses. This function is called after the base
|
subclasses. This function is called after the base
|
||||||
|
|
@ -86,7 +85,7 @@ type_modified(PyTypeObject *type)
|
||||||
ref = PyList_GET_ITEM(raw, i);
|
ref = PyList_GET_ITEM(raw, i);
|
||||||
ref = PyWeakref_GET_OBJECT(ref);
|
ref = PyWeakref_GET_OBJECT(ref);
|
||||||
if (ref != Py_None) {
|
if (ref != Py_None) {
|
||||||
type_modified((PyTypeObject *)ref);
|
PyType_Modified((PyTypeObject *)ref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -172,7 +171,7 @@ assign_version_tag(PyTypeObject *type)
|
||||||
Py_INCREF(Py_None);
|
Py_INCREF(Py_None);
|
||||||
}
|
}
|
||||||
/* mark all version tags as invalid */
|
/* mark all version tags as invalid */
|
||||||
type_modified(&PyBaseObject_Type);
|
PyType_Modified(&PyBaseObject_Type);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
bases = type->tp_bases;
|
bases = type->tp_bases;
|
||||||
|
|
@ -300,7 +299,7 @@ type_set_module(PyTypeObject *type, PyObject *value, void *context)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
type_modified(type);
|
PyType_Modified(type);
|
||||||
|
|
||||||
return PyDict_SetItemString(type->tp_dict, "__module__", value);
|
return PyDict_SetItemString(type->tp_dict, "__module__", value);
|
||||||
}
|
}
|
||||||
|
|
@ -328,7 +327,7 @@ type_set_abstractmethods(PyTypeObject *type, PyObject *value, void *context)
|
||||||
int res = PyDict_SetItemString(type->tp_dict,
|
int res = PyDict_SetItemString(type->tp_dict,
|
||||||
"__abstractmethods__", value);
|
"__abstractmethods__", value);
|
||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
type_modified(type);
|
PyType_Modified(type);
|
||||||
if (value && PyObject_IsTrue(value)) {
|
if (value && PyObject_IsTrue(value)) {
|
||||||
type->tp_flags |= Py_TPFLAGS_IS_ABSTRACT;
|
type->tp_flags |= Py_TPFLAGS_IS_ABSTRACT;
|
||||||
}
|
}
|
||||||
|
|
@ -1621,7 +1620,7 @@ mro_internal(PyTypeObject *type)
|
||||||
from the custom MRO */
|
from the custom MRO */
|
||||||
type_mro_modified(type, type->tp_bases);
|
type_mro_modified(type, type->tp_bases);
|
||||||
|
|
||||||
type_modified(type);
|
PyType_Modified(type);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -6092,7 +6091,7 @@ update_slot(PyTypeObject *type, PyObject *name)
|
||||||
update_subclasses() recursion below, but carefully:
|
update_subclasses() recursion below, but carefully:
|
||||||
they each have their own conditions on which to stop
|
they each have their own conditions on which to stop
|
||||||
recursing into subclasses. */
|
recursing into subclasses. */
|
||||||
type_modified(type);
|
PyType_Modified(type);
|
||||||
|
|
||||||
init_slotdefs();
|
init_slotdefs();
|
||||||
pp = ptrs;
|
pp = ptrs;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue