summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/arch/processor.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysalide/arch/processor.c')
-rw-r--r--plugins/pychrysalide/arch/processor.c39
1 files changed, 15 insertions, 24 deletions
diff --git a/plugins/pychrysalide/arch/processor.c b/plugins/pychrysalide/arch/processor.c
index 115f980..4feaa8b 100644
--- a/plugins/pychrysalide/arch/processor.c
+++ b/plugins/pychrysalide/arch/processor.c
@@ -31,6 +31,7 @@
#include <i18n.h>
#include <arch/processor-int.h>
+#include <plugins/dt.h>
#include "context.h"
@@ -38,7 +39,6 @@
#include "instruction.h"
#include "vmpa.h"
#include "../access.h"
-#include "../dt.h"
#include "../helpers.h"
#include "../analysis/content.h"
#include "../format/executable.h"
@@ -140,18 +140,16 @@ static bool define_python_arch_processor_constants(PyTypeObject *);
static PyObject *py_arch_processor_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyObject *result; /* Objet à retourner */
- bool abstract; /* Validation du type parent */
+ PyTypeObject *base; /* Type de base à dériver */
+ bool first_time; /* Evite les multiples passages*/
GType gtype; /* Nouveau type de processeur */
- PyObject *sys_mod_dict; /* Dictionnaire des modules */
- PyObject *modname; /* Nom du module du type */
- PyObject *module; /* Module à recompléter */
- PyObject *dict; /* Dictionnaire dudit module */
+ bool status; /* Bilan d'un enregistrement */
/* Validations diverses */
- abstract = (type == get_python_arch_processor_type());
+ base = get_python_arch_processor_type();
- if (abstract)
+ if (type == base)
{
result = NULL;
PyErr_Format(PyExc_RuntimeError, _("%s is an abstract class"), type->tp_name);
@@ -160,30 +158,23 @@ static PyObject *py_arch_processor_new(PyTypeObject *type, PyObject *args, PyObj
/* Mise en place d'un type dédié */
- gtype = built_dynamic_type(G_TYPE_ARCH_PROCESSOR, type->tp_name,
- (GClassInitFunc)py_arch_processor_init_gclass);
-
- /* Enregistrement du nouveau GType dans Python */
-
- sys_mod_dict = PyImport_GetModuleDict();
+ first_time = (g_type_from_name(type->tp_name) == 0);
- modname = PyDict_GetItemString(type->tp_dict, "__module__");
-
- module = PyObject_GetItem(sys_mod_dict, modname);
+ gtype = built_dynamic_type(G_TYPE_ARCH_PROCESSOR, type->tp_name,
+ (GClassInitFunc)py_arch_processor_init_gclass, NULL);
- dict = PyModule_GetDict(module);
+ if (first_time)
+ status = register_class_for_dynamic_pygobject(gtype, type, base);
+ else
+ status = true;
- if (!_register_class_for_pygobject(dict, gtype, type,
- &PyGObject_Type, get_python_arch_processor_type(), NULL))
+ if (!status)
{
result = NULL;
goto exit;
}
- Py_DECREF(module);
- Py_DECREF(modname);
-
- /* On créé, et on laisse ensuite la main à PyGObject_Type.tp_init() */
+ /* On crée, et on laisse ensuite la main à PyGObject_Type.tp_init() */
result = PyType_GenericNew(type, args, kwds);