|
48 | 48 | import com.oracle.graal.python.builtins.objects.function.PKeyword;
|
49 | 49 | import com.oracle.graal.python.builtins.objects.type.LazyPythonClass;
|
50 | 50 | import com.oracle.graal.python.builtins.objects.type.PythonClass;
|
| 51 | +import com.oracle.graal.python.nodes.argument.positional.PositionalArgumentsNode; |
51 | 52 | import com.oracle.graal.python.nodes.attributes.LookupAttributeInMRONode;
|
52 | 53 | import com.oracle.graal.python.nodes.attributes.WriteAttributeToObjectNode;
|
53 | 54 | import com.oracle.graal.python.nodes.call.special.CallVarargsMethodNode;
|
|
66 | 67 | import com.oracle.truffle.api.nodes.Node;
|
67 | 68 | import com.oracle.truffle.api.nodes.RootNode;
|
68 | 69 | import com.oracle.truffle.api.profiles.ConditionProfile;
|
69 |
| -import java.util.ArrayList; |
70 |
| -import java.util.List; |
71 | 70 |
|
72 | 71 | public abstract class PNodeWithContext extends Node {
|
73 | 72 | @Child private PythonObjectFactory factory;
|
@@ -130,54 +129,31 @@ public final PException raiseIndexError() {
|
130 | 129 | }
|
131 | 130 |
|
132 | 131 | public final PException raiseOSError(VirtualFrame frame, int errno) {
|
133 |
| - return raiseOSError(frame, errno, null, null, null); |
| 132 | + return raiseOSError(frame, new Object[]{errno}); |
134 | 133 | }
|
135 | 134 |
|
136 | 135 | public final PException raiseOSError(VirtualFrame frame, OSErrorEnum oserror) {
|
137 |
| - return raiseOSError(frame, oserror.getNumber(), oserror.getMessage(), null, null); |
| 136 | + return raiseOSError(frame, new Object[]{oserror.getNumber(), oserror.getMessage()}); |
138 | 137 | }
|
139 | 138 |
|
140 | 139 | public final PException raiseOSError(VirtualFrame frame, OSErrorEnum oserror, String filename) {
|
141 |
| - return raiseOSError(frame, oserror.getNumber(), oserror.getMessage(), filename, null); |
| 140 | + Object[] args = new Object[]{oserror.getNumber(), oserror.getMessage(), filename}; |
| 141 | + return raiseOSError(frame, args); |
142 | 142 | }
|
143 | 143 |
|
144 | 144 | public final PException raiseOSError(VirtualFrame frame, OSErrorEnum oserror, String filename, String filename2) {
|
145 |
| - return raiseOSError(frame, oserror.getNumber(), oserror.getMessage(), filename, filename2); |
| 145 | + Object[] args = new Object[]{oserror.getNumber(), oserror.getMessage(), filename, PNone.NONE, filename2}; |
| 146 | + return raiseOSError(frame, args); |
146 | 147 | }
|
147 | 148 |
|
148 |
| - public final PException raiseOSError(VirtualFrame frame, int errno, String errorstr, String filename, String filename2) { |
149 |
| - if (getNewFuncNode == null) { |
| 149 | + public final PException raiseOSError(VirtualFrame frame, Object[] arg) { |
| 150 | + if (callNode == null) { |
150 | 151 | CompilerDirectives.transferToInterpreterAndInvalidate();
|
151 |
| - getNewFuncNode = insert(LookupAttributeInMRONode.create("__new__")); |
| 152 | + callNode = insert(CallVarargsMethodNode.create()); |
152 | 153 | }
|
153 |
| - Object newFunc = getNewFuncNode.execute(PythonBuiltinClassType.OSError); |
154 |
| - if (newFunc != PNone.NO_VALUE) { |
155 |
| - if (callNode == null) { |
156 |
| - CompilerDirectives.transferToInterpreterAndInvalidate(); |
157 |
| - callNode = insert(CallVarargsMethodNode.create()); |
158 |
| - } |
159 |
| - Object[] args = createArgumentsForOSError(errno, errorstr, filename, filename2); |
160 |
| - PBaseException error = (PBaseException) callNode.execute(frame, newFunc, args, new PKeyword[]{}); |
161 |
| - return raise(error); |
162 |
| - } |
163 |
| - return raise(factory().createBaseException(PythonBuiltinClassType.OSError)); |
164 |
| - } |
165 |
| - |
166 |
| - private Object[] createArgumentsForOSError(int errno, String errorstr, String filename, String filename2) { |
167 |
| - List<Object> result = new ArrayList<>(); |
168 |
| - result.add(getBuiltinPythonClass(PythonBuiltinClassType.OSError)); |
169 |
| - result.add(errno); |
170 |
| - if (errorstr != null && !errorstr.isEmpty()) { |
171 |
| - result.add(errorstr); |
172 |
| - } |
173 |
| - if (filename != null && !filename.isEmpty()) { |
174 |
| - result.add(filename); |
175 |
| - if (filename2 != null && !filename2.isEmpty()) { |
176 |
| - result.add(PNone.NONE); // instead winerror |
177 |
| - result.add(filename2); |
178 |
| - } |
179 |
| - } |
180 |
| - return result.toArray(); |
| 154 | + Object[] args = PositionalArgumentsNode.prependArgument(getBuiltinPythonClass(PythonBuiltinClassType.OSError), arg, arg.length + 1); |
| 155 | + PBaseException error = (PBaseException) callNode.execute(frame, getBuiltinPythonClass(PythonBuiltinClassType.OSError), args, new PKeyword[]{}); |
| 156 | + return raise(error); |
181 | 157 | }
|
182 | 158 |
|
183 | 159 | public final PythonClass getPythonClass(LazyPythonClass lazyClass, ConditionProfile profile) {
|
|
0 commit comments