Skip to content

Commit 62239eb

Browse files
committed
Fix wrong usage of offsets in memoryview
Fixes #307
1 parent dcdd5f5 commit 62239eb

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_multiprocessing.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2022, 2022, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2022, 2023, 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
@@ -37,6 +37,7 @@
3737
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3838
# SOFTWARE.
3939
import multiprocessing
40+
import sys
4041
import time
4142
from multiprocessing.connection import wait
4243

@@ -71,3 +72,15 @@ def test_wait():
7172
assert set(res) == set([b, x])
7273
assert b.recv() == 1
7374
assert x.recv() == 2
75+
76+
77+
def test_array_read():
78+
# TODO multiprocessing.Array doesn't work on emulated backend
79+
if sys.implementation.name == 'graalpy' and __graalpython__.posix_module_backend() == 'java':
80+
return
81+
# This used to be buggy due to wrong usage of memoryview offsets when two objects were allocated in the same block
82+
# Don't remove the unused value on the next line
83+
# noinspection PyUnusedLocal
84+
num = multiprocessing.Value('d', 0.0)
85+
arr = multiprocessing.Array('i', range(10))
86+
assert arr[1] == 1

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/memoryview/PMemoryView.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2023, 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
@@ -381,7 +381,7 @@ void readIntoBuffer(int srcOffset, Object dest, int destOffset, int length, Pyth
381381
byte readByte(int byteOffset,
382382
@Shared("bufferLib") @CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib) {
383383
assert isCContiguous() && !isReleased();
384-
return bufferLib.readByte(buffer, byteOffset);
384+
return bufferLib.readByte(buffer, offset + byteOffset);
385385
}
386386

387387
@ExportMessage

0 commit comments

Comments
 (0)