Skip to content

Commit 8d11072

Browse files
committed
fix PyBytes_FromStringAndSize for a code path in sandboxed mode
1 parent 0a4b84e commit 8d11072

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
import com.oracle.graal.python.builtins.objects.PythonAbstractObject;
7171
import com.oracle.graal.python.builtins.objects.bytes.BytesBuiltins;
7272
import com.oracle.graal.python.builtins.objects.bytes.BytesNodes;
73+
import com.oracle.graal.python.builtins.objects.bytes.PByteArray;
7374
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
7475
import com.oracle.graal.python.builtins.objects.cext.CArrayWrappers.CByteArrayWrapper;
7576
import com.oracle.graal.python.builtins.objects.cext.CArrayWrappers.CStringWrapper;
@@ -2138,6 +2139,23 @@ protected static boolean isPSequence(Object object) {
21382139
@Builtin(name = "PyBytes_FromStringAndSize", minNumOfPositionalArgs = 2, declaresExplicitSelf = true)
21392140
@GenerateNodeFactory
21402141
abstract static class PyBytes_FromStringAndSize extends NativeBuiltin {
2142+
// n.b.: the specializations for PBytes/PByteArray are quite common on
2143+
// managed, when the PySequenceArrayWrapper that we used never went
2144+
// native, and during the upcall to here it was simply unwrapped again
2145+
// with the ToJava (rather than mapped from a native pointer back into a
2146+
// PythonNativeObject)
2147+
2148+
@Specialization
2149+
Object doGeneric(Object module, PByteArray object,
2150+
@Exclusive @Cached BytesNodes.ToBytesNode getByteArrayNode) {
2151+
return factory().createBytes(getByteArrayNode.execute(object));
2152+
}
2153+
2154+
@Specialization
2155+
Object doGeneric(Object module, PBytes object,
2156+
@Exclusive @Cached BytesNodes.ToBytesNode getByteArrayNode) {
2157+
return factory().createBytes(getByteArrayNode.execute(object));
2158+
}
21412159

21422160
@Specialization
21432161
Object doGeneric(Object module, PythonNativeObject object,

0 commit comments

Comments
 (0)