Skip to content

Commit b5cb2ef

Browse files
committed
Add missing specialization for constructing bytes from buffer
1 parent d36bb4b commit b5cb2ef

File tree

2 files changed

+13
-0
lines changed
  • graalpython
    • com.oracle.graal.python.test/src/tests/unittest_tags
    • com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes

2 files changed

+13
-0
lines changed

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_gzip.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,13 @@
4242
*graalpython.lib-python.3.test.test_gzip.TestGzip.test_textio_readlines
4343
*graalpython.lib-python.3.test.test_gzip.TestGzip.test_with_open
4444
*graalpython.lib-python.3.test.test_gzip.TestGzip.test_write
45+
*graalpython.lib-python.3.test.test_gzip.TestGzip.test_write_array
4546
*graalpython.lib-python.3.test.test_gzip.TestGzip.test_write_bytearray
4647
*graalpython.lib-python.3.test.test_gzip.TestGzip.test_write_incompatible_type
48+
*graalpython.lib-python.3.test.test_gzip.TestGzip.test_write_memoryview
4749
*graalpython.lib-python.3.test.test_gzip.TestGzip.test_write_read_with_pathlike_file
4850
*graalpython.lib-python.3.test.test_gzip.TestGzip.test_zero_padded_file
51+
*graalpython.lib-python.3.test.test_gzip.TestMain.test_main
4952
*graalpython.lib-python.3.test.test_gzip.TestOpen.test_bad_params
5053
*graalpython.lib-python.3.test.test_gzip.TestOpen.test_binary_modes
5154
*graalpython.lib-python.3.test.test_gzip.TestOpen.test_encoding

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesNodes.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,16 @@ static byte[] fromIndex(VirtualFrame frame, Object source, @SuppressWarnings("un
598598
return BytesUtils.fromSize(getCore(), cap);
599599
}
600600

601+
@Specialization(guards = {"lib.isBuffer(source)", "!lib.canBeIndex(source)"}, limit = "3")
602+
static byte[] fromBuffer(Object source, @SuppressWarnings("unused") PNone encoding, @SuppressWarnings("unused") PNone errors,
603+
@CachedLibrary("source") PythonObjectLibrary lib) {
604+
try {
605+
return lib.getBufferBytes(source);
606+
} catch (UnsupportedMessageException e) {
607+
throw CompilerDirectives.shouldNotReachHere();
608+
}
609+
}
610+
601611
@Specialization(guards = {"!isString(source)", "!isNoValue(source)", "!lib.canBeIndex(source)", "!lib.isBuffer(source)"}, limit = "3")
602612
static byte[] fromIterable(VirtualFrame frame, Object source, @SuppressWarnings("unused") PNone encoding, @SuppressWarnings("unused") PNone errors,
603613
@Cached IteratorNodes.GetLength lenNode,

0 commit comments

Comments
 (0)