Skip to content

Commit c9114f7

Browse files
committed
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
1 parent 105d64e commit c9114f7

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

src/converter/builtin_converters.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,18 @@ namespace
4040

4141
// An lvalue conversion function which extracts a char const* from a
4242
// Python String.
43-
#if PY_VERSION_HEX < 0x03000000
4443
void* convert_to_cstring(PyObject* obj)
4544
{
45+
#if PY_VERSION_HEX < 0x03000000
4646
return PyString_Check(obj) ? PyString_AsString(obj) : 0;
47-
}
4847
#elif PY_VERSION_HEX < 0x03070000
49-
void* convert_to_cstring(PyObject* obj)
50-
{
5148
return PyUnicode_Check(obj) ? _PyUnicode_AsString(obj) : 0;
52-
}
53-
#else
54-
void* convert_to_cstring(PyObject* obj)
55-
{
49+
#elif PY_VERSION_HEX < 0x030E0000
5650
return PyUnicode_Check(obj) ? const_cast<void*>(reinterpret_cast<const void*>(_PyUnicode_AsString(obj))) : 0;
57-
}
51+
#else
52+
return PyUnicode_Check(obj) ? const_cast<void*>(reinterpret_cast<const void*>(PyUnicode_AsUTF8(obj))) : 0;
5853
#endif
54+
}
5955

6056
// Given a target type and a SlotPolicy describing how to perform a
6157
// given conversion, registers from_python converters which use the

0 commit comments

Comments
 (0)