Skip to content

Commit d8a3dab

Browse files
committed
Fix upcall to PyUnicode_Decode
1 parent d540548 commit d8a3dab

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,12 +568,13 @@ PyObject * PyUnicode_AsUnicodeEscapeString(PyObject *unicode) {
568568
return UPCALL_CEXT_O(_jls_PyUnicode_AsUnicodeEscapeString, native_to_java(unicode));
569569
}
570570

571-
UPCALL_ID(PyUnicode_Decode);
571+
typedef PyObject* (*unicode_PyUnicode_Decode_fun_t)(void *data, const char *encoding, const char *errors);
572+
UPCALL_TYPED_ID(PyUnicode_Decode, unicode_PyUnicode_Decode_fun_t);
572573
PyObject * PyUnicode_Decode(const char *s, Py_ssize_t size, const char *encoding, const char *errors) {
573574
if (encoding == NULL) {
574575
return PyUnicode_DecodeUTF8Stateful(s, size, errors, NULL);
575576
}
576-
return UPCALL_CEXT_O(_jls_PyUnicode_Decode, s, size, polyglot_from_string(encoding, SRC_CS), convert_errors(errors));
577+
return _jls_PyUnicode_Decode(polyglot_from_i8_array(s, size), polyglot_from_string(encoding, SRC_CS), convert_errors(errors));
577578
}
578579

579580
PyObject * PyUnicode_DecodeASCII(const char *s, Py_ssize_t size, const char *errors) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PythonCextBuiltins.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2574,18 +2574,18 @@ protected static boolean isReprFormatCode(int formatCode) {
25742574
}
25752575
}
25762576

2577-
@Builtin(name = "PyUnicode_Decode", minNumOfPositionalArgs = 5, declaresExplicitSelf = true)
2577+
@Builtin(name = "PyUnicode_Decode", minNumOfPositionalArgs = 4, declaresExplicitSelf = true)
25782578
@GenerateNodeFactory
25792579
abstract static class PyUnicode_Decode extends NativeUnicodeBuiltin {
25802580

25812581
@Specialization
2582-
Object doDecode(VirtualFrame frame, Object module, Object cByteArray, long size, String encoding, String errors,
2582+
Object doDecode(VirtualFrame frame, Object module, Object cByteArray, String encoding, String errors,
25832583
@Cached CExtNodes.ToSulongNode toSulongNode,
25842584
@Cached GetByteArrayNode getByteArrayNode,
25852585
@Cached GetNativeNullNode getNativeNullNode) {
25862586

25872587
try {
2588-
ByteBuffer inputBuffer = wrap(getByteArrayNode.execute(cByteArray, size));
2588+
ByteBuffer inputBuffer = wrap(getByteArrayNode.execute(cByteArray, -1));
25892589
int n = remaining(inputBuffer);
25902590
CharBuffer resultBuffer = allocateCharBuffer(n * 4);
25912591
decode(resultBuffer, inputBuffer, encoding, errors);

0 commit comments

Comments
 (0)