Skip to content

Commit 59a107c

Browse files
committed
[GR-53371] Fixes for prophet
PullRequest: graalpython/3291
2 parents 7ff89fe + c2c29a9 commit 59a107c

File tree

71 files changed

+613
-1190
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+613
-1190
lines changed

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/builtin/modules/PathConversionNodeTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2024, 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
@@ -62,6 +62,7 @@
6262
import com.oracle.graal.python.builtins.modules.PosixModuleBuiltins.PosixPath;
6363
import com.oracle.graal.python.builtins.modules.PosixModuleBuiltinsFactory;
6464
import com.oracle.graal.python.builtins.objects.PNone;
65+
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
6566
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
6667
import com.oracle.graal.python.runtime.PosixSupportLibrary.Buffer;
6768
import com.oracle.graal.python.runtime.PythonContext;
@@ -341,8 +342,8 @@ private String callAndExpectPath(boolean nullable, boolean allowFd, Object arg,
341342

342343
private String callAndExpectPathEx(String script, boolean wasBufferLike) {
343344
PTuple o = (PTuple) evalValue(script);
344-
Object arg = o.getSequenceStorage().getItemNormalized(0);
345-
Object orig = o.getSequenceStorage().getItemNormalized(1);
345+
Object arg = SequenceStorageNodes.GetItemScalarNode.executeUncached(o.getSequenceStorage(), 0);
346+
Object orig = SequenceStorageNodes.GetItemScalarNode.executeUncached(o.getSequenceStorage(), 1);
346347
return callAndExpectPath(true, true, arg, orig, wasBufferLike);
347348
}
348349

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/datatype/ListTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2023, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2024, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -108,7 +108,8 @@ public void index() {
108108
@Test
109109
public void reverse() {
110110
String source = "llist = [1,2,3,4,5]\n" + //
111-
"print(llist.reverse())\n";
111+
"llist.reverse()\n" + //
112+
"print(llist)\n";
112113

113114
assertPrints("[5, 4, 3, 2, 1]\n", source);
114115
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018, 2024, 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
@@ -36,10 +36,11 @@
3636
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3737
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3838
# SOFTWARE.
39-
import sys
4039

4140
from array import array
4241

42+
from tests.util import storage_to_native
43+
4344

4445
def assert_raises(err, fn, *args, **kwargs):
4546
raised = False
@@ -102,9 +103,7 @@ def test_add_int_to_long_array():
102103

103104
def test_array_native_storage():
104105
a = array('l', [1, 2, 3])
105-
if sys.implementation.name == 'graalpy':
106-
assert hasattr(__graalpython__, 'storage_to_native'), "Needs to be run with --python.EnableDebuggingBuiltins"
107-
__graalpython__.storage_to_native(a)
106+
storage_to_native(a)
108107
assert a[1] == 2
109108
a[1] = 3
110109
assert a == array('l', [1, 3, 3])

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018, 2024, 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,8 +37,11 @@
3737
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3838
# SOFTWARE.
3939

40-
import unittest
4140
import sys
41+
import unittest
42+
43+
from tests.util import storage_to_native
44+
4245

4346
def assert_raises(err, fn, *args, **kwargs):
4447
raised = False
@@ -107,6 +110,10 @@ def test_reverse():
107110
assert not b
108111
b.reverse()
109112
assert not b
113+
b = bytearray(b'hello')
114+
storage_to_native(b)
115+
b.reverse()
116+
assert b == b'olleh'
110117

111118

112119
def test_clear():

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
# Copyright (c) 2018, 2023, Oracle and/or its affiliates.
1+
# Copyright (c) 2018, 2024, Oracle and/or its affiliates.
22
# Copyright (C) 1996-2017 Python Software Foundation
33
#
44
# Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
55

6-
import seq_tests
76
import sys
87
import unittest
8+
9+
from tests.util import storage_to_native
10+
911
# import pickle
1012

1113
LONG_NUMBER = 6227020800;
@@ -840,6 +842,20 @@ def test_generalize_store(self):
840842
l += [0x100000000, 'a']
841843
self.assertEqual([1, 0x100000000, 'a'], l)
842844

845+
def test_reverse(self):
846+
l = [1, 2, 3]
847+
self.assertEqual(None, l.reverse())
848+
self.assertEqual([3, 2, 1], l)
849+
storage_to_native(l)
850+
l.reverse()
851+
self.assertEqual([1, 2, 3], l)
852+
l.append(4)
853+
l.reverse()
854+
self.assertEqual([4, 3, 2, 1], l)
855+
del l[:-1]
856+
l.reverse()
857+
self.assertEqual([1], l)
858+
843859

844860
if __name__ == '__main__':
845861
unittest.main()

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2020, 2024, 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,10 +37,11 @@
3737
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3838
# SOFTWARE.
3939
import socket
40-
import sys
4140
import threading
4241
import unittest
4342

43+
from tests.util import storage_to_native
44+
4445

4546
def test_inet_aton():
4647
assert socket.inet_aton('127.255.1.2') == bytes([127, 255, 1, 2])
@@ -90,9 +91,7 @@ def server():
9091
buffer = memoryview(b)[1:]
9192
sock.recv_into(buffer, 1)
9293
assert b == b'12a'
93-
if sys.implementation.name == 'graalpy':
94-
assert hasattr(__graalpython__, 'storage_to_native'), "Needs to be run with --python.EnableDebuggingBuiltins"
95-
__graalpython__.storage_to_native(b)
94+
storage_to_native(b)
9695
# Native buffer, no internal array
9796
buffer = memoryview(buffer)[1:]
9897
sock.recv_into(buffer, 1)

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,7 @@ def test_tagged():
108108
cmd.append("--inspect")
109109
if "-debug-java" in sys.argv:
110110
cmd.append("-debug-java")
111-
cmd += [RUNNER]
112-
if "-vv" in sys.argv:
113-
cmd += ['-v']
111+
cmd += [RUNNER, '-v']
114112
for testpattern in working_test_group:
115113
if testpattern:
116114
cmd.extend(["-k", testpattern])
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
2+
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3+
#
4+
# The Universal Permissive License (UPL), Version 1.0
5+
#
6+
# Subject to the condition set forth below, permission is hereby granted to any
7+
# person obtaining a copy of this software, associated documentation and/or
8+
# data (collectively the "Software"), free of charge and under any and all
9+
# copyright rights in the Software, and any and all patent rights owned or
10+
# freely licensable by each licensor hereunder covering either (i) the
11+
# unmodified Software as contributed to or provided by such licensor, or (ii)
12+
# the Larger Works (as defined below), to deal in both
13+
#
14+
# (a) the Software, and
15+
#
16+
# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
17+
# one is included with the Software each a "Larger Work" to which the Software
18+
# is contributed by such licensors),
19+
#
20+
# without restriction, including without limitation the rights to copy, create
21+
# derivative works of, display, perform, and distribute the Software and make,
22+
# use, sell, offer for sale, import, export, have made, and have sold the
23+
# Software and the Larger Work(s), and to sublicense the foregoing rights on
24+
# either these or other terms.
25+
#
26+
# This license is subject to the following condition:
27+
#
28+
# The above copyright notice and either this complete permission notice or at a
29+
# minimum a reference to the UPL must be included in all copies or substantial
30+
# portions of the Software.
31+
#
32+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38+
# SOFTWARE.
39+
40+
import sys
41+
42+
43+
def storage_to_native(s):
44+
if sys.implementation.name == 'graalpy':
45+
assert hasattr(__graalpython__, 'storage_to_native'), "Needs to be run with --python.EnableDebuggingBuiltins"
46+
__graalpython__.storage_to_native(s)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2426,7 +2426,7 @@ static PTuple update(PTuple bases, Object[] arguments, int nargs,
24262426
}
24272427
SequenceStorage storage = newBaseTuple.getSequenceStorage();
24282428
for (int j = 0; j < storage.length(); j++) {
2429-
newBases.add(storage.getItemNormalized(j));
2429+
newBases.add(SequenceStorageNodes.GetItemScalarNode.executeUncached(storage, j));
24302430
}
24312431
}
24322432
if (newBases == null) {
@@ -2460,7 +2460,7 @@ static Object calculate(Object metatype, PTuple bases,
24602460
int nbases = storage.length();
24612461
Object winner = metatype;
24622462
for (int i = 0; i < nbases; i++) {
2463-
Object tmp = storage.getItemNormalized(i);
2463+
Object tmp = SequenceStorageNodes.GetItemScalarNode.executeUncached(storage, i);
24642464
Object tmpType = getClass.execute(inliningTarget, tmp);
24652465
if (isSubType.execute(winner, tmpType)) {
24662466
// nothing to do
@@ -2564,7 +2564,7 @@ class InitializeBuildClass {
25642564
meta = PythonContext.get(update).lookupType(PythonBuiltinClassType.PythonClass);
25652565
} else {
25662566
// else get the type of the first base
2567-
meta = getClass.execute(inliningTarget, bases.getSequenceStorage().getItemNormalized(0));
2567+
meta = getClass.execute(inliningTarget, SequenceStorageNodes.GetItemScalarNode.executeUncached(bases.getSequenceStorage(), 0));
25682568
}
25692569
isClass = true; // meta is really a class
25702570
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2024, 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
@@ -152,6 +152,7 @@
152152
import com.oracle.graal.python.runtime.PythonContext;
153153
import com.oracle.graal.python.runtime.exception.PException;
154154
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
155+
import com.oracle.graal.python.runtime.sequence.storage.ObjectSequenceStorage;
155156
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
156157
import com.oracle.graal.python.util.CharsetMapping;
157158
import com.oracle.graal.python.util.CharsetMapping.NormalizeEncodingNameNode;
@@ -1082,7 +1083,9 @@ abstract static class ForgetCodecNode extends PythonUnaryBuiltinNode {
10821083
@Specialization
10831084
Object forget(VirtualFrame frame, PBytesLike encoding,
10841085
@Cached AsciiDecodeNode asciiDecodeNode) {
1085-
forget((TruffleString) ((PTuple) asciiDecodeNode.execute(frame, encoding, PNone.NO_VALUE)).getSequenceStorage().getInternalArray()[0]);
1086+
PTuple decodeResult = (PTuple) asciiDecodeNode.execute(frame, encoding, PNone.NO_VALUE);
1087+
ObjectSequenceStorage resultStorage = (ObjectSequenceStorage) decodeResult.getSequenceStorage();
1088+
forget((TruffleString) resultStorage.getItemNormalized(0));
10861089
return PNone.NONE;
10871090
}
10881091

0 commit comments

Comments
 (0)