summaryrefslogtreecommitdiff
path: root/plugins/pychrysa/arch/instruction.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysa/arch/instruction.c')
-rw-r--r--plugins/pychrysa/arch/instruction.c62
1 files changed, 24 insertions, 38 deletions
diff --git a/plugins/pychrysa/arch/instruction.c b/plugins/pychrysa/arch/instruction.c
index bed937b..09397fc 100644
--- a/plugins/pychrysa/arch/instruction.c
+++ b/plugins/pychrysa/arch/instruction.c
@@ -30,6 +30,9 @@
#include <string.h>
+#include <arch/instruction.h>
+
+
#include "../quirks.h"
@@ -105,13 +108,14 @@ static PyObject *py_arch_instruction_iterator_create(PyObject *origin)
Py_DECREF(module);
result = (PyArchInstructionIter *)type->tp_alloc(type, 0);
+ Py_DECREF(type);
if (result != NULL)
{
+ Py_INCREF(origin);
result->head = G_ARCH_INSTRUCTION(pygobject_get(origin));
g_object_ref(G_OBJECT(result->head));
- Py_INCREF(origin);
result->current = origin;
}
@@ -134,8 +138,12 @@ static PyObject *py_arch_instruction_iterator_create(PyObject *origin)
static void py_arch_instruction_iterator_dealloc(PyArchInstructionIter *self)
{
+ PyObject *first; /* Récupération de la première */
+
+ first = pychrysalide_get_pygobject(G_OBJECT(self->head));
+
+ Py_DECREF(first);
g_object_unref(G_OBJECT(self->head));
- Py_DECREF(self->current);
#if PY_VERSION_HEX < 0x03000000
self->ob_type->tp_free((PyObject *)self);
@@ -167,6 +175,8 @@ static PyObject *py_arch_instruction_iterator_next(PyArchInstructionIter *self)
{
self->started = true;
result = self->current;
+ Py_INCREF(result);
+
}
else
{
@@ -175,17 +185,14 @@ static PyObject *py_arch_instruction_iterator_next(PyArchInstructionIter *self)
if (next != NULL)
{
- result = py_arch_instruction_from_c(next);
-
- Py_INCREF(result);
- Py_DECREF(self->current);
+ result = pygobject_new(G_OBJECT(next));
self->current = result;
-
}
else result = NULL;
}
+ Py_XINCREF(result);
return (PyObject *)result;
}
@@ -258,35 +265,7 @@ bool register_python_arch_instruction_iterator(PyObject *module)
static PyObject *py_arch_instruction_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
- return Py_None;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : binary = instance existante GLib. *
-* *
-* Description : Crée un nouvel objet Python de type 'ArchInstruction'. *
-* *
-* Retour : Instance Python mise en place. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-PyObject *py_arch_instruction_from_c(GArchInstruction *instr)
-{
- PyObject *module; /* Module d'appartenance */
- PyTypeObject *type; /* Type Python correspondant */
-
- module = PyImport_ImportModule("pychrysalide.arch");
- type = (PyTypeObject *)PyObject_GetAttrString(module, "ArchInstruction");
- Py_DECREF(module);
-
- pychrysalide_set_instance_data(G_OBJECT(instr), type);
-
- return pygobject_new(G_OBJECT(instr));
+ Py_RETURN_NONE;
}
@@ -337,12 +316,15 @@ static PyObject *py_arch_instruction_get_location(PyObject *self, char *name)
if (strcmp(name, "offset") == 0)
result = PyLong_FromLong(offset);
- else if (strcmp(name, "") == 0)
+ else if (strcmp(name, "length") == 0)
result = PyLong_FromLong(length);
- else /*if (strcmp(name, "") == 0)*/
+ else if (strcmp(name, "address") == 0)
result = PyLong_FromLongLong(address);
+ else
+ result = NULL;
+
return result;
}
@@ -449,6 +431,10 @@ bool register_python_arch_instruction(PyObject *module)
Py_INCREF(&py_arch_instruction_type);
ret = PyModule_AddObject(module, "ArchInstruction", (PyObject *)&py_arch_instruction_type);
+ pygobject_register_class(module, "GArchInstruction", G_TYPE_ARCH_INSTRUCTION,
+ &py_arch_instruction_type,
+ Py_BuildValue("(O)", py_arch_instruction_type.tp_base));
+
return (ret == 0);
}