|
41 | 41 | package com.oracle.graal.python.builtins.objects.object;
|
42 | 42 |
|
43 | 43 | import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError;
|
| 44 | +import static com.oracle.graal.python.nodes.SpecialMethodNames.__STR__; |
44 | 45 |
|
45 | 46 | import com.oracle.graal.python.PythonLanguage;
|
46 | 47 | import com.oracle.graal.python.builtins.PythonBuiltinClassType;
|
@@ -251,18 +252,12 @@ static boolean isForeignObject(Object receiver,
|
251 | 252 | }
|
252 | 253 |
|
253 | 254 | @ExportMessage
|
254 |
| - static Object asPString(Object receiver, |
255 |
| - @CachedLibrary(limit = "1") InteropLibrary lib, |
256 |
| - @Exclusive @Cached PRaiseNode raise) { |
257 |
| - if (lib.isString(receiver)) { |
258 |
| - try { |
259 |
| - return lib.asString(receiver); |
260 |
| - } catch (UnsupportedMessageException e) { |
261 |
| - CompilerDirectives.transferToInterpreterAndInvalidate(); |
262 |
| - throw new IllegalStateException(e); |
263 |
| - } |
264 |
| - } |
265 |
| - throw raise.raise(PythonBuiltinClassType.TypeError, ErrorMessages.EXPECTED_STR_BYTE_OSPATHLIKE_OBJ, receiver); |
| 255 | + static Object asPStringWithState(Object receiver, ThreadState state, |
| 256 | + @CachedLibrary("receiver") PythonObjectLibrary plib) { |
| 257 | + // Needs to go through ForeignObjectBuiltins.StrNode |
| 258 | + // The thread state may be necessary when the object is an array-like that contains python |
| 259 | + // objects whose __repr__ will be called by the library |
| 260 | + return plib.lookupAndCallSpecialMethodWithState(receiver, state, __STR__); |
266 | 261 | }
|
267 | 262 |
|
268 | 263 | @ExportMessage
|
|
0 commit comments