Skip to content

Commit e623945

Browse files
committed
[GR-23254] Various fixes for test_raise
PullRequest: graalpython/981
2 parents e76baa0 + 0d9b245 commit e623945

File tree

15 files changed

+285
-30
lines changed

15 files changed

+285
-30
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Builtin.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747

4848
boolean isSetter() default false;
4949

50+
boolean allowsDelete() default false;
51+
5052
boolean takesVarArgs() default false;
5153

5254
boolean varArgsMarker() default false;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/PythonBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void initialize(PythonCore core) {
9393
assert !builtin.isClassmethod() && !builtin.isStaticmethod();
9494
PBuiltinFunction get = builtin.isGetter() ? function : null;
9595
PBuiltinFunction set = builtin.isSetter() ? function : null;
96-
callable = core.factory().createGetSetDescriptor(get, set, builtin.name(), null);
96+
callable = core.factory().createGetSetDescriptor(get, set, builtin.name(), null, builtin.allowsDelete());
9797
} else if (builtin.isClassmethod()) {
9898
assert !builtin.isStaticmethod();
9999
callable = core.factory().createClassmethod(function);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinConstructors.java

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
import com.oracle.graal.python.builtins.objects.set.SetNodes;
137137
import com.oracle.graal.python.builtins.objects.str.PString;
138138
import com.oracle.graal.python.builtins.objects.superobject.SuperObject;
139+
import com.oracle.graal.python.builtins.objects.traceback.PTraceback;
139140
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
140141
import com.oracle.graal.python.builtins.objects.type.LazyPythonClass;
141142
import com.oracle.graal.python.builtins.objects.type.PythonAbstractClass;
@@ -189,6 +190,7 @@
189190
import com.oracle.graal.python.runtime.PythonContext;
190191
import com.oracle.graal.python.runtime.PythonCore;
191192
import com.oracle.graal.python.runtime.exception.PException;
193+
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
192194
import com.oracle.graal.python.runtime.sequence.PSequence;
193195
import com.oracle.graal.python.runtime.sequence.storage.ByteSequenceStorage;
194196
import com.oracle.graal.python.runtime.sequence.storage.ObjectSequenceStorage;
@@ -2827,12 +2829,40 @@ Object call() {
28272829
}
28282830
}
28292831

2830-
@Builtin(name = "traceback", constructsClass = PythonBuiltinClassType.PTraceback, isPublic = false)
2832+
@Builtin(name = "TracebackType", constructsClass = PythonBuiltinClassType.PTraceback, isPublic = false, minNumOfPositionalArgs = 5, parameterNames = {"$cls", "tb_next", "tb_frame", "tb_lasti",
2833+
"tb_lineno"})
28312834
@GenerateNodeFactory
28322835
public abstract static class TracebackTypeNode extends PythonBuiltinNode {
2833-
@Specialization
2834-
Object call() {
2835-
throw raise(RuntimeError, ErrorMessages.CANNOT_CALL_CTOR_OF, "traceback type");
2836+
@Specialization(limit = "1")
2837+
Object createTraceback(@SuppressWarnings("unused") LazyPythonClass cls, PTraceback next, PFrame frame, Object lasti, Object lineno,
2838+
@CachedLibrary("lasti") PythonObjectLibrary lastiLib,
2839+
@CachedLibrary("lineno") PythonObjectLibrary linenoLib,
2840+
@Cached PythonObjectFactory factory) {
2841+
return factory.createTraceback(frame, linenoLib.asSize(lineno), lastiLib.asSize(lasti), next);
2842+
}
2843+
2844+
@Specialization(limit = "1")
2845+
Object createTraceback(@SuppressWarnings("unused") LazyPythonClass cls, @SuppressWarnings("unused") PNone next, PFrame frame, Object lasti, Object lineno,
2846+
@CachedLibrary("lasti") PythonObjectLibrary lastiLib,
2847+
@CachedLibrary("lineno") PythonObjectLibrary linenoLib,
2848+
@Cached PythonObjectFactory factory) {
2849+
return factory.createTraceback(frame, linenoLib.asSize(lineno), lastiLib.asSize(lasti), null);
2850+
}
2851+
2852+
@Specialization(guards = {"!isPTraceback(next)", "!isNone(next)"})
2853+
@SuppressWarnings("unused")
2854+
Object errorNext(LazyPythonClass cls, Object next, Object frame, Object lasti, Object lineno) {
2855+
throw raise(TypeError, "expected traceback object or None, got '%p'", next);
2856+
}
2857+
2858+
@Specialization(guards = "!isPFrame(frame)")
2859+
@SuppressWarnings("unused")
2860+
Object errorFrame(LazyPythonClass cls, Object next, Object frame, Object lasti, Object lineno) {
2861+
throw raise(TypeError, "TracebackType() argument 'tb_frame' must be frame, not %p", frame);
2862+
}
2863+
2864+
protected static boolean isPFrame(Object obj) {
2865+
return obj instanceof PFrame;
28362866
}
28372867
}
28382868

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,7 +1653,7 @@ PThreadState get() {
16531653
public abstract static class GetSetDescriptorNode extends PythonBuiltinNode {
16541654
@Specialization(guards = {"!isNoValue(get)", "!isNoValue(set)"})
16551655
Object call(Object get, Object set, String name, LazyPythonClass owner) {
1656-
return factory().createGetSetDescriptor(get, set, name, owner);
1656+
return factory().createGetSetDescriptor(get, set, name, owner, true);
16571657
}
16581658

16591659
@Specialization(guards = {"!isNoValue(get)", "isNoValue(set)"})
@@ -1663,7 +1663,7 @@ Object call(Object get, @SuppressWarnings("unused") PNone set, String name, Lazy
16631663

16641664
@Specialization(guards = {"isNoValue(get)", "!isNoValue(set)"})
16651665
Object call(@SuppressWarnings("unused") PNone get, Object set, String name, LazyPythonClass owner) {
1666-
return factory().createGetSetDescriptor(null, set, name, owner);
1666+
return factory().createGetSetDescriptor(null, set, name, owner, true);
16671667
}
16681668
}
16691669

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
import com.oracle.graal.python.builtins.objects.floats.PFloat;
9191
import com.oracle.graal.python.builtins.objects.function.PFunction;
9292
import com.oracle.graal.python.builtins.objects.function.PKeyword;
93+
import com.oracle.graal.python.builtins.objects.getsetdescriptor.DescriptorDeleteMarker;
9394
import com.oracle.graal.python.builtins.objects.ints.PInt;
9495
import com.oracle.graal.python.builtins.objects.module.PythonModule;
9596
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
@@ -412,6 +413,14 @@ static Object doNativeNull(@SuppressWarnings("unused") CExtContext cextContext,
412413
return object.getPtr();
413414
}
414415

416+
@Specialization
417+
static Object doDeleteMarker(@SuppressWarnings("unused") CExtContext cextContext, DescriptorDeleteMarker marker,
418+
@Cached GetNativeNullNode getNativeNullNode) {
419+
assert marker == DescriptorDeleteMarker.INSTANCE;
420+
PythonNativeNull nativeNull = (PythonNativeNull) getNativeNullNode.execute();
421+
return nativeNull.getPtr();
422+
}
423+
415424
@Specialization(guards = {"object == cachedObject", "isSpecialSingleton(cachedObject)"})
416425
static Object doSingletonCached(CExtContext cextContext, @SuppressWarnings("unused") PythonAbstractObject object,
417426
@Cached("object") PythonAbstractObject cachedObject,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
package com.oracle.graal.python.builtins.objects.getsetdescriptor;
42+
43+
public class DescriptorDeleteMarker {
44+
public static final DescriptorDeleteMarker INSTANCE = new DescriptorDeleteMarker();
45+
46+
private DescriptorDeleteMarker() {
47+
}
48+
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,20 @@ public final class GetSetDescriptor extends PythonBuiltinObject implements Bound
5050
private final Object get;
5151
private final Object set;
5252
private final String name;
53+
private final boolean allowsDelete;
5354
private final LazyPythonClass type;
5455

5556
public GetSetDescriptor(Object get, Object set, String name, LazyPythonClass type) {
57+
this(get, set, name, type, false);
58+
}
59+
60+
public GetSetDescriptor(Object get, Object set, String name, LazyPythonClass type, boolean allowsDelete) {
5661
super(PythonBuiltinClassType.GetSetDescriptor, PythonBuiltinClassType.GetSetDescriptor.newInstance());
5762
this.get = get;
5863
this.set = set;
5964
this.name = name;
6065
this.type = type;
66+
this.allowsDelete = allowsDelete;
6167
}
6268

6369
public Object getGet() {
@@ -76,6 +82,10 @@ public LazyPythonClass getType() {
7682
return type;
7783
}
7884

85+
public boolean allowsDelete() {
86+
return allowsDelete;
87+
}
88+
7989
public GetSetDescriptor boundToObject(PythonBuiltinClassType klass, PythonObjectFactory factory) {
8090
if (klass == type) {
8191
return this;

0 commit comments

Comments
 (0)