Skip to content

Commit 95f2714

Browse files
committed
[GR-26079] Fix stringifying foreign objects
PullRequest: graalpython/1271
2 parents 308f589 + 2ed4ea6 commit 95f2714

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/DefaultPythonObjectExports.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
package com.oracle.graal.python.builtins.objects.object;
4242

4343
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError;
44+
import static com.oracle.graal.python.nodes.SpecialMethodNames.__STR__;
4445

4546
import com.oracle.graal.python.PythonLanguage;
4647
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
@@ -251,18 +252,12 @@ static boolean isForeignObject(Object receiver,
251252
}
252253

253254
@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__);
266261
}
267262

268263
@ExportMessage

0 commit comments

Comments
 (0)