summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlexis Hildebrandt <afh@surryhill.net>2023-01-31 18:16:29 +0100
committerMartin Michlmayr <tbm@cyrius.com>2023-02-01 09:31:25 +0800
commitc36affd3ee9606f43c70129d4820e70fda26f5bf (patch)
tree19404970c712456d8be9e6234b00b9a51bd99e9b /src
parentc94fccc2b825781e904a67e4bec6b99b427d8abd (diff)
downloadfork-ledger-c36affd3ee9606f43c70129d4820e70fda26f5bf.tar.gz
fork-ledger-c36affd3ee9606f43c70129d4820e70fda26f5bf.tar.bz2
fork-ledger-c36affd3ee9606f43c70129d4820e70fda26f5bf.zip
Fix deprecation warnings
Code clean-up
Diffstat (limited to 'src')
-rw-r--r--src/py_utils.cc32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/py_utils.cc b/src/py_utils.cc
index 94f6128f..04174677 100644
--- a/src/py_utils.cc
+++ b/src/py_utils.cc
@@ -97,24 +97,17 @@ struct string_from_python
{
VERIFY(PyUnicode_Check(obj_ptr));
- Py_ssize_t size = PyUnicode_GET_SIZE(obj_ptr);
- const Py_UNICODE* value = PyUnicode_AS_UNICODE(obj_ptr);
-
- string str;
-#if Py_UNICODE_SIZE == 2 // UTF-16
- utf8::unchecked::utf16to8(value, value + size, std::back_inserter(str));
-#elif Py_UNICODE_SIZE == 4 // UTF-32
- utf8::unchecked::utf32to8(value, value + size, std::back_inserter(str));
-#else
- assert("Py_UNICODE has an unexpected size" == NULL);
-#endif
-
- VERIFY(PyUnicode_Check(obj_ptr));
-
#if PY_MINOR_VERSION < 12
if (PyUnicode_READY(obj_ptr))
return;
#endif
+
+ const Py_UNICODE* value;
+ Py_ssize_t size;
+ string str;
+
+#if PY_MINOR_VERSION >= 3
+ size = PyUnicode_GET_LENGTH(obj_ptr);
switch (PyUnicode_KIND(obj_ptr)) {
case PyUnicode_1BYTE_KIND: {
Py_UCS1* value = PyUnicode_1BYTE_DATA(obj_ptr);
@@ -140,6 +133,17 @@ struct string_from_python
default:
assert("PyUnicode_KIND returned an unexpected kind" == NULL);
}
+#else
+ size = PyUnicode_GET_SIZE(obj_ptr);
+ value = PyUnicode_AS_UNICODE(obj_ptr);
+#if Py_UNICODE_SIZE == 2 // UTF-16
+ utf8::unchecked::utf16to8(value, value + size, std::back_inserter(str));
+#elif Py_UNICODE_SIZE == 4 // UTF-32
+ utf8::unchecked::utf32to8(value, value + size, std::back_inserter(str));
+#else
+ assert("Py_UNICODE has an unexpected size" == NULL);
+#endif
+#endif
void* storage =
reinterpret_cast<converter::rvalue_from_python_storage<string> *>