55
55
import com .oracle .graal .python .builtins .Builtin ;
56
56
import com .oracle .graal .python .builtins .CoreFunctions ;
57
57
import com .oracle .graal .python .builtins .PythonBuiltins ;
58
- import com .oracle .graal .python .builtins .modules .PosixModuleBuiltins .FspathNode ;
58
+ import com .oracle .graal .python .builtins .modules .PosixModuleBuiltins .ObjectToOpaquePathNode ;
59
59
import com .oracle .graal .python .builtins .modules .PosixSubprocessModuleBuiltinsClinicProviders .NewForkExecNodeClinicProviderGen ;
60
60
import com .oracle .graal .python .builtins .modules .PosixSubprocessModuleBuiltinsFactory .EnvConversionNodeGen ;
61
61
import com .oracle .graal .python .builtins .modules .PosixSubprocessModuleBuiltinsFactory .ProcessArgsConversionNodeGen ;
62
62
import com .oracle .graal .python .builtins .objects .PNone ;
63
63
import com .oracle .graal .python .builtins .objects .bytes .BytesNodes .ToBytesNode ;
64
- import com .oracle .graal .python .builtins .objects .bytes .PBytes ;
65
64
import com .oracle .graal .python .builtins .objects .common .SequenceNodes .GetSequenceStorageNode ;
66
65
import com .oracle .graal .python .builtins .objects .common .SequenceStorageNodes .GetItemNode ;
67
66
import com .oracle .graal .python .builtins .objects .common .SequenceStorageNodes .LenNode ;
68
67
import com .oracle .graal .python .builtins .objects .object .PythonObjectLibrary ;
69
- import com .oracle .graal .python .builtins .objects .str .PString ;
70
68
import com .oracle .graal .python .builtins .objects .tuple .PTuple ;
71
69
import com .oracle .graal .python .nodes .ErrorMessages ;
72
70
import com .oracle .graal .python .nodes .PGuards ;
73
- import com .oracle .graal .python .nodes .PNodeWithRaise ;
74
71
import com .oracle .graal .python .nodes .builtins .ListNodes .FastConstructListNode ;
75
72
import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
76
73
import com .oracle .graal .python .nodes .function .builtins .PythonClinicBuiltinNode ;
79
76
import com .oracle .graal .python .nodes .object .IsBuiltinClassProfile ;
80
77
import com .oracle .graal .python .nodes .util .CannotCastException ;
81
78
import com .oracle .graal .python .nodes .util .CastToJavaIntExactNode ;
82
- import com .oracle .graal .python .nodes .util .CastToJavaStringNode ;
83
79
import com .oracle .graal .python .runtime .PosixSupportLibrary ;
84
80
import com .oracle .graal .python .runtime .PosixSupportLibrary .PosixException ;
85
81
import com .oracle .graal .python .runtime .PythonContext ;
96
92
import com .oracle .truffle .api .dsl .Specialization ;
97
93
import com .oracle .truffle .api .frame .VirtualFrame ;
98
94
import com .oracle .truffle .api .library .CachedLibrary ;
99
- import com .oracle .truffle .api .nodes .Node ;
100
95
101
96
@ CoreFunctions (defineModule = "_posixsubprocess" )
102
97
public class PosixSubprocessModuleBuiltins extends PythonBuiltins {
@@ -105,61 +100,6 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
105
100
return PosixSubprocessModuleBuiltinsFactory .getFactories ();
106
101
}
107
102
108
- /**
109
- * Helper node that accepts either str or bytes and converts it to a representation specific to
110
- * the {@link PosixSupportLibrary} in use. Basically equivalent of
111
- * {@code PyUnicode_EncodeFSDefault}.
112
- */
113
- abstract static class StringOrBytesToOpaquePathNode extends PNodeWithRaise {
114
- abstract Object execute (Object obj );
115
-
116
- @ Specialization (limit = "1" )
117
- Object doString (String str ,
118
- @ CachedContext (PythonLanguage .class ) PythonContext context ,
119
- @ CachedLibrary ("context.getPosixSupport()" ) PosixSupportLibrary posixLib ) {
120
- return checkPath (posixLib .createPathFromString (context .getPosixSupport (), str ));
121
- }
122
-
123
- @ Specialization (limit = "1" )
124
- Object doPString (PString pstr ,
125
- @ Cached CastToJavaStringNode castToJavaStringNode ,
126
- @ CachedContext (PythonLanguage .class ) PythonContext context ,
127
- @ CachedLibrary ("context.getPosixSupport()" ) PosixSupportLibrary posixLib ) {
128
- String str = castToJavaStringNode .execute (pstr );
129
- return checkPath (posixLib .createPathFromString (context .getPosixSupport (), str ));
130
- }
131
-
132
- @ Specialization (limit = "1" )
133
- Object doBytes (PBytes bytes ,
134
- @ Cached ToBytesNode toBytesNode ,
135
- @ CachedContext (PythonLanguage .class ) PythonContext context ,
136
- @ CachedLibrary ("context.getPosixSupport()" ) PosixSupportLibrary posixLib ) {
137
- return checkPath (posixLib .createPathFromBytes (context .getPosixSupport (), toBytesNode .execute (bytes )));
138
- }
139
-
140
- private Object checkPath (Object path ) {
141
- if (path == null ) {
142
- throw raise (ValueError , ErrorMessages .EMBEDDED_NULL_BYTE );
143
- }
144
- return path ;
145
- }
146
- }
147
-
148
- /**
149
- * Similar to {@code PyUnicode_FSConverter}, but the actual conversion is delegated to the
150
- * {@link PosixSupportLibrary} implementation.
151
- */
152
- abstract static class ObjectToOpaquePathNode extends Node {
153
- abstract Object execute (VirtualFrame frame , Object obj );
154
-
155
- @ Specialization
156
- Object doIt (VirtualFrame frame , Object obj ,
157
- @ Cached FspathNode fspathNode ,
158
- @ Cached StringOrBytesToOpaquePathNode stringOrBytesToOpaquePathNode ) {
159
- return stringOrBytesToOpaquePathNode .execute (fspathNode .call (frame , obj ));
160
- }
161
- }
162
-
163
103
/**
164
104
* Helper converter which iterates the argv argument and converts each element to the opaque
165
105
* path representation used by {@link PosixSupportLibrary}.
0 commit comments