diff options
author | Hai Shi <shihai1992@gmail.com> | 2020-05-11 21:38:55 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-11 21:38:55 (GMT) |
commit | 86d69444e7cfe758212956df0be0ec7b8a4251a6 (patch) | |
tree | b413a6d5845e61f74f61e7972575e6c5f4b0e237 /Objects | |
parent | ef7973a981ff8f4687ef3fdb85a69fa15aa11fe5 (diff) | |
download | cpython-86d69444e7cfe758212956df0be0ec7b8a4251a6.zip cpython-86d69444e7cfe758212956df0be0ec7b8a4251a6.tar.gz cpython-86d69444e7cfe758212956df0be0ec7b8a4251a6.tar.bz2 |
bpo-40584: Update PyType_FromModuleAndSpec() to process tp_vectorcall_offset (GH-20026)
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/typeobject.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 525f5ac..a36b4dc 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -2954,10 +2954,10 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) PyTypeObject *type, *base; const PyType_Slot *slot; - Py_ssize_t nmembers, weaklistoffset, dictoffset; + Py_ssize_t nmembers, weaklistoffset, dictoffset, vectorcalloffset; char *res_start; - nmembers = weaklistoffset = dictoffset = 0; + nmembers = weaklistoffset = dictoffset = vectorcalloffset = 0; for (slot = spec->slots; slot->slot; slot++) { if (slot->slot == Py_tp_members) { nmembers = 0; @@ -2975,6 +2975,12 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) assert(memb->flags == READONLY); dictoffset = memb->offset; } + if (strcmp(memb->name, "__vectorcalloffset__") == 0) { + // The PyMemberDef must be a Py_ssize_t and readonly + assert(memb->type == T_PYSSIZET); + assert(memb->flags == READONLY); + vectorcalloffset = memb->offset; + } } } } @@ -3123,6 +3129,10 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) type->tp_dealloc = subtype_dealloc; } + if (vectorcalloffset) { + type->tp_vectorcall_offset = vectorcalloffset; + } + if (PyType_Ready(type) < 0) goto fail; |