From 170dc35d87e0a858c5400937a1ee2d2dde7f653a Mon Sep 17 00:00:00 2001
From: Cyrille Bagard <nocbos@gmail.com>
Date: Sat, 20 Feb 2021 10:16:15 +0100
Subject: Change some prototypes for GLib objects storage.

---
 plugins/pychrysalide/analysis/storage/serialize.c | 71 ++++++++++-------------
 src/analysis/storage/serialize-int.h              |  4 +-
 src/analysis/storage/serialize.c                  | 18 ++----
 src/analysis/storage/serialize.h                  |  4 +-
 src/analysis/storage/storage.c                    |  9 ++-
 5 files changed, 46 insertions(+), 60 deletions(-)

diff --git a/plugins/pychrysalide/analysis/storage/serialize.c b/plugins/pychrysalide/analysis/storage/serialize.c
index 3bf5183..6e1dd41 100644
--- a/plugins/pychrysalide/analysis/storage/serialize.c
+++ b/plugins/pychrysalide/analysis/storage/serialize.c
@@ -32,7 +32,6 @@
 
 
 #include "storage.h"
-#include "tpmem.h"
 #include "../../access.h"
 #include "../../helpers.h"
 #include "../../common/packed.h"
@@ -46,10 +45,10 @@
 static void py_serializable_object_interface_init(GSerializableObjectIface *, gpointer *);
 
 /* Charge un objet depuis une mémoire tampon. */
-static bool py_serializable_object_load_wrapper(GSerializableObject *, GObjectStorage *, GTypeMemory *, packed_buffer *);
+static bool py_serializable_object_load_wrapper(GSerializableObject *, GObjectStorage *, packed_buffer *);
 
 /* Sauvegarde un objet dans une mémoire tampon. */
-static bool py_serializable_object_store_wrapper(const GSerializableObject *, GObjectStorage *, GTypeMemory *, packed_buffer *);
+static bool py_serializable_object_store_wrapper(const GSerializableObject *, GObjectStorage *, packed_buffer *);
 
 
 
@@ -108,7 +107,6 @@ static void py_serializable_object_interface_init(GSerializableObjectIface *ifac
 *                                                                             *
 *  Paramètres  : object  = instruction d'assemblage à consulter.              *
 *                storage = conservateur de données à manipuler ou NULL.       *
-*                tpmem   = mémoire des types d'objets à compléter.            *
 *                pbuf    = zone tampon à remplir.                             *
 *                                                                             *
 *  Description : Charge un objet depuis une mémoire tampon.                   *
@@ -119,7 +117,7 @@ static void py_serializable_object_interface_init(GSerializableObjectIface *ifac
 *                                                                             *
 ******************************************************************************/
 
-static bool py_serializable_object_load_wrapper(GSerializableObject *object, GObjectStorage *storage, GTypeMemory *tpmem, packed_buffer *pbuf)
+static bool py_serializable_object_load_wrapper(GSerializableObject *object, GObjectStorage *storage, packed_buffer *pbuf)
 {
     bool result;                            /* Bilan à retourner           */
     PyGILState_STATE gstate;                /* Sauvegarde d'environnement  */
@@ -130,15 +128,14 @@ static bool py_serializable_object_load_wrapper(GSerializableObject *object, GOb
 
 #define SERIALIZABLE_OBJECT_LOAD_WRAPPER PYTHON_WRAPPER_DEF                     \
 (                                                                               \
-    _load, "$self, storage, tpmem, pbuf, /",                                    \
+    _load, "$self, storage, pbuf, /",                                           \
     METH_VARARGS,                                                               \
     "Abstract method used to load an object definition from buffered data.\n"   \
     "\n"                                                                        \
     "The *storage* is a pychrysalide.analysis.storage.ObjectStorage instance"   \
-    " provided to store inner objects, if relevant, or None. The *tpmem* object"\
-    " is a pychrysalide.analysis.storage.TypeMemory remembering all involved"   \
-    " GLib types. The *pbuf* argument points to a"                              \
-    " pychrysalide.common.PackedBuffer object containing the data to process.\n"\
+    " provided to store inner objects, if relevant, or None. The *pbuf*"        \
+    " argument points to a pychrysalide.common.PackedBuffer object containing"  \
+    " the data to process.\n"                                                   \
     "\n"                                                                        \
     "The result is a boolean indicating the status of the operation."           \
 )
@@ -159,10 +156,9 @@ static bool py_serializable_object_load_wrapper(GSerializableObject *object, GOb
         else
             storage_obj = pygobject_new(G_OBJECT(storage));
 
-        args = PyTuple_New(3);
+        args = PyTuple_New(2);
         PyTuple_SetItem(args, 0, storage_obj);
-        PyTuple_SetItem(args, 1, pygobject_new(G_OBJECT(tpmem)));
-        PyTuple_SetItem(args, 2, build_from_internal_packed_buffer(pbuf));
+        PyTuple_SetItem(args, 1, build_from_internal_packed_buffer(pbuf));
 
         pyret = run_python_method(pyobj, "_load", args);
 
@@ -187,7 +183,6 @@ static bool py_serializable_object_load_wrapper(GSerializableObject *object, GOb
 *                                                                             *
 *  Paramètres  : object  = instruction d'assemblage à consulter.              *
 *                storage = conservateur de données à manipuler ou NULL.       *
-*                tpmem   = mémoire des types d'objets à compléter.            *
 *                pbuf    = zone tampon à remplir.                             *
 *                                                                             *
 *  Description : Sauvegarde un objet dans une mémoire tampon.                 *
@@ -198,7 +193,7 @@ static bool py_serializable_object_load_wrapper(GSerializableObject *object, GOb
 *                                                                             *
 ******************************************************************************/
 
-static bool py_serializable_object_store_wrapper(const GSerializableObject *object, GObjectStorage *storage, GTypeMemory *tpmem, packed_buffer *pbuf)
+static bool py_serializable_object_store_wrapper(const GSerializableObject *object, GObjectStorage *storage, packed_buffer *pbuf)
 {
     bool result;                            /* Bilan à retourner           */
     PyGILState_STATE gstate;                /* Sauvegarde d'environnement  */
@@ -209,15 +204,14 @@ static bool py_serializable_object_store_wrapper(const GSerializableObject *obje
 
 #define SERIALIZABLE_OBJECT_STORE_WRAPPER PYTHON_WRAPPER_DEF                    \
 (                                                                               \
-    _store, "$self, storage, tpmem, pbuf, /",                                   \
+    _store, "$self, storage, pbuf, /",                                          \
     METH_VARARGS,                                                               \
     "Abstract method used to store an object definition into buffered data.\n"  \
     "\n"                                                                        \
     "The *storage* is a pychrysalide.analysis.storage.ObjectStorage instance"   \
-    " provided to store inner objects, if relevant, or None. The *tpmem* object"\
-    " is a pychrysalide.analysis.storage.TypeMemory remembering all involved"   \
-    " GLib types. The *pbuf* argument points to a"                              \
-    " pychrysalide.common.PackedBuffer object containing the data to process.\n"\
+    " provided to store inner objects, if relevant, or None. The *pbuf*"        \
+    " argument points to a pychrysalide.common.PackedBuffer object containing"  \
+    " the data to process.\n"                                                   \
     "\n"                                                                        \
     "The result is a boolean indicating the status of the operation."           \
 )
@@ -238,10 +232,9 @@ static bool py_serializable_object_store_wrapper(const GSerializableObject *obje
         else
             storage_obj = pygobject_new(G_OBJECT(storage));
 
-        args = PyTuple_New(3);
+        args = PyTuple_New(2);
         PyTuple_SetItem(args, 0, storage_obj);
-        PyTuple_SetItem(args, 1, pygobject_new(G_OBJECT(tpmem)));
-        PyTuple_SetItem(args, 2, build_from_internal_packed_buffer(pbuf));
+        PyTuple_SetItem(args, 1, build_from_internal_packed_buffer(pbuf));
 
         pyret = run_python_method(pyobj, "_store", args);
 
@@ -285,7 +278,6 @@ static bool py_serializable_object_load(PyObject *self, PyObject *args)
 {
     PyObject *result;                       /* Bilan à retourner           */
     GObjectStorage *storage;                /* Conservateur à manipuler    */
-    GTypeMemory *tpmem;                     /* Gestionnaire de types       */
     packed_buffer *pbuf;                    /* Tampon de données à employer*/
     int ret;                                /* Bilan de lecture des args.  */
     GSerializableObject *object;            /* Version native              */
@@ -293,26 +285,25 @@ static bool py_serializable_object_load(PyObject *self, PyObject *args)
 
 #define SERIALIZABLE_OBJECT_LOAD_METHOD PYTHON_METHOD_DEF                       \
 (                                                                               \
-    load, "$self, storage, tpmem, pbuf, /",                                     \
+    load, "$self, storage, pbuf, /",                                            \
     METH_VARARGS, py_serializable_object,                                       \
     "Load an object definition from buffered data.\n"                           \
     "\n"                                                                        \
     "The *storage* is a pychrysalide.analysis.storage.ObjectStorage instance"   \
-    " provided to store inner objects, if relevant, or None. The *tpmem* object"\
-    " is a pychrysalide.analysis.storage.TypeMemory remembering all involved"   \
-    " GLib types. The *pbuf* argument points to a"                              \
-    " pychrysalide.common.PackedBuffer object containing the data to process.\n"\
+    " provided to store inner objects, if relevant, or None. The *pbuf*"        \
+    " argument points to a pychrysalide.common.PackedBuffer object containing"  \
+    " the data to process.\n"                                                   \
     "\n"                                                                        \
     "The result is a boolean indicating the status of the operation."           \
 )
 
-    ret = PyArg_ParseTuple(args, "O&O&O&", convert_to_object_storage_or_none, &storage,
-                           convert_to_type_memory, &tpmem, convert_to_packed_buffer, &pbuf);
+    ret = PyArg_ParseTuple(args, "O&O&", convert_to_object_storage_or_none, &storage,
+                           convert_to_packed_buffer, &pbuf);
     if (!ret) return NULL;
 
     object = G_SERIALIZABLE_OBJECT(pygobject_get(self));
 
-    status = g_serializable_object_load(object, storage, tpmem, pbuf);
+    status = g_serializable_object_load(object, storage, pbuf);
 
     result = status ? Py_True : Py_False;
     Py_INCREF(result);
@@ -339,7 +330,6 @@ static bool py_serializable_object_store(PyObject *self, PyObject *args)
 {
     PyObject *result;                       /* Bilan à retourner           */
     GObjectStorage *storage;                /* Conservateur à manipuler    */
-    GTypeMemory *tpmem;                     /* Gestionnaire de types       */
     packed_buffer *pbuf;                    /* Tampon de données à employer*/
     int ret;                                /* Bilan de lecture des args.  */
     GSerializableObject *object;            /* Version native              */
@@ -347,26 +337,25 @@ static bool py_serializable_object_store(PyObject *self, PyObject *args)
 
 #define SERIALIZABLE_OBJECT_STORE_METHOD PYTHON_METHOD_DEF                      \
 (                                                                               \
-    store, "$self, storage, tpmem, pbuf, /",                                    \
+    store, "$self, storage, pbuf, /",                                           \
     METH_VARARGS, py_serializable_object,                                       \
     "Store an object definition into buffered data.\n"                          \
     "\n"                                                                        \
     "The *storage* is a pychrysalide.analysis.storage.ObjectStorage instance"   \
-    " provided to store inner objects, if relevant, or None. The *tpmem* object"\
-    " is a pychrysalide.analysis.storage.TypeMemory remembering all involved"   \
-    " GLib types. The *pbuf* argument points to a"                              \
-    " pychrysalide.common.PackedBuffer object containing the data to process.\n"\
+    " provided to store inner objects, if relevant, or None. The *pbuf*"        \
+    " argument points to a pychrysalide.common.PackedBuffer object containing"  \
+    " the data to process.\n"                                                   \
     "\n"                                                                        \
     "The result is a boolean indicating the status of the operation."           \
 )
 
-    ret = PyArg_ParseTuple(args, "O&O&O&", convert_to_object_storage_or_none, &storage,
-                           convert_to_type_memory, &tpmem, convert_to_packed_buffer, &pbuf);
+    ret = PyArg_ParseTuple(args, "O&O&", convert_to_object_storage_or_none, &storage,
+                           convert_to_packed_buffer, &pbuf);
     if (!ret) return NULL;
 
     object = G_SERIALIZABLE_OBJECT(pygobject_get(self));
 
-    status = g_serializable_object_store(object, storage, tpmem, pbuf);
+    status = g_serializable_object_store(object, storage, pbuf);
 
     result = status ? Py_True : Py_False;
     Py_INCREF(result);
diff --git a/src/analysis/storage/serialize-int.h b/src/analysis/storage/serialize-int.h
index 3a99b52..e7690d5 100644
--- a/src/analysis/storage/serialize-int.h
+++ b/src/analysis/storage/serialize-int.h
@@ -30,10 +30,10 @@
 
 
 /* Charge un objet depuis une mémoire tampon. */
-typedef bool (* load_serializable_object_cb) (GSerializableObject *, GObjectStorage *, GTypeMemory *, packed_buffer *);
+typedef bool (* load_serializable_object_cb) (GSerializableObject *, GObjectStorage *, packed_buffer *);
 
 /* Sauvegarde un objet dans une mémoire tampon. */
-typedef bool (* store_serializable_object_cb) (const GSerializableObject *, GObjectStorage *, GTypeMemory *, packed_buffer *);
+typedef bool (* store_serializable_object_cb) (const GSerializableObject *, GObjectStorage *, packed_buffer *);
 
 
 /* Intermédiaire pour la mise en cache d'objet (interface) */
diff --git a/src/analysis/storage/serialize.c b/src/analysis/storage/serialize.c
index 6ed1eab..43a231a 100644
--- a/src/analysis/storage/serialize.c
+++ b/src/analysis/storage/serialize.c
@@ -59,7 +59,6 @@ static void g_serializable_object_default_init(GSerializableObjectInterface *ifa
 *                                                                             *
 *  Paramètres  : object  = instruction d'assemblage à consulter.              *
 *                storage = conservateur de données à manipuler ou NULL.       *
-*                tpmem   = mémoire des types d'objets à compléter.            *
 *                pbuf    = zone tampon à remplir.                             *
 *                                                                             *
 *  Description : Charge un objet depuis une mémoire tampon.                   *
@@ -70,14 +69,14 @@ static void g_serializable_object_default_init(GSerializableObjectInterface *ifa
 *                                                                             *
 ******************************************************************************/
 
-bool g_serializable_object_load(GSerializableObject *object, GObjectStorage *storage, GTypeMemory *tpmem, packed_buffer *pbuf)
+bool g_serializable_object_load(GSerializableObject *object, GObjectStorage *storage, packed_buffer *pbuf)
 {
     bool result;                            /* Bilan à retourner           */
     GSerializableObjectIface *iface;        /* Interface utilisée          */
 
     iface = G_SERIALIZABLE_OBJECT_GET_IFACE(object);
 
-    result = iface->load(object, storage, tpmem, pbuf);
+    result = iface->load(object, storage, pbuf);
 
     return result;
 
@@ -88,7 +87,6 @@ bool g_serializable_object_load(GSerializableObject *object, GObjectStorage *sto
 *                                                                             *
 *  Paramètres  : object  = instruction d'assemblage à consulter.              *
 *                storage = conservateur de données à manipuler ou NULL.       *
-*                tpmem   = mémoire des types d'objets à compléter.            *
 *                pbuf    = zone tampon à remplir.                             *
 *                                                                             *
 *  Description : Sauvegarde un objet dans une mémoire tampon.                 *
@@ -99,20 +97,14 @@ bool g_serializable_object_load(GSerializableObject *object, GObjectStorage *sto
 *                                                                             *
 ******************************************************************************/
 
-bool g_serializable_object_store(const GSerializableObject *object, GObjectStorage *storage, GTypeMemory *tpmem, packed_buffer *pbuf)
+bool g_serializable_object_store(const GSerializableObject *object, GObjectStorage *storage, packed_buffer *pbuf)
 {
     bool result;                            /* Bilan à retourner           */
     GSerializableObjectIface *iface;        /* Interface utilisée          */
 
-    result = g_type_memory_store_object_gtype(tpmem, G_OBJECT(object), pbuf);
-
-    if (result)
-    {
-        iface = G_SERIALIZABLE_OBJECT_GET_IFACE(object);
-
-        result = iface->store(object, storage, tpmem, pbuf);
+    iface = G_SERIALIZABLE_OBJECT_GET_IFACE(object);
 
-    }
+    result = iface->store(object, storage, pbuf);
 
     return result;
 
diff --git a/src/analysis/storage/serialize.h b/src/analysis/storage/serialize.h
index d248b65..96234c1 100644
--- a/src/analysis/storage/serialize.h
+++ b/src/analysis/storage/serialize.h
@@ -55,10 +55,10 @@ GType g_serializable_object_get_type(void) G_GNUC_CONST;
 typedef struct _GObjectStorage GObjectStorage;
 
 /* Charge un objet depuis une mémoire tampon. */
-bool g_serializable_object_load(GSerializableObject *, GObjectStorage *, GTypeMemory *, packed_buffer *);
+bool g_serializable_object_load(GSerializableObject *, GObjectStorage *, packed_buffer *);
 
 /* Sauvegarde un objet dans une mémoire tampon. */
-bool g_serializable_object_store(const GSerializableObject *, GObjectStorage *, GTypeMemory *, packed_buffer *);
+bool g_serializable_object_store(const GSerializableObject *, GObjectStorage *, packed_buffer *);
 
 
 
diff --git a/src/analysis/storage/storage.c b/src/analysis/storage/storage.c
index d64a08e..c63f7d0 100644
--- a/src/analysis/storage/storage.c
+++ b/src/analysis/storage/storage.c
@@ -360,7 +360,7 @@ GSerializableObject *g_object_storage_load_object(GObjectStorage *storage, const
 
     if (result)
     {
-        status = g_serializable_object_load(result, storage, storage->tpmem, &pbuf);
+        status = g_serializable_object_load(result, storage, &pbuf);
 
         if (!status)
             g_clear_object(&result);
@@ -402,11 +402,16 @@ bool g_object_storage_store_object(GObjectStorage *storage, const char *name, co
 
     init_packed_buffer(&pbuf);
 
-    result = g_serializable_object_store(object, storage, storage->tpmem, &pbuf);
+    result = g_type_memory_store_object_gtype(storage->tpmem, G_OBJECT(object), &pbuf);
+    if (!result) goto exit;
+
+    result = g_serializable_object_store(object, storage, &pbuf);
     if (!result) goto exit;
 
     /* Enregistrement */
 
+    result = false;
+
     g_mutex_lock(&storage->mutex);
 
     backend = g_object_storage_find_backend(storage, name);
-- 
cgit v0.11.2-87-g4458