Skip to content

Commit dfcd90f

Browse files
committed
[GR-16873] Make numpy help work again
PullRequest: graalpython/800
2 parents 958aeb5 + 428f69f commit dfcd90f

File tree

8 files changed

+37
-29
lines changed

8 files changed

+37
-29
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/AbstractFunctionBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2019, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates.
33
* Copyright (c) 2014, Regents of the University of California
44
*
55
* All rights reserved.
@@ -79,7 +79,7 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
7979
return AbstractFunctionBuiltinsFactory.getFactories();
8080
}
8181

82-
@Builtin(name = __GET__, minNumOfPositionalArgs = 3)
82+
@Builtin(name = __GET__, minNumOfPositionalArgs = 2, maxNumOfPositionalArgs = 3)
8383
@GenerateNodeFactory
8484
@SuppressWarnings("unused")
8585
public abstract static class GetNode extends PythonTernaryBuiltinNode {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/getsetdescriptor/GetSetDescriptorTypeBuiltins.java

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2020, 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
@@ -67,7 +67,7 @@
6767
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
6868
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
6969
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
70-
import com.oracle.graal.python.nodes.object.GetClassNode;
70+
import com.oracle.graal.python.nodes.object.GetLazyClassNode;
7171
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
7272
import com.oracle.truffle.api.CompilerDirectives;
7373
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -101,19 +101,22 @@ abstract static class GetSetNode extends PythonTernaryBuiltinNode {
101101
@Child private GetMroNode getMroNode;
102102
@Child private GetNameNode getNameNode;
103103
@Child private IsSameTypeNode isSameTypeNode;
104+
@Child private GetLazyClassNode getLazyClassNode;
104105

105-
private final IsBuiltinClassProfile isNoneBuiltinClassProfile = IsBuiltinClassProfile.create();
106+
private final IsBuiltinClassProfile isBuiltinPythonClassObject = IsBuiltinClassProfile.create();
106107
private final ConditionProfile isBuiltinProfile = ConditionProfile.createBinaryProfile();
107108
private final IsBuiltinClassProfile isBuiltinClassProfile = IsBuiltinClassProfile.create();
108109
private final BranchProfile errorBranch = BranchProfile.create();
109110

110111
// https://github.com/python/cpython/blob/e8b19656396381407ad91473af5da8b0d4346e88/Objects/descrobject.c#L70
111-
protected boolean descr_check(LazyPythonClass descrType, String name, Object obj, LazyPythonClass type) {
112+
protected boolean descr_check(LazyPythonClass descrType, String name, Object obj) {
112113
if (PGuards.isNone(obj)) {
113-
if (!isNoneBuiltinClassProfile.profileClass(type, PythonBuiltinClassType.PNone)) {
114+
// object's descriptors (__class__,...) need to work on every object including None
115+
if (!isBuiltinPythonClassObject.profileClass(descrType, PythonBuiltinClassType.PythonObject)) {
114116
return true;
115117
}
116118
}
119+
LazyPythonClass type = getLazyClass(obj);
117120
if (isBuiltinProfile.profile(descrType instanceof PythonBuiltinClassType)) {
118121
PythonBuiltinClassType builtinClassType = (PythonBuiltinClassType) descrType;
119122
for (PythonAbstractClass o : getMro(type)) {
@@ -132,6 +135,14 @@ protected boolean descr_check(LazyPythonClass descrType, String name, Object obj
132135
throw raise(TypeError, "descriptor '%s' for '%s' objects doesn't apply to '%s' object", name, getTypeName(descrType), getTypeName(type));
133136
}
134137

138+
private LazyPythonClass getLazyClass(Object obj) {
139+
if (getLazyClassNode == null) {
140+
CompilerDirectives.transferToInterpreterAndInvalidate();
141+
getLazyClassNode = insert(GetLazyClassNode.create());
142+
}
143+
return getLazyClassNode.execute(obj);
144+
}
145+
135146
private PythonAbstractClass[] getMro(LazyPythonClass clazz) {
136147
if (getMroNode == null) {
137148
CompilerDirectives.transferToInterpreterAndInvalidate();
@@ -157,16 +168,16 @@ private boolean isSameType(Object left, Object right) {
157168
}
158169
}
159170

160-
@Builtin(name = __GET__, minNumOfPositionalArgs = 3)
171+
@Builtin(name = __GET__, minNumOfPositionalArgs = 2, maxNumOfPositionalArgs = 3)
161172
@GenerateNodeFactory
162173
abstract static class GetSetGetNode extends GetSetNode {
163174
private final BranchProfile branchProfile = BranchProfile.create();
164175

165176
// https://github.com/python/cpython/blob/e8b19656396381407ad91473af5da8b0d4346e88/Objects/descrobject.c#L149
166177
@Specialization
167-
Object get(VirtualFrame frame, GetSetDescriptor descr, Object obj, LazyPythonClass type,
178+
Object get(VirtualFrame frame, GetSetDescriptor descr, Object obj, @SuppressWarnings("unused") Object type,
168179
@Cached("create()") CallUnaryMethodNode callNode) {
169-
if (descr_check(descr.getType(), descr.getName(), obj, type)) {
180+
if (descr_check(descr.getType(), descr.getName(), obj)) {
170181
return descr;
171182
}
172183
if (descr.getGet() != null) {
@@ -178,10 +189,10 @@ Object get(VirtualFrame frame, GetSetDescriptor descr, Object obj, LazyPythonCla
178189
}
179190

180191
@Specialization
181-
Object getSlot(HiddenKeyDescriptor descr, Object obj, LazyPythonClass type,
192+
Object getSlot(HiddenKeyDescriptor descr, Object obj, @SuppressWarnings("unused") Object type,
182193
@Cached("create()") ReadAttributeFromObjectNode readNode,
183194
@Cached("createBinaryProfile()") ConditionProfile profile) {
184-
if (descr_check(descr.getType(), descr.getKey().getName(), obj, type)) {
195+
if (descr_check(descr.getType(), descr.getKey().getName(), obj)) {
185196
return descr;
186197
}
187198
Object val = readNode.execute(obj, descr.getKey());
@@ -195,14 +206,12 @@ Object getSlot(HiddenKeyDescriptor descr, Object obj, LazyPythonClass type,
195206
@Builtin(name = __SET__, minNumOfPositionalArgs = 3)
196207
@GenerateNodeFactory
197208
abstract static class GetSetSetNode extends GetSetNode {
198-
@Child GetClassNode getClassNode = GetClassNode.create();
199209
private final BranchProfile branchProfile = BranchProfile.create();
200210

201211
@Specialization
202212
Object set(VirtualFrame frame, GetSetDescriptor descr, Object obj, Object value,
203213
@Cached("create()") CallBinaryMethodNode callNode) {
204-
// the noneType is not important here - there are no setters on None
205-
if (descr_check(descr.getType(), descr.getName(), obj, getClassNode.execute(obj))) {
214+
if (descr_check(descr.getType(), descr.getName(), obj)) {
206215
return descr;
207216
}
208217
if (descr.getSet() != null) {
@@ -216,8 +225,7 @@ Object set(VirtualFrame frame, GetSetDescriptor descr, Object obj, Object value,
216225
@Specialization
217226
Object setSlot(HiddenKeyDescriptor descr, Object obj, Object value,
218227
@Cached("create()") WriteAttributeToObjectNode writeNode) {
219-
// the noneType is not important here - there are no setters on None
220-
if (descr_check(descr.getType(), descr.getKey().getName(), obj, getClassNode.execute(obj))) {
228+
if (descr_check(descr.getType(), descr.getKey().getName(), obj)) {
221229
return descr;
222230
}
223231
return writeNode.execute(obj, descr.getKey(), value);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/ClassmethodBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2020, 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
@@ -78,7 +78,7 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
7878
return ClassmethodBuiltinsFactory.getFactories();
7979
}
8080

81-
@Builtin(name = __GET__, minNumOfPositionalArgs = 2, maxNumOfPositionalArgs = 4)
81+
@Builtin(name = __GET__, minNumOfPositionalArgs = 2, maxNumOfPositionalArgs = 3)
8282
@GenerateNodeFactory
8383
abstract static class GetNode extends PythonBuiltinNode {
8484
@Child MakeMethodNode makeMethod = MakeMethodNode.create();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/MethodBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2019, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates.
33
* Copyright (c) 2014, Regents of the University of California
44
*
55
* All rights reserved.
@@ -185,7 +185,7 @@ Object doGeneric(@SuppressWarnings("unused") Object obj) {
185185
}
186186
}
187187

188-
@Builtin(name = __GET__, minNumOfPositionalArgs = 3)
188+
@Builtin(name = __GET__, minNumOfPositionalArgs = 2, maxNumOfPositionalArgs = 3)
189189
@GenerateNodeFactory
190190
public abstract static class GetNode extends PythonTernaryBuiltinNode {
191191
@Specialization

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/StaticmethodBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 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
@@ -64,7 +64,7 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
6464
return StaticmethodBuiltinsFactory.getFactories();
6565
}
6666

67-
@Builtin(name = __GET__, minNumOfPositionalArgs = 2, maxNumOfPositionalArgs = 4)
67+
@Builtin(name = __GET__, minNumOfPositionalArgs = 2, maxNumOfPositionalArgs = 3)
6868
@GenerateNodeFactory
6969
abstract static class GetNode extends PythonBuiltinNode {
7070
@Specialization

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/StringFormatter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2019, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates.
33
* Copyright (c) -2016 Jython Developers
44
*
55
* Licensed under PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -436,7 +436,7 @@ public Object format(Object args1, CallNode callNode, BiFunction<Object, String,
436436
break;
437437

438438
default:
439-
throw core.raise(ValueError, "unsupported format character '%c' (0x%x) at index %d", spec.type, spec.type, index - 1);
439+
throw core.raise(ValueError, "unsupported format character '%c' (0x%x) at index %d", spec.type, (int) spec.type, index - 1);
440440
}
441441

442442
// Pad the result as specified (in-place, in the buffer).

graalpython/lib-graalpython/property.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -75,7 +75,7 @@ def __init__(self, fget=None, fset=None, fdel=None, doc=None, name=None):
7575
self.name = name
7676
self._owner = None
7777

78-
def __get__(self, instance, owner):
78+
def __get__(self, instance, owner=None):
7979
if self._owner is None:
8080
self._owner = owner
8181
if instance is None:

graalpython/lib-graalpython/python_cext.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -816,7 +816,7 @@ def __init__(self, name, pointer, destructor):
816816
def __repr__(self):
817817
name = "NULL" if self.name is None else self.name
818818
quote = "" if self.name is None else '"'
819-
return "<capsule object %s%s%s at %p>" % (quote, name, quote, self.pointer)
819+
return "<capsule object %s%s%s at 0x%x>" % (quote, name, quote, id(self))
820820

821821

822822
@may_raise

0 commit comments

Comments
 (0)