Skip to content

Commit bd7ad3c

Browse files
committed
[GR-55955] Fixes for virtualenv
PullRequest: graalpython/3618
2 parents 824103a + 5753d47 commit bd7ad3c

File tree

10 files changed

+63
-35
lines changed

10 files changed

+63
-35
lines changed

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_unicode.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,19 @@ class TestPyUnicode(CPyExtTestCase):
946946
cmpfunc=unhandled_error_compare
947947
)
948948

949+
test_PyUnicode_EncodeLocale = CPyExtFunction(
950+
# We don't want to make tests dependent on the current locale, so just test that ascii works
951+
lambda args: args[0].encode('ascii', args[1]),
952+
lambda: (
953+
("hello", "strict"),
954+
(UnicodeSubclass("asdf"), "strict"),
955+
),
956+
resultspec="O",
957+
argspec='Os',
958+
arguments=["PyObject* str", "const char* errors"],
959+
cmpfunc=unhandled_error_compare
960+
)
961+
949962
test_PyUnicode_AsUnicodeEscapeString = CPyExtFunction(
950963
_reference_as_unicode_escape_string,
951964
lambda: (

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,10 @@ public void postInitialize(Python3Core core) {
330330
}
331331
Object key, val;
332332
if (PythonOS.getPythonOS() == PythonOS.PLATFORM_WIN32) {
333+
if (entry.getKey().startsWith("=")) {
334+
// Hidden variable, shouldn't be visible to python
335+
continue;
336+
}
333337
key = toTruffleStringUncached(entry.getKey());
334338
} else {
335339
key = core.factory().createBytes(entry.getKey().getBytes());

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextUnicodeBuiltins.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
import com.oracle.graal.python.builtins.modules.BuiltinFunctions.ChrNode;
9090
import com.oracle.graal.python.builtins.modules.CodecsModuleBuiltins;
9191
import com.oracle.graal.python.builtins.modules.CodecsModuleBuiltins.CodecsEncodeNode;
92+
import com.oracle.graal.python.builtins.modules.CodecsTruffleModuleBuiltins;
9293
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApi5BuiltinNode;
9394
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApi6BuiltinNode;
9495
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiBinaryBuiltinNode;
@@ -954,6 +955,18 @@ static PBytes fromObject(Object s,
954955
}
955956
}
956957

958+
@CApiBuiltin(ret = PyObjectTransfer, args = {PyObject, ConstCharPtrAsTruffleString}, call = Direct)
959+
abstract static class PyUnicode_EncodeLocale extends CApiBinaryBuiltinNode {
960+
@Specialization
961+
static Object encode(Object s, Object errors,
962+
@Bind("this") Node inliningTarget,
963+
@Cached CastToTruffleStringNode cast,
964+
@Cached CodecsTruffleModuleBuiltins.GetEncodingNode getEncodingNode,
965+
@Cached CodecsModuleBuiltins.EncodeNode encodeNode) {
966+
return encodeNode.execute(null, cast.execute(inliningTarget, s), getEncodingNode.execute(null), errors);
967+
}
968+
}
969+
957970
@CApiBuiltin(ret = PyObjectTransfer, args = {CONST_WCHAR_PTR, Py_ssize_t}, call = Direct)
958971
abstract static class PyUnicode_FromWideChar extends CApiBinaryBuiltinNode {
959972
@Specialization

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiFunction.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,6 @@ public final class CApiFunction {
937937
@CApiBuiltin(name = "PyUnicode_DecodeUTF7", ret = PyObject, args = {ConstCharPtrAsTruffleString, Py_ssize_t, ConstCharPtrAsTruffleString}, call = NotImplemented)
938938
@CApiBuiltin(name = "PyUnicode_DecodeUTF7Stateful", ret = PyObject, args = {ConstCharPtrAsTruffleString, Py_ssize_t, ConstCharPtrAsTruffleString, PY_SSIZE_T_PTR}, call = NotImplemented)
939939
@CApiBuiltin(name = "PyUnicode_DecodeUnicodeEscape", ret = PyObject, args = {ConstCharPtrAsTruffleString, Py_ssize_t, ConstCharPtrAsTruffleString}, call = NotImplemented)
940-
@CApiBuiltin(name = "PyUnicode_EncodeLocale", ret = PyObject, args = {PyObject, ConstCharPtrAsTruffleString}, call = NotImplemented)
941940
@CApiBuiltin(name = "PyUnicode_FSDecoder", ret = Int, args = {PyObject, Pointer}, call = NotImplemented)
942941
@CApiBuiltin(name = "PyUnicode_Fill", ret = Py_ssize_t, args = {PyObject, Py_ssize_t, Py_ssize_t, PY_UCS4}, call = NotImplemented)
943942
@CApiBuiltin(name = "PyUnicode_GetDefaultEncoding", ret = ConstCharPtrAsTruffleString, args = {}, call = NotImplemented)

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberCheckNode.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@
6666
public abstract class PyNumberCheckNode extends PNodeWithContext {
6767
public abstract boolean execute(Node inliningTarget, Object object);
6868

69+
public static boolean executeUncached(Object object) {
70+
return PyNumberCheckNodeGen.getUncached().execute(null, object);
71+
}
72+
6973
@Specialization
7074
static boolean doString(@SuppressWarnings("unused") TruffleString object) {
7175
return false;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberIndexNode.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 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
@@ -86,6 +86,10 @@
8686
public abstract class PyNumberIndexNode extends PNodeWithContext {
8787
public abstract Object execute(Frame frame, Node inliningTarget, Object object);
8888

89+
public static Object executeUncached(Object object) {
90+
return PyNumberIndexNodeGen.getUncached().execute(null, null, object);
91+
}
92+
8993
@Specialization
9094
static int doInt(int object) {
9195
return object;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupAndCallBinaryNode.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
4747
import com.oracle.graal.python.nodes.PGuards;
4848
import com.oracle.graal.python.nodes.PNodeWithContext;
49-
import com.oracle.graal.python.nodes.object.GetClassNode;
5049
import com.oracle.graal.python.runtime.PythonOptions;
5150
import com.oracle.graal.python.util.Supplier;
5251
import com.oracle.truffle.api.CompilerDirectives;
@@ -124,10 +123,6 @@ public static LookupAndCallBinaryNode create(SpecialMethodSlot slot, SpecialMeth
124123
return LookupAndCallReversibleBinaryNodeGen.create(slot, rslot, null, alwaysCheckReverse, ignoreDescriptorException);
125124
}
126125

127-
protected static Object getMethod(Object receiver, TruffleString methodName) {
128-
return LookupSpecialMethodNode.Dynamic.executeUncached(null, GetClassNode.executeUncached(receiver), methodName, receiver);
129-
}
130-
131126
@ImportStatic(PGuards.class)
132127
@GenerateInline
133128
@GenerateCached(false)

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupSpecialMethodNode.java

Lines changed: 3 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
@@ -87,8 +87,8 @@ public abstract static class Dynamic extends Node {
8787

8888
public abstract Object execute(Frame frame, Node inliningTarget, Object type, TruffleString name, Object receiver);
8989

90-
public static Object executeUncached(Frame frame, Object type, TruffleString name, Object receiver) {
91-
return LookupSpecialMethodNodeGen.DynamicNodeGen.getUncached().execute(frame, null, type, name, receiver);
90+
public static Object executeUncached(Object type, TruffleString name, Object receiver) {
91+
return LookupSpecialMethodNodeGen.DynamicNodeGen.getUncached().execute(null, null, type, name, receiver);
9292
}
9393

9494
@Specialization

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/FormatProcessor.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
*/
77
package com.oracle.graal.python.runtime.formatting;
88

9-
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___INDEX__;
10-
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___INT__;
11-
import static com.oracle.graal.python.runtime.exception.PythonErrorType.AttributeError;
129
import static com.oracle.graal.python.runtime.exception.PythonErrorType.MemoryError;
1310
import static com.oracle.graal.python.runtime.exception.PythonErrorType.OverflowError;
1411
import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
@@ -20,19 +17,19 @@
2017

2118
import com.oracle.graal.python.builtins.Python3Core;
2219
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
23-
import com.oracle.graal.python.builtins.objects.PNone;
24-
import com.oracle.graal.python.builtins.objects.PythonAbstractObject;
2520
import com.oracle.graal.python.builtins.objects.function.PKeyword;
2621
import com.oracle.graal.python.builtins.objects.ints.PInt;
2722
import com.oracle.graal.python.builtins.objects.tuple.TupleBuiltins;
2823
import com.oracle.graal.python.lib.PyFloatAsDoubleNode;
24+
import com.oracle.graal.python.lib.PyNumberCheckNode;
25+
import com.oracle.graal.python.lib.PyNumberIndexNode;
2926
import com.oracle.graal.python.lib.PyObjectGetItem;
3027
import com.oracle.graal.python.lib.PyObjectSizeNode;
3128
import com.oracle.graal.python.nodes.ErrorMessages;
3229
import com.oracle.graal.python.nodes.PGuards;
3330
import com.oracle.graal.python.nodes.PRaiseNode;
34-
import com.oracle.graal.python.nodes.attributes.LookupAttributeInMRONode;
3531
import com.oracle.graal.python.nodes.call.CallNode;
32+
import com.oracle.graal.python.nodes.call.special.LookupSpecialMethodNode;
3633
import com.oracle.graal.python.nodes.classes.IsSubtypeNodeGen;
3734
import com.oracle.graal.python.nodes.object.GetClassNode;
3835
import com.oracle.graal.python.nodes.util.CannotCastException;
@@ -94,7 +91,7 @@ <F extends InternalFormat.Formatter> F setupFormat(F f) {
9491
protected abstract boolean isMapping(Object obj);
9592

9693
static Object lookupAttribute(Object owner, TruffleString name) {
97-
return LookupAttributeInMRONode.Dynamic.getUncached().execute(GetClassNode.executeUncached(owner), name);
94+
return LookupSpecialMethodNode.Dynamic.executeUncached(GetClassNode.executeUncached(owner), name, owner);
9895
}
9996

10097
static Object call(Object callable, Object... args) {
@@ -190,20 +187,18 @@ protected final Object asNumber(Object arg, char specType) {
190187
} else if (arg instanceof Boolean) {
191188
// Fast path for simple booleans
192189
return (Boolean) arg ? 1 : 0;
193-
} else if (arg instanceof PythonAbstractObject) {
194-
// Try again with arg.__int__() or __index__() depending on the spec type
190+
} else if (PyNumberCheckNode.executeUncached(arg)) {
195191
try {
196-
TruffleString magicName = useIndexMagicMethod(specType) ? T___INDEX__ : T___INT__;
197-
Object attribute = lookupAttribute(arg, magicName);
198-
if (!(attribute instanceof PNone)) {
199-
return call(attribute, arg);
192+
if (useIndexMagicMethod(specType)) {
193+
return PyNumberIndexNode.executeUncached(arg);
194+
} else {
195+
return CallNode.executeUncached(PythonBuiltinClassType.PInt, arg);
200196
}
201197
} catch (PException e) {
202-
e.expectUncached(AttributeError);
203-
// No __int__/__index__ defined (at Python level)
198+
e.expectUncached(TypeError);
204199
}
205200
}
206-
return arg;
201+
return null;
207202
}
208203

209204
protected double asFloat(Object arg) {

graalpython/lib-python/3/subprocess.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,8 @@
7272
except ModuleNotFoundError:
7373
_mswindows = False
7474
else:
75-
# Truffle change
76-
# _mswindows = True
77-
_mswindows = False
75+
# GraalPy change: under emulated posix, use the posix APIs even under windows
76+
_mswindows = not (sys.implementation.name == 'graalpy' and __graalpython__.posix_module_backend() == 'java')
7877

7978
# wasm32-emscripten and wasm32-wasi do not support processes
8079
_can_fork_exec = sys.platform not in {"emscripten", "wasi"}
@@ -850,12 +849,14 @@ def __init__(self, args, bufsize=-1, executable=None,
850849
if pass_fds and not close_fds:
851850
warnings.warn("pass_fds overriding close_fds.", RuntimeWarning)
852851
close_fds = True
853-
if startupinfo is not None:
854-
raise ValueError("startupinfo is only supported on Windows "
855-
"platforms")
856-
if creationflags != 0:
857-
raise ValueError("creationflags is only supported on Windows "
858-
"platforms")
852+
# GraalPy change: allow and ignore windows-specific flags on windows on posix backend
853+
if sys.platform != 'win32':
854+
if startupinfo is not None:
855+
raise ValueError("startupinfo is only supported on Windows "
856+
"platforms")
857+
if creationflags != 0:
858+
raise ValueError("creationflags is only supported on Windows "
859+
"platforms")
859860

860861
self.args = args
861862
self.stdin = None

0 commit comments

Comments
 (0)