parent
575ae8a527
commit
990df7f5c8
@ -0,0 +1,58 @@
|
|||||||
|
From 34f93cdc383432aeb34c31184de8a2fb5940e0c7 Mon Sep 17 00:00:00 2001
|
||||||
|
From: David Tardon <dtardon@redhat.com>
|
||||||
|
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
|
||||||
|
|
Loading…
Reference in new issue