Skip to content

Commit 97f7c2c

Browse files
committed
Add support for PyUnicode_FSDecoder
1 parent 535b5ff commit 97f7c2c

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

graalpython/com.oracle.graal.python.cext/src/unicodeobject.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3719,7 +3719,6 @@ PyUnicode_FSConverter(PyObject* arg, void* addr)
37193719
}
37203720

37213721

3722-
#if 0 // GraalPy change
37233722
int
37243723
PyUnicode_FSDecoder(PyObject* arg, void* addr)
37253724
{
@@ -3729,6 +3728,7 @@ PyUnicode_FSDecoder(PyObject* arg, void* addr)
37293728
return 1;
37303729
}
37313730

3731+
#if 0 // GraalPy change: 'findchar' not supported
37323732
PyObject *path = PyOS_FSPath(arg);
37333733
if (path == NULL) {
37343734
return 0;
@@ -3760,11 +3760,19 @@ PyUnicode_FSDecoder(PyObject* arg, void* addr)
37603760
Py_DECREF(output);
37613761
return 0;
37623762
}
3763+
#else // GraalPy change: different implementation
3764+
PyObject *output = NULL;
3765+
output = GraalPyTruffleUnicode_FSDecoder(arg);
3766+
if (!output) {
3767+
return 0;
3768+
}
3769+
#endif // GraalPy change
37633770
*(PyObject**)addr = output;
37643771
return Py_CLEANUP_SUPPORTED;
37653772
}
37663773

37673774

3775+
#if 0 // GraalPy change
37683776
static int unicode_fill_utf8(PyObject *unicode);
37693777
#endif // GraalPy change
37703778

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextUnicodeBuiltins.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
import com.oracle.graal.python.lib.PySliceNew;
145145
import com.oracle.graal.python.lib.PyTupleGetItem;
146146
import com.oracle.graal.python.lib.PyUnicodeCheckExactNode;
147+
import com.oracle.graal.python.lib.PyUnicodeFSDecoderNode;
147148
import com.oracle.graal.python.lib.PyUnicodeFromEncodedObject;
148149
import com.oracle.graal.python.lib.RichCmpOp;
149150
import com.oracle.graal.python.nodes.ErrorMessages;
@@ -880,6 +881,16 @@ static Object doManaged(Object ptr, long byteLength, int kind,
880881
}
881882
}
882883

884+
@CApiBuiltin(ret = PyObjectTransfer, args = {PyObject}, call = Ignored)
885+
abstract static class PyTruffleUnicode_FSDecoder extends CApiUnaryBuiltinNode {
886+
887+
@Specialization
888+
static Object fsDecoder(Object arg,
889+
@Cached PyUnicodeFSDecoderNode fsDecoderNode) {
890+
return fsDecoderNode.execute(null, arg);
891+
}
892+
}
893+
883894
@CApiBuiltin(ret = PyObjectTransfer, args = {Pointer, Py_ssize_t, Int}, call = Ignored)
884895
abstract static class PyTruffleUnicode_FromUTF extends CApiTernaryBuiltinNode {
885896

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ public final class CApiFunction {
974974
@CApiBuiltin(name = "PyUnicode_DecodeUTF7", ret = PyObject, args = {ConstCharPtrAsTruffleString, Py_ssize_t, ConstCharPtrAsTruffleString}, call = NotImplemented)
975975
@CApiBuiltin(name = "PyUnicode_DecodeUTF7Stateful", ret = PyObject, args = {ConstCharPtrAsTruffleString, Py_ssize_t, ConstCharPtrAsTruffleString, PY_SSIZE_T_PTR}, call = NotImplemented)
976976
@CApiBuiltin(name = "PyUnicode_DecodeUnicodeEscape", ret = PyObject, args = {ConstCharPtrAsTruffleString, Py_ssize_t, ConstCharPtrAsTruffleString}, call = NotImplemented)
977-
@CApiBuiltin(name = "PyUnicode_FSDecoder", ret = Int, args = {PyObject, Pointer}, call = NotImplemented)
977+
@CApiBuiltin(name = "PyUnicode_FSDecoder", ret = Int, args = {PyObject, Pointer}, call = CImpl)
978978
@CApiBuiltin(name = "PyUnicode_Fill", ret = Py_ssize_t, args = {PyObject, Py_ssize_t, Py_ssize_t, PY_UCS4}, call = CImpl)
979979
@CApiBuiltin(name = "PyUnicode_GetDefaultEncoding", ret = ConstCharPtrAsTruffleString, args = {}, call = CImpl)
980980
@CApiBuiltin(name = "PyUnicode_IsIdentifier", ret = Int, args = {PyObject}, call = NotImplemented)

0 commit comments

Comments
 (0)