Skip to content

Commit 39e9a6b

Browse files
committed
[GR-21045] Add missing guards to CastToPathNode::doObject specialization
PullRequest: graalpython/810
2 parents b65b050 + a1f446f commit 39e9a6b

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018, 2020, 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
@@ -83,6 +83,13 @@ def test_execv_with_env(self):
8383
assert 'the_text' in result.readline()
8484
self.delete_file(new_file_path, cwd)
8585

86+
def test_path_respecialization(self):
87+
# regression test for https://github.com/graalvm/graalpython/issues/124
88+
from pathlib import PurePath
89+
p = PurePath(".")
90+
for path in [p, "."]:
91+
os.scandir(path)
92+
8693
def create_file(self):
8794
cwd = os.getcwd()
8895
new_file_path = os.path.join(cwd , 'myscript.sh')

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToPathNode.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2020, 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
@@ -48,6 +48,7 @@
4848
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.ToByteArrayNode;
4949
import com.oracle.graal.python.builtins.objects.memoryview.PMemoryView;
5050
import com.oracle.graal.python.builtins.objects.str.PString;
51+
import com.oracle.graal.python.nodes.PGuards;
5152
import com.oracle.graal.python.nodes.PRaiseNode;
5253
import com.oracle.graal.python.nodes.SpecialMethodNames;
5354
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
@@ -63,7 +64,7 @@
6364
/**
6465
* Converts a Python object to a Path string
6566
*/
66-
@ImportStatic(SpecialMethodNames.class)
67+
@ImportStatic({SpecialMethodNames.class, PGuards.class})
6768
public abstract class CastToPathNode extends Node {
6869
private static final String ERROR_MESSAGE = "path should be string, bytes or os.PathLike, not %p";
6970

@@ -108,7 +109,7 @@ String doPString(PString x) {
108109
return x.getValue();
109110
}
110111

111-
@Specialization
112+
@Specialization(guards = {"!isString(object)", "!isBytes(object)", "!isMemoryView(object)"})
112113
String doObject(VirtualFrame frame, Object object,
113114
@Cached("createClassProfile()") ValueProfile resultTypeProfile,
114115
@Cached PRaiseNode raise,

0 commit comments

Comments
 (0)