Skip to content

Commit cb16046

Browse files
committed
Fix segfault in type() with NULL tp_new metaclasses
1 parent 476b649 commit cb16046

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

Objects/typeobject.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5031,6 +5031,13 @@ type_new_get_bases(type_new_ctx *ctx, PyObject **type)
50315031

50325032
if (winner != ctx->metatype) {
50335033
if (winner->tp_new != type_new) {
5034+
/* Check if tp_new is NULL (cannot instantiate this type) */
5035+
if (winner->tp_new == NULL) {
5036+
PyErr_Format(PyExc_TypeError,
5037+
"cannot create '%.400s' instances",
5038+
winner->tp_name);
5039+
return -1;
5040+
}
50345041
/* Pass it to the winner */
50355042
*type = winner->tp_new(winner, ctx->args, ctx->kwds);
50365043
if (*type == NULL) {

0 commit comments

Comments
 (0)