10000 gh-121654: Add PyType_Freeze() function by vstinner · Pull Request #122457 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-121654: Add PyType_Freeze() function #122457

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

Merged
merged 11 commits into from
Oct 25, 2024
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
Merge branch 'main' into type_freeze
  • Loading branch information
vstinner committed Sep 30, 2024
commit a9f1f011c89839d6da3405a1b12a120b0753449b
24 changes: 24 additions & 0 deletions Misc/stable_abi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2512,5 +2512,29 @@
added = '3.14'
[function.PyIter_NextItem]
added = '3.14'
[function.PyLong_FromInt32]
added = '3.14'
[function.PyLong_FromUInt32]
added = '3.14'
[function.PyLong_AsInt32]
added = '3.14'
[function.PyLong_AsUInt32]
added = '3.14'
[function.PyLong_FromInt64]
added = '3.14'
[function.PyLong_FromUInt64]
added = '3.14'
[function.PyLong_AsInt64]
added = '3.14'
[function.PyLong_AsUInt64]
added = '3.14'
[const.Py_tp_vectorcall]
added = '3.14'
[function.PyType_GetBaseByToken]
added = '3.14'
[const.Py_tp_token]
added = '3.14'
[const.Py_TP_USE_SPEC]
added = '3.14'
[function.PyType_Freeze]
added = '3.14'
40 changes: 38 additions & 2 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -4662,8 +4662,44 @@ check_immutable_bases(const char *type_name, PyObject *bases, int skip_first)
return 0;
}

static PyObject *
_PyType_FromMetaclass_impl(

/* Set *dest to the offset specified by a special "__*offset__" member.
* Return 0 on success, -1 on failure.
*/
static inline int
special_offset_from_member(
const PyMemberDef *memb /* may be NULL */,
Py_ssize_t type_data_offset,
Py_ssize_t *dest /* not NULL */)
{
if (memb == NULL) {
*dest = 0;
return 0;
}
if (memb->type != Py_T_PYSSIZET) {
PyErr_Format(
PyExc_SystemError,
"type of %s must be Py_T_PYSSIZET",
memb->name);
return -1;
}
if (memb->flags == Py_READONLY) {
*dest = memb->offset;
return 0;
}
else if (memb->flags == (Py_READONLY | Py_RELATIVE_OFFSET)) {
*dest = memb->offset + type_data_offset;
return 0;
}
PyErr_Format(
PyExc_SystemError,
"flags for %s must be Py_READONLY or (Py_READONLY | Py_RELATIVE_OFFSET)",
memb->name);
return -1;
}

PyObject *
PyType_FromMetaclass(
PyTypeObject *metaclass, PyObject *module,
PyType_Spec *spec, PyObject *bases_in)
{
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.
0