Skip to content

Commit 4c2c435

Browse files
committed
moved PyDescr nodes to PythnonCextDescrBuiltins
1 parent 03118f4 commit 4c2c435

File tree

3 files changed

+70
-83
lines changed

3 files changed

+70
-83
lines changed

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_descr.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ def _reference_classmethod(args):
4646
return classmethod(args[0])()
4747
raise TypeError
4848

49-
def _reference_method_descr(args):
50-
return 1 if isinstance(args[0], type(list.append)) else 0
51-
5249
class TestDescrObject(object):
5350

5451
def test_new_classmethod(self):
@@ -343,16 +340,3 @@ def compile_module(self, name):
343340
callfunction="wrap_PyDescr_NewClassMethod",
344341
cmpfunc=unhandled_error_compare
345342
)
346-
347-
test_PyMethodDescr_Check = CPyExtFunction(
348-
_reference_method_descr,
349-
lambda: (
350-
(tuple.__add__,),
351-
(lambda x: x,),
352-
(_reference_method_descr,),
353-
),
354-
resultspec="i",
355-
argspec="O",
356-
arguments=["PyObject* func"],
357-
cmpfunc=unhandled_error_compare
358-
)

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

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.SystemError;
4545
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError;
4646
import static com.oracle.graal.python.builtins.objects.cext.common.CExtContext.METH_CLASS;
47-
import static com.oracle.graal.python.builtins.objects.cext.common.CExtContext.isClassOrStaticMethod;
4847
import static com.oracle.graal.python.nodes.SpecialAttributeNames.__DOC__;
4948
import static com.oracle.graal.python.nodes.SpecialAttributeNames.__MODULE__;
5049
import static com.oracle.graal.python.nodes.SpecialAttributeNames.__NAME__;
@@ -76,7 +75,6 @@
7675
import com.oracle.graal.python.builtins.Python3Core;
7776
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
7877
import com.oracle.graal.python.builtins.PythonBuiltins;
79-
import com.oracle.graal.python.builtins.modules.BuiltinConstructors.MappingproxyNode;
8078
import com.oracle.graal.python.builtins.modules.SysModuleBuiltins;
8179
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltinsFactory.CreateFunctionNodeGen;
8280
import com.oracle.graal.python.builtins.objects.PNone;
@@ -427,16 +425,6 @@ static Object run() {
427425

428426
///////////// mappingproxy /////////////
429427

430-
@Builtin(name = "PyDictProxy_New", minNumOfPositionalArgs = 1)
431-
@GenerateNodeFactory
432-
public abstract static class PyDictProxyNewNode extends PythonUnaryBuiltinNode {
433-
@Specialization
434-
public static Object values(VirtualFrame frame, Object obj,
435-
@Cached MappingproxyNode mappingNode) {
436-
return mappingNode.execute(frame, PythonBuiltinClassType.PMappingproxy, obj);
437-
}
438-
}
439-
440428
@Builtin(name = "Py_DECREF", minNumOfPositionalArgs = 1)
441429
@Builtin(name = "Py_INCREF", minNumOfPositionalArgs = 1)
442430
@Builtin(name = "Py_XINCREF", minNumOfPositionalArgs = 1)
@@ -2407,34 +2395,6 @@ private static void addSlot(Object clsPtr, Object tpDictPtr, Object namePtr, Obj
24072395
}
24082396
}
24092397

2410-
// directly called without landing function
2411-
@Builtin(name = "PyDescr_NewClassMethod", minNumOfPositionalArgs = 6, parameterNames = {"name", "doc", "flags", "wrapper", "cfunc", "primary"})
2412-
@ArgumentClinic(name = "name", conversion = ArgumentClinic.ClinicConversion.String)
2413-
@GenerateNodeFactory
2414-
abstract static class PyDescrNewClassMethod extends PythonClinicBuiltinNode {
2415-
@Override
2416-
protected ArgumentClinicProvider getArgumentClinic() {
2417-
return PythonCextBuiltinsClinicProviders.PyDescrNewClassMethodClinicProviderGen.INSTANCE;
2418-
}
2419-
2420-
@Specialization
2421-
Object doNativeCallable(String name, Object doc, int flags, Object wrapper, Object methObj, Object primary,
2422-
@Cached AsPythonObjectNode asPythonObjectNode,
2423-
@Cached NewClassMethodNode newClassMethodNode,
2424-
@Cached ToNewRefNode newRefNode) {
2425-
Object type = asPythonObjectNode.execute(primary);
2426-
Object func = newClassMethodNode.execute(name, methObj, flags, wrapper, type, doc, factory());
2427-
if (!isClassOrStaticMethod(flags)) {
2428-
/*
2429-
* NewClassMethodNode only wraps method with METH_CLASS and METH_STATIC set but we
2430-
* need to do so here.
2431-
*/
2432-
func = factory().createClassmethodFromCallableObj(func);
2433-
}
2434-
return newRefNode.execute(func);
2435-
}
2436-
}
2437-
24382398
abstract static class CFunctionNewExMethodNode extends Node {
24392399

24402400
abstract Object execute(String name, Object methObj, Object flags, Object wrapper, Object self, Object module, Object doc,
@@ -2658,26 +2618,6 @@ private static RootCallTarget setterCallTarget(String name, PythonLanguage lang)
26582618
}
26592619
}
26602620

2661-
// directly called without landing function
2662-
@Builtin(name = "PyDescr_NewGetSet", minNumOfPositionalArgs = 6, parameterNames = {"name", "cls", "getter", "setter", "doc", "closure"})
2663-
@ArgumentClinic(name = "name", conversion = ClinicConversion.String)
2664-
@GenerateNodeFactory
2665-
abstract static class PyDescrNewGetSetNode extends PythonClinicBuiltinNode {
2666-
@Override
2667-
protected ArgumentClinicProvider getArgumentClinic() {
2668-
return PythonCextBuiltinsClinicProviders.PyDescrNewGetSetNodeClinicProviderGen.INSTANCE;
2669-
}
2670-
2671-
@Specialization
2672-
Object doNativeCallable(String name, Object cls, Object getter, Object setter, Object doc, Object closure,
2673-
@Cached CreateGetSetNode createGetSetNode,
2674-
@Cached CExtNodes.ToSulongNode toSulongNode) {
2675-
GetSetDescriptor descr = createGetSetNode.execute(name, cls, getter, setter, doc, closure,
2676-
getLanguage(), factory());
2677-
return toSulongNode.execute(descr);
2678-
}
2679-
}
2680-
26812621
// directly called without landing function
26822622
@Builtin(name = "AddGetSet", minNumOfPositionalArgs = 7, parameterNames = {"cls", "tpDict", "name", "getter", "setter", "doc", "closure"})
26832623
@ArgumentClinic(name = "name", conversion = ClinicConversion.String)

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

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -40,16 +40,25 @@
4040
*/
4141
package com.oracle.graal.python.builtins.modules.cext;
4242

43+
import static com.oracle.graal.python.builtins.objects.cext.common.CExtContext.isClassOrStaticMethod;
4344

45+
import com.oracle.graal.python.annotations.ArgumentClinic;
4446
import java.util.List;
4547
import com.oracle.graal.python.builtins.Builtin;
4648
import com.oracle.graal.python.builtins.CoreFunctions;
4749
import com.oracle.graal.python.builtins.Python3Core;
4850
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
4951
import com.oracle.graal.python.builtins.PythonBuiltins;
52+
import com.oracle.graal.python.builtins.modules.BuiltinConstructors;
5053
import com.oracle.graal.python.builtins.modules.BuiltinFunctions.IsInstanceNode;
54+
import com.oracle.graal.python.builtins.modules.cext.PythonCextDescrBuiltinsClinicProviders.PyDescrNewClassMethodClinicProviderGen;
55+
import com.oracle.graal.python.builtins.modules.cext.PythonCextDescrBuiltinsClinicProviders.PyDescrNewGetSetNodeClinicProviderGen;
56+
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes;
57+
import com.oracle.graal.python.builtins.objects.getsetdescriptor.GetSetDescriptor;
5158
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
59+
import com.oracle.graal.python.nodes.function.builtins.PythonClinicBuiltinNode;
5260
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
61+
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
5362
import com.oracle.truffle.api.dsl.Cached;
5463
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
5564
import com.oracle.truffle.api.dsl.NodeFactory;
@@ -70,20 +79,74 @@ public void initialize(Python3Core core) {
7079
super.initialize(core);
7180
}
7281

73-
//def PyMethodDescr_Check(func):
74-
// return 1 if isinstance(func, type(list.append)) else 0
75-
82+
@Builtin(name = "PyDictProxy_New", minNumOfPositionalArgs = 1)
83+
@GenerateNodeFactory
84+
public abstract static class PyDictProxyNewNode extends PythonUnaryBuiltinNode {
85+
@Specialization
86+
public static Object values(VirtualFrame frame, Object obj,
87+
@Cached BuiltinConstructors.MappingproxyNode mappingNode) {
88+
return mappingNode.execute(frame, PythonBuiltinClassType.PMappingproxy, obj);
89+
}
90+
}
91+
92+
// directly called without landing function
93+
@Builtin(name = "PyDescr_NewGetSet", minNumOfPositionalArgs = 6, parameterNames = {"name", "cls", "getter", "setter", "doc", "closure"})
94+
@ArgumentClinic(name = "name", conversion = ArgumentClinic.ClinicConversion.String)
95+
@GenerateNodeFactory
96+
abstract static class PyDescrNewGetSetNode extends PythonClinicBuiltinNode {
97+
@Override
98+
protected ArgumentClinicProvider getArgumentClinic() {
99+
return PyDescrNewGetSetNodeClinicProviderGen.INSTANCE;
100+
}
101+
102+
@Specialization
103+
Object doNativeCallable(String name, Object cls, Object getter, Object setter, Object doc, Object closure,
104+
@Cached PythonCextBuiltins.CreateGetSetNode createGetSetNode,
105+
@Cached CExtNodes.ToSulongNode toSulongNode) {
106+
GetSetDescriptor descr = createGetSetNode.execute(name, cls, getter, setter, doc, closure,
107+
getLanguage(), factory());
108+
return toSulongNode.execute(descr);
109+
}
110+
}
111+
112+
// directly called without landing function
113+
@Builtin(name = "PyDescr_NewClassMethod", minNumOfPositionalArgs = 6, parameterNames = {"name", "doc", "flags", "wrapper", "cfunc", "primary"})
114+
@ArgumentClinic(name = "name", conversion = ArgumentClinic.ClinicConversion.String)
115+
@GenerateNodeFactory
116+
abstract static class PyDescrNewClassMethod extends PythonClinicBuiltinNode {
117+
@Override
118+
protected ArgumentClinicProvider getArgumentClinic() {
119+
return PyDescrNewClassMethodClinicProviderGen.INSTANCE;
120+
}
121+
122+
@Specialization
123+
Object doNativeCallable(String name, Object doc, int flags, Object wrapper, Object methObj, Object primary,
124+
@Cached CExtNodes.AsPythonObjectNode asPythonObjectNode,
125+
@Cached PythonCextBuiltins.NewClassMethodNode newClassMethodNode,
126+
@Cached CExtNodes.ToNewRefNode newRefNode) {
127+
Object type = asPythonObjectNode.execute(primary);
128+
Object func = newClassMethodNode.execute(name, methObj, flags, wrapper, type, doc, factory());
129+
if (!isClassOrStaticMethod(flags)) {
130+
/*
131+
* NewClassMethodNode only wraps method with METH_CLASS and METH_STATIC set but we
132+
* need to do so here.
133+
*/
134+
func = factory().createClassmethodFromCallableObj(func);
135+
}
136+
return newRefNode.execute(func);
137+
}
138+
}
139+
76140
@Builtin(name = "PyMethodDescr_Check", minNumOfPositionalArgs = 1)
77141
@GenerateNodeFactory
78142
public abstract static class PyMethodDescrCheckNode extends PythonUnaryBuiltinNode {
79143

80144
@SuppressWarnings("unused")
81145
@Specialization
82-
int check(VirtualFrame frame, Object func,
83-
@Cached IsInstanceNode isInstanceNode) {
146+
static int check(VirtualFrame frame, Object func,
147+
@Cached IsInstanceNode isInstanceNode) {
84148
return isInstanceNode.executeWith(frame, func, PythonBuiltinClassType.PBuiltinFunction) ? 1 : 0;
85149
}
86150
}
87151

88-
89152
}

0 commit comments

Comments
 (0)