summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/helpers.h
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2018-01-16 19:02:56 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2018-01-16 19:02:56 (GMT)
commit9da8f8b37e3edebc917b4e223dd2447cd7cbc818 (patch)
tree3f330b13e7ca2a0a163882be3043ca9571f25211 /plugins/pychrysalide/helpers.h
parenteb9b7fd76451db5c9f07a800c0394480e4b88c9c (diff)
Changed the Python bindings source directory and updated code.
Diffstat (limited to 'plugins/pychrysalide/helpers.h')
-rw-r--r--plugins/pychrysalide/helpers.h93
1 files changed, 93 insertions, 0 deletions
diff --git a/plugins/pychrysalide/helpers.h b/plugins/pychrysalide/helpers.h
new file mode 100644
index 0000000..9c914e5
--- /dev/null
+++ b/plugins/pychrysalide/helpers.h
@@ -0,0 +1,93 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * helpers.h - prototypes pour la simplification des interactions de base avec Python
+ *
+ * Copyright (C) 2012-2017 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * Chrysalide is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Chrysalide is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _PLUGINS_PYCHRYSALIDE_HELPERS_H
+#define _PLUGINS_PYCHRYSALIDE_HELPERS_H
+
+
+#include <glib-object.h>
+#include <Python.h>
+#include <stdbool.h>
+
+
+
+/* ---------------------- ACCELERATEURS POUR PYTHON UNIQUEMENT ---------------------- */
+
+
+/* Traduit pour Python le bilan d'une comparaison riche. */
+PyObject *status_to_rich_cmp_state(int, int);
+
+/* Indique si une routine Python existe ou non. */
+bool has_python_method(PyObject *, const char *);
+
+/* Appelle une routine Python. */
+PyObject *_run_python_method(PyObject *, PyObject *);
+
+/* Appelle une routine Python. */
+PyObject *run_python_method(PyObject *, const char *, PyObject *);
+
+/* Ajoute une constante au dictionnaire d'un type Python donné. */
+bool PyDict_AddIntConstant(PyTypeObject *, const char *, long);
+
+/* Ajoute une constante au dictionnaire d'un type Python donné. */
+bool PyDict_AddStringConstant(PyTypeObject *, const char *, const char *);
+
+
+#define PyDict_AddIntMacro(tp, c) PyDict_AddIntConstant(tp, #c, c)
+#define PyDict_AddStringMacro(tp, c) PyDict_AddStringConstant(tp, #c, c)
+
+
+
+/* --------------------------- CONFORTS CIBLANT PYGOBJECT --------------------------- */
+
+
+/**
+ * Quelque chose est mal fait au niveau de l'abstraction GObject.
+ * Du coup, Py_TPFLAGS_IS_ABSTRACT n'est pas pris en compte.
+ * On force alors la méthode de base pour obtenir un traitement correct.
+ *
+ * Cf. http://stackoverflow.com/questions/20432335/can-python-abstract-base-classes-inherit-from-c-extensions
+ */
+#define APPLY_ABSTRACT_FLAG(tp) tp->tp_new = PyBaseObject_Type.tp_new
+
+
+/* Définit dans le tas de Python un nouveau type. */
+PyTypeObject *define_python_dynamic_type(const PyTypeObject *);
+
+/* Enregistre correctement une surcouche de conversion GObject. */
+bool _register_class_for_pygobject(PyObject *, GType, PyTypeObject *, PyTypeObject *, ...);
+
+#define register_class_for_pygobject(dict, gtype, type, base) \
+ _register_class_for_pygobject(dict, gtype, type, base, NULL)
+
+
+/**
+ * Quand on remplace un objet GLib dans le dos de Python, il faut
+ * le remplacer de la même manière qu'on l'a obtenu !
+ */
+
+#define pygobject_set(p, v) ((PyGObject *)(p))->obj = (GObject *)v
+
+
+
+#endif /* _PLUGINS_PYCHRYSALIDE_HELPERS_H */