gh-128262: Allow specialization of calls to classes with __slots__ (G… · python/cpython@7ef4907

GitHub

Original file line numberDiff line numberDiff line change@@ -3765,13 +3765,15 @@ dummy_func(

37653765DEOPT_IF(!PyType_Check(callable_o));

37663766PyTypeObject*tp= (PyTypeObject*)callable_o;

37673767DEOPT_IF(FT_ATOMIC_LOAD_UINT32_RELAXED(tp->tp_version_tag) !=type_version);

3768-assert(tp->tp_flags&Py_TPFLAGS_INLINE_VALUES);

3768+assert(tp->tp_new==PyBaseObject_Type.tp_new);

3769+assert(tp->tp_flags&Py_TPFLAGS_HEAPTYPE);

3770+assert(tp->tp_alloc==PyType_GenericAlloc);

37693771PyHeapTypeObject*cls= (PyHeapTypeObject*)callable_o;

37703772PyFunctionObject*init_func= (PyFunctionObject*)FT_ATOMIC_LOAD_PTR_ACQUIRE(cls->_spec_cache.init);

37713773PyCodeObject*code= (PyCodeObject*)init_func->func_code;

37723774DEOPT_IF(!_PyThreadState_HasStackSpace(tstate, code->co_framesize+_Py_InitCleanup.co_framesize));

37733775STAT_INC(CALL, hit);

3774-PyObject*self_o=_PyType_NewManagedObject(tp);

3776+PyObject*self_o=PyType_GenericAlloc(tp, 0);

37753777if (self_o==NULL) {

37763778ERROR_NO_POP();

37773779 }

Original file line numberDiff line numberDiff line change@@ -2002,10 +2002,6 @@ get_init_for_simple_managed_python_class(PyTypeObject *tp, unsigned int *tp_vers

20022002returnNULL;

20032003 }

20042004unsigned longtp_flags=PyType_GetFlags(tp);

2005-if ((tp_flags&Py_TPFLAGS_INLINE_VALUES) ==0) {

2006-SPECIALIZATION_FAIL(CALL, SPEC_FAIL_CALL_INIT_NOT_INLINE_VALUES);

2007-returnNULL;

2008- }

20092005if (!(tp_flags&Py_TPFLAGS_HEAPTYPE)) {

20102006/* Is this possible? */

20112007SPECIALIZATION_FAIL(CALL, SPEC_FAIL_EXPECTED_ERROR);