From c9114f758b1ad3298c8a7a399721f74eab82a010 Mon Sep 17 00:00:00 2001 From: Eisuke Kawashima Date: Sun, 3 May 2026 15:55:57 +0900 Subject: [PATCH] refactor: use PyUnicode_AsUTF8 with Python 3.14+ _PyUnicode_AsString is deprecated since Python 3.14 https://docs.python.org/3.14/deprecations/index.html#id2 fix #512 --- src/converter/builtin_converters.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/converter/builtin_converters.cpp b/src/converter/builtin_converters.cpp index ee2d5b4794..227fe2f805 100644 --- a/src/converter/builtin_converters.cpp +++ b/src/converter/builtin_converters.cpp @@ -40,22 +40,18 @@ namespace // An lvalue conversion function which extracts a char const* from a // Python String. -#if PY_VERSION_HEX < 0x03000000 void* convert_to_cstring(PyObject* obj) { +#if PY_VERSION_HEX < 0x03000000 return PyString_Check(obj) ? PyString_AsString(obj) : 0; - } #elif PY_VERSION_HEX < 0x03070000 - void* convert_to_cstring(PyObject* obj) - { return PyUnicode_Check(obj) ? _PyUnicode_AsString(obj) : 0; - } -#else - void* convert_to_cstring(PyObject* obj) - { +#elif PY_VERSION_HEX < 0x030E0000 return PyUnicode_Check(obj) ? const_cast(reinterpret_cast(_PyUnicode_AsString(obj))) : 0; - } +#else + return PyUnicode_Check(obj) ? const_cast(reinterpret_cast(PyUnicode_AsUTF8(obj))) : 0; #endif + } // Given a target type and a SlotPolicy describing how to perform a // given conversion, registers from_python converters which use the