From 810b5d805465020cd5d047be0fe5e30932fe795b Mon Sep 17 00:00:00 2001
From: Justin Carpentier <justin.carpentier@inria.fr>
Date: Wed, 10 Aug 2022 07:29:56 +0200
Subject: [PATCH] FIx issue related to Python 3.10 (#304)

* cmake: use REQUIRED

* core: fix issue with Python 3.10 and more

* core: fix logic

* core: fix

* core: further fix

* Core: use official solution

Co-authored-by: Guilhem Saurel <guilhem.saurel@laas.fr>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* core: fix

Co-authored-by: Guilhem Saurel <guilhem.saurel@laas.fr>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
---
 CMakeLists.txt             |  2 +-
 include/eigenpy/memory.hpp | 11 +++++++++--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index f1d468ef..1c8a30ab 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -80,7 +80,7 @@ else()
   set(PYTHON_COMPONENTS Interpreter Development.Module NumPy)
 endif()
 set(PYTHON_EXPORT_DEPENDENCY ON)
-findpython()
+findpython(REQUIRED)
 
 if(WIN32)
   link_directories(${PYTHON_LIBRARY_DIRS})
diff --git a/include/eigenpy/memory.hpp b/include/eigenpy/memory.hpp
index f6f75f10..447694e4 100644
--- a/include/eigenpy/memory.hpp
+++ b/include/eigenpy/memory.hpp
@@ -1,6 +1,6 @@
 /*
  * Copyright 2014-2019, CNRS
- * Copyright 2018-2019, INRIA
+ * Copyright 2018-2022, INRIA
  */
 
 #ifndef __eigenpy_memory_hpp__
@@ -8,6 +8,13 @@
 
 #include "eigenpy/fwd.hpp"
 
+#if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_SIZE)
+static inline void _Py_SET_SIZE(PyVarObject* ob, Py_ssize_t size) {
+  ob->ob_size = size;
+}
+#define Py_SET_SIZE(ob, size) _Py_SET_SIZE((PyVarObject*)(ob), size)
+#endif
+
 /**
  * This section contains a convenience MACRO which allows an easy specialization
  * of Boost Python Object allocator for struct data types containing Eigen
@@ -66,7 +73,7 @@
             reinterpret_cast<Py_ssize_t>(holder) -                             \
             reinterpret_cast<Py_ssize_t>(&instance->storage) +                 \
             static_cast<Py_ssize_t>(offsetof(instance_t, storage));            \
-        Py_SIZE(instance) = holder_offset;                                     \
+        Py_SET_SIZE(instance, holder_offset);                                  \
                                                                                \
         protect.cancel();                                                      \
       }                                                                        \
-- 
GitLab