Skip to content

Commit 4334b02

Browse files
committed
Add wrapper for tp_descr_get
1 parent 971d294 commit 4334b02

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

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

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ static RootCallTarget getOrCreateCallTarget(PExternalFunctionWrapper sig, Python
262262
rootNodeFunction = doArgAndResultConversion ? l -> new AllocFuncRootNode(l, name, sig) : l -> new AllocFuncRootNode(l, name);
263263
break;
264264
case DIRECT:
265-
case DESCR_GET:
266265
case DESCR_SET:
267266
case LENFUNC:
268267
case HASHFUNC:
@@ -318,6 +317,10 @@ static RootCallTarget getOrCreateCallTarget(PExternalFunctionWrapper sig, Python
318317
nodeKlass = SetAttrFuncRootNode.class;
319318
rootNodeFunction = doArgAndResultConversion ? l -> new SetAttrFuncRootNode(l, name, sig) : l -> new SetAttrFuncRootNode(l, name);
320319
break;
320+
case DESCR_GET:
321+
nodeKlass = DescrGetRootNode.class;
322+
rootNodeFunction = doArgAndResultConversion ? l -> new DescrGetRootNode(l, name, sig) : l -> new DescrGetRootNode(l, name);
323+
break;
321324
case RICHCMP:
322325
nodeKlass = RichCmpFuncRootNode.class;
323326
rootNodeFunction = doArgAndResultConversion ? l -> new RichCmpFuncRootNode(l, name, sig) : l -> new RichCmpFuncRootNode(l, name);
@@ -1357,6 +1360,46 @@ public Signature getSignature() {
13571360
}
13581361
}
13591362

1363+
/**
1364+
* Implements semantics of {@code typeobject.c:wrap_descr_get}
1365+
*/
1366+
public static final class DescrGetRootNode extends MethodDescriptorRoot {
1367+
private static final Signature SIGNATURE = new Signature(-1, false, -1, false, new String[]{"self", "obj", "type"}, KEYWORDS_HIDDEN_CALLABLE, true);
1368+
@Child private ReadIndexedArgumentNode readObj;
1369+
@Child private ReadIndexedArgumentNode readType;
1370+
1371+
public DescrGetRootNode(PythonLanguage language, String name) {
1372+
super(language, name, false);
1373+
}
1374+
1375+
public DescrGetRootNode(PythonLanguage language, String name, PExternalFunctionWrapper provider) {
1376+
super(language, name, false, provider);
1377+
this.readObj = ReadIndexedArgumentNode.create(1);
1378+
this.readType = ReadIndexedArgumentNode.create(2);
1379+
}
1380+
1381+
@Override
1382+
protected Object[] prepareCArguments(VirtualFrame frame) {
1383+
Object self = readSelf(frame);
1384+
Object obj = readObj.execute(frame);
1385+
Object type = readType.execute(frame);
1386+
return new Object[]{self, obj == PNone.NONE ? PNone.NO_VALUE : obj, type == PNone.NONE ? PNone.NO_VALUE : type};
1387+
}
1388+
1389+
@Override
1390+
protected void postprocessCArguments(VirtualFrame frame, Object[] cArguments) {
1391+
ReleaseNativeWrapperNode releaseNativeWrapperNode = ensureReleaseNativeWrapperNode();
1392+
releaseNativeWrapperNode.execute(cArguments[0]);
1393+
releaseNativeWrapperNode.execute(cArguments[1]);
1394+
releaseNativeWrapperNode.execute(cArguments[2]);
1395+
}
1396+
1397+
@Override
1398+
public Signature getSignature() {
1399+
return SIGNATURE;
1400+
}
1401+
}
1402+
13601403
/**
13611404
* Implement mapping of {@code __delitem__} to {@code mp_ass_subscript}. It handles adding the
13621405
* NULL 3rd argument.

0 commit comments

Comments
 (0)