Skip to content

Commit e6729d8

Browse files
committed
[GR-37249] Fix pickle / struct issues.
PullRequest: graalpython/2199
2 parents 206158a + 886f7c3 commit e6729d8

File tree

7 files changed

+85
-19
lines changed

7 files changed

+85
-19
lines changed

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "overlay": "61d85a232c44f3e9131549f92a042d168bb65a07" }
1+
{ "overlay": "2fb56d2621f3b269485587d232a94182b1aeb795" }

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2019, 2022, 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
@@ -40,9 +40,8 @@
4040
import glob
4141
import os
4242
import subprocess
43-
import test
44-
4543
import sys
44+
import test
4645

4746
if os.environ.get("ENABLE_CPYTHON_TAGGED_UNITTESTS") == "true" or __name__ == "__main__":
4847
TAGS_DIR = os.path.join(os.path.dirname(__file__), "unittest_tags")
@@ -139,7 +138,18 @@ class TestTaggedUnittests(unittest.TestCase):
139138
total = 1
140139
assert selected < total
141140

142-
working_tests = collect_working_tests()[selected::total]
141+
working_tests = collect_working_tests()
142+
selection = os.environ.get('TAGGED_UNITTEST_SELECTION')
143+
if not selection:
144+
working_tests = working_tests[selected::total]
145+
else:
146+
selection = set(s.strip() for s in selection.split(","))
147+
working_tests = [x for x in working_tests if x[0] in selection]
148+
print("-----------------------------------------------------------------------------------------------------------")
149+
print("working tests: ")
150+
print([x[0] for x in working_tests])
151+
print("-----------------------------------------------------------------------------------------------------------")
152+
143153
for idx, working_test in enumerate(working_tests):
144154
fn = make_test_function(working_test)
145155
fn.__name__ = "%s[%d/%d]" % (fn.__name__, idx + 1, len(working_tests))

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
*graalpython.lib-python.3.test.test_pickle.InMemoryPickleTests.test_binunicode8
2222
*graalpython.lib-python.3.test.test_pickle.InMemoryPickleTests.test_buffer_callback_error
2323
*graalpython.lib-python.3.test.test_pickle.InMemoryPickleTests.test_buffers_error
24-
*graalpython.lib-python.3.test.test_pickle.InMemoryPickleTests.test_buffers_numpy
2524
*graalpython.lib-python.3.test.test_pickle.InMemoryPickleTests.test_bytearray
2625
*graalpython.lib-python.3.test.test_pickle.InMemoryPickleTests.test_bytearray8
2726
*graalpython.lib-python.3.test.test_pickle.InMemoryPickleTests.test_bytes
@@ -170,7 +169,6 @@
170169
*graalpython.lib-python.3.test.test_pickle.PyPicklerTests.test_bad_getattr
171170
*graalpython.lib-python.3.test.test_pickle.PyPicklerTests.test_buffer_callback_error
172171
*graalpython.lib-python.3.test.test_pickle.PyPicklerTests.test_buffers_error
173-
*graalpython.lib-python.3.test.test_pickle.PyPicklerTests.test_buffers_numpy
174172
*graalpython.lib-python.3.test.test_pickle.PyPicklerTests.test_bytearray
175173
*graalpython.lib-python.3.test.test_pickle.PyPicklerTests.test_bytes
176174
*graalpython.lib-python.3.test.test_pickle.PyPicklerTests.test_c_methods
@@ -315,7 +313,6 @@
315313
*test.pickletester.AbstractPickleTests.test_bad_getattr
316314
*test.pickletester.AbstractPickleTests.test_buffer_callback_error
317315
*test.pickletester.AbstractPickleTests.test_buffers_error
318-
*test.pickletester.AbstractPickleTests.test_buffers_numpy
319316
*test.pickletester.AbstractPickleTests.test_in_band_buffers
320317
*test.pickletester.AbstractPickleTests.test_local_lookup_error
321318
*test.pickletester.AbstractPickleTests.test_oob_buffers

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/sequence/storage/EmptySequenceStorage.java

Lines changed: 46 additions & 1 deletion
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.
@@ -27,11 +27,15 @@
2727

2828
import static com.oracle.graal.python.runtime.exception.PythonErrorType.ValueError;
2929

30+
import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAccessLibrary;
3031
import com.oracle.graal.python.nodes.ErrorMessages;
3132
import com.oracle.graal.python.nodes.PRaiseNode;
3233
import com.oracle.graal.python.util.PythonUtils;
3334
import com.oracle.truffle.api.CompilerDirectives;
35+
import com.oracle.truffle.api.library.ExportLibrary;
36+
import com.oracle.truffle.api.library.ExportMessage;
3437

38+
@ExportLibrary(PythonBufferAccessLibrary.class)
3539
public final class EmptySequenceStorage extends SequenceStorage {
3640

3741
public static final EmptySequenceStorage INSTANCE = new EmptySequenceStorage();
@@ -149,4 +153,45 @@ public Object getInternalArrayObject() {
149153
public ListStorageType getElementType() {
150154
return ListStorageType.Empty;
151155
}
156+
157+
@ExportMessage
158+
@SuppressWarnings("static-method")
159+
boolean isBuffer() {
160+
return true;
161+
}
162+
163+
@ExportMessage
164+
int getBufferLength() {
165+
return 0;
166+
}
167+
168+
@ExportMessage
169+
byte readByte(@SuppressWarnings("unused") int byteOffset) throws IndexOutOfBoundsException {
170+
throw new IndexOutOfBoundsException("EmptySequenceStorage is always empty!");
171+
}
172+
173+
@ExportMessage
174+
short readShort(@SuppressWarnings("unused") int byteOffset) throws IndexOutOfBoundsException {
175+
throw new IndexOutOfBoundsException("EmptySequenceStorage is always empty!");
176+
}
177+
178+
@ExportMessage
179+
int readInt(@SuppressWarnings("unused") int byteOffset) throws IndexOutOfBoundsException {
180+
throw new IndexOutOfBoundsException("EmptySequenceStorage is always empty!");
181+
}
182+
183+
@ExportMessage
184+
long readLong(@SuppressWarnings("unused") int byteOffset) throws IndexOutOfBoundsException {
185+
throw new IndexOutOfBoundsException("EmptySequenceStorage is always empty!");
186+
}
187+
188+
@ExportMessage
189+
float readFloat(@SuppressWarnings("unused") int byteOffset) throws IndexOutOfBoundsException {
190+
throw new IndexOutOfBoundsException("EmptySequenceStorage is always empty!");
191+
}
192+
193+
@ExportMessage
194+
double readDouble(@SuppressWarnings("unused") int byteOffset) throws IndexOutOfBoundsException {
195+
throw new IndexOutOfBoundsException("EmptySequenceStorage is always empty!");
196+
}
152197
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/util/NumericSupport.java

Lines changed: 9 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
@@ -315,7 +315,7 @@ public void putBigInteger(byte[] buffer, int index, BigInteger value, int numByt
315315
final byte[] src = value.toByteArray();
316316
int srcIndex = 0;
317317
int srcBytes = src.length;
318-
if (src.length > numBytes) {
318+
if (srcBytes > numBytes) {
319319
for (int i = 0; i < src.length; i++) {
320320
srcIndex = i;
321321
if (src[i] != 0) {
@@ -326,6 +326,13 @@ public void putBigInteger(byte[] buffer, int index, BigInteger value, int numByt
326326
if (srcBytes > numBytes) {
327327
throw OverflowException.INSTANCE;
328328
}
329+
} else if (srcBytes < numBytes) {
330+
// perform sign extension
331+
if (value.signum() < 0) {
332+
for (int i = 0; i < numBytes - srcBytes; i++) {
333+
buffer[i] = -1;
334+
}
335+
}
329336
}
330337
int dstIndex = index + (numBytes - srcBytes);
331338
PythonUtils.arraycopy(src, srcIndex, buffer, dstIndex, srcBytes);

mx.graalpython/mx_graalpython.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ class GraalPythonTags(object):
465465
unittest_hpy_sandboxed = 'python-unittest-hpy-sandboxed'
466466
unittest_posix = 'python-unittest-posix'
467467
tagged = 'python-tagged-unittest'
468+
tagged_sandboxed = 'python-tagged-unittest-sandboxed'
468469
svmunit = 'python-svm-unittest'
469470
svmunit_sandboxed = 'python-svm-unittest-sandboxed'
470471
shared_object = 'python-so'
@@ -563,6 +564,11 @@ def python_managed_gvm(_=None):
563564
mx.log(launcher)
564565
return launcher
565566

567+
def python_enterprise_gvm(_=None):
568+
home = _graalvm_home(envfile="graalpython-managed-bash-launcher")
569+
launcher = _join_bin(home, "graalpython")
570+
mx.log(launcher)
571+
return launcher
566572

567573
def python_gvm_with_assertions():
568574
launcher = python_gvm()
@@ -668,7 +674,7 @@ def is_included(path):
668674
return testfiles
669675

670676

671-
def run_python_unittests(python_binary, args=None, paths=None, aot_compatible=False, exclude=None, env=None, use_pytest=False):
677+
def run_python_unittests(python_binary, args=None, paths=None, aot_compatible=False, exclude=None, env=None, use_pytest=False, cwd=None):
672678
# ensure that the test distribution is up-to-date
673679
mx.command_function("build")(["--dep", "com.oracle.graal.python.test"])
674680

@@ -714,7 +720,7 @@ def run_python_unittests(python_binary, args=None, paths=None, aot_compatible=Fa
714720
# jacoco only dumps the data on exit, and when we run all our unittests
715721
# at once it generates so much data we run out of heap space
716722
for testfile in testfiles:
717-
mx.run([launcher_path] + args + [testfile], nonZeroIsFatal=False, env=env)
723+
mx.run([launcher_path] + args + [testfile], nonZeroIsFatal=False, env=env, cwd=cwd)
718724
finally:
719725
shutil.move(launcher_path_bak, launcher_path)
720726
else:
@@ -727,11 +733,11 @@ def graalvm_vm_arg(java_arg):
727733
# jacoco only dumps the data on exit, and when we run all our unittests
728734
# at once it generates so much data we run out of heap space
729735
for testfile in testfiles:
730-
mx.run([python_binary, "--jvm", agent_args] + args + [testfile], nonZeroIsFatal=False, env=env)
736+
mx.run([python_binary, "--jvm", agent_args] + args + [testfile], nonZeroIsFatal=False, env=env, cwd=cwd)
731737
else:
732738
args += testfiles
733739
mx.logv(" ".join([python_binary] + args))
734-
return mx.run([python_binary] + args, nonZeroIsFatal=True, env=env)
740+
return mx.run([python_binary] + args, nonZeroIsFatal=True, env=env, cwd=cwd)
735741

736742

737743
def is_bash_launcher(launcher_path):
@@ -764,7 +770,7 @@ def run_hpy_unittests(python_binary, args=None):
764770
return run_python_unittests(python_binary, args=args, paths=[_hpy_test_root()], env=env, use_pytest=True)
765771

766772

767-
def run_tagged_unittests(python_binary, env=None):
773+
def run_tagged_unittests(python_binary, env=None, cwd=None):
768774
if env is None:
769775
env = os.environ
770776
sub_env = dict(
@@ -778,6 +784,7 @@ def run_tagged_unittests(python_binary, env=None):
778784
args=["-v"],
779785
paths=["test_tagged_unittests.py"],
780786
env=sub_env,
787+
cwd=cwd
781788
)
782789

783790

mx.graalpython/suite.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,23 @@
4444
},
4545
{
4646
"name": "tools",
47-
"version": "63f1a04fe54b7986537d04199359699f1c079713",
47+
"version": "53208652115456e57e02126b8dae044f7d84d9ed",
4848
"subdir": True,
4949
"urls": [
5050
{"url": "https://github.com/oracle/graal", "kind": "git"},
5151
],
5252
},
5353
{
5454
"name": "sulong",
55-
"version": "63f1a04fe54b7986537d04199359699f1c079713",
55+
"version": "53208652115456e57e02126b8dae044f7d84d9ed",
5656
"subdir": True,
5757
"urls": [
5858
{"url": "https://github.com/oracle/graal", "kind": "git"},
5959
]
6060
},
6161
{
6262
"name": "regex",
63-
"version": "63f1a04fe54b7986537d04199359699f1c079713",
63+
"version": "53208652115456e57e02126b8dae044f7d84d9ed",
6464
"subdir": True,
6565
"urls": [
6666
{"url": "https://github.com/oracle/graal", "kind": "git"},

0 commit comments

Comments
 (0)