summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/glibext
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-07-21 20:21:59 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-07-21 20:21:59 (GMT)
commit6a8385724c74b07cf9ed4cb9052f1af1816e3ea5 (patch)
treea7bea8a4bb9c816da77cf5c3dd44fbd8fb89b3a7 /plugins/pychrysalide/glibext
parentf0682e7b195acbd4d83148f3829479d682f9ee9f (diff)
Created more converters for Python arguments.
Diffstat (limited to 'plugins/pychrysalide/glibext')
-rw-r--r--plugins/pychrysalide/glibext/bufferline.c46
-rw-r--r--plugins/pychrysalide/glibext/bufferline.h3
-rw-r--r--plugins/pychrysalide/glibext/linegen.c14
-rw-r--r--plugins/pychrysalide/glibext/loadedpanel.c46
-rw-r--r--plugins/pychrysalide/glibext/loadedpanel.h3
5 files changed, 102 insertions, 10 deletions
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 <assert.h>
#include <malloc.h>
#include <pygobject.h>
@@ -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 <assert.h>
#include <pygobject.h>
@@ -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 */