summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/analysis/contents/memory.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysalide/analysis/contents/memory.c')
-rw-r--r--plugins/pychrysalide/analysis/contents/memory.c54
1 files changed, 32 insertions, 22 deletions
diff --git a/plugins/pychrysalide/analysis/contents/memory.c b/plugins/pychrysalide/analysis/contents/memory.c
index 4782445..7464779 100644
--- a/plugins/pychrysalide/analysis/contents/memory.c
+++ b/plugins/pychrysalide/analysis/contents/memory.c
@@ -28,42 +28,43 @@
#include <pygobject.h>
-#include <analysis/contents/memory.h>
+#include <i18n.h>
+#include <analysis/contents/memory-int.h>
#include "../content.h"
-#include "../storage/serialize.h"
#include "../../access.h"
#include "../../helpers.h"
-/* Crée un nouvel objet Python de type 'BinContent'. */
-static PyObject *py_memory_content_new(PyTypeObject *, PyObject *, PyObject *);
+CREATE_DYN_CONSTRUCTOR(memory_content, G_TYPE_MEMORY_CONTENT);
+
+/* Initialise une instance sur la base du dérivé de GObject. */
+static int py_memory_content_init(PyObject *, PyObject *, PyObject *);
/******************************************************************************
* *
-* Paramètres : type = type de l'objet à instancier. *
+* Paramètres : self = objet à initialiser (théoriquement). *
* args = arguments fournis à l'appel. *
* kwds = arguments de type key=val fournis. *
* *
-* Description : Crée un nouvel objet Python de type 'BinContent'. *
+* Description : Initialise une instance sur la base du dérivé de GObject. *
* *
-* Retour : Instance Python mise en place. *
+* Retour : 0. *
* *
* Remarques : - *
* *
******************************************************************************/
-static PyObject *py_memory_content_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+static int py_memory_content_init(PyObject *self, PyObject *args, PyObject *kwds)
{
- PyObject *result; /* Instance à retourner */
const char *data; /* Tampon interne de Python */
- int length; /* Taille utilisé de ce tampon */
+ Py_ssize_t length; /* Taille utilisé de ce tampon */
int ret; /* Bilan de lecture des args. */
- GBinContent *content; /* Version GLib du contenu */
+ GMemoryContent *content; /* Version GLib du contenu */
#define MEMORY_CONTENT_DOC \
"MemoryContent builds a binary content from memory data only." \
@@ -76,22 +77,32 @@ static PyObject *py_memory_content_new(PyTypeObject *type, PyObject *args, PyObj
"Where data is provided as string or read-only bytes-like object." \
" The string may contain embedded null bytes."
+ /* Récupération des paramètres */
+
/**
* La taille doit être de type 'int' et non 'Py_ssize_t', sinon les 32 bits
* de poids fort ne sont pas initialisés !
*/
ret = PyArg_ParseTuple(args, "s#", &data, &length);
- if (!ret) return NULL;
+ if (!ret) return -1;
+
+ /* Initialisation d'un objet GLib */
- content = g_memory_content_new((const bin_t *)data, length);
+ ret = forward_pygobjet_init(self);
+ if (ret == -1) return -1;
- result = pygobject_new(G_OBJECT(content));
+ /* Eléments de base */
- if (content != NULL)
- g_object_unref(content);
+ content = G_MEMORY_CONTENT(pygobject_get(self));
- return result;
+ if (!g_memory_content_create(content, (const bin_t *)data, length))
+ {
+ PyErr_SetString(PyExc_ValueError, _("Unable to create memory content."));
+ return -1;
+ }
+
+ return 0;
}
@@ -131,7 +142,9 @@ PyTypeObject *get_python_memory_content_type(void)
.tp_methods = py_memory_content_methods,
.tp_getset = py_memory_content_getseters,
- .tp_new = py_memory_content_new
+
+ .tp_init = py_memory_content_init,
+ .tp_new = py_memory_content_new,
};
@@ -166,13 +179,10 @@ bool ensure_python_memory_content_is_registered(void)
dict = PyModule_GetDict(module);
- if (!ensure_python_serializable_object_is_registered())
- return false;
-
if (!ensure_python_binary_content_is_registered())
return false;
- if (!register_class_for_pygobject(dict, G_TYPE_MEMORY_CONTENT, type, &PyGObject_Type))
+ if (!register_class_for_pygobject(dict, G_TYPE_MEMORY_CONTENT, type))
return false;
}