From 6a8385724c74b07cf9ed4cb9052f1af1816e3ea5 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Sun, 21 Jul 2019 22:21:59 +0200 Subject: Created more converters for Python arguments. --- plugins/dex/python/format.c | 7 +--- plugins/elf/python/format.c | 7 +--- plugins/pychrysalide/analysis/binary.c | 7 +--- .../pychrysalide/analysis/contents/encapsulated.c | 15 +++---- plugins/pychrysalide/analysis/loaded.c | 45 +++++++++++++++++++++ plugins/pychrysalide/analysis/loaded.h | 3 ++ plugins/pychrysalide/analysis/loading.c | 18 +++------ plugins/pychrysalide/analysis/project.c | 7 +--- plugins/pychrysalide/analysis/type.c | 46 ++++++++++++++++++++++ plugins/pychrysalide/analysis/type.h | 3 ++ plugins/pychrysalide/analysis/types/array.c | 7 +--- plugins/pychrysalide/analysis/types/encaps.c | 7 +--- plugins/pychrysalide/analysis/types/proto.c | 7 +--- plugins/pychrysalide/analysis/types/template.c | 7 +--- plugins/pychrysalide/arch/targetableop.c | 2 +- plugins/pychrysalide/format/flat.c | 7 +--- plugins/pychrysalide/format/format.c | 12 ++---- plugins/pychrysalide/format/symbol.c | 46 ++++++++++++++++++++++ plugins/pychrysalide/format/symbol.h | 3 ++ plugins/pychrysalide/glibext/bufferline.c | 46 ++++++++++++++++++++++ plugins/pychrysalide/glibext/bufferline.h | 3 ++ plugins/pychrysalide/glibext/linegen.c | 14 ++----- plugins/pychrysalide/glibext/loadedpanel.c | 46 ++++++++++++++++++++++ plugins/pychrysalide/glibext/loadedpanel.h | 3 ++ plugins/pychrysalide/gtkext/graph/cluster.c | 3 +- plugins/pychrysalide/gui/core/items.c | 28 ++++--------- 26 files changed, 291 insertions(+), 108 deletions(-) diff --git a/plugins/dex/python/format.c b/plugins/dex/python/format.c index f798981..04473ef 100644 --- a/plugins/dex/python/format.c +++ b/plugins/dex/python/format.c @@ -69,16 +69,13 @@ static PyObject *py_dex_format_get_pool(PyObject *, void *); static PyObject *py_dex_format_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { PyObject *result; /* Instance à retourner */ - PyObject *content_obj; /* Objet pour le contenu */ - int ret; /* Bilan de lecture des args. */ GBinContent *content; /* Instance GLib du contenu */ + int ret; /* Bilan de lecture des args. */ GExeFormat *format; /* Création GLib à transmettre */ - ret = PyArg_ParseTuple(args, "O!", get_python_binary_content_type(), &content_obj); + ret = PyArg_ParseTuple(args, "O&", convert_to_binary_content, &content); if (!ret) return NULL; - content = G_BIN_CONTENT(pygobject_get(content_obj)); - format = g_dex_format_new(content); if (format == NULL) diff --git a/plugins/elf/python/format.c b/plugins/elf/python/format.c index b78dadb..277d0b4 100644 --- a/plugins/elf/python/format.c +++ b/plugins/elf/python/format.c @@ -71,16 +71,13 @@ static PyObject *py_elf_format_get_header(PyObject *, PyObject *); static PyObject *py_elf_format_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { PyObject *result; /* Instance à retourner */ - PyObject *content_obj; /* Objet pour le contenu */ - int ret; /* Bilan de lecture des args. */ GBinContent *content; /* Instance GLib du contenu */ + int ret; /* Bilan de lecture des args. */ GExeFormat *format; /* Création GLib à transmettre */ - ret = PyArg_ParseTuple(args, "O!", get_python_binary_content_type(), &content_obj); + ret = PyArg_ParseTuple(args, "O&", convert_to_binary_content, &content); if (!ret) return NULL; - content = G_BIN_CONTENT(pygobject_get(content_obj)); - format = g_elf_format_new(content); if (format == NULL) diff --git a/plugins/pychrysalide/analysis/binary.c b/plugins/pychrysalide/analysis/binary.c index a98d11a..e137f87 100644 --- a/plugins/pychrysalide/analysis/binary.c +++ b/plugins/pychrysalide/analysis/binary.c @@ -75,16 +75,13 @@ static PyObject *py_loaded_binary_get_disassembled_cache(PyObject *, void *); static PyObject *py_loaded_binary_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { PyObject *result; /* Instance à retourner */ - PyObject *format_obj; /* Objet pour le contenu */ - int ret; /* Bilan de lecture des args. */ GExeFormat *format; /* Instance GLib correspondante*/ + int ret; /* Bilan de lecture des args. */ GLoadedContent *binary; /* Version GLib du binaire */ - ret = PyArg_ParseTuple(args, "O!", get_python_executable_format_type(), &format_obj); + ret = PyArg_ParseTuple(args, "O&", convert_to_executable_format, &format); if (!ret) return NULL; - format = G_EXE_FORMAT(pygobject_get(format_obj)); - g_object_ref(G_OBJECT(format)); binary = g_loaded_binary_new(format); diff --git a/plugins/pychrysalide/analysis/contents/encapsulated.c b/plugins/pychrysalide/analysis/contents/encapsulated.c index 7af79e8..031c49f 100644 --- a/plugins/pychrysalide/analysis/contents/encapsulated.c +++ b/plugins/pychrysalide/analysis/contents/encapsulated.c @@ -59,23 +59,18 @@ static PyObject *py_encaps_content_new(PyTypeObject *, PyObject *, PyObject *); static PyObject *py_encaps_content_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { PyObject *result; /* Instance à retourner */ - PyObject *base_obj; /* Base en Python */ - const char *path; /* Chemin vers le contenu final*/ - PyObject *endpoint_obj; /* Contenu final en Python */ - int ret; /* Bilan de lecture des args. */ GBinContent *base; /* Base de l'extraction */ + const char *path; /* Chemin vers le contenu final*/ GBinContent *endpoint; /* Contenu accessible au final */ + int ret; /* Bilan de lecture des args. */ GBinContent *content; /* Version GLib du contenu */ - ret = PyArg_ParseTuple(args, "O!sO!", - get_python_binary_content_type(), &base_obj, + ret = PyArg_ParseTuple(args, "O&sO&", + convert_to_binary_content, &base, &path, - get_python_binary_content_type(), &endpoint_obj); + convert_to_binary_content, &endpoint); if (!ret) return NULL; - base = G_BIN_CONTENT(pygobject_get(base_obj)); - endpoint = G_BIN_CONTENT(pygobject_get(endpoint_obj)); - content = g_encaps_content_new(base, path, endpoint); result = pygobject_new(G_OBJECT(content)); diff --git a/plugins/pychrysalide/analysis/loaded.c b/plugins/pychrysalide/analysis/loaded.c index ae14164..43e749c 100644 --- a/plugins/pychrysalide/analysis/loaded.c +++ b/plugins/pychrysalide/analysis/loaded.c @@ -345,3 +345,48 @@ bool ensure_python_loaded_content_is_registered(void) return true; } + + +/****************************************************************************** +* * +* Paramètres : arg = argument quelconque à tenter de convertir. * +* dst = destination des valeurs récupérées en cas de succès. * +* * +* Description : Tente de convertir en contenu chargé. * +* * +* Retour : Bilan de l'opération, voire indications supplémentaires. * +* * +* Remarques : - * +* * +******************************************************************************/ + +int convert_to_loaded_content(PyObject *arg, void *dst) +{ + int result; /* Bilan à retourner */ + + result = PyObject_IsInstance(arg, (PyObject *)get_python_loaded_content_type()); + + switch (result) + { + case -1: + /* L'exception est déjà fixée par Python */ + result = 0; + break; + + case 0: + PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to loaded content"); + break; + + case 1: + *((GLoadedContent **)dst) = G_LOADED_CONTENT(pygobject_get(arg)); + break; + + default: + assert(false); + break; + + } + + return result; + +} diff --git a/plugins/pychrysalide/analysis/loaded.h b/plugins/pychrysalide/analysis/loaded.h index d87867f..8917e0c 100644 --- a/plugins/pychrysalide/analysis/loaded.h +++ b/plugins/pychrysalide/analysis/loaded.h @@ -37,6 +37,9 @@ PyTypeObject *get_python_loaded_content_type(void); /* Prend en charge l'objet 'pychrysalide.analysis.LoadedContent'. */ bool ensure_python_loaded_content_is_registered(void); +/* Tente de convertir en contenu chargé. */ +int convert_to_loaded_content(PyObject *, void *); + #endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_CONTENT_H */ diff --git a/plugins/pychrysalide/analysis/loading.c b/plugins/pychrysalide/analysis/loading.c index 0b06bd1..11a9854 100644 --- a/plugins/pychrysalide/analysis/loading.c +++ b/plugins/pychrysalide/analysis/loading.c @@ -79,16 +79,14 @@ static PyObject *py_content_explorer_populate_group(PyObject *self, PyObject *ar { PyObject *result; /* Valeur à retourner */ unsigned long long wid; /* Identifiant de groupe */ - PyObject *content_obj; /* Nouveau contenu Python */ + GBinContent *content; /* Contenu nouveau au final */ int ret; /* Bilan de lecture des args. */ GContentExplorer *explorer; /* Explorateur à manipuler */ - GBinContent *content; /* Contenu nouveau au final */ - ret = PyArg_ParseTuple(args, "KO!", &wid, get_python_binary_content_type(), &content_obj); + ret = PyArg_ParseTuple(args, "KO&", &wid, convert_to_binary_content, &content); if (!ret) return NULL; explorer = G_CONTENT_EXPLORER(pygobject_get(self)); - content = G_BIN_CONTENT(pygobject_get(content_obj)); g_content_explorer_populate_group(explorer, wid, content); @@ -116,16 +114,14 @@ static PyObject *py_content_explorer_note_detected(PyObject *self, PyObject *arg { PyObject *result; /* Valeur à retourner */ unsigned long long wid; /* Identifiant de groupe */ - PyObject *loaded_obj; /* Contenu chargé en Python */ + GLoadedContent *loaded; /* Contenu chargé au final */ int ret; /* Bilan de lecture des args. */ GContentExplorer *explorer; /* Explorateur à manipuler */ - GLoadedContent *loaded; /* Contenu chargé au final */ - ret = PyArg_ParseTuple(args, "KO!", &wid, get_python_loaded_content_type(), &loaded_obj); + ret = PyArg_ParseTuple(args, "KO&", &wid, convert_to_loaded_content, &loaded); if (!ret) return NULL; explorer = G_CONTENT_EXPLORER(pygobject_get(self)); - loaded = G_LOADED_CONTENT(pygobject_get(loaded_obj)); g_content_explorer_note_detected(explorer, wid, loaded); @@ -248,16 +244,14 @@ static PyObject *py_content_resolver_add_detected(PyObject *self, PyObject *args { PyObject *result; /* Valeur à retourner */ unsigned long long wid; /* Identifiant de groupe */ - PyObject *loaded_obj; /* Contenu chargé en Python */ + GLoadedContent *loaded; /* Contenu chargé au final */ int ret; /* Bilan de lecture des args. */ GContentResolver *resolver; /* Résolveur à manipuler */ - GLoadedContent *loaded; /* Contenu chargé au final */ - ret = PyArg_ParseTuple(args, "KO!", &wid, get_python_loaded_content_type(), &loaded_obj); + ret = PyArg_ParseTuple(args, "KO&", &wid, convert_to_loaded_content, &loaded); if (!ret) return NULL; resolver = G_CONTENT_RESOLVER(pygobject_get(self)); - loaded = G_LOADED_CONTENT(pygobject_get(loaded_obj)); g_content_resolver_add_detected(resolver, wid, loaded); diff --git a/plugins/pychrysalide/analysis/project.c b/plugins/pychrysalide/analysis/project.c index 98610d5..335a350 100644 --- a/plugins/pychrysalide/analysis/project.c +++ b/plugins/pychrysalide/analysis/project.c @@ -254,18 +254,15 @@ static PyObject *py_study_project_discover_binary_content(PyObject *self, PyObje static PyObject *py_study_project_attach_content(PyObject *self, PyObject *args) { - PyObject *content_obj; /* Objet pour le contenu */ - int ret; /* Bilan de lecture des args. */ GLoadedContent *content; /* Instance GLib correspondante*/ + int ret; /* Bilan de lecture des args. */ GStudyProject *project; /* Version GLib du format */ - ret = PyArg_ParseTuple(args, "O!", get_python_loaded_content_type(), &content_obj); + ret = PyArg_ParseTuple(args, "O&", convert_to_loaded_content, &content); if (!ret) return NULL; project = G_STUDY_PROJECT(pygobject_get(self)); - content = G_LOADED_CONTENT(pygobject_get(content_obj)); - g_study_project_attach_content(project, content); Py_RETURN_NONE; diff --git a/plugins/pychrysalide/analysis/type.c b/plugins/pychrysalide/analysis/type.c index 0134b0a..736656b 100644 --- a/plugins/pychrysalide/analysis/type.c +++ b/plugins/pychrysalide/analysis/type.c @@ -25,6 +25,7 @@ #include "type.h" +#include #include #include @@ -455,3 +456,48 @@ bool ensure_python_data_type_is_registered(void) return true; } + + +/****************************************************************************** +* * +* Paramètres : arg = argument quelconque à tenter de convertir. * +* dst = destination des valeurs récupérées en cas de succès. * +* * +* Description : Tente de convertir en type de donnée. * +* * +* Retour : Bilan de l'opération, voire indications supplémentaires. * +* * +* Remarques : - * +* * +******************************************************************************/ + +int convert_to_data_type(PyObject *arg, void *dst) +{ + int result; /* Bilan à retourner */ + + result = PyObject_IsInstance(arg, (PyObject *)get_python_data_type_type()); + + switch (result) + { + case -1: + /* L'exception est déjà fixée par Python */ + result = 0; + break; + + case 0: + PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to data type"); + break; + + case 1: + *((GDataType **)dst) = G_DATA_TYPE(pygobject_get(arg)); + break; + + default: + assert(false); + break; + + } + + return result; + +} diff --git a/plugins/pychrysalide/analysis/type.h b/plugins/pychrysalide/analysis/type.h index e75a993..57258bb 100644 --- a/plugins/pychrysalide/analysis/type.h +++ b/plugins/pychrysalide/analysis/type.h @@ -37,6 +37,9 @@ PyTypeObject *get_python_data_type_type(void); /* Prend en charge l'objet 'pychrysalide.analysis.DataType'. */ bool ensure_python_data_type_is_registered(void); +/* Tente de convertir en type de donnée. */ +int convert_to_data_type(PyObject *, void *); + #endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_TYPE_H */ diff --git a/plugins/pychrysalide/analysis/types/array.c b/plugins/pychrysalide/analysis/types/array.c index 5224d36..9c3a1ea 100644 --- a/plugins/pychrysalide/analysis/types/array.c +++ b/plugins/pychrysalide/analysis/types/array.c @@ -82,16 +82,13 @@ static int py_array_type_set_dimension_expression(PyObject *, PyObject *, void * static PyObject *py_array_type_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { PyObject *result; /* Instance à retourner */ - PyObject *members_obj; /* Objet du type d'éléments */ - int ret; /* Bilan de lecture des args. */ GDataType *members; /* Version GLib du type */ + int ret; /* Bilan de lecture des args. */ GDataType *dtype; /* Version GLib du type */ - ret = PyArg_ParseTuple(args, "O!", get_python_data_type_type(), &members_obj); + ret = PyArg_ParseTuple(args, "O&", convert_to_data_type, &members); if (!ret) return NULL; - members = G_DATA_TYPE(pygobject_get(members_obj)); - dtype = g_array_type_new(members); result = pygobject_new(G_OBJECT(dtype)); g_object_unref(dtype); diff --git a/plugins/pychrysalide/analysis/types/encaps.c b/plugins/pychrysalide/analysis/types/encaps.c index c2d435c..b876547 100644 --- a/plugins/pychrysalide/analysis/types/encaps.c +++ b/plugins/pychrysalide/analysis/types/encaps.c @@ -66,16 +66,13 @@ static PyObject *py_encapsulated_type_new(PyTypeObject *type, PyObject *args, Py { PyObject *result; /* Instance à retourner */ EncapsulationType encapsulation; /* Type d'encapsulation */ - PyObject *encaps_obj; /* Objet du type encapsulé */ - int ret; /* Bilan de lecture des args. */ GDataType *encapsulated; /* Type encapsulé */ + int ret; /* Bilan de lecture des args. */ GDataType *dtype; /* Version GLib du type */ - ret = PyArg_ParseTuple(args, "kO!", &encapsulation, get_python_data_type_type(), &encaps_obj); + ret = PyArg_ParseTuple(args, "kO&", &encapsulation, convert_to_data_type, &encapsulated); if (!ret) return NULL; - encapsulated = G_DATA_TYPE(pygobject_get(encaps_obj)); - dtype = g_encapsulated_type_new(encapsulation, encapsulated); result = pygobject_new(G_OBJECT(dtype)); g_object_unref(dtype); diff --git a/plugins/pychrysalide/analysis/types/proto.c b/plugins/pychrysalide/analysis/types/proto.c index a6046ab..975be1e 100644 --- a/plugins/pychrysalide/analysis/types/proto.c +++ b/plugins/pychrysalide/analysis/types/proto.c @@ -98,18 +98,15 @@ static PyObject *py_proto_type_new(PyTypeObject *type, PyObject *args, PyObject static PyObject *py_proto_type_add_arg(PyObject *self, PyObject *args) { - PyObject *arg_obj; /* Objet du type d'argument */ - int ret; /* Bilan de lecture des args. */ GDataType *arg; /* Version GLib du type */ + int ret; /* Bilan de lecture des args. */ GProtoType *type; /* Version GLib du type */ - ret = PyArg_ParseTuple(args, "O!", get_python_data_type_type(), &arg_obj); + ret = PyArg_ParseTuple(args, "O&", convert_to_data_type, &arg); if (!ret) return NULL; type = G_PROTO_TYPE(pygobject_get(self)); - arg = G_DATA_TYPE(pygobject_get(arg_obj)); - g_object_ref(G_OBJECT(arg)); g_proto_type_add_arg(type, arg); diff --git a/plugins/pychrysalide/analysis/types/template.c b/plugins/pychrysalide/analysis/types/template.c index 485eca4..0f6c002 100644 --- a/plugins/pychrysalide/analysis/types/template.c +++ b/plugins/pychrysalide/analysis/types/template.c @@ -99,18 +99,15 @@ static PyObject *py_template_type_new(PyTypeObject *type, PyObject *args, PyObje static PyObject *py_template_type_add_param(PyObject *self, PyObject *args) { - PyObject *param_obj; /* Objet du type de paramètre */ - int ret; /* Bilan de lecture des args. */ GDataType *param; /* Version GLib du type */ + int ret; /* Bilan de lecture des args. */ GTemplateType *type; /* Version GLib du type */ - ret = PyArg_ParseTuple(args, "O!", get_python_data_type_type(), ¶m_obj); + ret = PyArg_ParseTuple(args, "O&", convert_to_data_type, ¶m); if (!ret) return NULL; type = G_TEMPLATE_TYPE(pygobject_get(self)); - param = G_DATA_TYPE(pygobject_get(param_obj)); - g_object_ref(G_OBJECT(param)); g_template_type_add_param(type, param); diff --git a/plugins/pychrysalide/arch/targetableop.c b/plugins/pychrysalide/arch/targetableop.c index 52d00e0..bc9e3af 100644 --- a/plugins/pychrysalide/arch/targetableop.c +++ b/plugins/pychrysalide/arch/targetableop.c @@ -75,7 +75,7 @@ static PyObject *py_targetable_operand_get_addr(PyObject *self, PyObject *args) vmpa2t addr; /* Localisation à cibler */ bool defined; /* Cible définie ? */ - ret = PyArg_ParseTuple(args, "O!", + ret = PyArg_ParseTuple(args, "O!O!O!", get_python_vmpa_type(), &src_obj, get_python_binary_format_type(), &format_obj, get_python_arch_processor_type(), &proc_obj); diff --git a/plugins/pychrysalide/format/flat.c b/plugins/pychrysalide/format/flat.c index 3f32832..ce93493 100644 --- a/plugins/pychrysalide/format/flat.c +++ b/plugins/pychrysalide/format/flat.c @@ -63,16 +63,13 @@ static PyObject *py_flat_format_set_target_machine(PyObject *, PyObject *); static PyObject *py_flat_format_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { PyObject *result; /* Instance à retourner */ - PyObject *content_obj; /* Objet pour le contenu */ - int ret; /* Bilan de lecture des args. */ GBinContent *content; /* Instance GLib du contenu */ + int ret; /* Bilan de lecture des args. */ GExeFormat *format; /* Création GLib à transmettre */ - ret = PyArg_ParseTuple(args, "O!", get_python_binary_content_type(), &content_obj); + ret = PyArg_ParseTuple(args, "O&", convert_to_binary_content, &content); if (!ret) return NULL; - content = G_BIN_CONTENT(pygobject_get(content_obj)); - format = g_flat_format_new(content); if (format == NULL) diff --git a/plugins/pychrysalide/format/format.c b/plugins/pychrysalide/format/format.c index 82cb575..1dc4edd 100644 --- a/plugins/pychrysalide/format/format.c +++ b/plugins/pychrysalide/format/format.c @@ -150,17 +150,15 @@ static PyObject *py_binary_format_register_code_point(PyObject *self, PyObject * static PyObject *py_binary_format_add_symbol(PyObject *self, PyObject *args) { PyObject *result; /* Valeur à retourner */ - PyObject *symbol_obj; /* Version Python d'un symbole */ + GBinSymbol *symbol; /* Enventuel symbole trouvé */ int ret; /* Bilan de lecture des args. */ GBinFormat *format; /* Format de binaire manipulé */ - GBinSymbol *symbol; /* Enventuel symbole trouvé */ bool added; /* Bilan de l'appel interne */ - ret = PyArg_ParseTuple(args, "O!", get_python_binary_symbol_type(), &symbol_obj); + ret = PyArg_ParseTuple(args, "O&", convert_to_binary_symbol, &symbol); if (!ret) return NULL; format = G_BIN_FORMAT(pygobject_get(self)); - symbol = G_BIN_SYMBOL(pygobject_get(symbol_obj)); g_object_ref(G_OBJECT(symbol)); added = g_binary_format_add_symbol(format, symbol); @@ -189,16 +187,14 @@ static PyObject *py_binary_format_add_symbol(PyObject *self, PyObject *args) static PyObject *py_binary_format_remove_symbol(PyObject *self, PyObject *args) { PyObject *result; /* Valeur à retourner */ - PyObject *symbol_obj; /* Version Python d'un symbole */ + GBinSymbol *symbol; /* Enventuel symbole trouvé */ int ret; /* Bilan de lecture des args. */ GBinFormat *format; /* Format de binaire manipulé */ - GBinSymbol *symbol; /* Enventuel symbole trouvé */ - ret = PyArg_ParseTuple(args, "O!", get_python_binary_symbol_type(), &symbol_obj); + ret = PyArg_ParseTuple(args, "O&", convert_to_binary_symbol, &symbol); if (!ret) return NULL; format = G_BIN_FORMAT(pygobject_get(self)); - symbol = G_BIN_SYMBOL(pygobject_get(symbol_obj)); g_binary_format_remove_symbol(format, symbol); diff --git a/plugins/pychrysalide/format/symbol.c b/plugins/pychrysalide/format/symbol.c index bb58f64..3295e8c 100644 --- a/plugins/pychrysalide/format/symbol.c +++ b/plugins/pychrysalide/format/symbol.c @@ -25,6 +25,7 @@ #include "symbol.h" +#include #include #include @@ -502,3 +503,48 @@ bool ensure_python_binary_symbol_is_registered(void) return true; } + + +/****************************************************************************** +* * +* Paramètres : arg = argument quelconque à tenter de convertir. * +* dst = destination des valeurs récupérées en cas de succès. * +* * +* Description : Tente de convertir en symbole binaire. * +* * +* Retour : Bilan de l'opération, voire indications supplémentaires. * +* * +* Remarques : - * +* * +******************************************************************************/ + +int convert_to_binary_symbol(PyObject *arg, void *dst) +{ + int result; /* Bilan à retourner */ + + result = PyObject_IsInstance(arg, (PyObject *)get_python_binary_symbol_type()); + + switch (result) + { + case -1: + /* L'exception est déjà fixée par Python */ + result = 0; + break; + + case 0: + PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to binary symbol"); + break; + + case 1: + *((GBinSymbol **)dst) = G_BIN_SYMBOL(pygobject_get(arg)); + break; + + default: + assert(false); + break; + + } + + return result; + +} diff --git a/plugins/pychrysalide/format/symbol.h b/plugins/pychrysalide/format/symbol.h index a9161c6..2e3b013 100644 --- a/plugins/pychrysalide/format/symbol.h +++ b/plugins/pychrysalide/format/symbol.h @@ -37,6 +37,9 @@ PyTypeObject *get_python_binary_symbol_type(void); /* Prend en charge l'objet 'pychrysalide.format.BinSymbol'. */ bool ensure_python_binary_symbol_is_registered(void); +/* Tente de convertir en symbole binaire. */ +int convert_to_binary_symbol(PyObject *, void *); + #endif /* _PLUGINS_PYCHRYSALIDE_FORMAT_SYMBOL_H */ diff --git a/plugins/pychrysalide/glibext/bufferline.c b/plugins/pychrysalide/glibext/bufferline.c index 40bbcbf..e7734bd 100644 --- a/plugins/pychrysalide/glibext/bufferline.c +++ b/plugins/pychrysalide/glibext/bufferline.c @@ -25,6 +25,7 @@ #include "bufferline.h" +#include #include #include @@ -379,3 +380,48 @@ bool ensure_python_buffer_line_is_registered(void) return true; } + + +/****************************************************************************** +* * +* Paramètres : arg = argument quelconque à tenter de convertir. * +* dst = destination des valeurs récupérées en cas de succès. * +* * +* Description : Tente de convertir en ligne de tampon. * +* * +* Retour : Bilan de l'opération, voire indications supplémentaires. * +* * +* Remarques : - * +* * +******************************************************************************/ + +int convert_to_buffer_line(PyObject *arg, void *dst) +{ + int result; /* Bilan à retourner */ + + result = PyObject_IsInstance(arg, (PyObject *)get_python_buffer_line_type()); + + switch (result) + { + case -1: + /* L'exception est déjà fixée par Python */ + result = 0; + break; + + case 0: + PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to buffer line"); + break; + + case 1: + *((GBufferLine **)dst) = G_BUFFER_LINE(pygobject_get(arg)); + break; + + default: + assert(false); + break; + + } + + return result; + +} diff --git a/plugins/pychrysalide/glibext/bufferline.h b/plugins/pychrysalide/glibext/bufferline.h index 9fbebe5..7a33dc5 100644 --- a/plugins/pychrysalide/glibext/bufferline.h +++ b/plugins/pychrysalide/glibext/bufferline.h @@ -37,6 +37,9 @@ PyTypeObject *get_python_buffer_line_type(void); /* Prend en charge l'objet 'pychrysalide.glibext.BufferLine'. */ bool ensure_python_buffer_line_is_registered(void); +/* Tente de convertir en ligne de tampon. */ +int convert_to_buffer_line(PyObject *, void *); + #endif /* _PLUGINS_PYCHRYSALIDE_GLIBEXT_BUFFERLINE_H */ diff --git a/plugins/pychrysalide/glibext/linegen.c b/plugins/pychrysalide/glibext/linegen.c index c9ad013..d0e6f23 100644 --- a/plugins/pychrysalide/glibext/linegen.c +++ b/plugins/pychrysalide/glibext/linegen.c @@ -215,24 +215,18 @@ static PyObject *py_line_generator_get_flags(PyObject *self, PyObject *args) static PyObject *py_line_generator_print(PyObject *self, PyObject *args) { GLineGenerator *generator; /* Version native */ - PyObject *py_line; /* Ligne version Python */ + GBufferLine *line; /* Ligne de rendu à compléter */ size_t index; /* Indice dans le tampon */ size_t repeat; /* Utilisations successives */ - PyObject *py_content; /* Contenu version Python */ - int ret; /* Bilan de lecture des args. */ - GBufferLine *line; /* Ligne de rendu à compléter */ GBinContent *content; /* Contenu binaire associé */ + int ret; /* Bilan de lecture des args. */ generator = G_LINE_GENERATOR(pygobject_get(self)); - ret = PyArg_ParseTuple(args, "O!kkO!", get_python_buffer_line_type(), &py_line, &index, - &repeat, get_python_binary_content_type(), &py_content); + ret = PyArg_ParseTuple(args, "O&kkO&", convert_to_buffer_line, &line, &index, + &repeat, convert_to_binary_content, &content); if (!ret) return NULL; - line = G_BUFFER_LINE(pygobject_get(py_line)); - - content = G_BIN_CONTENT(pygobject_get(py_content)); - g_line_generator_print(generator, line, index, repeat, content); Py_RETURN_NONE; diff --git a/plugins/pychrysalide/glibext/loadedpanel.c b/plugins/pychrysalide/glibext/loadedpanel.c index d9364c5..a3f6dc8 100644 --- a/plugins/pychrysalide/glibext/loadedpanel.c +++ b/plugins/pychrysalide/glibext/loadedpanel.c @@ -25,6 +25,7 @@ #include "loadedpanel.h" +#include #include @@ -198,3 +199,48 @@ bool ensure_python_loaded_panel_is_registered(void) return true; } + + +/****************************************************************************** +* * +* Paramètres : arg = argument quelconque à tenter de convertir. * +* dst = destination des valeurs récupérées en cas de succès. * +* * +* Description : Tente de convertir en panneau de contenu chargé. * +* * +* Retour : Bilan de l'opération, voire indications supplémentaires. * +* * +* Remarques : - * +* * +******************************************************************************/ + +int convert_to_loaded_panel(PyObject *arg, void *dst) +{ + int result; /* Bilan à retourner */ + + result = PyObject_IsInstance(arg, (PyObject *)get_python_loaded_panel_type()); + + switch (result) + { + case -1: + /* L'exception est déjà fixée par Python */ + result = 0; + break; + + case 0: + PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to loaded panel"); + break; + + case 1: + *((GLoadedPanel **)dst) = G_LOADED_PANEL(pygobject_get(arg)); + break; + + default: + assert(false); + break; + + } + + return result; + +} diff --git a/plugins/pychrysalide/glibext/loadedpanel.h b/plugins/pychrysalide/glibext/loadedpanel.h index 35a76d1..89abfee 100644 --- a/plugins/pychrysalide/glibext/loadedpanel.h +++ b/plugins/pychrysalide/glibext/loadedpanel.h @@ -37,6 +37,9 @@ PyTypeObject *get_python_loaded_panel_type(void); /* Prend en charge l'objet 'pychrysalide.glibext.LoadedPanel'. */ bool ensure_python_loaded_panel_is_registered(void); +/* Tente de convertir en panneau de contenu chargé. */ +int convert_to_loaded_panel(PyObject *, void *); + #endif /* _PLUGINS_PYCHRYSALIDE_GLIBEXT_LOADEDPANEL_H */ diff --git a/plugins/pychrysalide/gtkext/graph/cluster.c b/plugins/pychrysalide/gtkext/graph/cluster.c index 1c664a0..c87655a 100644 --- a/plugins/pychrysalide/gtkext/graph/cluster.c +++ b/plugins/pychrysalide/gtkext/graph/cluster.c @@ -155,8 +155,7 @@ static PyObject *py_graph_cluster_find_by_widget(PyObject *self, PyObject *args) Py_DECREF(gtk_mod); - ret = PyArg_ParseTuple(args, "O!", - type, &widget_obj); + ret = PyArg_ParseTuple(args, "O!", type, &widget_obj); Py_DECREF(type); diff --git a/plugins/pychrysalide/gui/core/items.c b/plugins/pychrysalide/gui/core/items.c index 0912bc4..bc5bbd6 100644 --- a/plugins/pychrysalide/gui/core/items.c +++ b/plugins/pychrysalide/gui/core/items.c @@ -68,15 +68,12 @@ static PyObject *py_items_update_project(PyObject *, PyObject *); static PyObject *py_items_change_current_content(PyObject *self, PyObject *args) { - PyObject *content_obj; /* Objet pour le contenu */ - int ret; /* Bilan de lecture des args. */ GLoadedContent *content; /* Instance GLib correspondante*/ + int ret; /* Bilan de lecture des args. */ - ret = PyArg_ParseTuple(args, "O!", get_python_loaded_content_type(), &content_obj); + ret = PyArg_ParseTuple(args, "O&", convert_to_loaded_content, &content); if (!ret) return NULL; - content = G_LOADED_CONTENT(pygobject_get(content_obj)); - change_editor_items_current_content(content); Py_RETURN_NONE; @@ -99,15 +96,12 @@ static PyObject *py_items_change_current_content(PyObject *self, PyObject *args) static PyObject *py_items_change_current_view(PyObject *self, PyObject *args) { - PyObject *panel_obj; /* Objet de panneau chargé */ - int ret; /* Bilan de lecture des args. */ GLoadedPanel *panel; /* Instance GLib correspondante*/ + int ret; /* Bilan de lecture des args. */ - ret = PyArg_ParseTuple(args, "O!", get_python_loaded_panel_type(), &panel_obj); + ret = PyArg_ParseTuple(args, "O&", convert_to_loaded_panel, &panel); if (!ret) return NULL; - panel = G_LOADED_PANEL(pygobject_get(panel_obj)); - change_editor_items_current_view(panel); Py_RETURN_NONE; @@ -130,15 +124,12 @@ static PyObject *py_items_change_current_view(PyObject *self, PyObject *args) static PyObject *py_items_update_current_view(PyObject *self, PyObject *args) { - PyObject *panel_obj; /* Objet de panneau chargé */ - int ret; /* Bilan de lecture des args. */ GLoadedPanel *panel; /* Instance GLib correspondante*/ + int ret; /* Bilan de lecture des args. */ - ret = PyArg_ParseTuple(args, "O!", get_python_loaded_panel_type(), &panel_obj); + ret = PyArg_ParseTuple(args, "O&", convert_to_loaded_panel, &panel); if (!ret) return NULL; - panel = G_LOADED_PANEL(pygobject_get(panel_obj)); - update_editor_items_current_view(panel); Py_RETURN_NONE; @@ -163,15 +154,12 @@ static PyObject *py_items_update_current_view(PyObject *self, PyObject *args) static PyObject *py_items_update_project(PyObject *self, PyObject *args) { - PyObject *project_obj; /* Objet de panneau chargé */ - int ret; /* Bilan de lecture des args. */ GStudyProject *project; /* Instance GLib correspondante*/ + int ret; /* Bilan de lecture des args. */ - ret = PyArg_ParseTuple(args, "O!", get_python_study_project_type(), &project_obj); + ret = PyArg_ParseTuple(args, "O&", convert_to_study_project, &project); if (!ret) return NULL; - project = G_STUDY_PROJECT(pygobject_get(project_obj)); - update_project_area(project); Py_RETURN_NONE; -- cgit v0.11.2-87-g4458