summaryrefslogtreecommitdiff
path: root/plugins/pychrysa/format/dex
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/dex
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/dex')
-rw-r--r--plugins/pychrysa/format/dex/class.c91
-rw-r--r--plugins/pychrysa/format/dex/class.h3
-rw-r--r--plugins/pychrysa/format/dex/dex.c99
-rw-r--r--plugins/pychrysa/format/dex/dex.h5
-rw-r--r--plugins/pychrysa/format/dex/module.c36
5 files changed, 124 insertions, 110 deletions
diff --git a/plugins/pychrysa/format/dex/class.c b/plugins/pychrysa/format/dex/class.c
index 538fd25..1741b52 100644
--- a/plugins/pychrysa/format/dex/class.c
+++ b/plugins/pychrysa/format/dex/class.c
@@ -31,48 +31,48 @@
#include <format/dex/class.h>
-#include "../../quirks.h"
-
-
-
-/* Crée un nouvel objet Python de type 'DexClass'. */
-static PyObject *py_dex_class_new(PyTypeObject *, PyObject *, PyObject *);
-
-
/******************************************************************************
* *
-* 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 'DexClass'. *
+* 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_dex_class_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+PyTypeObject *get_python_dex_class_type(void)
{
- Py_RETURN_NONE;
-
-}
-
-
-
-
+ static PyMethodDef py_dex_class_methods[] = {
+ { NULL }
+ };
+ static PyGetSetDef py_dex_class_getseters[] = {
+ { NULL }
+ };
+ static PyTypeObject py_dex_class_type = {
+ PyVarObject_HEAD_INIT(NULL, 0)
+ .tp_name = "pychrysalide.format.dex.DexClass",
+ .tp_basicsize = sizeof(PyGObject),
+ .tp_flags = Py_TPFLAGS_DEFAULT,
+ .tp_doc = "PyChrysalide Dex class.",
+ .tp_methods = py_dex_class_methods,
+ .tp_getset = py_dex_class_getseters
+ };
+ return &py_dex_class_type;
+}
/******************************************************************************
@@ -89,49 +89,26 @@ static PyObject *py_dex_class_new(PyTypeObject *type, PyObject *args, PyObject *
bool register_python_dex_class(PyObject *module)
{
- PyObject *pygobj_mod; /* Module Python-GObject */
+ PyTypeObject *py_dex_class_type; /* Type Python 'DexClass' */
int ret; /* Bilan d'un appel */
+ PyObject *dict; /* Dictionnaire du module */
- static PyMethodDef py_dex_class_methods[] = {
- { NULL }
- };
-
- static PyGetSetDef py_dex_class_getseters[] = {
- { NULL }
- };
-
- static PyTypeObject py_dex_class_type = {
-
- PyObject_HEAD_INIT(NULL)
-
- .tp_name = "pychrysalide.format.dex.DexClass",
- .tp_basicsize = sizeof(PyGObject),
-
- .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
-
- .tp_doc = "PyChrysalide Dex class",
-
- .tp_methods = py_dex_class_methods,
- .tp_getset = py_dex_class_getseters,
- .tp_new = (newfunc)py_dex_class_new
-
- };
-
- pygobj_mod = PyImport_ImportModule("gobject");
- if (pygobj_mod == NULL) return false;
+ py_dex_class_type = get_python_dex_class_type();
- py_dex_class_type.tp_base = (PyTypeObject *)PyObject_GetAttrString(pygobj_mod, "GObject");
- Py_DECREF(pygobj_mod);
+ py_dex_class_type->tp_base = &PyGObject_Type;
+ py_dex_class_type->tp_basicsize = py_dex_class_type->tp_base->tp_basicsize;
- if (PyType_Ready(&py_dex_class_type) < 0)
+ if (PyType_Ready(py_dex_class_type) != 0)
return false;
- Py_INCREF(&py_dex_class_type);
- ret = PyModule_AddObject(module, "DexClass", (PyObject *)&py_dex_class_type);
+ Py_INCREF(py_dex_class_type);
+ ret = PyModule_AddObject(module, "DexClass", (PyObject *)py_dex_class_type);
+ if (ret != 0) return false;
- pygobject_register_class(module, "GDexClass", G_TYPE_DEX_CLASS, &py_dex_class_type,
- Py_BuildValue("(O)", py_dex_class_type.tp_base));
+ dict = PyModule_GetDict(module);
+ pygobject_register_class(dict, "DexClass", G_TYPE_DEX_CLASS, py_dex_class_type,
+ Py_BuildValue("(O)", py_dex_class_type->tp_base));
- return (ret == 0);
+ return true;
}
diff --git a/plugins/pychrysa/format/dex/class.h b/plugins/pychrysa/format/dex/class.h
index d767d12..9bfcde2 100644
--- a/plugins/pychrysa/format/dex/class.h
+++ b/plugins/pychrysa/format/dex/class.h
@@ -31,6 +31,9 @@
+/* Fournit un accès à une définition de type à diffuser. */
+PyTypeObject *get_python_dex_class_type(void);
+
/* Prend en charge l'objet 'pychrysalide.format.dex.DexClass'. */
bool register_python_dex_class(PyObject *module);
diff --git a/plugins/pychrysa/format/dex/dex.c b/plugins/pychrysa/format/dex/dex.c
index 6f422a4..a11af52 100644
--- a/plugins/pychrysa/format/dex/dex.c
+++ b/plugins/pychrysa/format/dex/dex.c
@@ -28,11 +28,12 @@
#include <pygobject.h>
-#include <format/dex/dex-int.h>
+#include <format/dex/class.h>
+#include <format/dex/dex.h>
-#include "class.h"
-#include "../../quirks.h"
+#include "../executable.h"
+#include "../../glibext/bincontent.h"
@@ -64,19 +65,23 @@ static PyObject *py_dex_format_get_class(PyObject *, PyObject *);
static PyObject *py_dex_format_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyObject *result; /* Instance à retourner */
- const bin_t *content; /* Données binaires */
- int length; /* Quantité de ces données */
+ PyObject *content_obj; /* Objet pour le contenu */
int ret; /* Bilan de lecture des args. */
- GBinFormat *format; /* Version GLib du format */
+ GBinContent *content; /* Instance GLib correspondante*/
+ GBinFormat *format; /* Création GLib à transmettre */
- ret = PyArg_ParseTuple(args, "s#", &content, &length);
- if (!ret) Py_RETURN_NONE;
+ ret = PyArg_ParseTuple(args, "O", &content_obj);
+ if (!ret) return NULL;
+
+ ret = PyObject_IsInstance(content_obj, (PyObject *)get_python_binary_content_type());
+ if (!ret) return NULL;
- format = g_dex_format_new(content, length);
- if (format == NULL) Py_RETURN_NONE;
+ content = G_BIN_CONTENT(pygobject_get(content_obj));
+ format = g_dex_format_new(/* FIXME */(bin_t *)content, 0/*content*/);
result = pygobject_new(G_OBJECT(format));
- //g_object_unref(format);
+
+ g_object_unref(format);
return (PyObject *)result;
@@ -149,38 +154,30 @@ static PyObject *py_dex_format_get_class(PyObject *self, PyObject *args)
}
-
-
-
-
-
/******************************************************************************
* *
-* Paramètres : module = module dont la définition est à compléter. *
+* Paramètres : - *
* *
-* Description : Prend en charge l'objet 'pychrysalide.format.dex.DexFormat'. *
+* Description : Fournit un accès à une définition de type à diffuser. *
* *
-* Retour : Bilan de l'opération. *
+* Retour : Définition d'objet pour Python. *
* *
* Remarques : - *
* *
******************************************************************************/
-bool register_python_dex_format(PyObject *module)
+PyTypeObject *get_python_dex_format_type(void)
{
- PyObject *parent_mod; /* Accès au module parent */
- int ret; /* Bilan d'un appel */
-
static PyMethodDef py_dex_format_methods[] = {
{
"count_classes", (PyCFunction)py_dex_format_count_classes,
METH_NOARGS,
- "Count the quantity of loaded Dex classes."
+ "count_classes($self, /)\n--\n\nCount the quantity of loaded Dex classes."
},
{
"get_class", (PyCFunction)py_dex_format_get_class,
METH_VARARGS,
- "Provide a given loaded Dex class."
+ "get_class($self, index, /)\n--\n\nProvide a given loaded Dex class."
},
{ NULL }
};
@@ -191,12 +188,12 @@ bool register_python_dex_format(PyObject *module)
static PyTypeObject py_dex_format_type = {
- PyObject_HEAD_INIT(NULL)
+ PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "pychrysalide.format.dex.DexFormat",
.tp_basicsize = sizeof(PyGObject),
- .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+ .tp_flags = Py_TPFLAGS_DEFAULT,
.tp_doc = "PyChrysalide Dex format",
@@ -206,27 +203,45 @@ bool register_python_dex_format(PyObject *module)
};
- parent_mod = PyImport_ImportModule("pychrysalide.format");
- if (parent_mod == NULL) return false;
+ return &py_dex_format_type;
+
+}
- py_dex_format_type.tp_base = (PyTypeObject *)PyObject_GetAttrString(parent_mod, "ExeFormat");
- Py_DECREF(parent_mod);
- if (PyType_Ready(&py_dex_format_type) < 0)
- return false;
+/******************************************************************************
+* *
+* Paramètres : module = module dont la définition est à compléter. *
+* *
+* Description : Prend en charge l'objet 'pychrysalide.format.dex.DexFormat'. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool register_python_dex_format(PyObject *module)
+{
+ PyTypeObject *py_dex_format_type; /* Type Python 'DexFormat' */
+ int ret; /* Bilan d'un appel */
+ PyObject *dict; /* Dictionnaire du module */
- Py_INCREF(&py_dex_format_type);
- ret = PyModule_AddObject(module, "DexFormat", (PyObject *)&py_dex_format_type);
+ py_dex_format_type = get_python_dex_format_type();
- parent_mod = PyImport_ImportModule("pychrysalide.format");
- if (parent_mod == NULL) return false;
+ py_dex_format_type->tp_base = get_python_executable_format_type();
+ py_dex_format_type->tp_basicsize = py_dex_format_type->tp_base->tp_basicsize;
+
+ if (PyType_Ready(py_dex_format_type) != 0)
+ return false;
- pygobject_register_class(module, "GDexFormat", G_TYPE_DEX_FORMAT, &py_dex_format_type,
- Py_BuildValue("(OO)", py_dex_format_type.tp_base,
- PyObject_GetAttrString(parent_mod, "BinFormat")));
+ Py_INCREF(py_dex_format_type);
+ ret = PyModule_AddObject(module, "DexFormat", (PyObject *)py_dex_format_type);
+ if (ret != 0) return false;
- Py_DECREF(parent_mod);
+ dict = PyModule_GetDict(module);
+ pygobject_register_class(dict, "DexFormat", G_TYPE_DEX_FORMAT, py_dex_format_type,
+ Py_BuildValue("(O)", py_dex_format_type->tp_base));
- return (ret == 0);
+ return true;
}
diff --git a/plugins/pychrysa/format/dex/dex.h b/plugins/pychrysa/format/dex/dex.h
index 9a4c481..9d524bb 100644
--- a/plugins/pychrysa/format/dex/dex.h
+++ b/plugins/pychrysa/format/dex/dex.h
@@ -31,8 +31,11 @@
+/* Fournit un accès à une définition de type à diffuser. */
+PyTypeObject *get_python_dex_format_type(void);
+
/* Prend en charge l'objet 'pychrysalide.format.dex.DexFormat'. */
-bool register_python_dex_format(PyObject *module);
+bool register_python_dex_format(PyObject *);
diff --git a/plugins/pychrysa/format/dex/module.c b/plugins/pychrysa/format/dex/module.c
index 43f0dbb..41f48c4 100644
--- a/plugins/pychrysa/format/dex/module.c
+++ b/plugins/pychrysa/format/dex/module.c
@@ -44,27 +44,43 @@
bool add_format_dex_module_to_python_module(PyObject *super)
{
- bool result;
- PyObject *module;
+ bool result; /* Bilan à retourner */
+ PyObject *module; /* Sous-module mis en place */
int ret; /* Bilan d'un appel */
- static PyMethodDef py_format_dex_methods[] = {
- { NULL }
+ static PyModuleDef py_chrysalide_dex_module = {
+
+ .m_base = PyModuleDef_HEAD_INIT,
+
+ .m_name = "pychrysalide.format.dex",
+ .m_doc = "Python module for Chrysalide.format.dex",
+
+ .m_size = -1,
+
};
- module = Py_InitModule("pychrysalide.format.dex", py_format_dex_methods);
+ result = false;
+
+ module = PyModule_Create(&py_chrysalide_dex_module);
if (module == NULL) return false;
- Py_INCREF(module);
- ret = PyModule_AddObject(super, "pychrysalide.format.dex", module);
+ ret = PyState_AddModule(super, &py_chrysalide_dex_module);
+ if (ret != 0) goto loading_failed;
+
+ ret = _PyImport_FixupBuiltin(module, "pychrysalide.format.dex");
+ if (ret != 0) goto loading_failed;
- result = (ret == 0);
+ Py_INCREF(module);
+ ret = PyModule_AddObject(super, "dex", module);
+ if (ret != 0) goto loading_failed;
- if (ret != 0) /* ... */;
+ result = true;
result &= register_python_dex_class(module);
result &= register_python_dex_format(module);
- return true;
+ loading_failed:
+
+ return result;
}