Skip to content

Commit ed4dbf4

Browse files
committed
Merge branch 'master' into mq/GR-57401_1
2 parents 59552c1 + 4a25dcd commit ed4dbf4

File tree

12 files changed

+185
-745
lines changed

12 files changed

+185
-745
lines changed

graalpython/com.oracle.graal.python.cext/src/typeobject.c

Lines changed: 10 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ _Py_IDENTIFIER(__module__);
7474
_Py_IDENTIFIER(__eq__);
7575
_Py_IDENTIFIER(__hash__);
7676

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);
8077

8178
static void
8279
slot_bf_releasebuffer(PyObject *self, Py_buffer *buffer);
@@ -5041,6 +5038,7 @@ type_setattro(PyTypeObject *type, PyObject *name, PyObject *value)
50415038
extern void
50425039
_PyDictKeys_DecRef(PyDictKeysObject *keys);
50435040

5041+
50445042
static void
50455043
type_dealloc_common(PyTypeObject *type)
50465044
{
@@ -5480,6 +5478,7 @@ PyTypeObject PyType_Type = {
54805478
#endif // GraalPy change
54815479
};
54825480

5481+
54835482
#if 0 // GraalPy change
54845483
/* The base type of all types (eventually)... except itself. */
54855484

@@ -7230,11 +7229,9 @@ static int
72307229
type_ready_fill_dict(PyTypeObject *type)
72317230
{
72327231
/* Add type-specific descriptors to tp_dict */
7233-
#if 0 // GraalPy change
72347232
if (add_operators(type) < 0) {
72357233
return -1;
72367234
}
7237-
#endif // GraalPy change
72387235
if (type_add_methods(type) < 0) {
72397236
return -1;
72407237
}
@@ -7485,12 +7482,10 @@ type_ready_set_new(PyTypeObject *type, int rerunbuiltin)
74857482
if (!rerunbuiltin || base == NULL || type->tp_new != base->tp_new) {
74867483
// If "__new__" key does not exists in the type dictionary,
74877484
// 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
74897486
if (add_tp_new_wrapper(type) < 0) {
74907487
return -1;
74917488
}
7492-
#else // GraalPy change
7493-
add_slot(type, "__new__", type->tp_new, METH_KEYWORDS | METH_VARARGS, JWRAPPER_NEW, NULL);
74947489
#endif // GraalPy change
74957490
}
74967491
}
@@ -7563,10 +7558,8 @@ type_ready_post_checks(PyTypeObject *type)
75637558
}
75647559
return 0;
75657560
}
7566-
#endif // GraalPy change
75677561

7568-
// GraalPy-specific
7569-
static int type_ready_graalpy_slot_conv(PyTypeObject* cls);
7562+
#endif // GraalPy change
75707563

75717564
static int
75727565
type_ready(PyTypeObject *type, int rerunbuiltin)
@@ -7616,10 +7609,6 @@ type_ready(PyTypeObject *type, int rerunbuiltin)
76167609
if (type_ready_fill_dict(type) < 0) {
76177610
goto error;
76187611
}
7619-
// GraalPy change
7620-
if (type_ready_graalpy_slot_conv(type) < 0) {
7621-
goto error;
7622-
}
76237612
if (!rerunbuiltin) {
76247613
if (type_ready_inherit(type) < 0) {
76257614
goto error;
@@ -10217,6 +10206,7 @@ recurse_down_subclasses(PyTypeObject *type, PyObject *attr_name,
1021710206
}
1021810207
return 0;
1021910208
}
10209+
#endif // GraalPy change
1022010210

1022110211
static int
1022210212
expect_manually_inherited(PyTypeObject *type, void **slot)
@@ -10329,6 +10319,7 @@ expect_manually_inherited(PyTypeObject *type, void **slot)
1032910319
static int
1033010320
add_operators(PyTypeObject *type)
1033110321
{
10322+
#if 0 // GraalPy change: different implementation
1033210323
PyObject *dict = lookup_tp_dict(type);
1033310324
pytype_slotdef *p;
1033410325
PyObject *descr;
@@ -10385,9 +10376,13 @@ add_operators(PyTypeObject *type)
1038510376
}
1038610377
}
1038710378
return 0;
10379+
#else // GraalPy change
10380+
return GraalPyTruffleType_AddOperators(type);
10381+
#endif // GraalPy change
1038810382
}
1038910383

1039010384

10385+
#if 0 // GraalPy change
1039110386
/* Cooperative 'super' */
1039210387

1039310388
typedef struct {
@@ -10889,165 +10884,3 @@ PyTypeObject PySuper_Type = {
1088910884
.tp_vectorcall = (vectorcallfunc)super_vectorcall,
1089010885
};
1089110886
#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-
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextMethodBuiltins.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApi9BuiltinNode;
5757
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBuiltin;
5858
import com.oracle.graal.python.builtins.objects.PNone;
59-
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.CreateFunctionNode;
59+
import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionNodes;
6060
import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction;
6161
import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod;
6262
import com.oracle.graal.python.nodes.HiddenAttr;
@@ -83,19 +83,18 @@ public final class PythonCextMethodBuiltins {
8383
@GenerateCached(false)
8484
abstract static class CFunctionNewExMethodNode extends Node {
8585

86-
abstract Object execute(Node inliningTarget, Object methodDefPtr, TruffleString name, Object methObj, Object flags, int wrapper, Object self, Object module, Object cls, Object doc);
86+
abstract Object execute(Node inliningTarget, Object methodDefPtr, TruffleString name, Object methObj, int flags, int wrapper, Object self, Object module, Object cls, Object doc);
8787

88-
final Object execute(Node inliningTarget, Object methodDefPtr, TruffleString name, Object methObj, Object flags, int wrapper, Object self, Object module, Object doc) {
88+
final Object execute(Node inliningTarget, Object methodDefPtr, TruffleString name, Object methObj, int flags, int wrapper, Object self, Object module, Object doc) {
8989
return execute(inliningTarget, methodDefPtr, name, methObj, flags, wrapper, self, module, PNone.NO_VALUE, doc);
9090
}
9191

9292
@Specialization
93-
static Object doNativeCallable(Node inliningTarget, Object methodDefPtr, TruffleString name, Object methObj, Object flags, int wrapper, Object self, Object module, Object cls, Object doc,
93+
static Object doNativeCallable(Node inliningTarget, Object methodDefPtr, TruffleString name, Object methObj, int flags, int wrapper, Object self, Object module, Object cls, Object doc,
9494
@Bind PythonLanguage language,
95-
@Cached CreateFunctionNode createFunctionNode,
9695
@Cached HiddenAttr.WriteNode writeHiddenAttrNode,
9796
@Cached(inline = false) WriteAttributeToPythonObjectNode writeAttrNode) {
98-
Object f = createFunctionNode.execute(inliningTarget, name, methObj, wrapper, PNone.NO_VALUE, flags);
97+
Object f = ExternalFunctionNodes.PExternalFunctionWrapper.createWrapperFunction(name, methObj, PNone.NO_VALUE, flags, wrapper, language);
9998
assert f instanceof PBuiltinFunction;
10099
PBuiltinFunction func = (PBuiltinFunction) f;
101100
writeHiddenAttrNode.execute(inliningTarget, func, METHOD_DEF_PTR, methodDefPtr);

0 commit comments

Comments
 (0)