summaryrefslogtreecommitdiff
path: root/plugins/pychrysa/format/dex/class.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysa/format/dex/class.c')
-rw-r--r--plugins/pychrysa/format/dex/class.c91
1 files changed, 34 insertions, 57 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;
}