summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2020-10-18 19:32:15 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2020-10-18 19:32:15 (GMT)
commite0949633787945ca7ca8b2498f2bbcbf1255ff4b (patch)
tree1ebec2469d12676a5efbdb41c6c404e80574185c /plugins/pychrysalide
parent601b8149bf81231a09e2977dbdbfe8e8e568c1f4 (diff)
Updated the code for template types.
Diffstat (limited to 'plugins/pychrysalide')
-rw-r--r--plugins/pychrysalide/analysis/types/template.c73
1 files changed, 55 insertions, 18 deletions
diff --git a/plugins/pychrysalide/analysis/types/template.c b/plugins/pychrysalide/analysis/types/template.c
index 830eeb6..6fc50e4 100644
--- a/plugins/pychrysalide/analysis/types/template.c
+++ b/plugins/pychrysalide/analysis/types/template.c
@@ -75,6 +75,16 @@ static PyObject *py_template_type_new(PyTypeObject *type, PyObject *args, PyObje
PyObject *result; /* Instance à retourner */
GDataType *dtype; /* Version GLib du type */
+#define TEMPLATE_TYPE_DOC \
+ "The TemplateType class declares an empty template type.\n" \
+ "\n" \
+ "Instances can be created using the following constructor:\n" \
+ "\n" \
+ " TemplateType()" \
+ "\n" \
+ "Name and template parameters have then to be filled in the created" \
+ " declaration with the relevant methods or properties."
+
dtype = g_template_type_new();
result = pygobject_new(G_OBJECT(dtype));
g_object_unref(dtype);
@@ -99,19 +109,32 @@ static PyObject *py_template_type_new(PyTypeObject *type, PyObject *args, PyObje
static PyObject *py_template_type_add_param(PyObject *self, PyObject *args)
{
+ PyObject *result; /* Absence de retour Python */
GDataType *param; /* Version GLib du type */
int ret; /* Bilan de lecture des args. */
GTemplateType *type; /* Version GLib du type */
+#define TEMPLATE_TYPE_ADD_PARAM_METHOD PYTHON_METHOD_DEF \
+( \
+ add_param, "$self, param, /", \
+ METH_VARARGS, py_template_type, \
+ "Add an extra parameter to the template type.\n" \
+ "\n" \
+ "This extra parameter has to be a pychrysalide.analysis.DataType" \
+ " instance." \
+)
+
ret = PyArg_ParseTuple(args, "O&", convert_to_data_type, &param);
if (!ret) return NULL;
type = G_TEMPLATE_TYPE(pygobject_get(self));
- g_object_ref(G_OBJECT(param));
g_template_type_add_param(type, param);
- Py_RETURN_NONE;
+ result = Py_None;
+ Py_INCREF(result);
+
+ return result;
}
@@ -135,11 +158,26 @@ static PyObject *py_template_type_get_name(PyObject *self, void *closure)
GTemplateType *type; /* Version GLib du type */
const char *name; /* Désignation humaine */
+#define TEMPLATE_TYPE_NAME_ATTRIB PYTHON_GETSET_DEF_FULL \
+( \
+ name, py_template_type, \
+ "Name of the template type.\n" \
+ "\n" \
+ "This property is a simple string, or None is the" \
+ " template type has no name." \
+)
+
type = G_TEMPLATE_TYPE(pygobject_get(self));
name = g_template_type_get_name(type);
- result = PyUnicode_FromString(name);
+ if (name == NULL)
+ {
+ result = Py_None;
+ Py_INCREF(result);
+ }
+ else
+ result = PyUnicode_FromString(name);
return result;
@@ -172,7 +210,7 @@ static int py_template_type_set_name(PyObject *self, PyObject *value, void *clos
type = G_TEMPLATE_TYPE(pygobject_get(self));
- g_template_type_set_name(type, strdup(PyUnicode_DATA(value)));
+ g_template_type_set_name(type, PyUnicode_DATA(value));
return 0;
@@ -201,6 +239,15 @@ static PyObject *py_template_type_get_params(PyObject *self, void *closure)
size_t i; /* Boucle de parcours */
GDataType *param; /* Paramètre du gabarit */
+#define TEMPLATE_TYPE_PARAMS_ATTRIB PYTHON_GET_DEF_FULL \
+( \
+ params, py_template_type, \
+ "List of all parameters of the template type.\n" \
+ "\n" \
+ "The returned value is a tuple of pychrysalide.analysis.DataType" \
+ " instances." \
+)
+
type = G_TEMPLATE_TYPE(pygobject_get(self));
count = g_template_type_count_params(type);
@@ -237,23 +284,13 @@ static PyObject *py_template_type_get_params(PyObject *self, void *closure)
PyTypeObject *get_python_template_type_type(void)
{
static PyMethodDef py_template_type_methods[] = {
- {
- "add_param", py_template_type_add_param,
- METH_VARARGS,
- "add_param($self, type, /)\n--\n\nAdd an extra parameter to the template type."
- },
+ TEMPLATE_TYPE_ADD_PARAM_METHOD,
{ NULL }
};
static PyGetSetDef py_template_type_getseters[] = {
- {
- "name", py_template_type_get_name, py_template_type_set_name,
- "Give access to the name of the template type.", NULL
- },
- {
- "params", py_template_type_get_params, NULL,
- "Give all parameters of the template type.", NULL
- },
+ TEMPLATE_TYPE_NAME_ATTRIB,
+ TEMPLATE_TYPE_PARAMS_ATTRIB,
{ NULL }
};
@@ -266,7 +303,7 @@ PyTypeObject *get_python_template_type_type(void)
.tp_flags = Py_TPFLAGS_DEFAULT,
- .tp_doc = "PyChrysalide template type",
+ .tp_doc = TEMPLATE_TYPE_DOC,
.tp_methods = py_template_type_methods,
.tp_getset = py_template_type_getseters,