diff --git a/0001-make-FormatType-conversion-work-with-python-3.10.patch b/0001-make-FormatType-conversion-work-with-python-3.10.patch new file mode 100644 index 0000000..7c57b00 --- /dev/null +++ b/0001-make-FormatType-conversion-work-with-python-3.10.patch @@ -0,0 +1,58 @@ +From 34f93cdc383432aeb34c31184de8a2fb5940e0c7 Mon Sep 17 00:00:00 2001 +From: David Tardon +Date: Sun, 2 May 2021 20:46:42 +0200 +Subject: [PATCH] make FormatType conversion work with python 3.10 + +The str() function for Enum returns only the member name since 3.10: +https://docs.python.org/3.10/whatsnew/3.10.html#enum +Let's just check separately the enum type name and the member name. +--- + src/python/sheet.cpp | 18 +++++++++--------- + 1 file changed, 9 insertions(+), 9 deletions(-) + +diff --git a/src/python/sheet.cpp b/src/python/sheet.cpp +index 85067868..cf6d8b2c 100644 +--- a/src/python/sheet.cpp ++++ b/src/python/sheet.cpp +@@ -113,29 +113,29 @@ format_t to_format_type_enum(PyObject* format) + static const char* err_not_format_type = "An enum value of 'orcus.FormatType' was expected."; + static const char* err_format_not_supported = "Unsupported format type."; + +- PyObject* format_s = PyObject_Str(format); // new reference +- if (!format_s) ++ // Check the type name. ++ ++ PyTypeObject* type = Py_TYPE(format); ++ if (!type || strncmp(type->tp_name, "FormatType", 10u) != 0) + { + PyErr_SetString(PyExc_RuntimeError, err_not_format_type); + return format_t::unknown; + } + +- const char* p = PyUnicode_AsUTF8(format_s); ++ // Now check the member name. + +- // Make sure that the string starts with 'FormatType.'. +- if (!p || strnlen(p, 11u) < 11u || strncmp(p, "FormatType.", 11u)) ++ PyObject* format_s = PyObject_GetAttrString(format, "name"); // new reference ++ if (!format_s) + { + PyErr_SetString(PyExc_RuntimeError, err_not_format_type); +- Py_DECREF(format_s); + return format_t::unknown; + } + +- p += 11; // Move it to the char past the '.'. +- + // TODO : currently we only support csv format. Change this code when we + // add more format type(s) to support. + +- if (strncmp(p, "CSV", 3u)) ++ const char* p = PyUnicode_AsUTF8(format_s); ++ if (!p || strncmp(p, "CSV", 3u) != 0) + { + PyErr_SetString(PyExc_RuntimeError, err_format_not_supported); + Py_DECREF(format_s); +-- +2.31.1 + diff --git a/liborcus.spec b/liborcus.spec index 4c3ce5a..270db78 100644 --- a/liborcus.spec +++ b/liborcus.spec @@ -25,6 +25,7 @@ URL: https://gitlab.com/orcus/orcus Source0: https://kohei.us/files/orcus/src/%{name}-%{version}.tar.xz Patch0: %{name}-gcc11.patch Patch1: liborcus-noexamples.patch +Patch2: 0001-make-FormatType-conversion-work-with-python-3.10.patch BuildRequires: make BuildRequires: boost-devel