Skip to content

Commit 3004cf3

Browse files
committed
[GR-61700] Backport to 24.2: Update XZ version.
PullRequest: graalpython/3684
2 parents 98d9629 + 96d33d8 commit 3004cf3

File tree

17 files changed

+474
-220
lines changed

17 files changed

+474
-220
lines changed

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "overlay": "da4fbb453006eea9997babadc69b70c2e0cee0ab" }
1+
{ "overlay": "585265d3c6bafc1d12054374377589b360307957" }

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,8 @@ protected void launch(Builder contextBuilder) {
843843
} catch (PolyglotException e) {
844844
if (e.isExit()) {
845845
rc = e.getExitStatus();
846+
} else {
847+
throw e;
846848
}
847849
} catch (NoSuchFileException e) {
848850
printFileNotFoundException(e);

graalpython/com.oracle.graal.python.test/src/tests/standalone/test_gradle_plugin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -677,11 +677,11 @@ def setUpClass(cls):
677677
cls.build_file_name = "build.gradle.kts"
678678
cls.settings_file_name = "settings.gradle.kts"
679679

680-
@unittest.skipUnless(util.is_gradle_plugin_test_enabled, "ENABLE_GRADLE_PLUGIN_UNITTESTS is not true")
680+
@unittest.skipUnless(util.is_gradle_plugin_long_running_test_enabled, "ENABLE_GRADLE_PLUGIN_LONG_RUNNING_UNITTESTS is not true")
681681
def test_gradle_generated_app(self):
682682
self.check_gradle_generated_app(community=True)
683683

684-
@unittest.skipUnless(util.is_gradle_plugin_test_enabled, "ENABLE_GRADLE_PLUGIN_UNITTESTS is not true")
684+
@unittest.skipUnless(util.is_gradle_plugin_long_running_test_enabled, "ENABLE_GRADLE_PLUGIN_LONG_RUNNING_UNITTESTS is not true")
685685
def test_gradle_generated_app_external_resources(self):
686686
self.check_gradle_generated_app_external_resources()
687687

@@ -701,7 +701,7 @@ def test_gradle_check_home(self):
701701
def test_gradle_empty_packages(self):
702702
self.check_gradle_empty_packages()
703703

704-
@unittest.skipUnless(util.is_gradle_plugin_test_enabled, "ENABLE_GRADLE_PLUGIN_UNITTESTS is not true")
704+
@unittest.skipUnless(util.is_gradle_plugin_long_running_test_enabled, "ENABLE_GRADLE_PLUGIN_LONG_RUNNING_UNITTESTS is not true")
705705
def test_gradle_namespaced_vfs(self):
706706
self.check_gradle_namespaced_vfs()
707707

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018, 2025, 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
@@ -150,7 +150,7 @@ def t(obj):
150150
# ForeignInstantiable
151151
self.assertEqual(t((e for e in [1])), polyglot.ForeignIteratorIterable)
152152
self.assertEqual(t(iter([1])), polyglot.ForeignIteratorIterable)
153-
self.assertEqual(t(object), polyglot.ForeignExecutableClass)
153+
self.assertEqual(t(object), polyglot.ForeignClassExecutable)
154154
self.assertEqual(t(None), polyglot.ForeignNone)
155155
self.assertEqual(t(1), polyglot.ForeignNumber)
156156
self.assertEqual(t("abc"), polyglot.ForeignString)
@@ -471,10 +471,19 @@ def test_java_import_from_jar(self):
471471
os.unlink(tempname)
472472

473473
def test_java_class(self):
474-
from java.lang import Integer, Number, NumberFormatException
475-
self.assertEqual(type(Integer).mro(), [polyglot.ForeignClass, polyglot.ForeignInstantiable, polyglot.ForeignAbstractClass, polyglot.ForeignObject, object])
474+
from java.lang import Number, NumberFormatException
475+
from java.util import ArrayList
476+
self.assertEqual(type(ArrayList).mro(), [polyglot.ForeignClass, polyglot.ForeignAbstractClass, polyglot.ForeignInstantiable, polyglot.ForeignObject, object])
476477
self.assertEqual(type(Number).mro(), [polyglot.ForeignAbstractClass, polyglot.ForeignObject, object])
477-
self.assertEqual(type(NumberFormatException).mro(), [polyglot.ForeignClass, polyglot.ForeignInstantiable, polyglot.ForeignAbstractClass, polyglot.ForeignObject, object])
478+
self.assertEqual(type(NumberFormatException).mro(), [polyglot.ForeignClass, polyglot.ForeignAbstractClass, polyglot.ForeignInstantiable, polyglot.ForeignObject, object])
479+
480+
from java.util import ArrayList
481+
l = ArrayList()
482+
assert isinstance(l, ArrayList)
483+
self.assertEqual(getattr(ArrayList, 'class'), l.getClass())
484+
485+
with self.assertRaisesRegex(TypeError, "ForeignInstantiable.__call__\(\) got an unexpected keyword argument 'kwarg'"):
486+
ArrayList(kwarg=42)
478487

479488
def test_java_exceptions(self):
480489
# TODO: more tests
@@ -1040,7 +1049,9 @@ def test_java_map(self):
10401049
h.__init__(a=1, b=2)
10411050
assert h == {'a': 1, 'b': 2}
10421051

1043-
with self.assertRaisesRegex(TypeError, 'invalid instantiation of foreign object'):
1052+
# Because it tries to call ForeignDict.__call__, but ForeignDict is not executable/instantiable,
1053+
# so it resolves to type.__call__, which cannot create a ForeignDict
1054+
with self.assertRaisesRegex(TypeError, "descriptor requires a 'dict' object but received a 'ForeignDict'"):
10441055
type(h).fromkeys(['a', 'b'], 42)
10451056

10461057
def test_java_iterator(self):

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
import java.util.ServiceLoader;
6060
import java.util.logging.Level;
6161

62+
import com.oracle.graal.python.builtins.objects.foreign.ForeignExecutableBuiltins;
63+
import com.oracle.graal.python.builtins.objects.foreign.ForeignInstantiableBuiltins;
64+
import com.oracle.graal.python.builtins.objects.foreign.ForeignIterableBuiltins;
6265
import org.graalvm.nativeimage.ImageInfo;
6366

6467
import com.oracle.graal.python.PythonLanguage;
@@ -259,6 +262,7 @@
259262
import com.oracle.graal.python.builtins.objects.exception.UnicodeTranslateErrorBuiltins;
260263
import com.oracle.graal.python.builtins.objects.floats.FloatBuiltins;
261264
import com.oracle.graal.python.builtins.objects.floats.PFloat;
265+
import com.oracle.graal.python.builtins.objects.foreign.ForeignAbstractClassBuiltins;
262266
import com.oracle.graal.python.builtins.objects.foreign.ForeignBooleanBuiltins;
263267
import com.oracle.graal.python.builtins.objects.foreign.ForeignNumberBuiltins;
264268
import com.oracle.graal.python.builtins.objects.foreign.ForeignObjectBuiltins;
@@ -487,6 +491,10 @@ private static PythonBuiltins[] initializeBuiltins(boolean nativeAccessAllowed,
487491
new ForeignObjectBuiltins(),
488492
new ForeignNumberBuiltins(),
489493
new ForeignBooleanBuiltins(),
494+
new ForeignAbstractClassBuiltins(),
495+
new ForeignExecutableBuiltins(),
496+
new ForeignInstantiableBuiltins(),
497+
new ForeignIterableBuiltins(),
490498
new ListBuiltins(),
491499
new DictBuiltins(),
492500
new DictReprBuiltin(),

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,12 @@ public enum PythonBuiltinClassType implements TruffleObject {
302302

303303
// Foreign
304304
ForeignObject("ForeignObject", J_POLYGLOT, Flags.PUBLIC_BASE_WDICT, ForeignObjectBuiltins.SLOTS),
305-
ForeignNumber("ForeignNumber", J_POLYGLOT, Flags.PUBLIC_BASE_WDICT, FOREIGNNUMBER_M_FLAGS, ForeignNumberBuiltins.SLOTS),
306-
ForeignBoolean("ForeignBoolean", J_POLYGLOT, Flags.PUBLIC_BASE_WDICT, FOREIGNNUMBER_M_FLAGS, ForeignBooleanBuiltins.SLOTS),
305+
ForeignNumber("ForeignNumber", J_POLYGLOT, ForeignObject, Flags.PUBLIC_BASE_WDICT, FOREIGNNUMBER_M_FLAGS, ForeignNumberBuiltins.SLOTS),
306+
ForeignBoolean("ForeignBoolean", J_POLYGLOT, ForeignNumber, Flags.PUBLIC_BASE_WDICT, FOREIGNNUMBER_M_FLAGS, ForeignBooleanBuiltins.SLOTS),
307+
ForeignAbstractClass("ForeignAbstractClass", J_POLYGLOT, ForeignObject, Flags.PUBLIC_BASE_WDICT),
308+
ForeignExecutable("ForeignExecutable", J_POLYGLOT, ForeignObject, Flags.PUBLIC_BASE_WDICT),
309+
ForeignInstantiable("ForeignInstantiable", J_POLYGLOT, ForeignObject, Flags.PUBLIC_BASE_WDICT),
310+
ForeignIterable("ForeignIterable", J_POLYGLOT, ForeignObject, Flags.PUBLIC_BASE_WDICT),
307311

308312
// bz2
309313
BZ2Compressor("BZ2Compressor", "_bz2"),
@@ -627,6 +631,11 @@ private static class Flags {
627631
this(name, module, module, flags);
628632
}
629633

634+
PythonBuiltinClassType(String name, String module, PythonBuiltinClassType base, Flags flags) {
635+
this(name, module, module, flags);
636+
this.base = base;
637+
}
638+
630639
PythonBuiltinClassType(String name, String module, Flags flags, TpSlots slots) {
631640
this(name, module, module, flags, DEFAULT_M_FLAGS, slots);
632641
}
@@ -639,6 +648,11 @@ private static class Flags {
639648
this(name, module, module, flags, methodsFlags, slots);
640649
}
641650

651+
PythonBuiltinClassType(String name, String module, PythonBuiltinClassType base, Flags flags, long methodsFlags, TpSlots slots) {
652+
this(name, module, module, flags, methodsFlags, slots);
653+
this.base = base;
654+
}
655+
642656
PythonBuiltinClassType(String name, String publishInModule, String moduleName, Flags flags) {
643657
this(name, publishInModule, moduleName, flags, DEFAULT_M_FLAGS, TpSlots.createEmpty());
644658
}
@@ -837,9 +851,6 @@ public final Shape getInstanceShape(PythonLanguage lang) {
837851

838852
Boolean.base = PInt;
839853

840-
ForeignNumber.base = ForeignObject;
841-
ForeignBoolean.base = ForeignNumber;
842-
843854
PBaseExceptionGroup.base = PBaseException;
844855
SystemExit.base = PBaseException;
845856
KeyboardInterrupt.base = PBaseException;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright (c) 2017, 2025, Oracle and/or its affiliates.
3+
* Copyright (c) 2014, Regents of the University of California
4+
*
5+
* All rights reserved.
6+
*
7+
* Redistribution and use in source and binary forms, with or without modification, are
8+
* permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice, this list of
11+
* conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
13+
* conditions and the following disclaimer in the documentation and/or other materials provided
14+
* with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
17+
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18+
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19+
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
21+
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
22+
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
24+
* OF THE POSSIBILITY OF SUCH DAMAGE.
25+
*/
26+
27+
package com.oracle.graal.python.builtins.objects.foreign;
28+
29+
import com.oracle.graal.python.builtins.Builtin;
30+
import com.oracle.graal.python.builtins.CoreFunctions;
31+
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
32+
import com.oracle.graal.python.builtins.PythonBuiltins;
33+
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
34+
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
35+
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
36+
import com.oracle.graal.python.runtime.GilNode;
37+
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
38+
import com.oracle.graal.python.util.PythonUtils;
39+
import com.oracle.truffle.api.CompilerDirectives;
40+
import com.oracle.truffle.api.dsl.Cached;
41+
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
42+
import com.oracle.truffle.api.dsl.NodeFactory;
43+
import com.oracle.truffle.api.dsl.Specialization;
44+
import com.oracle.truffle.api.interop.InteropLibrary;
45+
import com.oracle.truffle.api.interop.UnsupportedMessageException;
46+
import com.oracle.truffle.api.library.CachedLibrary;
47+
48+
import java.util.List;
49+
50+
import static com.oracle.graal.python.nodes.SpecialAttributeNames.J___BASES__;
51+
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___INSTANCECHECK__;
52+
53+
/*
54+
* NOTE: We are not using IndirectCallContext here in this file
55+
* because it seems unlikely that these interop messages would call back to Python
56+
* and that we would also need precise frame info for that case.
57+
* Adding it shouldn't hurt peak, but might be a non-trivial overhead in interpreter.
58+
*/
59+
@CoreFunctions(extendClasses = PythonBuiltinClassType.ForeignAbstractClass)
60+
public final class ForeignAbstractClassBuiltins extends PythonBuiltins {
61+
@Override
62+
protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFactories() {
63+
return ForeignAbstractClassBuiltinsFactory.getFactories();
64+
}
65+
66+
@Builtin(name = J___BASES__, minNumOfPositionalArgs = 1, isGetter = true, isSetter = false)
67+
@GenerateNodeFactory
68+
abstract static class BasesNode extends PythonUnaryBuiltinNode {
69+
@Specialization
70+
static Object getBases(Object self,
71+
@Cached PythonObjectFactory factory) {
72+
return factory.createTuple(PythonUtils.EMPTY_OBJECT_ARRAY);
73+
}
74+
}
75+
76+
@Builtin(name = J___INSTANCECHECK__, minNumOfPositionalArgs = 2)
77+
@GenerateNodeFactory
78+
abstract static class InstancecheckNode extends PythonBinaryBuiltinNode {
79+
@Specialization(limit = "3")
80+
static Object check(Object self, Object instance,
81+
@CachedLibrary("self") InteropLibrary lib,
82+
@Cached GilNode gil) {
83+
gil.release(true);
84+
try {
85+
return lib.isMetaInstance(self, instance);
86+
} catch (UnsupportedMessageException e) {
87+
throw CompilerDirectives.shouldNotReachHere();
88+
} finally {
89+
gil.acquire();
90+
}
91+
}
92+
}
93+
94+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Copyright (c) 2017, 2025, Oracle and/or its affiliates.
3+
* Copyright (c) 2014, Regents of the University of California
4+
*
5+
* All rights reserved.
6+
*
7+
* Redistribution and use in source and binary forms, with or without modification, are
8+
* permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice, this list of
11+
* conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
13+
* conditions and the following disclaimer in the documentation and/or other materials provided
14+
* with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
17+
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18+
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19+
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
21+
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
22+
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
24+
* OF THE POSSIBILITY OF SUCH DAMAGE.
25+
*/
26+
27+
package com.oracle.graal.python.builtins.objects.foreign;
28+
29+
import static com.oracle.graal.python.nodes.SpecialMethodNames.J___CALL__;
30+
31+
import java.util.List;
32+
33+
import com.oracle.graal.python.PythonLanguage;
34+
import com.oracle.graal.python.builtins.Builtin;
35+
import com.oracle.graal.python.builtins.CoreFunctions;
36+
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
37+
import com.oracle.graal.python.builtins.PythonBuiltins;
38+
import com.oracle.graal.python.nodes.ErrorMessages;
39+
import com.oracle.graal.python.nodes.PRaiseNode;
40+
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
41+
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
42+
import com.oracle.graal.python.nodes.interop.PForeignToPTypeNode;
43+
import com.oracle.graal.python.runtime.ExecutionContext.IndirectCallContext;
44+
import com.oracle.graal.python.runtime.GilNode;
45+
import com.oracle.graal.python.runtime.IndirectCallData;
46+
import com.oracle.graal.python.runtime.PythonContext;
47+
import com.oracle.graal.python.runtime.exception.PythonErrorType;
48+
import com.oracle.truffle.api.CompilerDirectives;
49+
import com.oracle.truffle.api.dsl.Bind;
50+
import com.oracle.truffle.api.dsl.Cached;
51+
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
52+
import com.oracle.truffle.api.dsl.NodeFactory;
53+
import com.oracle.truffle.api.dsl.Specialization;
54+
import com.oracle.truffle.api.frame.VirtualFrame;
55+
import com.oracle.truffle.api.interop.ArityException;
56+
import com.oracle.truffle.api.interop.InteropLibrary;
57+
import com.oracle.truffle.api.interop.UnsupportedMessageException;
58+
import com.oracle.truffle.api.interop.UnsupportedTypeException;
59+
import com.oracle.truffle.api.library.CachedLibrary;
60+
import com.oracle.truffle.api.nodes.Node;
61+
62+
@CoreFunctions(extendClasses = PythonBuiltinClassType.ForeignExecutable)
63+
public final class ForeignExecutableBuiltins extends PythonBuiltins {
64+
@Override
65+
protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFactories() {
66+
return ForeignExecutableBuiltinsFactory.getFactories();
67+
}
68+
69+
@Builtin(name = J___CALL__, minNumOfPositionalArgs = 1, takesVarArgs = true)
70+
@GenerateNodeFactory
71+
public abstract static class CallNode extends PythonBuiltinNode {
72+
@Specialization
73+
static Object doInteropCall(VirtualFrame frame, Object callee, Object[] arguments,
74+
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
75+
@Cached("createFor(this)") IndirectCallData indirectCallData,
76+
@CachedLibrary(limit = "4") InteropLibrary lib,
77+
@Cached PForeignToPTypeNode toPTypeNode,
78+
@Cached GilNode gil,
79+
@Cached PRaiseNode.Lazy raiseNode) {
80+
PythonLanguage language = PythonLanguage.get(inliningTarget);
81+
PythonContext context = PythonContext.get(inliningTarget);
82+
try {
83+
Object state = IndirectCallContext.enter(frame, language, context, indirectCallData);
84+
gil.release(true);
85+
try {
86+
return toPTypeNode.executeConvert(lib.execute(callee, arguments));
87+
} finally {
88+
gil.acquire();
89+
IndirectCallContext.exit(frame, language, context, state);
90+
}
91+
} catch (ArityException | UnsupportedTypeException e) {
92+
throw raiseNode.get(inliningTarget).raise(PythonErrorType.TypeError, ErrorMessages.INVALID_INSTANTIATION_OF_FOREIGN_OBJ);
93+
} catch (UnsupportedMessageException e) {
94+
throw CompilerDirectives.shouldNotReachHere(e);
95+
}
96+
}
97+
}
98+
99+
}

0 commit comments

Comments
 (0)