diff options
Diffstat (limited to 'plugins/pychrysa/glibext/codebuffer.c')
-rw-r--r-- | plugins/pychrysa/glibext/codebuffer.c | 87 |
1 files changed, 60 insertions, 27 deletions
diff --git a/plugins/pychrysa/glibext/codebuffer.c b/plugins/pychrysa/glibext/codebuffer.c index 6368ee7..9d9bc96 100644 --- a/plugins/pychrysa/glibext/codebuffer.c +++ b/plugins/pychrysa/glibext/codebuffer.c @@ -31,7 +31,7 @@ #include <glibext/gcodebuffer.h> -#include "../quirks.h" +#include "../arch/vmpa.h" @@ -56,15 +56,22 @@ static PyObject *py_code_buffer_find_line_by_addr(PyObject *, PyObject *); static PyObject *py_code_buffer_find_line_by_addr(PyObject *self, PyObject *args) { PyObject *result; /* Trouvailles à retourner */ - GCodeBuffer *buffer; /* Version native */ - vmpa_t addr; /* Adresse visée par l'opérat° */ + PyObject *py_vmpa; /* Localisation version Python */ int ret; /* Bilan de lecture des args. */ + vmpa2t *addr; /* Adresse visée par l'opérat° */ + GCodeBuffer *buffer; /* Version native */ GBufferLine *line; /* Ligne trouvée */ - buffer = G_CODE_BUFFER(pygobject_get(self)); + ret = PyArg_ParseTuple(args, "O", &py_vmpa); + if (!ret) return NULL; - ret = PyArg_ParseTuple(args, "K", &addr); - if (!ret) Py_RETURN_NONE; + ret = PyObject_IsInstance(py_vmpa, (PyObject *)get_python_vmpa_type()); + if (!ret) return NULL; + + addr = get_internal_vmpa(py_vmpa); + if (addr == NULL) return NULL; + + buffer = G_CODE_BUFFER(pygobject_get(self)); line = g_code_buffer_find_line_by_addr(buffer, addr, 0, NULL); if (line == NULL) Py_RETURN_NONE; @@ -78,60 +85,86 @@ static PyObject *py_code_buffer_find_line_by_addr(PyObject *self, PyObject *args /****************************************************************************** * * -* Paramètres : module = module dont la définition est à compléter. * +* Paramètres : - * * * -* Description : Prend en charge l'objet 'pychrysalide.glibext.Codebuffer'. * +* 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_code_buffer(PyObject *module) +PyTypeObject *get_python_code_buffer_type(void) { - PyObject *pygobj_mod; /* Module Python-GObject */ - int ret; /* Bilan d'un appel */ - static PyMethodDef py_code_buffer_methods[] = { { "find_line_by_addr", (PyCFunction)py_code_buffer_find_line_by_addr, METH_VARARGS, - "Find a buffer line with a given address." + "find_line_by_addr($self, addr, /)\n--\n\nFind a buffer line with a given address." }, { NULL } }; + static PyGetSetDef py_code_buffer_getseters[] = { + { NULL } + }; + static PyTypeObject py_code_buffer_type = { - PyObject_HEAD_INIT(NULL) + PyVarObject_HEAD_INIT(NULL, 0) .tp_name = "pychrysalide.glibext.CodeBuffer", .tp_basicsize = sizeof(PyGObject), - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + .tp_flags = Py_TPFLAGS_DEFAULT, .tp_doc = "PyChrysalide code buffer", - .tp_methods = py_code_buffer_methods + .tp_methods = py_code_buffer_methods, + .tp_getset = py_code_buffer_getseters, }; - pygobj_mod = PyImport_ImportModule("gobject"); - if (pygobj_mod == NULL) return false; + return &py_code_buffer_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.glibext.CodeBuffer'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_code_buffer(PyObject *module) +{ + PyTypeObject *py_code_buffer_type; /* Type Python 'CodeBuffer' */ + int ret; /* Bilan d'un appel */ + PyObject *dict; /* Dictionnaire du module */ + + py_code_buffer_type = get_python_code_buffer_type(); - py_code_buffer_type.tp_base = (PyTypeObject *)PyObject_GetAttrString(pygobj_mod, "GObject"); - Py_DECREF(pygobj_mod); + py_code_buffer_type->tp_base = &PyGObject_Type; + py_code_buffer_type->tp_basicsize = py_code_buffer_type->tp_base->tp_basicsize; - if (PyType_Ready(&py_code_buffer_type) < 0) + if (PyType_Ready(py_code_buffer_type) != 0) return false; - Py_INCREF(&py_code_buffer_type); - ret = PyModule_AddObject(module, "CodeBuffer", (PyObject *)&py_code_buffer_type); + Py_INCREF(py_code_buffer_type); + ret = PyModule_AddObject(module, "CodeBuffer", (PyObject *)py_code_buffer_type); + if (ret != 0) return false; - pygobject_register_class(module, "GCodeBuffer", G_TYPE_CODE_BUFFER, &py_code_buffer_type, - Py_BuildValue("(O)", py_code_buffer_type.tp_base)); + dict = PyModule_GetDict(module); + pygobject_register_class(dict, "CodeBuffer", G_TYPE_CODE_BUFFER, py_code_buffer_type, + Py_BuildValue("(O)", py_code_buffer_type->tp_base)); - return (ret == 0); + return true; } |