diff options
| author | Cyrille Bagard <nocbos@gmail.com> | 2017-07-27 17:13:19 (GMT) | 
|---|---|---|
| committer | Cyrille Bagard <nocbos@gmail.com> | 2017-07-27 17:13:19 (GMT) | 
| commit | 77f88a59bfb9296df7e995e99218d27862136588 (patch) | |
| tree | 6e9897f690b50da53d77266095eccb358912a1cb /plugins/pychrysa/gtkext/displaypanel.c | |
| parent | 359055e28bcd195fb03fd0deb1a30e5a04d5ce58 (diff) | |
Fixed several mistakes in the Python bindings.
Diffstat (limited to 'plugins/pychrysa/gtkext/displaypanel.c')
| -rw-r--r-- | plugins/pychrysa/gtkext/displaypanel.c | 35 | 
1 files changed, 28 insertions, 7 deletions
| diff --git a/plugins/pychrysa/gtkext/displaypanel.c b/plugins/pychrysa/gtkext/displaypanel.c index d085f4f..e857475 100644 --- a/plugins/pychrysa/gtkext/displaypanel.c +++ b/plugins/pychrysa/gtkext/displaypanel.c @@ -25,6 +25,7 @@  #include "displaypanel.h" +#include <string.h>  #include <pygobject.h> @@ -196,7 +197,7 @@ PyTypeObject *get_python_display_panel_type(void)          .tp_name        = "pychrysalide.gtkext.DisplayPanel",          .tp_basicsize   = sizeof(PyGObject), -        .tp_flags       = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, +        .tp_flags       = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HEAPTYPE,          .tp_doc         = "PyChrysalide view panel.", @@ -207,7 +208,17 @@ PyTypeObject *get_python_display_panel_type(void)      }; -    return &py_display_panel_type; +    static PyTypeObject *result = NULL; + +    if (result == NULL) +    { +        result = calloc(1, sizeof(PyTypeObject)); + +        memcpy(result, &py_display_panel_type, sizeof(PyTypeObject)); + +    } + +    return result;  } @@ -226,27 +237,37 @@ PyTypeObject *get_python_display_panel_type(void)  bool register_python_display_panel(PyObject *module)  { +    bool result;                            /* Bilan à retourner           */      PyTypeObject *py_display_panel_type;    /* Type Python 'DisplayPanel'  */      PyObject *parent_mod;                   /* Module Python Fixed         */      PyObject *fixed;                        /* Module "GtkFixed"           */      PyObject *dict;                         /* Dictionnaire du module      */ +    result = false; +      py_display_panel_type = get_python_display_panel_type();      parent_mod = PyImport_ImportModule("gi.repository.Gtk");      if (parent_mod == NULL) return false;      fixed = PyObject_GetAttrString(parent_mod, "Fixed"); +      Py_DECREF(parent_mod);      dict = PyModule_GetDict(module); -    if (!register_class_for_pygobject(dict, GTK_TYPE_DISPLAY_PANEL, py_display_panel_type, (PyTypeObject *)fixed)) -        return false; +    result = register_class_for_pygobject(dict, GTK_TYPE_DISPLAY_PANEL, +                                          py_display_panel_type, (PyTypeObject *)fixed); + +    Py_DECREF(fixed); -    if (!py_display_panel_define_constants(py_display_panel_type)) -        return false; +    if (!result) +        goto rpdp_exit; -    return true; +    result = py_display_panel_define_constants(py_display_panel_type); + + rpdp_exit: + +    return result;  } | 
