@@ -74,9 +74,6 @@ _Py_IDENTIFIER(__module__);
74
74
_Py_IDENTIFIER (__eq__ );
75
75
_Py_IDENTIFIER (__hash__ );
76
76
77
- // GraalPy change: forward delcarations of our helpers
78
- static void add_slot (PyTypeObject * cls , char * name , void * meth , int flags , int signature , char * doc );
79
- static int type_ready_graalpy_slot_conv (PyTypeObject * cls );
80
77
81
78
static void
82
79
slot_bf_releasebuffer (PyObject * self , Py_buffer * buffer );
@@ -5041,6 +5038,7 @@ type_setattro(PyTypeObject *type, PyObject *name, PyObject *value)
5041
5038
extern void
5042
5039
_PyDictKeys_DecRef (PyDictKeysObject * keys );
5043
5040
5041
+
5044
5042
static void
5045
5043
type_dealloc_common (PyTypeObject * type )
5046
5044
{
@@ -5480,6 +5478,7 @@ PyTypeObject PyType_Type = {
5480
5478
#endif // GraalPy change
5481
5479
};
5482
5480
5481
+
5483
5482
#if 0 // GraalPy change
5484
5483
/* The base type of all types (eventually)... except itself. */
5485
5484
@@ -7230,11 +7229,9 @@ static int
7230
7229
type_ready_fill_dict (PyTypeObject * type )
7231
7230
{
7232
7231
/* Add type-specific descriptors to tp_dict */
7233
- #if 0 // GraalPy change
7234
7232
if (add_operators (type ) < 0 ) {
7235
7233
return -1 ;
7236
7234
}
7237
- #endif // GraalPy change
7238
7235
if (type_add_methods (type ) < 0 ) {
7239
7236
return -1 ;
7240
7237
}
@@ -7485,12 +7482,10 @@ type_ready_set_new(PyTypeObject *type, int rerunbuiltin)
7485
7482
if (!rerunbuiltin || base == NULL || type -> tp_new != base -> tp_new ) {
7486
7483
// If "__new__" key does not exists in the type dictionary,
7487
7484
// set it to tp_new_wrapper().
7488
- #if 0 // GraalPy change
7485
+ #if 0 // GraalPy change: the wrapper is created in add_operators with the rest of slots
7489
7486
if (add_tp_new_wrapper (type ) < 0 ) {
7490
7487
return -1 ;
7491
7488
}
7492
- #else // GraalPy change
7493
- add_slot (type , "__new__" , type -> tp_new , METH_KEYWORDS | METH_VARARGS , JWRAPPER_NEW , NULL );
7494
7489
#endif // GraalPy change
7495
7490
}
7496
7491
}
@@ -7563,10 +7558,8 @@ type_ready_post_checks(PyTypeObject *type)
7563
7558
}
7564
7559
return 0 ;
7565
7560
}
7566
- #endif // GraalPy change
7567
7561
7568
- // GraalPy-specific
7569
- static int type_ready_graalpy_slot_conv (PyTypeObject * cls );
7562
+ #endif // GraalPy change
7570
7563
7571
7564
static int
7572
7565
type_ready (PyTypeObject * type , int rerunbuiltin )
@@ -7616,10 +7609,6 @@ type_ready(PyTypeObject *type, int rerunbuiltin)
7616
7609
if (type_ready_fill_dict (type ) < 0 ) {
7617
7610
goto error ;
7618
7611
}
7619
- // GraalPy change
7620
- if (type_ready_graalpy_slot_conv (type ) < 0 ) {
7621
- goto error ;
7622
- }
7623
7612
if (!rerunbuiltin ) {
7624
7613
if (type_ready_inherit (type ) < 0 ) {
7625
7614
goto error ;
@@ -10217,6 +10206,7 @@ recurse_down_subclasses(PyTypeObject *type, PyObject *attr_name,
10217
10206
}
10218
10207
return 0 ;
10219
10208
}
10209
+ #endif // GraalPy change
10220
10210
10221
10211
static int
10222
10212
expect_manually_inherited (PyTypeObject * type , void * * slot )
@@ -10329,6 +10319,7 @@ expect_manually_inherited(PyTypeObject *type, void **slot)
10329
10319
static int
10330
10320
add_operators (PyTypeObject * type )
10331
10321
{
10322
+ #if 0 // GraalPy change: different implementation
10332
10323
PyObject * dict = lookup_tp_dict (type );
10333
10324
pytype_slotdef * p ;
10334
10325
PyObject * descr ;
@@ -10385,9 +10376,13 @@ add_operators(PyTypeObject *type)
10385
10376
}
10386
10377
}
10387
10378
return 0 ;
10379
+ #else // GraalPy change
10380
+ return GraalPyTruffleType_AddOperators (type );
10381
+ #endif // GraalPy change
10388
10382
}
10389
10383
10390
10384
10385
+ #if 0 // GraalPy change
10391
10386
/* Cooperative 'super' */
10392
10387
10393
10388
typedef struct {
@@ -10889,165 +10884,3 @@ PyTypeObject PySuper_Type = {
10889
10884
.tp_vectorcall = (vectorcallfunc )super_vectorcall ,
10890
10885
};
10891
10886
#endif // GraalPy change
10892
-
10893
-
10894
- // GraalPy additions
10895
-
10896
- static void add_slot (PyTypeObject * type , char * name , void * meth , int flags , int signature , char * doc ) {
10897
- if (meth ) {
10898
- GraalPyTruffleType_AddSlot (type ,
10899
- type -> tp_dict ,
10900
- name ,
10901
- meth ,
10902
- flags ,
10903
- (signature != 0 ? signature : get_method_flags_wrapper (flags )),
10904
- doc );
10905
- }
10906
- }
10907
-
10908
- static int type_ready_graalpy_slot_conv (PyTypeObject * cls ) {
10909
- #define ADD_SLOT_CONV (__name__ , __meth__ , __flags__ , __signature__ ) add_slot(cls, (__name__), (__meth__), (__flags__), (__signature__), NULL)
10910
-
10911
- // TODO: once all slots are converted, we can do one upcall to managed implementation
10912
- // of add_operators that will use TpSlots#SLOTDEFS and the same algorithm as CPython
10913
-
10914
- /*
10915
- * NOTE: ADD_SLOT_CONV won't overwrite existing attributes, so the order is crucial and must
10916
- * reflect CPython's 'slotdefs' array.
10917
- */
10918
-
10919
- // add special methods defined directly on the type structs
10920
- ADD_SLOT_CONV ("__dealloc__" , cls -> tp_dealloc , -1 , JWRAPPER_DIRECT );
10921
- // https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_getattr
10922
- // tp_getattr and tp_setattr are deprecated, and should be the same as
10923
- // tp_getattro and tp_setattro
10924
-
10925
- // NOTE: The slots may be called from managed code, i.e., we need to wrap the functions
10926
- // and convert arguments that should be C primitives.
10927
- // ADD_SLOT_CONV("__getattribute__", cls->tp_getattr, -2, JWRAPPER_GETATTR); tp_getattr does not have wrapper set in slotdefs and hence is ignored in add_operators
10928
- // ADD_SLOT_CONV("__setattr__", cls->tp_setattr, -3, JWRAPPER_SETATTR); dtto for tp_setattr
10929
- ADD_SLOT_CONV ("__repr__" , cls -> tp_repr , -1 , JWRAPPER_REPR );
10930
- ADD_SLOT_CONV ("__hash__" , cls -> tp_hash , -1 , JWRAPPER_HASHFUNC );
10931
- ADD_SLOT_CONV ("__call__" , cls -> tp_call , METH_KEYWORDS | METH_VARARGS , JWRAPPER_CALL );
10932
- ADD_SLOT_CONV ("__str__" , cls -> tp_str , -1 , JWRAPPER_STR );
10933
- ADD_SLOT_CONV ("__getattribute__" , cls -> tp_getattro , -2 , JWRAPPER_BINARYFUNC );
10934
- ADD_SLOT_CONV ("__setattr__" , cls -> tp_setattro , -3 , JWRAPPER_SETATTRO );
10935
- ADD_SLOT_CONV ("__delattr__" , cls -> tp_setattro , -3 , JWRAPPER_DELATTRO );
10936
- ADD_SLOT_CONV ("__clear__" , cls -> tp_clear , -1 , JWRAPPER_INQUIRY );
10937
-
10938
- richcmpfunc richcompare = cls -> tp_richcompare ;
10939
- if (richcompare ) {
10940
- ADD_SLOT_CONV ("__lt__" , richcompare , -2 , JWRAPPER_LT );
10941
- ADD_SLOT_CONV ("__le__" , richcompare , -2 , JWRAPPER_LE );
10942
- ADD_SLOT_CONV ("__eq__" , richcompare , -2 , JWRAPPER_EQ );
10943
- ADD_SLOT_CONV ("__ne__" , richcompare , -2 , JWRAPPER_NE );
10944
- ADD_SLOT_CONV ("__gt__" , richcompare , -2 , JWRAPPER_GT );
10945
- ADD_SLOT_CONV ("__ge__" , richcompare , -2 , JWRAPPER_GE );
10946
- }
10947
- ADD_SLOT_CONV ("__iter__" , cls -> tp_iter , -1 , JWRAPPER_UNARYFUNC );
10948
- ADD_SLOT_CONV ("__next__" , cls -> tp_iternext , -1 , JWRAPPER_ITERNEXT );
10949
- ADD_SLOT_CONV ("__get__" , cls -> tp_descr_get , -3 , JWRAPPER_DESCR_GET );
10950
- ADD_SLOT_CONV ("__set__" , cls -> tp_descr_set , -3 , JWRAPPER_DESCR_SET );
10951
- ADD_SLOT_CONV ("__delete__" , cls -> tp_descr_set , -2 , JWRAPPER_DESCR_DELETE );
10952
- ADD_SLOT_CONV ("__init__" , cls -> tp_init , METH_KEYWORDS | METH_VARARGS , JWRAPPER_INITPROC );
10953
- ADD_SLOT_CONV ("__alloc__" , cls -> tp_alloc , -2 , JWRAPPER_ALLOC );
10954
- /* Note: '__new__' was added here previously but we don't do it similar to CPython.
10955
- They also skip it because the appropriate 'slotdef' doesn't have a wrapper.
10956
- Adding '__new__' is done by function 'type_ready_set_new'. */
10957
- ADD_SLOT_CONV ("__free__" , cls -> tp_free , -1 , JWRAPPER_DIRECT );
10958
- ADD_SLOT_CONV ("__del__" , cls -> tp_del , -1 , JWRAPPER_DIRECT );
10959
- ADD_SLOT_CONV ("__finalize__" , cls -> tp_finalize , -1 , JWRAPPER_DIRECT );
10960
-
10961
- // 'tp_as_number' takes precedence over 'tp_as_mapping' and 'tp_as_sequence' !
10962
- PyNumberMethods * numbers = cls -> tp_as_number ;
10963
- if (numbers ) {
10964
- ADD_SLOT_CONV ("__add__" , numbers -> nb_add , -2 , JWRAPPER_BINARYFUNC_L );
10965
- ADD_SLOT_CONV ("__radd__" , numbers -> nb_add , -2 , JWRAPPER_BINARYFUNC_R );
10966
- ADD_SLOT_CONV ("__sub__" , numbers -> nb_subtract , -2 , JWRAPPER_BINARYFUNC_L );
10967
- ADD_SLOT_CONV ("__rsub__" , numbers -> nb_subtract , -2 , JWRAPPER_BINARYFUNC_R );
10968
- ADD_SLOT_CONV ("__mul__" , numbers -> nb_multiply , -2 , JWRAPPER_BINARYFUNC_L );
10969
- ADD_SLOT_CONV ("__rmul__" , numbers -> nb_multiply , -2 , JWRAPPER_BINARYFUNC_R );
10970
- ADD_SLOT_CONV ("__mod__" , numbers -> nb_remainder , -2 , JWRAPPER_BINARYFUNC_L );
10971
- ADD_SLOT_CONV ("__rmod__" , numbers -> nb_remainder , -2 , JWRAPPER_BINARYFUNC_R );
10972
- ADD_SLOT_CONV ("__divmod__" , numbers -> nb_divmod , -2 , JWRAPPER_BINARYFUNC_L );
10973
- ADD_SLOT_CONV ("__rdivmod__" , numbers -> nb_divmod , -2 , JWRAPPER_BINARYFUNC_R );
10974
- ADD_SLOT_CONV ("__pow__" , numbers -> nb_power , -3 , JWRAPPER_TERNARYFUNC );
10975
- ADD_SLOT_CONV ("__rpow__" , numbers -> nb_power , -3 , JWRAPPER_TERNARYFUNC_R );
10976
- ADD_SLOT_CONV ("__neg__" , numbers -> nb_negative , -1 , JWRAPPER_UNARYFUNC );
10977
- ADD_SLOT_CONV ("__pos__" , numbers -> nb_positive , -1 , JWRAPPER_UNARYFUNC );
10978
- ADD_SLOT_CONV ("__abs__" , numbers -> nb_absolute , -1 , JWRAPPER_UNARYFUNC );
10979
- ADD_SLOT_CONV ("__bool__" , numbers -> nb_bool , -1 , JWRAPPER_INQUIRY );
10980
- ADD_SLOT_CONV ("__invert__" , numbers -> nb_invert , -1 , JWRAPPER_UNARYFUNC );
10981
- ADD_SLOT_CONV ("__lshift__" , numbers -> nb_lshift , -2 , JWRAPPER_BINARYFUNC_L );
10982
- ADD_SLOT_CONV ("__rlshift__" , numbers -> nb_lshift , -2 , JWRAPPER_BINARYFUNC_R );
10983
- ADD_SLOT_CONV ("__rshift__" , numbers -> nb_rshift , -2 , JWRAPPER_BINARYFUNC_L );
10984
- ADD_SLOT_CONV ("__rrshift__" , numbers -> nb_rshift , -2 , JWRAPPER_BINARYFUNC_R );
10985
- ADD_SLOT_CONV ("__and__" , numbers -> nb_and , -2 , JWRAPPER_BINARYFUNC_L );
10986
- ADD_SLOT_CONV ("__rand__" , numbers -> nb_and , -2 , JWRAPPER_BINARYFUNC_R );
10987
- ADD_SLOT_CONV ("__xor__" , numbers -> nb_xor , -2 , JWRAPPER_BINARYFUNC_L );
10988
- ADD_SLOT_CONV ("__rxor__" , numbers -> nb_xor , -2 , JWRAPPER_BINARYFUNC_R );
10989
- ADD_SLOT_CONV ("__or__" , numbers -> nb_or , -2 , JWRAPPER_BINARYFUNC_L );
10990
- ADD_SLOT_CONV ("__ror__" , numbers -> nb_or , -2 , JWRAPPER_BINARYFUNC_R );
10991
- ADD_SLOT_CONV ("__int__" , numbers -> nb_int , -1 , JWRAPPER_UNARYFUNC );
10992
- ADD_SLOT_CONV ("__float__" , numbers -> nb_float , -1 , JWRAPPER_UNARYFUNC );
10993
- ADD_SLOT_CONV ("__iadd__" , numbers -> nb_inplace_add , -2 , JWRAPPER_BINARYFUNC );
10994
- ADD_SLOT_CONV ("__isub__" , numbers -> nb_inplace_subtract , -2 , JWRAPPER_BINARYFUNC );
10995
- ADD_SLOT_CONV ("__imul__" , numbers -> nb_inplace_multiply , -2 , JWRAPPER_BINARYFUNC );
10996
- ADD_SLOT_CONV ("__imod__" , numbers -> nb_inplace_remainder , -2 , JWRAPPER_BINARYFUNC );
10997
- ADD_SLOT_CONV ("__ipow__" , numbers -> nb_inplace_power , -3 , JWRAPPER_TERNARYFUNC );
10998
- ADD_SLOT_CONV ("__ilshift__" , numbers -> nb_inplace_lshift , -2 , JWRAPPER_BINARYFUNC );
10999
- ADD_SLOT_CONV ("__irshift__" , numbers -> nb_inplace_rshift , -2 , JWRAPPER_BINARYFUNC );
11000
- ADD_SLOT_CONV ("__iand__" , numbers -> nb_inplace_and , -2 , JWRAPPER_BINARYFUNC );
11001
- ADD_SLOT_CONV ("__ixor__" , numbers -> nb_inplace_xor , -2 , JWRAPPER_BINARYFUNC );
11002
- ADD_SLOT_CONV ("__ior__" , numbers -> nb_inplace_or , -2 , JWRAPPER_BINARYFUNC );
11003
- ADD_SLOT_CONV ("__floordiv__" , numbers -> nb_floor_divide , -2 , JWRAPPER_BINARYFUNC_L );
11004
- ADD_SLOT_CONV ("__rfloordiv__" , numbers -> nb_floor_divide , -2 , JWRAPPER_BINARYFUNC_R );
11005
- ADD_SLOT_CONV ("__truediv__" , numbers -> nb_true_divide , -2 , JWRAPPER_BINARYFUNC_L );
11006
- ADD_SLOT_CONV ("__rtruediv__" , numbers -> nb_true_divide , -2 , JWRAPPER_BINARYFUNC_R );
11007
- ADD_SLOT_CONV ("__ifloordiv__" , numbers -> nb_inplace_floor_divide , -2 , JWRAPPER_BINARYFUNC );
11008
- ADD_SLOT_CONV ("__itruediv__" , numbers -> nb_inplace_true_divide , -2 , JWRAPPER_BINARYFUNC );
11009
- ADD_SLOT_CONV ("__index__" , numbers -> nb_index , -1 , JWRAPPER_UNARYFUNC );
11010
- ADD_SLOT_CONV ("__matmul__" , numbers -> nb_matrix_multiply , -2 , JWRAPPER_BINARYFUNC_L );
11011
- ADD_SLOT_CONV ("__rmatmul__" , numbers -> nb_matrix_multiply , -2 , JWRAPPER_BINARYFUNC_R );
11012
- ADD_SLOT_CONV ("__imatmul__" , numbers -> nb_inplace_matrix_multiply , -2 , JWRAPPER_BINARYFUNC_L );
11013
- }
11014
-
11015
- // 'tp_as_mapping' takes precedence over 'tp_as_sequence' !
11016
- PyMappingMethods * mappings = cls -> tp_as_mapping ;
11017
- if (mappings ) {
11018
- ADD_SLOT_CONV ("__len__" , mappings -> mp_length , -1 , JWRAPPER_LENFUNC );
11019
- ADD_SLOT_CONV ("__getitem__" , mappings -> mp_subscript , -2 , JWRAPPER_BINARYFUNC );
11020
- ADD_SLOT_CONV ("__setitem__" , mappings -> mp_ass_subscript , -3 , JWRAPPER_OBJOBJARGPROC );
11021
- ADD_SLOT_CONV ("__delitem__" , mappings -> mp_ass_subscript , -3 , JWRAPPER_MP_DELITEM );
11022
- }
11023
-
11024
- PySequenceMethods * sequences = cls -> tp_as_sequence ;
11025
- if (sequences ) {
11026
- // sequence functions first, so that the number functions take precendence
11027
- ADD_SLOT_CONV ("__len__" , sequences -> sq_length , -1 , JWRAPPER_LENFUNC );
11028
- ADD_SLOT_CONV ("__add__" , sequences -> sq_concat , -2 , JWRAPPER_BINARYFUNC );
11029
- ADD_SLOT_CONV ("__mul__" , sequences -> sq_repeat , -2 , JWRAPPER_SSIZE_ARG );
11030
- ADD_SLOT_CONV ("__rmul__" , sequences -> sq_repeat , -2 , JWRAPPER_SSIZE_ARG );
11031
- ADD_SLOT_CONV ("__getitem__" , sequences -> sq_item , -2 , JWRAPPER_GETITEM );
11032
- ADD_SLOT_CONV ("__setitem__" , sequences -> sq_ass_item , -3 , JWRAPPER_SETITEM );
11033
- ADD_SLOT_CONV ("__delitem__" , sequences -> sq_ass_item , -3 , JWRAPPER_DELITEM );
11034
- ADD_SLOT_CONV ("__contains__" , sequences -> sq_contains , -2 , JWRAPPER_OBJOBJPROC );
11035
- ADD_SLOT_CONV ("__iadd__" , sequences -> sq_inplace_concat , -2 , JWRAPPER_BINARYFUNC );
11036
- ADD_SLOT_CONV ("__imul__" , sequences -> sq_inplace_repeat , -2 , JWRAPPER_SSIZE_ARG );
11037
- }
11038
-
11039
- PyAsyncMethods * async = cls -> tp_as_async ;
11040
- if (async ) {
11041
- ADD_SLOT_CONV ("__await__" , async -> am_await , -1 , JWRAPPER_UNARYFUNC );
11042
- ADD_SLOT_CONV ("__aiter__" , async -> am_aiter , -1 , JWRAPPER_UNARYFUNC );
11043
- ADD_SLOT_CONV ("__anext__" , async -> am_anext , -1 , JWRAPPER_UNARYFUNC );
11044
- }
11045
-
11046
- PyBufferProcs * buffers = cls -> tp_as_buffer ;
11047
- if (buffers ) {
11048
- // TODO ...
11049
- }
11050
-
11051
- #undef ADD_SLOT_CONV
11052
- return 0 ;
11053
- }
0 commit comments