diff options
Diffstat (limited to 'plugins/pychrysa/format/executable.c')
-rw-r--r-- | plugins/pychrysa/format/executable.c | 97 |
1 files changed, 40 insertions, 57 deletions
diff --git a/plugins/pychrysa/format/executable.c b/plugins/pychrysa/format/executable.c index 21da818..e7e218d 100644 --- a/plugins/pychrysa/format/executable.c +++ b/plugins/pychrysa/format/executable.c @@ -31,55 +31,58 @@ #include <format/format.h> -#include "../quirks.h" - - - -/* Crée un nouvel objet Python de type 'BinFormat'. */ -static PyObject *py_executable_format_new(PyTypeObject *, PyObject *, PyObject *); - - - - -#define _(str) str - +#include "format.h" /****************************************************************************** * * -* Paramètres : type = type de l'objet à instancier. * -* args = arguments fournis à l'appel. * -* kwds = arguments de type key=val fournis. * +* Paramètres : - * * * -* Description : Crée un nouvel objet Python de type 'BinFormat'. * +* Description : Fournit un accès à une définition de type à diffuser. * * * -* Retour : Instance Python mise en place. * +* Retour : Définition d'objet pour Python. * * * * Remarques : - * * * ******************************************************************************/ -static PyObject *py_executable_format_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +PyTypeObject *get_python_executable_format_type(void) { - PyErr_SetString(PyExc_ValueError, - _("pychrysalide.format.ExeFormat can not be instanciated directly")); + static PyMethodDef py_exe_format_methods[] = { + { NULL } + }; - return NULL; + static PyGetSetDef py_exe_format_getseters[] = { + { NULL } + }; -} + static PyTypeObject py_exe_format_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.format.ExeFormat", + .tp_basicsize = sizeof(PyGObject), + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + .tp_doc = "PyChrysalide executable format", + .tp_methods = py_exe_format_methods, + .tp_getset = py_exe_format_getseters, + }; + return &py_exe_format_type; + +} /****************************************************************************** * * * Paramètres : module = module dont la définition est à compléter. * * * -* Description : Prend en charge l'objet 'pychrysalide.gui.panels.BinFormat'. * +* Description : Prend en charge l'objet 'pychrysalide.format.ExeFormat'. * * * * Retour : Bilan de l'opération. * * * @@ -89,46 +92,26 @@ static PyObject *py_executable_format_new(PyTypeObject *type, PyObject *args, Py bool register_python_executable_format(PyObject *module) { - PyObject *parent_mod; /* Accès au module parent */ + PyTypeObject *py_exe_format_type; /* Type Python 'ExeFormat' */ int ret; /* Bilan d'un appel */ + PyObject *dict; /* Dictionnaire du module */ - static PyMethodDef py_executable_format_methods[] = { - { NULL } - }; - - static PyGetSetDef py_executable_format_getseters[] = { - { NULL } - }; - - static PyTypeObject py_executable_format_type = { - - PyObject_HEAD_INIT(NULL) - - .tp_name = "pychrysalide.format.ExeFormat", - .tp_basicsize = sizeof(PyGObject), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyChrysalide executable format", - - .tp_methods = py_executable_format_methods, - .tp_getset = py_executable_format_getseters, - .tp_new = (newfunc)py_executable_format_new - - }; + py_exe_format_type = get_python_executable_format_type(); - parent_mod = PyImport_ImportModule("pychrysalide.format"); - if (parent_mod == NULL) return false; + py_exe_format_type->tp_base = get_python_binary_format_type(); + py_exe_format_type->tp_basicsize = py_exe_format_type->tp_base->tp_basicsize; - py_executable_format_type.tp_base = (PyTypeObject *)PyObject_GetAttrString(parent_mod, "BinFormat"); - Py_DECREF(parent_mod); - - if (PyType_Ready(&py_executable_format_type) < 0) + if (PyType_Ready(py_exe_format_type) != 0) return false; - Py_INCREF(&py_executable_format_type); - ret = PyModule_AddObject(module, "ExeFormat", (PyObject *)&py_executable_format_type); + Py_INCREF(py_exe_format_type); + ret = PyModule_AddObject(module, "ExeFormat", (PyObject *)py_exe_format_type); + if (ret != 0) return false; + + dict = PyModule_GetDict(module); + pygobject_register_class(dict, "ExeFormat", G_TYPE_EXE_FORMAT, py_exe_format_type, + Py_BuildValue("(O)", py_exe_format_type->tp_base)); - return (ret == 0); + return true; } |