Skip to content
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

gh-103091: Add PyUnstable_Type_AssignVersionTag #103095

Merged
merged 4 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename to PyUnstable_AssignVersionTag, move to Include/cptyhon/object…
….h, fix some newlines
  • Loading branch information
swtaarrs committed Mar 31, 2023
commit 840f6c9b508fa1a6eaf12991ed4f606108de1ac4
2 changes: 1 addition & 1 deletion Doc/c-api/type.rst
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ Type Objects

.. versionadded:: 3.11

.. c:function:: int PyType_AssignVersionTag(PyTypeObject *type)
.. c:function:: int PyUnstable_AssignVersionTag(PyTypeObject *type)

Attempt to assign a version tag to the given type.

Expand Down
7 changes: 7 additions & 0 deletions Include/cpython/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -553,3 +553,10 @@ PyAPI_FUNC(int) PyType_AddWatcher(PyType_WatchCallback callback);
PyAPI_FUNC(int) PyType_ClearWatcher(int watcher_id);
PyAPI_FUNC(int) PyType_Watch(int watcher_id, PyObject *type);
PyAPI_FUNC(int) PyType_Unwatch(int watcher_id, PyObject *type);

/* Attempt to assign a version tag to the given type.
*
* Returns 1 if the type already had a valid version tag or a new one was
* assigned, or 0 if a new tag could not be assigned.
*/
PyAPI_FUNC(int) PyUnstable_AssignVersionTag(PyTypeObject *type);
9 changes: 0 additions & 9 deletions Include/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -861,15 +861,6 @@ static inline int PyType_CheckExact(PyObject *op) {
# define PyType_CheckExact(op) PyType_CheckExact(_PyObject_CAST(op))
#endif

#if !defined(Py_LIMITED_API)
/* Attempt to assign a version tag to the given type.
*
* Returns 1 if the type already had a valid version tag or a new one was
* assigned, or 0 if a new tag could not be assigned.
*/
PyAPI_FUNC(int) PyType_AssignVersionTag(PyTypeObject *type);
#endif

#ifdef __cplusplus
}
#endif
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_type_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
type_get_version = import_helper.import_module('_testcapi').type_get_version
type_assign_version = import_helper.import_module('_testcapi').type_assign_version


@support.cpython_only
@unittest.skipIf(_clear_type_cache is None, "requires sys._clear_type_cache")
class TypeCacheTests(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Add a new C-API function to eagerly assign a version tag to a PyTypeObject: ``PyType_AssignVersionTag()``.
Add a new C-API function to eagerly assign a version tag to a PyTypeObject: ``PyUnstable_AssignVersionTag()``.
4 changes: 2 additions & 2 deletions Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2740,7 +2740,7 @@ type_assign_version(PyObject *self, PyObject *type)
PyErr_SetString(PyExc_TypeError, "argument must be a type");
return NULL;
}
int res = PyType_AssignVersionTag((PyTypeObject *)type);
int res = PyUnstable_AssignVersionTag((PyTypeObject *)type);
return PyLong_FromLong(res);
}

Expand Down Expand Up @@ -3511,7 +3511,7 @@ static PyMethodDef TestMethods[] = {
{"test_py_is_macros", test_py_is_macros, METH_NOARGS},
{"test_py_is_funcs", test_py_is_funcs, METH_NOARGS},
{"type_get_version", type_get_version, METH_O, PyDoc_STR("type->tp_version_tag")},
{"type_assign_version", type_assign_version, METH_O, PyDoc_STR("PyType_AssignVersionTag")},
{"type_assign_version", type_assign_version, METH_O, PyDoc_STR("PyUnstable_AssignVersionTag")},
{"test_tstate_capi", test_tstate_capi, METH_NOARGS, NULL},
{"frame_getlocals", frame_getlocals, METH_O, NULL},
{"frame_getglobals", frame_getglobals, METH_O, NULL},
Expand Down
3 changes: 2 additions & 1 deletion Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,11 +598,12 @@ assign_version_tag(PyTypeObject *type)
return 1;
}

int PyType_AssignVersionTag(PyTypeObject *type)
int PyUnstable_AssignVersionTag(PyTypeObject *type)
{
return assign_version_tag(type);
}


static PyMemberDef type_members[] = {
{"__basicsize__", T_PYSSIZET, offsetof(PyTypeObject,tp_basicsize),READONLY},
{"__itemsize__", T_PYSSIZET, offsetof(PyTypeObject, tp_itemsize), READONLY},
Expand Down