From c0b4a73f9e5fa206fedef24c1336e35f01d6e415 Mon Sep 17 00:00:00 2001
From: Jean-Paul Chaput <Jean-Paul.Chaput@lip6.fr>
Date: Sun, 14 Aug 2022 13:05:35 +0200
Subject: [PATCH] Alternate PyTypeObject inititalization in PythonAttributes
 for old GCC.

---
 hurricane/src/isobar/PyHurricane.cpp      |  2 +-
 hurricane/src/isobar/PythonAttributes.cpp | 53 +++++++++++++++++++++++
 2 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/hurricane/src/isobar/PyHurricane.cpp b/hurricane/src/isobar/PyHurricane.cpp
index eb92cc84..b7e2ed0b 100644
--- a/hurricane/src/isobar/PyHurricane.cpp
+++ b/hurricane/src/isobar/PyHurricane.cpp
@@ -904,7 +904,7 @@ extern "C" {
     PyInstance_postModuleInit();
     PyQuery_postModuleInit();
 
-    Py_AtExit( showAtExit );
+  //Py_AtExit( showAtExit );
 
     cdebug_log(20,0) << "Hurricane.so loaded " << (void*)&typeid(string) << endl;
 
diff --git a/hurricane/src/isobar/PythonAttributes.cpp b/hurricane/src/isobar/PythonAttributes.cpp
index 2e4c7ffc..e7446c15 100644
--- a/hurricane/src/isobar/PythonAttributes.cpp
+++ b/hurricane/src/isobar/PythonAttributes.cpp
@@ -70,6 +70,7 @@ namespace Isobar {
       };
 
 
+#if __GNUC__ && (__GNUC__ > 8)
     PyTypeObject  PyTypeAttributesHolder = {
       PyVarObject_HEAD_INIT(NULL,0)
       .tp_name       = "Hurricane.AttributesHolder",
@@ -82,6 +83,58 @@ namespace Isobar {
       .tp_methods    =  PyAttributesHolder_Methods,
       .tp_dictoffset =  offsetof( PyAttributesHolder, dict ),
     };
+#else
+    PyTypeObject  PyTypeAttributesHolder =
+      { PyVarObject_HEAD_INIT(NULL,0)
+        "Hurricane.AttributeHolder"             /* tp_name.          */
+      , sizeof( PyAttributeHolder )             /* tp_basicsize.     */          
+      , 0                                       /* tp_itemsize.      */          
+      , (destructor)PyAttribute_DeAlloc         /* tp_dealloc.       */          
+      , 0                                       /* tp_print.         */          
+      , 0                                       /* tp_getattr.       */          
+      , 0                                       /* tp_setattr.       */          
+      , 0                                       /* tp_compare.       */          
+      , 0                                       /* tp_repr.          */          
+      , 0                                       /* tp_as_number.     */          
+      , 0                                       /* tp_as_sequence.   */          
+      , 0                                       /* tp_as_mapping.    */          
+      , 0                                       /* tp_hash.          */          
+      , 0                                       /* tp_call.          */          
+      , 0                                       /* tp_str            */          
+      , PyObject_GenericGetAttr                 /* tp_getattro.      */          
+      , PyObject_GenericSetAttr                 /* tp_setattro.      */          
+      , 0                                       /* tp_as_buffer.     */          
+      , Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE  /* tp_flags          */          
+      , PyDoc_STR("Attributes holder for ancillary Python object (Property).")
+                                                /* tp_doc.           */          
+      , 0                                       /* tp_traverse       */
+      , 0                                       /* tp_clear          */
+      , 0                                       /* tp_richcompare    */
+      , 0                                       /* tp_weaklistoffset */
+      , 0                                       /* tp_iter           */
+      , 0                                       /* tp_iternext       */
+      , PyAttributesHolder_Methods              /* tp_methods        */
+      , 0                                       /* tp_members        */
+      , 0                                       /* tp_getset         */
+      , 0                                       /* tp_base           */
+      , 0                                       /* tp_dict           */
+      , 0                                       /* tp_decr_get       */
+      , 0                                       /* tp_decr_set       */
+      , offsetof( PyAttributesHolder, dict )    /* tp_dictoffset     */
+      };
+
+      PyVarObject_HEAD_INIT(NULL,0)
+      .tp_name       = "Hurricane.AttributesHolder",
+      .tp_basicsize  =  sizeof( PyAttributesHolder ),
+      .tp_dealloc    =  (destructor)PyAttributesHolder_DeAlloc,
+      .tp_getattro   =  PyObject_GenericGetAttr,
+      .tp_setattro   =  PyObject_GenericSetAttr,
+      .tp_flags      =  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
+      .tp_doc        =  PyDoc_STR("Attributes holder for ancillary Python object (Property)."),
+      .tp_methods    =  PyAttributesHolder_Methods,
+      .tp_dictoffset =  offsetof( PyAttributesHolder, dict ),
+    };
+#endif
 
   }  // extern "C".