Skip to content

Commit bbe31dd

Browse files
committed
[GR-36268] Small bug fixes
PullRequest: graalpython/2098
2 parents 24fdddc + 2ab9fe6 commit bbe31dd

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2021, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2022, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -79,7 +79,6 @@
7979
import com.oracle.graal.python.lib.PyTupleCheckExactNodeGen;
8080
import com.oracle.graal.python.lib.PyUnicodeCheckExactNodeGen;
8181
import com.oracle.graal.python.nodes.ErrorMessages;
82-
import com.oracle.graal.python.nodes.PRaiseNode;
8382
import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode;
8483
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
8584
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
@@ -180,18 +179,17 @@ protected static LookupAndCallBinaryNode createCallReadNode() {
180179
@Specialization
181180
Object doit(VirtualFrame frame, Object file,
182181
@Cached("createCallReadNode()") LookupAndCallBinaryNode callNode,
183-
@CachedLibrary(limit = "3") PythonBufferAcquireLibrary bufferLib,
184-
@Cached PRaiseNode raise) {
182+
@CachedLibrary(limit = "3") PythonBufferAcquireLibrary bufferLib) {
185183
Object buffer = callNode.executeObject(frame, file, 0);
186184
if (!bufferLib.hasBuffer(buffer)) {
187185
throw raise(PythonBuiltinClassType.TypeError, "file.read() returned not bytes but %p", buffer);
188186
}
189187
try {
190188
return Marshal.loadFile(file);
191189
} catch (NumberFormatException e) {
192-
throw raise.raise(PythonBuiltinClassType.ValueError, ErrorMessages.BAD_MARSHAL_DATA_S, e.getMessage());
190+
throw raise(PythonBuiltinClassType.ValueError, ErrorMessages.BAD_MARSHAL_DATA_S, e.getMessage());
193191
} catch (Marshal.MarshalError me) {
194-
throw raise.raise(me.type, me.message, me.arguments);
192+
throw raise(me.type, me.message, me.arguments);
195193
}
196194
}
197195
}
@@ -200,17 +198,18 @@ Object doit(VirtualFrame frame, Object file,
200198
@ArgumentClinic(name = "bytes", conversion = ClinicConversion.ReadableBuffer)
201199
@GenerateNodeFactory
202200
abstract static class LoadsNode extends PythonUnaryClinicBuiltinNode {
203-
@TruffleBoundary
204-
@Specialization(limit = "3")
205-
static Object doit(Object buffer,
206-
@CachedLibrary("buffer") PythonBufferAccessLibrary bufferLib,
207-
@Cached PRaiseNode raise) {
201+
202+
@Specialization
203+
Object doit(VirtualFrame frame, Object buffer,
204+
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib) {
208205
try {
209206
return Marshal.load(bufferLib.getInternalOrCopiedByteArray(buffer), bufferLib.getBufferLength(buffer));
210207
} catch (NumberFormatException e) {
211-
throw raise.raise(PythonBuiltinClassType.ValueError, ErrorMessages.BAD_MARSHAL_DATA_S, e.getMessage());
208+
throw raise(PythonBuiltinClassType.ValueError, ErrorMessages.BAD_MARSHAL_DATA_S, e.getMessage());
212209
} catch (Marshal.MarshalError me) {
213-
throw raise.raise(me.type, me.message, me.arguments);
210+
throw raise(me.type, me.message, me.arguments);
211+
} finally {
212+
bufferLib.release(buffer, frame, this);
214213
}
215214
}
216215

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1849,7 +1849,7 @@ Object doIt(Object self, String className) {
18491849
}
18501850
}
18511851

1852-
@Builtin(name = "PyTruffle_NewTypeDict")
1852+
@Builtin(name = "PyTruffle_NewTypeDict", minNumOfPositionalArgs = 1)
18531853
@GenerateNodeFactory
18541854
@TypeSystemReference(PythonTypes.class)
18551855
public abstract static class PyTruffleNewTypeDict extends PythonUnaryBuiltinNode {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CDataObject.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 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
@@ -136,6 +136,7 @@ void writeByte(int byteIndex, byte value,
136136
@CachedLibrary(limit = "2") PythonBufferAccessLibrary bufferLib) {
137137
if (b_ptr.ptr != null) {
138138
bufferLib.writeByte(b_ptr.ptr, b_ptr.offset + byteIndex, value);
139+
return;
139140
}
140141
throw CompilerDirectives.shouldNotReachHere("buffer write to empty CDataObject");
141142
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/buffer/PythonBufferAccessLibrary.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 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
@@ -100,7 +100,11 @@ public static void assertIsBuffer(Object receiver) {
100100

101101
/**
102102
* Release the buffer. Equivalent of CPython's {@code PyBuffer_Release}, but must not be called
103-
* multiple times on the same buffer.
103+
* multiple times on the same buffer. If the caller has access to a VirtualFrame
104+
* {@link #release(Object, VirtualFrame, PNodeWithRaiseAndIndirectCall)} or
105+
* {@link #release(Object, VirtualFrame, PythonContext, PythonLanguage, IndirectCallNode)}
106+
* should be used. If the caller doesn't have access to a VirtualFrame it must be ensured that
107+
* an IndirectCallContext was already created in the call path.
104108
*/
105109
public void release(@SuppressWarnings("unused") Object receiver) {
106110
}

0 commit comments

Comments
 (0)