Skip to content

Commit f8f1778

Browse files
committed
[GR-36979] Materialize string on HPyUnicode_FromString
PullRequest: graalpython/2152
2 parents 6ed5460 + 0af6eeb commit f8f1778

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

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

Lines changed: 12 additions & 5 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,15 +1106,20 @@ 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,
1110+
@Cached CastToJavaStringNode toString,
1111+
@Cached PythonObjectFactory factory,
11081112
@Cached HPyTransformExceptionToNativeNode transformExceptionToNativeNode,
11091113
@Cached HPyAsHandleNode asHandleNode) throws ArityException {
11101114
checkArity(arguments, 2);
11111115
GraalHPyContext context = asContextNode.execute(arguments[0]);
11121116
try {
1113-
// TODO(fa) provide encoding (utf8)
1114-
Object str = fromCharPointerNode.execute(arguments[1]);
1115-
return asHandleNode.execute(context, str);
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);
1122+
return asHandleNode.execute(context, factory.createString(str));
11161123
} catch (PException e) {
11171124
transformExceptionToNativeNode.execute(context, e);
11181125
return GraalHPyHandle.NULL_HANDLE;

0 commit comments

Comments
 (0)