|
1 | 1 | /*
|
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. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * The Universal Permissive License (UPL), Version 1.0
|
|
77 | 77 | import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.CreateMethodNode;
|
78 | 78 | import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.FromCharPointerNode;
|
79 | 79 | import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.GetLLVMType;
|
| 80 | +import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.PCallCapiFunction; |
80 | 81 | import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.ResolveHandleNode;
|
81 | 82 | import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.ToNewRefNode;
|
82 | 83 | import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.TransformExceptionToNativeNode;
|
| 84 | +import com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol; |
83 | 85 | import com.oracle.graal.python.builtins.objects.cext.capi.NativeReferenceCache.ResolveNativeReferenceNode;
|
84 | 86 | import com.oracle.graal.python.builtins.objects.cext.capi.PySequenceArrayWrapper;
|
85 | 87 | import com.oracle.graal.python.builtins.objects.cext.common.CArrayWrappers.CByteArrayWrapper;
|
@@ -1104,15 +1106,20 @@ public static final class GraalHPyUnicodeFromString extends GraalHPyContextFunct
|
1104 | 1106 | @ExportMessage
|
1105 | 1107 | Object execute(Object[] arguments,
|
1106 | 1108 | @Cached HPyAsContextNode asContextNode,
|
1107 |
| - @Cached FromCharPointerNode fromCharPointerNode, |
| 1109 | + @Cached PCallCapiFunction callGetNameNode, |
| 1110 | + @Cached CastToJavaStringNode toString, |
| 1111 | + @Cached PythonObjectFactory factory, |
1108 | 1112 | @Cached HPyTransformExceptionToNativeNode transformExceptionToNativeNode,
|
1109 | 1113 | @Cached HPyAsHandleNode asHandleNode) throws ArityException {
|
1110 | 1114 | checkArity(arguments, 2);
|
1111 | 1115 | GraalHPyContext context = asContextNode.execute(arguments[0]);
|
1112 | 1116 | 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)); |
1116 | 1123 | } catch (PException e) {
|
1117 | 1124 | transformExceptionToNativeNode.execute(context, e);
|
1118 | 1125 | return GraalHPyHandle.NULL_HANDLE;
|
|
0 commit comments