Skip to content

Commit 0af6eeb

Browse files
committed
Use polyglot from string in HPyUnicodeFromString
1 parent 38d980b commit 0af6eeb

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContextFunctions.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -77,9 +77,11 @@
7777
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.CreateMethodNode;
7878
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.FromCharPointerNode;
7979
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.GetLLVMType;
80+
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.PCallCapiFunction;
8081
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.ResolveHandleNode;
8182
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.ToNewRefNode;
8283
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.TransformExceptionToNativeNode;
84+
import com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol;
8385
import com.oracle.graal.python.builtins.objects.cext.capi.NativeReferenceCache.ResolveNativeReferenceNode;
8486
import com.oracle.graal.python.builtins.objects.cext.capi.PySequenceArrayWrapper;
8587
import com.oracle.graal.python.builtins.objects.cext.common.CArrayWrappers.CByteArrayWrapper;
@@ -1104,16 +1106,19 @@ public static final class GraalHPyUnicodeFromString extends GraalHPyContextFunct
11041106
@ExportMessage
11051107
Object execute(Object[] arguments,
11061108
@Cached HPyAsContextNode asContextNode,
1107-
@Cached FromCharPointerNode fromCharPointerNode,
1109+
@Cached PCallCapiFunction callGetNameNode,
11081110
@Cached CastToJavaStringNode toString,
11091111
@Cached PythonObjectFactory factory,
11101112
@Cached HPyTransformExceptionToNativeNode transformExceptionToNativeNode,
11111113
@Cached HPyAsHandleNode asHandleNode) throws ArityException {
11121114
checkArity(arguments, 2);
11131115
GraalHPyContext context = asContextNode.execute(arguments[0]);
11141116
try {
1115-
// TODO(fa) provide encoding (utf8)
1116-
String str = toString.execute(fromCharPointerNode.execute(arguments[1]));
1117+
Object cstr = callGetNameNode.call(context.getContext().getCApiContext(),
1118+
NativeCAPISymbol.FUN_POLYGLOT_FROM_STRING,
1119+
arguments[1],
1120+
StandardCharsets.UTF_8.name());
1121+
String str = toString.execute(cstr);
11171122
return asHandleNode.execute(context, factory.createString(str));
11181123
} catch (PException e) {
11191124
transformExceptionToNativeNode.execute(context, e);

0 commit comments

Comments
 (0)