From 1614639e270005a2a44805ac0e3075e735b20f2e Mon Sep 17 00:00:00 2001
From: Cyrille Bagard <nocbos@gmail.com>
Date: Mon, 16 Dec 2024 08:39:50 +0100
Subject: Extend the Python API for GObject holes.

---
 plugins/pychrysalide/glibext/objhole.c | 41 ++++++++++++++++++++++++++++++++--
 tests/glibext/objhole.py               |  9 ++++++++
 2 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/plugins/pychrysalide/glibext/objhole.c b/plugins/pychrysalide/glibext/objhole.c
index 23f7f4c..2a3ad6f 100644
--- a/plugins/pychrysalide/glibext/objhole.c
+++ b/plugins/pychrysalide/glibext/objhole.c
@@ -43,6 +43,9 @@ CREATE_DYN_CONSTRUCTOR(thick_object, G_TYPE_THICK_OBJECT);
 /* Initialise une instance sur la base du dérivé de GObject. */
 static int py_thick_object_init(PyObject *, PyObject *, PyObject *);
 
+/* Indique le nombre de bits accaparés par la GLib. */
+static PyObject *py_thick_object_get__GOBJECT_RESERVED_EXTRA_BITS(PyObject *, void *);
+
 /* Fournit la valeur courante de la zone de stockage d'un objet. */
 static PyObject *py_thick_object_get_extra(PyObject *, void *);
 
@@ -94,6 +97,39 @@ static int py_thick_object_init(PyObject *self, PyObject *args, PyObject *kwds)
 *  Paramètres  : self    = objet Python concerné par l'appel.                 *
 *                closure = non utilisé ici.                                   *
 *                                                                             *
+*  Description : Indique le nombre de bits accaparés par la GLib.             *
+*                                                                             *
+*  Retour      : Nombre de bits, à priori inférieur à 32.                     *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+static PyObject *py_thick_object_get__GOBJECT_RESERVED_EXTRA_BITS(PyObject *self, void *closure)
+{
+    PyObject *result;                       /* Résultat à retourner        */
+
+#define THICK_OBJECT__GOBJECT_RESERVED_EXTRA_BITS_ATTRIB PYTHON_GET_DEF_FULL    \
+(                                                                               \
+    _GOBJECT_RESERVED_EXTRA_BITS, py_thick_object,                              \
+    "Quantity of lower bits used by the GLib inside the memory hole.\n"         \
+    "\n"                                                                        \
+    "The returned value should be less then 32 and is provided for"             \
+    " pychrysalide.glibext.ThickObject subclass implementation."                \
+)
+
+    result = PyLong_FromUnsignedLong(GOBJECT_RESERVED_EXTRA_BITS);
+
+    return result;
+
+}
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : self    = objet Python concerné par l'appel.                 *
+*                closure = non utilisé ici.                                   *
+*                                                                             *
 *  Description : Fournit la valeur courante de la zone de stockage d'un objet.*
 *                                                                             *
 *  Retour      : Valeur de 32 lues et expurgées des bits GLib.                *
@@ -111,8 +147,8 @@ static PyObject *py_thick_object_get_extra(PyObject *self, void *closure)
 #define THICK_OBJECT_EXTRA_ATTRIB PYTHON_GETSET_DEF_FULL            \
 (                                                                   \
     extra, py_thick_object,                                         \
-    "Define and retrieve the data stored inside the structure"      \
-    " memory hole of all GObject native instances.\n"               \
+    "Data stored inside the structure memory hole of all GObject"   \
+    " native instances.\n"                                          \
     "\n"                                                            \
     "Less than 32 bits are available for storing arbitrary values." \
 )
@@ -183,6 +219,7 @@ PyTypeObject *get_python_thick_object_type(void)
     };
 
     static PyGetSetDef py_thick_object_getseters[] = {
+        THICK_OBJECT__GOBJECT_RESERVED_EXTRA_BITS_ATTRIB,
         THICK_OBJECT_EXTRA_ATTRIB,
         { NULL }
     };
diff --git a/tests/glibext/objhole.py b/tests/glibext/objhole.py
index 09bd8f5..6a7c2e8 100644
--- a/tests/glibext/objhole.py
+++ b/tests/glibext/objhole.py
@@ -20,3 +20,12 @@ class TestWorks(ChrysalideTestCase):
         obj.extra = 0x00123000
 
         self.assertEqual(obj.extra, 0x00123000)
+
+
+    def testRservedBits(self):
+        """Check space leaved as available by the GLib."""
+
+        obj = ThickObject()
+
+        self.assertTrue(obj._GOBJECT_RESERVED_EXTRA_BITS > 0)
+        self.assertTrue(obj._GOBJECT_RESERVED_EXTRA_BITS < 32)
-- 
cgit v0.11.2-87-g4458