From 401fede79815c3396b9a915622347424ef76ac8d Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Sat, 1 Oct 2022 20:32:41 +0200 Subject: Handle return value of PyUnicode_READY to ensure access macros are only called on "legacy" unicode string objects that are "ready". See https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_READY --- src/py_utils.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/py_utils.cc b/src/py_utils.cc index cd44aa93..8765bb78 100644 --- a/src/py_utils.cc +++ b/src/py_utils.cc @@ -134,7 +134,8 @@ struct string_from_python PyUnicode_GET_SIZE(obj_ptr); #endif #if PY_MINOR_VERSION < 12 - PyUnicode_READY(obj_ptr); + if (PyUnicode_READY(obj_ptr)) + return; #endif switch (PyUnicode_KIND(obj_ptr)) { case PyUnicode_1BYTE_KIND: { -- cgit v1.2.3