Skip to content

Commit b8aac32

Browse files
committed
remove duplicate functionality of PyOSFSPathNode
1 parent 2a23366 commit b8aac32

File tree

3 files changed

+12
-27
lines changed

3 files changed

+12
-27
lines changed

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

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
import com.oracle.graal.python.lib.PyLongAsLongAndOverflowNode;
8181
import com.oracle.graal.python.lib.PyLongAsLongNode;
8282
import com.oracle.graal.python.lib.PyNumberIndexNode;
83+
import com.oracle.graal.python.lib.PyOSFSPathNode;
8384
import com.oracle.graal.python.lib.PyObjectAsFileDescriptor;
8485
import com.oracle.graal.python.lib.PyObjectSizeNode;
8586
import com.oracle.graal.python.nodes.ErrorMessages;
@@ -2130,27 +2131,10 @@ PNone kill(VirtualFrame frame, long pid, int signal,
21302131
@GenerateNodeFactory
21312132
// Can be used as an equivalent of PyOS_FSPath()
21322133
public abstract static class FspathNode extends PythonUnaryBuiltinNode {
2133-
2134-
@Specialization(guards = "isPath(value)")
2135-
static Object doTrivial(Object value) {
2136-
return value;
2137-
}
2138-
2139-
@Specialization(guards = "!isPath(value)")
2140-
Object callFspath(VirtualFrame frame, Object value,
2141-
@Cached("create(T___FSPATH__)") LookupAndCallUnaryNode callFSPath) {
2142-
Object pathObject = callFSPath.executeObject(frame, value);
2143-
if (isPath(pathObject)) {
2144-
return pathObject;
2145-
} else if (pathObject == PNone.NO_VALUE) {
2146-
throw raise(TypeError, ErrorMessages.EXPECTED_STR_BYTE_OSPATHLIKE_OBJ, value);
2147-
} else {
2148-
throw raise(TypeError, ErrorMessages.EXPECTED_FSPATH_TO_RETURN_STR_OR_BYTES, value, pathObject);
2149-
}
2150-
}
2151-
2152-
protected static boolean isPath(Object obj) {
2153-
return PGuards.isString(obj) || obj instanceof PBytes;
2134+
@Specialization
2135+
static Object doTrivial(VirtualFrame frame, Object value,
2136+
@Cached PyOSFSPathNode fsPathNode) {
2137+
return fsPathNode.execute(frame, value);
21542138
}
21552139
}
21562140

@@ -2243,14 +2227,14 @@ abstract static class ObjectToOpaquePathNode extends PNodeWithRaise {
22432227

22442228
@Specialization(guards = "!checkEmpty")
22452229
static Object noCheck(VirtualFrame frame, Object obj, @SuppressWarnings("unused") boolean checkEmpty,
2246-
@Cached FspathNode fspathNode,
2230+
@Cached PyOSFSPathNode fspathNode,
22472231
@Cached StringOrBytesToOpaquePathNode stringOrBytesToOpaquePathNode) {
22482232
return stringOrBytesToOpaquePathNode.execute(fspathNode.execute(frame, obj));
22492233
}
22502234

22512235
@Specialization(guards = "checkEmpty")
22522236
Object withCheck(VirtualFrame frame, Object obj, @SuppressWarnings("unused") boolean checkEmpty,
2253-
@Cached FspathNode fspathNode,
2237+
@Cached PyOSFSPathNode fspathNode,
22542238
@Cached PyObjectSizeNode sizeNode,
22552239
@Cached StringOrBytesToOpaquePathNode stringOrBytesToOpaquePathNode) {
22562240
Object stringOrBytes = fspathNode.execute(frame, obj);
@@ -2415,7 +2399,7 @@ public static PBytes opaquePathToBytes(Object opaquePath, PosixSupportLibrary po
24152399
public abstract static class FsConverterNode extends ArgumentCastNodeWithRaise {
24162400
@Specialization
24172401
static PBytes convert(VirtualFrame frame, Object value,
2418-
@Cached FspathNode fspathNode,
2402+
@Cached PyOSFSPathNode fspathNode,
24192403
@Cached StringOrBytesToBytesNode stringOrBytesToBytesNode) {
24202404
return stringOrBytesToBytesNode.execute(fspathNode.execute(frame, value));
24212405
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesNodes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
import com.oracle.graal.python.annotations.ClinicConverterFactory.ArgumentIndex;
6161
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
6262
import com.oracle.graal.python.builtins.modules.CodecsModuleBuiltins;
63-
import com.oracle.graal.python.builtins.modules.PosixModuleBuiltins;
6463
import com.oracle.graal.python.builtins.modules.SysModuleBuiltins;
6564
import com.oracle.graal.python.builtins.objects.PNone;
6665
import com.oracle.graal.python.builtins.objects.buffer.BufferFlags;
@@ -79,6 +78,7 @@
7978
import com.oracle.graal.python.lib.PyIndexCheckNode;
8079
import com.oracle.graal.python.lib.PyNumberAsSizeNode;
8180
import com.oracle.graal.python.lib.PyNumberIndexNode;
81+
import com.oracle.graal.python.lib.PyOSFSPathNode;
8282
import com.oracle.graal.python.lib.PyObjectGetIter;
8383
import com.oracle.graal.python.nodes.ErrorMessages;
8484
import com.oracle.graal.python.nodes.PGuards;
@@ -848,7 +848,7 @@ TruffleString doit(VirtualFrame frame, Object value,
848848
@CachedLibrary(limit = "3") PythonBufferAcquireLibrary bufferAcquireLib,
849849
@CachedLibrary(limit = "3") PythonBufferAccessLibrary bufferLib,
850850
@Cached CastToTruffleStringNode toString,
851-
@Cached PosixModuleBuiltins.FspathNode fsPath,
851+
@Cached PyOSFSPathNode fsPath,
852852
@Cached TruffleString.FromByteArrayNode fromByteArrayNode,
853853
@Cached TruffleString.SwitchEncodingNode switchEncodingNode) {
854854
Object path = fsPath.execute(frame, value);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ static Object callFspath(VirtualFrame frame, Object object,
9696
throw raiseNode.raise(TypeError, ErrorMessages.EXPECTED_STR_BYTE_OSPATHLIKE_OBJ, object);
9797
}
9898
Object result = callFSPath.executeObject(frame, fspathMethod, object);
99-
if (isJavaString(result) || result instanceof TruffleString || result instanceof PString || result instanceof PBytes) {
99+
assert !isJavaString(result);
100+
if (result instanceof TruffleString || result instanceof PString || result instanceof PBytes) {
100101
return result;
101102
}
102103
throw raiseNode.raise(TypeError, ErrorMessages.EXPECTED_FSPATH_TO_RETURN_STR_OR_BYTES, object, result);

0 commit comments

Comments
 (0)