summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/pychrysalide/plugin.c58
1 files changed, 35 insertions, 23 deletions
diff --git a/plugins/pychrysalide/plugin.c b/plugins/pychrysalide/plugin.c
index 0fd6c26..495cecf 100644
--- a/plugins/pychrysalide/plugin.c
+++ b/plugins/pychrysalide/plugin.c
@@ -317,25 +317,28 @@ static int py_plugin_module_init(PyObject *self, PyObject *args, PyObject *kwds)
iface = calloc(1, sizeof(plugin_interface));
plugin->interface = iface;
-#define LOAD_PYTHON_IFACE(attr) \
- do \
- { \
- if (PyObject_HasAttrString(self, "_" #attr)) \
- { \
- value = PyObject_GetAttrString(self, "_" #attr); \
- if (value != NULL) \
- { \
- if (PyUnicode_Check(value)) \
- iface->attr = strdup(PyUnicode_AsUTF8(value)); \
- Py_DECREF(value); \
- } \
- } \
- if (iface->attr == NULL) \
- { \
- PyErr_SetString(PyExc_TypeError, _("A '_" #attr "' class attributes is missing.")); \
- return -1; \
- } \
- } \
+#define LOAD_PYTHON_IFACE(attr) \
+ do \
+ { \
+ value = PyObject_GetAttrString(self, "_" #attr); \
+ if (value == NULL) \
+ { \
+ PyErr_SetString(PyExc_TypeError, _("A '_" #attr "' class attributes is missing.")); \
+ return -1; \
+ } \
+ if (PyUnicode_Check(value)) \
+ { \
+ iface->attr = strdup(PyUnicode_AsUTF8(value)); \
+ Py_DECREF(value); \
+ } \
+ else \
+ { \
+ Py_DECREF(value); \
+ PyErr_SetString(PyExc_TypeError, _("The '_" #attr "' class attributes must be a string.")); \
+ return -1; \
+ } \
+ assert(iface->attr != NULL); \
+ } \
while (0);
LOAD_PYTHON_IFACE(name);
@@ -349,12 +352,18 @@ static int py_plugin_module_init(PyObject *self, PyObject *args, PyObject *kwds)
iface->required[0] = "PyChrysalide";
iface->required_count = 1;
- if (PyObject_HasAttrString(self, "_actions"))
- value = PyObject_GetAttrString(self, "_actions");
+ value = PyObject_GetAttrString(self, "_actions");
- else
+ if (value == NULL)
+ {
+ PyErr_SetString(PyExc_TypeError, _("An '_actions' class attributes is missing."));
+ return -1;
+ }
+
+ if (!PyTuple_Check(value))
{
- PyErr_SetString(PyExc_TypeError, _("A '_actions' class attributes is missing."));
+ Py_DECREF(value);
+ PyErr_SetString(PyExc_TypeError, _("The '_actions' class attributes must be a tuple."));
return -1;
}
@@ -367,6 +376,7 @@ static int py_plugin_module_init(PyObject *self, PyObject *args, PyObject *kwds)
if (!PyLong_Check(action))
{
+ Py_DECREF(value);
PyErr_SetString(PyExc_TypeError, _("invalid type for plugin action."));
return -1;
}
@@ -375,6 +385,8 @@ static int py_plugin_module_init(PyObject *self, PyObject *args, PyObject *kwds)
}
+ Py_DECREF(value);
+
return 0;
}