summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/analysis
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2020-12-11 14:29:09 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2020-12-11 14:29:09 (GMT)
commit57e3511bbc5fce4eedfad7b57e775338b3eed56a (patch)
tree218201453a1ddd6b219c936dc83e33647377e443 /plugins/pychrysalide/analysis
parent4e0a2b71a5937b7382dc14881672a13b84afddac (diff)
Updated the Python API to use properly handled constants.
Diffstat (limited to 'plugins/pychrysalide/analysis')
-rw-r--r--plugins/pychrysalide/analysis/types/constants.c100
-rw-r--r--plugins/pychrysalide/analysis/types/constants.h6
-rw-r--r--plugins/pychrysalide/analysis/types/encaps.c37
3 files changed, 108 insertions, 35 deletions
diff --git a/plugins/pychrysalide/analysis/types/constants.c b/plugins/pychrysalide/analysis/types/constants.c
index 1112410..76eaaf8 100644
--- a/plugins/pychrysalide/analysis/types/constants.c
+++ b/plugins/pychrysalide/analysis/types/constants.c
@@ -27,6 +27,7 @@
#include <analysis/types/basic.h>
#include <analysis/types/cse.h>
+#include <analysis/types/encaps.h>
#include "../../helpers.h"
@@ -254,3 +255,102 @@ int convert_to_class_enum_type_class_enum_kind(PyObject *arg, void *dst)
return result;
}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type dont le dictionnaire est à compléter. *
+* *
+* Description : Définit les constantes relatives aux types encapsulés. *
+* *
+* Retour : true en cas de succès de l'opération, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool define_encapsulated_type_constants(PyTypeObject *type)
+{
+ bool result; /* Bilan à retourner */
+ PyObject *values; /* Groupe de valeurs à établir */
+
+ values = PyDict_New();
+
+ result = add_const_to_group(values, "POINTER", ECT_POINTER);
+ if (result) result = add_const_to_group(values, "ARRAY", ECT_ARRAY);
+ if (result) result = add_const_to_group(values, "REFERENCE", ECT_REFERENCE);
+ if (result) result = add_const_to_group(values, "RVALUE_REF", ECT_RVALUE_REF);
+ if (result) result = add_const_to_group(values, "COMPLEX", ECT_COMPLEX);
+ if (result) result = add_const_to_group(values, "IMAGINARY", ECT_IMAGINARY);
+ if (result) result = add_const_to_group(values, "COUNT", ECT_COUNT);
+
+ if (!result)
+ {
+ Py_DECREF(values);
+ goto exit;
+ }
+
+ result = attach_constants_group_to_type(type, false, "EncapsulationType", values,
+ "Identifiers for basic data types.");
+
+ exit:
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : arg = argument quelconque à tenter de convertir. *
+* dst = destination des valeurs récupérées en cas de succès. *
+* *
+* Description : Tente de convertir en constante EncapsulationType. *
+* *
+* Retour : Bilan de l'opération, voire indications supplémentaires. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int convert_to_encapsulation_type(PyObject *arg, void *dst)
+{
+ int result; /* Bilan à retourner */
+ unsigned long value; /* Valeur transcrite */
+
+ result = PyObject_IsInstance(arg, (PyObject *)&PyLong_Type);
+
+ switch (result)
+ {
+ case -1:
+ /* L'exception est déjà fixée par Python */
+ result = 0;
+ break;
+
+ case 0:
+ PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to EncapsulationType");
+ break;
+
+ case 1:
+ value = PyLong_AsUnsignedLong(arg);
+
+ if (value > ECT_COUNT)
+ {
+ PyErr_SetString(PyExc_TypeError, "invalid value for EncapsulationType");
+ result = 0;
+ }
+
+ else
+ *((EncapsulationType *)dst) = value;
+
+ break;
+
+ default:
+ assert(false);
+ break;
+
+ }
+
+ return result;
+
+}
diff --git a/plugins/pychrysalide/analysis/types/constants.h b/plugins/pychrysalide/analysis/types/constants.h
index b695e8d..9245c56 100644
--- a/plugins/pychrysalide/analysis/types/constants.h
+++ b/plugins/pychrysalide/analysis/types/constants.h
@@ -43,6 +43,12 @@ bool define_class_enum_type_constants(PyTypeObject *);
/* Tente de convertir en constante ClassEnumKind. */
int convert_to_class_enum_type_class_enum_kind(PyObject *, void *);
+/* Définit les constantes relatives aux types encapsulés. */
+bool define_encapsulated_type_constants(PyTypeObject *);
+
+/* Tente de convertir en constante EncapsulationType. */
+int convert_to_encapsulation_type(PyObject *, void *);
+
#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_TYPES_CONSTANTS_H */
diff --git a/plugins/pychrysalide/analysis/types/encaps.c b/plugins/pychrysalide/analysis/types/encaps.c
index b530394..3a5acb5 100644
--- a/plugins/pychrysalide/analysis/types/encaps.c
+++ b/plugins/pychrysalide/analysis/types/encaps.c
@@ -31,6 +31,7 @@
#include <analysis/types/encaps.h>
+#include "constants.h"
#include "../type.h"
#include "../../access.h"
#include "../../helpers.h"
@@ -43,9 +44,6 @@ static PyObject *py_encapsulated_type_new(PyTypeObject *, PyObject *, PyObject *
/* Fournit le type encapsulée dans le type. */
static PyObject *py_encapsulated_type_get_item(PyObject *, void *);
-/* Définit les constantes pour les types d'encapsulation. */
-static bool py_encapsulated_type_define_constants(PyTypeObject *);
-
/******************************************************************************
@@ -198,37 +196,6 @@ PyTypeObject *get_python_encapsulated_type_type(void)
/******************************************************************************
* *
-* Paramètres : obj_type = type dont le dictionnaire est à compléter. *
-* *
-* Description : Définit les constantes pour les types d'encapsulation. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static bool py_encapsulated_type_define_constants(PyTypeObject *obj_type)
-{
- bool result; /* Bilan à retourner */
-
- result = true;
-
- result &= PyDict_AddULongMacro(obj_type, ECT_POINTER);
- result &= PyDict_AddULongMacro(obj_type, ECT_REFERENCE);
- result &= PyDict_AddULongMacro(obj_type, ECT_RVALUE_REF);
- result &= PyDict_AddULongMacro(obj_type, ECT_COMPLEX);
- result &= PyDict_AddULongMacro(obj_type, ECT_IMAGINARY);
-
- result &= PyDict_AddULongMacro(obj_type, ECT_COUNT);
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
* Paramètres : module = module dont la définition est à compléter. *
* *
* Description : Prend en charge l'objet 'pychrysalide.....EncapsulatedType'. *
@@ -259,7 +226,7 @@ bool ensure_python_encapsulated_type_is_registered(void)
if (!register_class_for_pygobject(dict, G_TYPE_ENCAPSULATED_TYPE, type, get_python_data_type_type()))
return false;
- if (!py_encapsulated_type_define_constants(type))
+ if (!define_encapsulated_type_constants(type))
return false;
}