Revert "gh-133395: add option for extension modules to specialize BIN… · python/cpython@296cd12 · GitHub
Skip to content

Commit 296cd12

Browse files
authored
Revert "gh-133395: add option for extension modules to specialize BINARY_OP/SUBSCR, apply to arrays (#133396)" (#133498)
1 parent 3c73cf5 commit 296cd12

14 files changed

Lines changed: 44 additions & 171 deletions

File tree

Include/cpython/object.h

Lines changed: 0 additions & 12 deletions

Include/internal/pycore_code.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -480,18 +480,13 @@ adaptive_counter_backoff(_Py_BackoffCounter counter) {
480480
/* Specialization Extensions */
481481

482482
/* callbacks for an external specialization */
483-
484-
struct _PyBinopSpecializationDescr;
485-
486483
typedef int (*binaryopguardfunc)(PyObject *lhs, PyObject *rhs);
487-
typedef PyObject* (*binaryopactionfunc)(PyObject *lhs, PyObject *rhs);
488-
typedef void (*binaryopfreefunc)(struct _PyBinopSpecializationDescr *descr);
484+
typedef PyObject *(*binaryopactionfunc)(PyObject *lhs, PyObject *rhs);
489485

490-
typedef struct _PyBinopSpecializationDescr {
486+
typedef struct {
491487
int oparg;
492488
binaryopguardfunc guard;
493489
binaryopactionfunc action;
494-
binaryopfreefunc free;
495490
} _PyBinaryOpSpecializationDescr;
496491

497492
/* Comparison bit masks. */

Include/internal/pycore_opcode_metadata.h

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_metadata.h

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/typeslots.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,4 @@
9393
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030E0000
9494
/* New in 3.14 */
9595
#define Py_tp_token 83
96-
#define Py_tp_binop_specialize 84
9796
#endif

Lib/test/test_sys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1776,7 +1776,7 @@ def delx(self): del self.__x
17761776
check((1,2,3), vsize('') + self.P + 3*self.P)
17771777
# type
17781778
# static type: PyTypeObject
1779-
fmt = 'P2nPI13Pl4Pn9Pn12PI3Pc'
1779+
fmt = 'P2nPI13Pl4Pn9Pn12PIPc'
17801780
s = vsize(fmt)
17811781
check(int, s)
17821782
typeid = 'n' if support.Py_GIL_DISABLED else ''

Misc/NEWS.d/next/Core_and_Builtins/2025-05-04-19-32-47.gh-issue-133395.VhWWEP.rst

Lines changed: 0 additions & 2 deletions
This file was deleted.

Modules/arraymodule.c

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
#include "pycore_modsupport.h" // _PyArg_NoKeywords()
1515
#include "pycore_moduleobject.h" // _PyModule_GetState()
1616

17-
#include "opcode.h" // binary op opargs (NB_*)
18-
1917
#include <stddef.h> // offsetof()
2018
#include <stdbool.h>
2119

@@ -850,10 +848,6 @@ array_richcompare(PyObject *v, PyObject *w, int op)
850848
return res;
851849
}
852850

853-
static int
854-
array_binop_specialize(PyObject *v, PyObject *w, int oparg,
855-
_PyBinaryOpSpecializationDescr **descr);
856-
857851
static Py_ssize_t
858852
array_length(PyObject *op)
859853
{
@@ -2969,8 +2963,6 @@ static PyType_Slot array_slots[] = {
29692963
{Py_tp_alloc, PyType_GenericAlloc},
29702964
{Py_tp_new, array_new},
29712965
{Py_tp_traverse, array_tp_traverse},
2972-
{Py_tp_token, Py_TP_USE_SPEC},
2973-
{Py_tp_binop_specialize, array_binop_specialize},
29742966

29752967
/* as sequence */
29762968
{Py_sq_length, array_length},
@@ -3003,70 +2995,6 @@ static PyType_Spec array_spec = {
30032995
.slots = array_slots,
30042996
};
30052997

3006-
static inline int
3007-
array_subscr_guard(PyObject *lhs, PyObject *rhs)
3008-
{
3009-
PyObject *exc = PyErr_GetRaisedException();
3010-
int ret = PyType_GetBaseByToken(Py_TYPE(lhs), &array_spec, NULL);
3011-
if (ret < 0) {
3012-
if (PyErr_ExceptionMatches(PyExc_TypeError)) {
3013-
PyErr_Clear();
3014-
ret = 0;
3015-
}
3016-
}
3017-
_PyErr_ChainExceptions1(exc);
3018-
return ret;
3019-
}
3020-
3021-
static PyObject *
3022-
array_subscr_action(PyObject *lhs, PyObject *rhs)
3023-
{
3024-
return array_subscr(lhs, rhs);
3025-
}
3026-
3027-
static void
3028-
array_subscr_free(_PyBinaryOpSpecializationDescr* descr)
3029-
{
3030-
if (descr != NULL) {
3031-
PyMem_Free(descr);
3032-
}
3033-
}
3034-
3035-
static int
3036-
array_binop_specialize(PyObject *v, PyObject *w, int oparg,
3037-
_PyBinaryOpSpecializationDescr **descr)
3038-
{
3039-
array_state *state = find_array_state_by_type(Py_TYPE(v));
3040-
3041-
if (!array_Check(v, state)) {
3042-
return 0;
3043-
}
3044-
3045-
*descr = NULL;
3046-
switch(oparg) {
3047-
case NB_SUBSCR:
3048-
if (array_subscr_guard(v, w)) {
3049-
*descr = (_PyBinaryOpSpecializationDescr*)PyMem_Malloc(
3050-
sizeof(_PyBinaryOpSpecializationDescr));
3051-
if (*descr == NULL) {
3052-
PyErr_NoMemory();
3053-
return -1;
3054-
}
3055-
**descr = (_PyBinaryOpSpecializationDescr) {
3056-
.oparg = oparg,
3057-
.guard = array_subscr_guard,
3058-
.action = array_subscr_action,
3059-
.free = array_subscr_free,
3060-
};
3061-
return 1;
3062-
}
3063-
break;
3064-
}
3065-
3066-
return 0;
3067-
}
3068-
3069-
30702998
/*********************** Array Iterator **************************/
30712999

30723000
/*[clinic input]

Objects/typeslots.inc

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/bytecodes.c

Lines changed: 2 additions & 13 deletions

0 commit comments

Comments
 (0)