7
7
8
8
#include "Python.h"
9
9
#include "capi.h" // GraalPy change
10
- #if 0 // GraalPy change
11
10
#include "pycore_abstract.h" // _PyIndex_Check()
11
+ #if 0 // GraalPy change
12
12
#include "pycore_call.h" // _PyObject_CallNoArgs()
13
13
#include "pycore_ceval.h" // _Py_EnterRecursiveCallTstate()
14
14
#include "pycore_object.h" // _Py_CheckSlotResult()
@@ -844,6 +844,7 @@ PyObject_Format(PyObject *obj, PyObject *format_spec)
844
844
Py_XDECREF (empty );
845
845
return result ;
846
846
}
847
+ #endif // GraalPy
847
848
/* Operations on numbers */
848
849
849
850
int
@@ -854,7 +855,6 @@ PyNumber_Check(PyObject *o)
854
855
PyNumberMethods * nb = Py_TYPE (o )-> tp_as_number ;
855
856
return nb && (nb -> nb_index || nb -> nb_int || nb -> nb_float || PyComplex_Check (o ));
856
857
}
857
- #endif // GraalPy
858
858
859
859
/* Binary operators */
860
860
@@ -1072,13 +1072,16 @@ ternary_op(PyObject *v,
1072
1072
return NULL ;
1073
1073
}
1074
1074
1075
+ // GraalPy change: upcall when both managed to save on doing multiple upcalls
1075
1076
#define BINARY_FUNC (func , op , op_name ) \
1076
1077
PyObject * \
1077
1078
func(PyObject *v, PyObject *w) { \
1079
+ if (points_to_py_handle_space(v) && points_to_py_handle_space(w)) { \
1080
+ return GraalPyTruffle##func(v, w); \
1081
+ } \
1078
1082
return binary_op(v, w, NB_SLOT(op), op_name); \
1079
1083
}
1080
1084
1081
- #if 0 // GraalPy
1082
1085
BINARY_FUNC (PyNumber_Or , nb_or , "|" )
1083
1086
BINARY_FUNC (PyNumber_Xor , nb_xor , "^" )
1084
1087
BINARY_FUNC (PyNumber_And , nb_and , "&" )
@@ -1090,6 +1093,10 @@ BINARY_FUNC(PyNumber_Divmod, nb_divmod, "divmod()")
1090
1093
PyObject *
1091
1094
PyNumber_Add (PyObject * v , PyObject * w )
1092
1095
{
1096
+ // GraalPy change: upcall when both managed to save on doing multiple upcalls
1097
+ if (points_to_py_handle_space (v ) && points_to_py_handle_space (w )) {
1098
+ return GraalPyTrufflePyNumber_Add (v , w );
1099
+ }
1093
1100
PyObject * result = BINARY_OP1 (v , w , NB_SLOT (nb_add ), "+" );
1094
1101
if (result != Py_NotImplemented ) {
1095
1102
return result ;
@@ -1128,6 +1135,10 @@ sequence_repeat(ssizeargfunc repeatfunc, PyObject *seq, PyObject *n)
1128
1135
PyObject *
1129
1136
PyNumber_Multiply (PyObject * v , PyObject * w )
1130
1137
{
1138
+ // GraalPy change: upcall when both managed to save on doing multiple upcalls
1139
+ if (points_to_py_handle_space (v ) && points_to_py_handle_space (w )) {
1140
+ return GraalPyTrufflePyNumber_Multiply (v , w );
1141
+ }
1131
1142
PyObject * result = BINARY_OP1 (v , w , NB_SLOT (nb_multiply ), "*" );
1132
1143
if (result == Py_NotImplemented ) {
1133
1144
PySequenceMethods * mv = Py_TYPE (v )-> tp_as_sequence ;
@@ -1147,30 +1158,50 @@ PyNumber_Multiply(PyObject *v, PyObject *w)
1147
1158
PyObject *
1148
1159
PyNumber_MatrixMultiply (PyObject * v , PyObject * w )
1149
1160
{
1161
+ // GraalPy change: upcall when both managed to save on doing multiple upcalls
1162
+ if (points_to_py_handle_space (v ) && points_to_py_handle_space (w )) {
1163
+ return GraalPyTrufflePyNumber_MatrixMultiply (v , w );
1164
+ }
1150
1165
return binary_op (v , w , NB_SLOT (nb_matrix_multiply ), "@" );
1151
1166
}
1152
1167
1153
1168
PyObject *
1154
1169
PyNumber_FloorDivide (PyObject * v , PyObject * w )
1155
1170
{
1171
+ // GraalPy change: upcall when both managed to save on doing multiple upcalls
1172
+ if (points_to_py_handle_space (v ) && points_to_py_handle_space (w )) {
1173
+ return GraalPyTrufflePyNumber_FloorDivide (v , w );
1174
+ }
1156
1175
return binary_op (v , w , NB_SLOT (nb_floor_divide ), "//" );
1157
1176
}
1158
1177
1159
1178
PyObject *
1160
1179
PyNumber_TrueDivide (PyObject * v , PyObject * w )
1161
1180
{
1181
+ // GraalPy change: upcall when both managed to save on doing multiple upcalls
1182
+ if (points_to_py_handle_space (v ) && points_to_py_handle_space (w )) {
1183
+ return GraalPyTrufflePyNumber_TrueDivide (v , w );
1184
+ }
1162
1185
return binary_op (v , w , NB_SLOT (nb_true_divide ), "/" );
1163
1186
}
1164
1187
1165
1188
PyObject *
1166
1189
PyNumber_Remainder (PyObject * v , PyObject * w )
1167
1190
{
1191
+ // GraalPy change: upcall when both managed to save on doing multiple upcalls
1192
+ if (points_to_py_handle_space (v ) && points_to_py_handle_space (w )) {
1193
+ return GraalPyTrufflePyNumber_Remainder (v , w );
1194
+ }
1168
1195
return binary_op (v , w , NB_SLOT (nb_remainder ), "%" );
1169
1196
}
1170
1197
1171
1198
PyObject *
1172
1199
PyNumber_Power (PyObject * v , PyObject * w , PyObject * z )
1173
1200
{
1201
+ // GraalPy change: upcall when both managed to save on doing multiple upcalls
1202
+ if (points_to_py_handle_space (v ) && points_to_py_handle_space (w )) {
1203
+ return GraalPyTrufflePyNumber_Power (v , w , z );
1204
+ }
1174
1205
return ternary_op (v , w , z , NB_SLOT (nb_power ), "** or pow()" );
1175
1206
}
1176
1207
@@ -1258,9 +1289,13 @@ ternary_iop(PyObject *v, PyObject *w, PyObject *z, const int iop_slot, const int
1258
1289
return ternary_op (v , w , z , op_slot , op_name );
1259
1290
}
1260
1291
1292
+ // GraalPy change: upcall when v is managed to avoid multiple upcalls
1261
1293
#define INPLACE_BINOP (func , iop , op , op_name ) \
1262
1294
PyObject * \
1263
1295
func(PyObject *v, PyObject *w) { \
1296
+ if (points_to_py_handle_space(v)) { \
1297
+ return GraalPyTruffle##func(v, w); \
1298
+ } \
1264
1299
return binary_iop(v, w, NB_SLOT(iop), NB_SLOT(op), op_name); \
1265
1300
}
1266
1301
@@ -1278,6 +1313,10 @@ INPLACE_BINOP(PyNumber_InPlaceRemainder, nb_inplace_remainder, nb_remainder, "%=
1278
1313
PyObject *
1279
1314
PyNumber_InPlaceAdd (PyObject * v , PyObject * w )
1280
1315
{
1316
+ // GraalPy change: upcall when v is managed to avoid multiple upcalls
1317
+ if (points_to_py_handle_space (v )) {
1318
+ return GraalPyTrufflePyNumber_InPlaceAdd (v , w );
1319
+ }
1281
1320
PyObject * result = BINARY_IOP1 (v , w , NB_SLOT (nb_inplace_add ),
1282
1321
NB_SLOT (nb_add ), "+=" );
1283
1322
if (result == Py_NotImplemented ) {
@@ -1301,6 +1340,10 @@ PyNumber_InPlaceAdd(PyObject *v, PyObject *w)
1301
1340
PyObject *
1302
1341
PyNumber_InPlaceMultiply (PyObject * v , PyObject * w )
1303
1342
{
1343
+ // GraalPy change: upcall when v is managed to avoid multiple upcalls
1344
+ if (points_to_py_handle_space (v )) {
1345
+ return GraalPyTrufflePyNumber_InPlaceMultiply (v , w );
1346
+ }
1304
1347
PyObject * result = BINARY_IOP1 (v , w , NB_SLOT (nb_inplace_multiply ),
1305
1348
NB_SLOT (nb_multiply ), "*=" );
1306
1349
if (result == Py_NotImplemented ) {
@@ -1330,6 +1373,10 @@ PyNumber_InPlaceMultiply(PyObject *v, PyObject *w)
1330
1373
PyObject *
1331
1374
PyNumber_InPlacePower (PyObject * v , PyObject * w , PyObject * z )
1332
1375
{
1376
+ // GraalPy change: upcall when v is managed to avoid multiple upcalls
1377
+ if (points_to_py_handle_space (v )) {
1378
+ return GraalPyTrufflePyNumber_InPlacePower (v , w , z );
1379
+ }
1333
1380
return ternary_iop (v , w , z , NB_SLOT (nb_inplace_power ),
1334
1381
NB_SLOT (nb_power ), "**=" );
1335
1382
}
@@ -1340,7 +1387,6 @@ _PyNumber_InPlacePowerNoMod(PyObject *lhs, PyObject *rhs)
1340
1387
return PyNumber_InPlacePower (lhs , rhs , Py_None );
1341
1388
}
1342
1389
1343
-
1344
1390
/* Unary operators and functions */
1345
1391
1346
1392
PyObject *
@@ -1419,6 +1465,7 @@ PyIndex_Check(PyObject *obj)
1419
1465
}
1420
1466
1421
1467
1468
+ #if 0 // GraalPy change
1422
1469
/* Return a Python int from the object item.
1423
1470
Can return an instance of int subclass.
1424
1471
Raise TypeError if the result is not an int
@@ -3027,6 +3074,6 @@ PyTruffleSequence_Fast_ITEMS(PyObject *o)
3027
3074
PyObject *
3028
3075
PyTruffleSequence_ITEM (PyObject * obj , Py_ssize_t index )
3029
3076
{
3030
- PySequenceMethods * methods = Py_TYPE (obj )-> tp_as_sequence ;
3031
- return methods -> sq_item (obj , index );
3077
+ PySequenceMethods * methods = Py_TYPE (obj )-> tp_as_sequence ;
3078
+ return methods -> sq_item (obj , index );
3032
3079
}
0 commit comments