Skip to content

Commit 7cfffb7

Browse files
committed
simplify PyUnicode_DecodeLatin1
1 parent 327bab9 commit 7cfffb7

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,12 @@ PyObject * PyUnicode_DecodeASCII(const char *s, Py_ssize_t size, const char *err
590590
}
591591

592592
PyObject * PyUnicode_DecodeLatin(const char *s, Py_ssize_t size, const char *errors) {
593-
return PyUnicode_Decode(s, size, "latin1", errors);
593+
if (size < 0) {
594+
PyErr_SetString(PyExc_SystemError,
595+
"Negative size passed to PyUnicode_New");
596+
return NULL;
597+
}
598+
return to_sulong(polyglot_from_string_n(s, size, "latin1"));
594599
}
595600

596601
UPCALL_ID(PyUnicode_Tailmatch);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,6 +1472,7 @@ Object execute(Object[] arguments,
14721472
} catch (OverflowException | InteropException ex) {
14731473
throw CompilerDirectives.shouldNotReachHere(ex);
14741474
}
1475+
// TODO: TruffleString - when we have ISO-8859-1, we can just force the encoding and short-circuit the error reading etc
14751476
String errors = castToJavaStringNode.execute(callHPyFunction.call(context, GraalHPyNativeSymbol.POLYGLOT_FROM_STRING, arguments[3], "ascii"));
14761477
CodingErrorAction errorAction = CodecsModuleBuiltins.convertCodingErrorAction(errors);
14771478
String result = decode(errorAction, bytes);

0 commit comments

Comments
 (0)