Skip to content

Commit 74cc1b0

Browse files
committed
Merge branch 'master' into feature/GR-20901
# Conflicts: # graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MarshalModuleBuiltins.java # graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/CodeNodes.java
2 parents f4e4ded + 05b0c88 commit 74cc1b0

File tree

60 files changed

+1419
-507
lines changed

Some content is hidden

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

60 files changed

+1419
-507
lines changed

graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/GraalPythonMain.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ public static void main(String[] args) {
6666
private static final String LANGUAGE_ID = "python";
6767
private static final String MIME_TYPE = "text/x-python";
6868

69+
// provided by GraalVM bash launchers, ignored in native image mode
70+
private static final String BASH_LAUNCHER_EXEC_NAME = System.getProperty("org.graalvm.launcher.executablename");
71+
6972
private ArrayList<String> programArgs = null;
7073
private String commandString = null;
7174
private String inputFile = null;
@@ -289,6 +292,17 @@ private void addRelaunchArg(String arg) {
289292
relaunchArgs.add(arg);
290293
}
291294

295+
private String[] execListWithRelaunchArgs(String executableName) {
296+
if (relaunchArgs == null) {
297+
return new String[]{executableName};
298+
} else {
299+
ArrayList<String> execList = new ArrayList<>(relaunchArgs.size() + 1);
300+
execList.add(executableName);
301+
execList.addAll(relaunchArgs);
302+
return execList.toArray(new String[execList.size()]);
303+
}
304+
}
305+
292306
private static void printShortHelp() {
293307
print("usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...\n" +
294308
"Try `python -h' for more information.");
@@ -300,13 +314,11 @@ private static void print(String string) {
300314

301315
private String[] getExecutableList() {
302316
if (ImageInfo.inImageCode()) {
303-
ArrayList<String> exec_list = new ArrayList<>();
304-
exec_list.add(ProcessProperties.getExecutableName());
305-
if (relaunchArgs != null) {
306-
exec_list.addAll(relaunchArgs);
307-
}
308-
return exec_list.toArray(new String[exec_list.size()]);
317+
return execListWithRelaunchArgs(ProcessProperties.getExecutableName());
309318
} else {
319+
if (BASH_LAUNCHER_EXEC_NAME != null) {
320+
return execListWithRelaunchArgs(BASH_LAUNCHER_EXEC_NAME);
321+
}
310322
StringBuilder sb = new StringBuilder();
311323
ArrayList<String> exec_list = new ArrayList<>();
312324
sb.append(System.getProperty("java.home")).append(File.separator).append("bin").append(File.separator).append("java");
@@ -340,6 +352,9 @@ private String getExecutable() {
340352
if (ImageInfo.inImageBuildtimeCode()) {
341353
return "";
342354
} else {
355+
if (BASH_LAUNCHER_EXEC_NAME != null) {
356+
return BASH_LAUNCHER_EXEC_NAME;
357+
}
343358
String[] executableList = getExecutableList();
344359
for (int i = 0; i < executableList.length; i++) {
345360
if (executableList[i].matches("\\s")) {
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Copyright (c) 2018, 2020, 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+
import csv
42+
import argparse
43+
44+
def read_file(filename):
45+
with open(filename) as csvfile:
46+
return {x["unittest"]:x for x in csv.DictReader(csvfile) if x["unittest"] != "TOTAL"}
47+
48+
# ----------------------------------------------------------------------------------------------------------------------
49+
#
50+
# main tool
51+
#
52+
# ----------------------------------------------------------------------------------------------------------------------
53+
def main(prog, args):
54+
parser = argparse.ArgumentParser(prog=prog,
55+
description="Compare the result of two runs of the standard python unittests based on their csv reports.")
56+
parser.add_argument("-v", "--verbose", help="Verbose output.", action="store_true")
57+
parser.add_argument("csvfile1", help="first input csv file")
58+
parser.add_argument("csvfile2", help="first input csv file")
59+
60+
global flags
61+
flags = parser.parse_args(args=args)
62+
print("comparing {} and {}".format(flags.csvfile1, flags.csvfile2))
63+
64+
raw1 = read_file(flags.csvfile1)
65+
raw2 = read_file(flags.csvfile2)
66+
print("number of entries: {} / {}".format(len(raw1.keys()), len(raw2.keys())))
67+
68+
result = []
69+
missing_tests = []
70+
new_tests = []
71+
for name, data in raw1.items():
72+
other_data = raw2.get(name)
73+
if other_data:
74+
result.append({'name':name, 'old_passing':int(data['num_passes']), 'new_passing':int(other_data['num_passes'])})
75+
else:
76+
missing_tests.append(name)
77+
78+
for name in raw2.keys():
79+
if not raw1.get(name):
80+
new_tests.append(name)
81+
82+
def custom(a):
83+
return (a['new_passing'] - a['old_passing']) * 1000000 + a['old_passing']
84+
85+
result = sorted(result, key=custom)
86+
87+
RED = u"\u001b[31m"
88+
GREEN = u"\u001b[32m"
89+
RESET = u"\u001b[0m"
90+
91+
for entry in result:
92+
delta = entry['new_passing'] - entry['old_passing']
93+
if delta != 0:
94+
print("%s%30s: %d (from %d to %d passing tests)" % (GREEN if delta > 0 else RED, entry['name'], delta, entry['old_passing'], entry['new_passing']))
95+
print(RESET)
96+
97+
if __name__ == "__main__":
98+
main(sys.argv[0], sys.argv[1:])

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,3 +290,8 @@ def test_lshift():
290290
assert 1 << 32 == 0x100000000
291291
assert 1 << 64 == 0x10000000000000000
292292
assert 1 << 128 == 0x100000000000000000000000000000000
293+
294+
295+
def test_pow():
296+
# (0xffffffffffffffff >> 63) is used to produce a non-narrowed int
297+
assert 2**(0xffffffffffffffff >> 63) == 2

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,18 @@ def test_key_info():
262262
assert not polyglot.__key_info__(builtinObj, "__len__", "removable")
263263
assert not polyglot.__key_info__(builtinObj, "__len__", "insertable")
264264

265+
def test_java_classpath():
266+
import java
267+
try:
268+
java.add_to_classpath(1)
269+
except TypeError as e:
270+
assert "classpath argument 1 must be string, not int" in str(e)
271+
272+
try:
273+
java.add_to_classpath('a', 1)
274+
except TypeError as e:
275+
assert "classpath argument 2 must be string, not int" in str(e)
276+
265277
def test_host_lookup():
266278
import java
267279
try:
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright (c) 2020, 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+
def test_select_raises_on_object_with_no_fileno_func():
41+
import select
42+
try :
43+
select.select('abc', [], [], 0)
44+
except TypeError:
45+
raised = True
46+
assert raised
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright (c) 2020, 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+
def test_SemLock_raises_on_non_string_name():
41+
from _multiprocessing import SemLock
42+
try :
43+
SemLock(kind=1, value=1, name={1:2}, maxvalue=1, unlink=1)
44+
except TypeError:
45+
raised = True
46+
assert raised

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,12 @@ def test_inet_aton_errs(self):
5757
self.assertRaises(OSError, lambda : socket.inet_aton('oracle.com'))
5858
self.assertRaises(OSError, lambda : socket.inet_aton('0x7000000000000000'))
5959
self.assertRaises(OSError, lambda : socket.inet_aton('255.255.256.1'))
60-
self.assertRaises(TypeError, lambda : socket.inet_aton(255))
60+
self.assertRaises(TypeError, lambda : socket.inet_aton(255))
61+
62+
def test_get_name_info():
63+
import socket
64+
try :
65+
socket.getnameinfo((1, 0, 0, 0), 0)
66+
except TypeError:
67+
raised = True
68+
assert raised

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import com.oracle.graal.python.builtins.modules.BinasciiModuleBuiltins;
4949
import com.oracle.graal.python.builtins.modules.BuiltinConstructors;
5050
import com.oracle.graal.python.builtins.modules.BuiltinFunctions;
51+
import com.oracle.graal.python.builtins.modules.CmathModuleBuiltins;
5152
import com.oracle.graal.python.builtins.modules.CodecsModuleBuiltins;
5253
import com.oracle.graal.python.builtins.modules.CollectionsModuleBuiltins;
5354
import com.oracle.graal.python.builtins.modules.ContextvarsModuleBuiltins;
@@ -357,6 +358,7 @@ private static final PythonBuiltins[] initializeBuiltins() {
357358
new TimeModuleBuiltins(),
358359
new ModuleBuiltins(),
359360
new MathModuleBuiltins(),
361+
new CmathModuleBuiltins(),
360362
new MarshalModuleBuiltins(),
361363
new RandomModuleBuiltins(),
362364
new RandomBuiltins(),

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,12 @@
177177
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
178178
import com.oracle.graal.python.nodes.subscript.SliceLiteralNode;
179179
import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
180+
import com.oracle.graal.python.nodes.util.CannotCastException;
180181
import com.oracle.graal.python.nodes.util.CastToByteNode;
181182
import com.oracle.graal.python.nodes.util.CastToJavaIntNode;
182183
import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
183184
import com.oracle.graal.python.nodes.util.CastToJavaStringNodeGen;
184185
import com.oracle.graal.python.nodes.util.CoerceToDoubleNode;
185-
import com.oracle.graal.python.nodes.util.CoerceToStringNode;
186186
import com.oracle.graal.python.nodes.util.SplitArgsNode;
187187
import com.oracle.graal.python.runtime.ExecutionContext.ForeignCallContext;
188188
import com.oracle.graal.python.runtime.ExecutionContext.IndirectCallContext;
@@ -1861,16 +1861,16 @@ Object strNoArgs(LazyPythonClass strClass, PNone arg, PNone encoding, PNone erro
18611861
}
18621862

18631863
@Specialization(guards = {"!isNativeClass(strClass)", "!isNoValue(obj)", "isNoValue(encoding)", "isNoValue(errors)"})
1864-
Object strOneArg(VirtualFrame frame, LazyPythonClass strClass, Object obj, @SuppressWarnings("unused") PNone encoding, @SuppressWarnings("unused") PNone errors,
1865-
@Cached CoerceToStringNode coerceToStringNode) {
1866-
Object result = coerceToStringNode.execute(frame, obj);
1864+
Object strOneArg(LazyPythonClass strClass, Object obj, @SuppressWarnings("unused") PNone encoding, @SuppressWarnings("unused") PNone errors,
1865+
@CachedLibrary(limit = "1") PythonObjectLibrary lib) {
1866+
Object result = lib.asPString(obj);
18671867

18681868
// try to return a primitive if possible
18691869
if (getIsStringProfile().profile(result instanceof String)) {
18701870
return asPString(strClass, (String) result);
18711871
}
18721872

1873-
// CoerceToStringNode guarantees that the returned object is an instanceof of 'str'
1873+
// PythonObjectLibrary guarantees that the returned object is an instanceof of 'str'
18741874
return result;
18751875
}
18761876

@@ -1906,11 +1906,12 @@ private Object decodeBytes(VirtualFrame frame, LazyPythonClass strClass, PBytes
19061906
* into a natively allocated subtype structure
19071907
*/
19081908
@Specialization(guards = {"isSubtypeOfString(frame, isSubtype, cls)", "isNoValue(encoding)", "isNoValue(errors)"}, limit = "1")
1909-
Object doNativeSubclass(VirtualFrame frame, PythonNativeClass cls, Object obj, @SuppressWarnings("unused") Object encoding, @SuppressWarnings("unused") Object errors,
1909+
Object doNativeSubclass(@SuppressWarnings("unused") VirtualFrame frame, PythonNativeClass cls, Object obj, @SuppressWarnings("unused") Object encoding,
1910+
@SuppressWarnings("unused") Object errors,
19101911
@Cached @SuppressWarnings("unused") IsSubtypeNode isSubtype,
1911-
@Cached CoerceToStringNode castToStringNode,
1912+
@CachedLibrary(limit = "1") PythonObjectLibrary lib,
19121913
@Cached CExtNodes.StringSubtypeNew subtypeNew) {
1913-
return subtypeNew.call(cls, castToStringNode.execute(frame, obj));
1914+
return subtypeNew.call(cls, lib.asPString(obj));
19141915
}
19151916

19161917
protected static boolean isSubtypeOfString(VirtualFrame frame, IsSubtypeNode isSubtypeNode, PythonNativeClass cls) {
@@ -2197,7 +2198,12 @@ private String getModuleNameFromGlobals(PythonObject globals, HashingStorageLibr
21972198
CompilerDirectives.transferToInterpreterAndInvalidate();
21982199
throw new IllegalStateException("invalid globals object");
21992200
}
2200-
return ensureCastToStringNode().execute(nameAttr);
2201+
try {
2202+
return ensureCastToStringNode().execute(nameAttr);
2203+
} catch (CannotCastException e) {
2204+
CompilerDirectives.transferToInterpreterAndInvalidate();
2205+
throw new IllegalStateException();
2206+
}
22012207
}
22022208

22032209
@SuppressWarnings("try")

0 commit comments

Comments
 (0)