Skip to content

Commit 8f72b31

Browse files
committed
Copy tp_descr_get and tp_descr_set slots
1 parent c492486 commit 8f72b31

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___FLOORDIV__;
138138
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___GETATTRIBUTE__;
139139
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___GETITEM__;
140+
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___GET__;
140141
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___HASH__;
141142
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IADD__;
142143
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___IAND__;
@@ -169,6 +170,7 @@
169170
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___RSHIFT__;
170171
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___SETATTR__;
171172
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___SETITEM__;
173+
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___SET__;
172174
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___STR__;
173175
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___SUB__;
174176
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___TRUEDIV__;
@@ -1566,6 +1568,22 @@ public Object get(@SuppressWarnings("unused") PythonManagedClass object) {
15661568
}
15671569
}
15681570

1571+
@CApiBuiltin(ret = descrgetfunc, args = {PyTypeObject}, call = Ignored)
1572+
public abstract static class Py_get_PyTypeObject_tp_descr_get extends PyGetTypeSlotNode {
1573+
1574+
Py_get_PyTypeObject_tp_descr_get() {
1575+
super(T___GET__);
1576+
}
1577+
}
1578+
1579+
@CApiBuiltin(ret = descrsetfunc, args = {PyTypeObject}, call = Ignored)
1580+
public abstract static class Py_get_PyTypeObject_tp_descr_set extends PyGetTypeSlotNode {
1581+
1582+
Py_get_PyTypeObject_tp_descr_set() {
1583+
super(T___SET__);
1584+
}
1585+
}
1586+
15691587
@CApiBuiltin(name = "Py_get_PyTypeObject_tp_traverse", ret = traverseproc, args = {PyTypeObject}, call = Ignored)
15701588
@CApiBuiltin(name = "Py_get_PyTypeObject_tp_clear", ret = inquiry, args = {PyTypeObject}, call = Ignored)
15711589
public abstract static class Py_get_PyTypeObject_tp_TraverseClear extends CApiUnaryBuiltinNode {
@@ -1927,8 +1945,6 @@ Object doTpBases(PythonManagedClass type,
19271945
@CApiBuiltin(name = "Py_get_PyTypeObject_tp_methods", ret = PyMethodDef, args = {PyTypeObject}, call = Ignored)
19281946
@CApiBuiltin(name = "Py_get_PyTypeObject_tp_members", ret = PyMemberDef, args = {PyTypeObject}, call = Ignored)
19291947
@CApiBuiltin(name = "Py_get_PyTypeObject_tp_getset", ret = PyGetSetDef, args = {PyTypeObject}, call = Ignored)
1930-
@CApiBuiltin(name = "Py_get_PyTypeObject_tp_descr_get", ret = descrgetfunc, args = {PyTypeObject}, call = Ignored)
1931-
@CApiBuiltin(name = "Py_get_PyTypeObject_tp_descr_set", ret = descrsetfunc, args = {PyTypeObject}, call = Ignored)
19321948
@CApiBuiltin(name = "Py_get_PyTypeObject_tp_is_gc", ret = inquiry, args = {PyTypeObject}, call = Ignored)
19331949
@CApiBuiltin(name = "Py_get_PyTypeObject_tp_finalize", ret = destructor, args = {PyTypeObject}, call = Ignored)
19341950
@CApiBuiltin(name = "Py_get_PyTypeObject_tp_vectorcall", ret = vectorcallfunc, args = {PyTypeObject}, call = Ignored)
@@ -2029,9 +2045,12 @@ private Object createProcsWrapper(Object value) {
20292045
return new PyProcsWrapper.RichcmpFunctionWrapper(value);
20302046
case objobjargproc:
20312047
case setattrofunc:
2048+
case descrsetfunc:
20322049
return new PyProcsWrapper.SetAttrWrapper(value);
20332050
case getattrofunc:
20342051
return new PyProcsWrapper.GetAttrWrapper(value);
2052+
case descrgetfunc:
2053+
return new PyProcsWrapper.DescrGetFunctionWrapper(value);
20352054
}
20362055
throw CompilerDirectives.shouldNotReachHere("descriptor: " + getRetDescriptor());
20372056
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PyProcsWrapper.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,59 @@ protected String getSignature() {
753753
}
754754
}
755755

756+
@ExportLibrary(InteropLibrary.class)
757+
public static final class DescrGetFunctionWrapper extends PyProcsWrapper {
758+
759+
public DescrGetFunctionWrapper(Object delegate) {
760+
super(delegate);
761+
}
762+
763+
@ExportMessage(name = "execute")
764+
static class Execute {
765+
766+
@Specialization(guards = "arguments.length == 3")
767+
static Object call(DescrGetFunctionWrapper self, Object[] arguments,
768+
@Cached CallTernaryMethodNode callNode,
769+
@Cached ToJavaNode toJavaNode,
770+
@Cached ToNewRefNode toNewRefNode,
771+
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode,
772+
@Exclusive @Cached GilNode gil) {
773+
boolean mustRelease = gil.acquire();
774+
CApiTiming.enter();
775+
try {
776+
try {
777+
// convert args
778+
Object receiver = toJavaNode.execute(arguments[0]);
779+
Object obj = toJavaNode.execute(arguments[1]);
780+
Object cls = toJavaNode.execute(arguments[2]);
781+
782+
Object result = callNode.execute(null, self.getDelegate(), receiver, obj, cls);
783+
return toNewRefNode.execute(result);
784+
} catch (Throwable t) {
785+
throw checkThrowableBeforeNative(t, "DescrGetFunctionWrapper", self.getDelegate());
786+
}
787+
} catch (PException e) {
788+
transformExceptionToNativeNode.execute(null, e);
789+
return PythonContext.get(gil).getNativeNull().getPtr();
790+
} finally {
791+
CApiTiming.exit(self.timing);
792+
gil.release(mustRelease);
793+
}
794+
}
795+
796+
@Specialization(guards = "arguments.length != 3")
797+
static Object error(@SuppressWarnings("unused") DescrGetFunctionWrapper self, Object[] arguments) throws ArityException {
798+
CompilerDirectives.transferToInterpreterAndInvalidate();
799+
throw ArityException.create(3, 3, arguments.length);
800+
}
801+
}
802+
803+
@Override
804+
protected String getSignature() {
805+
return "(POINTER,POINTER,POINTER):POINTER";
806+
}
807+
}
808+
756809
public static GetAttrWrapper createGetAttrWrapper(Object method) {
757810
assert !(method instanceof PNone) && !(method instanceof PNotImplemented);
758811
return new GetAttrWrapper(method);

0 commit comments

Comments
 (0)