summaryrefslogtreecommitdiff
path: root/plugins/pychrysa/helpers.c
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/helpers.c
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/helpers.c')
-rw-r--r--plugins/pychrysa/helpers.c89
1 files changed, 76 insertions, 13 deletions
diff --git a/plugins/pychrysa/helpers.c b/plugins/pychrysa/helpers.c
index e2fc13a..d344a7f 100644
--- a/plugins/pychrysa/helpers.c
+++ b/plugins/pychrysa/helpers.c
@@ -27,6 +27,37 @@
/******************************************************************************
* *
+* Paramètres : func = fonction Python à appeler. *
+* args = arguments à associer à l'opération. *
+* *
+* Description : Appelle une routine Python. *
+* *
+* Retour : Retour obtenu ou NULL si erreur. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+PyObject *_run_python_method(PyObject *func, PyObject *args)
+{
+ PyObject *result; /* Bilan à retourner */
+
+ result = NULL;
+
+ if (PyCallable_Check(func))
+ {
+ result = PyObject_CallObject(func, args);
+ if (result == NULL) PyErr_Print();
+ }
+ else if (PyErr_Occurred()) PyErr_Print();
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : target = propriétaire de la routine visée. *
* method = désignation de la fonction à appeler. *
* args = arguments à associer à l'opération. *
@@ -58,32 +89,64 @@ PyObject *run_python_method(PyObject *module, const char *method, PyObject *args
}
+/******************************************************************************
+* *
+* Paramètres : obj_type = type dont le dictionnaire est à compléter. *
+* key = désignation de la constante à intégrer. *
+* value = valeur de la constante à intégrer. *
+* *
+* Description : Ajoute une constante au dictionnaire d'un type Python donné. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool PyDict_AddIntConstant(PyTypeObject *obj_type, const char *key, long value)
+{
+ bool result; /* Bilan à retourner */
+ PyObject *item; /* Nouvel élément à insérer */
+ int ret; /* Bilan d'un ajout */
+
+ item = PyLong_FromLong(value);
+
+ ret = PyDict_SetItemString(obj_type->tp_dict, key, item);
+ result = (ret != -1);
+
+ Py_DECREF(item);
+
+ return result;
+
+}
+
/******************************************************************************
* *
-* Paramètres : func = fonction Python à appeler. *
-* args = arguments à associer à l'opération. *
+* Paramètres : obj_type = type dont le dictionnaire est à compléter. *
+* key = désignation de la constante à intégrer. *
+* value = valeur de la constante à intégrer. *
* *
-* Description : Appelle une routine Python. *
+* Description : Ajoute une constante au dictionnaire d'un type Python donné. *
* *
-* Retour : Retour obtenu ou NULL si erreur. *
+* Retour : Bilan de l'opération. *
* *
* Remarques : - *
* *
******************************************************************************/
-PyObject *_run_python_method(PyObject *func, PyObject *args)
+bool PyDict_AddStringConstant(PyTypeObject *obj_type, const char *key, const char *value)
{
- PyObject *result; /* Bilan à retourner */
+ bool result; /* Bilan à retourner */
+ PyObject *item; /* Nouvel élément à insérer */
+ int ret; /* Bilan d'un ajout */
- result = NULL;
+ item = PyUnicode_FromString(value);
- if (PyCallable_Check(func))
- {
- result = PyObject_CallObject(func, args);
- if (result == NULL) PyErr_Print();
- }
- else if (PyErr_Occurred()) PyErr_Print();
+ ret = PyDict_SetItemString(obj_type->tp_dict, key, item);
+ result = (ret != -1);
+
+ Py_DECREF(item);
return result;