summaryrefslogtreecommitdiff
path: root/plugins/pychrysa/format/executable.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2015-07-17 16:36:21 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2015-07-17 16:36:21 (GMT)
commit24d3836fcf8d443eb654b981f65478cd9923b8f1 (patch)
tree7672a28b864127e8958c3c6cce751dcf646d2fbe /plugins/pychrysa/format/executable.c
parenta61f089babe336b012da31a494b0f7470b6e1a9a (diff)
Updated the Python bindings.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@552 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'plugins/pychrysa/format/executable.c')
-rw-r--r--plugins/pychrysa/format/executable.c97
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;
}