diff options
Diffstat (limited to 'plugins/pychrysalide/analysis')
| -rw-r--r-- | plugins/pychrysalide/analysis/type.c | 100 | 
1 files changed, 100 insertions, 0 deletions
| diff --git a/plugins/pychrysalide/analysis/type.c b/plugins/pychrysalide/analysis/type.c index cd849e4..d2801bf 100644 --- a/plugins/pychrysalide/analysis/type.c +++ b/plugins/pychrysalide/analysis/type.c @@ -52,6 +52,9 @@ static PyObject *py_data_type_new(PyTypeObject *, PyObject *, PyObject *);  /* Initialise la classe des types quelconques. */  static void py_data_type_init_gclass(GDataTypeClass *, gpointer); +/* Calcule une empreinte pour un type de données. */ +static guint py_data_type_hash_wrapper(const GDataType *); +  /* Crée un copie d'un type existant. */  static GDataType *py_data_type_dup_wrapper(const GDataType *); @@ -81,6 +84,9 @@ static PyObject *py_data_type_to_str(PyObject *);  /* Crée un copie d'un type existant. */  static PyObject *py_data_type_dup(PyObject *, PyObject *); +/* Calcule une empreinte pour un type de données. */ +static PyObject *py_data_type_get_hash(PyObject *, void *); +  /* Fournit le groupe d'appartenance d'un type donné. */  static PyObject *py_data_type_get_namespace(PyObject *, void *); @@ -187,6 +193,7 @@ static PyObject *py_data_type_new(PyTypeObject *type, PyObject *args, PyObject *  static void py_data_type_init_gclass(GDataTypeClass *class, gpointer unused)  { +    class->hash = py_data_type_hash_wrapper;      class->dup = py_data_type_dup_wrapper;      class->to_string = py_data_type_to_string_wrapper; @@ -199,6 +206,58 @@ static void py_data_type_init_gclass(GDataTypeClass *class, gpointer unused)  /******************************************************************************  *                                                                             * +*  Paramètres  : type = type à consulter.                                     * +*                                                                             * +*  Description : Calcule une empreinte pour un type de données.               * +*                                                                             * +*  Retour      : Valeur arbitraire sur 32 bits, idéalement unique par type.   * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static guint py_data_type_hash_wrapper(const GDataType *type) +{ +    guint result;                           /* Empreinte à renvoyer        */ +    PyObject *pyobj;                        /* Objet Python concerné       */ +    PyObject *pyret;                        /* Bilan de consultation       */ + +#define DATA_TYPE_HASH_WRAPPER PYTHON_WRAPPER_DEF               \ +(                                                               \ +    _hash, "$self, /",                                          \ +    METH_NOARGS,                                                \ +    "Abstract method used to create a hash of the data type.\n" \ +    "\n"                                                        \ +    "The returned value has to be a 32-bit integer."            \ +) + +    result = 0; + +    pyobj = pygobject_new(G_OBJECT(type)); + +    if (has_python_method(pyobj, "_hash")) +    { +        pyret = run_python_method(pyobj, "_hash", NULL); + +        if (pyret != NULL) +        { +            if (PyLong_Check(pyret)) +                result = PyLong_AsUnsignedLong(pyret); +        } + +        Py_XDECREF(pyret); + +    } + +    Py_DECREF(pyobj); + +    return result; + +} + + +/****************************************************************************** +*                                                                             *  *  Paramètres  : type = type à dupliquer.                                     *  *                                                                             *  *  Description : Crée un copie d'un type existant.                            * @@ -496,6 +555,7 @@ static int py_data_type_init(PyObject *self, PyObject *args, PyObject *kwds)      "    DataType()"                                                    \      "\n"                                                                \      "The following methods have to be defined for new classes:\n"       \ +    "* pychrysalide.analysis.DataType._hash();\n"                       \      "* pychrysalide.analysis.DataType._dup();\n"                        \      "* pychrysalide.analysis.DataType._to_string()."                    \      "\n"                                                                \ @@ -606,6 +666,44 @@ static PyObject *py_data_type_dup(PyObject *self, PyObject *args)  *  Paramètres  : self    = objet Python concerné par l'appel.                 *  *                closure = non utilisé ici.                                   *  *                                                                             * +*  Description : Calcule une empreinte pour un type de données.               * +*                                                                             * +*  Retour      : Valeur arbitraire sur 32 bits, idéalement unique par type.   * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static PyObject *py_data_type_get_hash(PyObject *self, void *closure) +{ +    PyObject *result;                       /* Valeur à retourner          */ +    GDataType *type;                        /* Elément à consulter         */ +    guint hash;                             /* Empreinte à transmettre     */ + +#define DATA_TYPE_HASH_ATTRIB PYTHON_GET_DEF_FULL       \ +(                                                       \ +    hash, py_data_type,                                 \ +    "Hash value for the type, as a 32-bit integer.\n"   \ +    "\n"                                                \ +    "Each proporty change implies a hash change."       \ +) + +    type = G_DATA_TYPE(pygobject_get(self)); + +    hash = g_data_type_hash(type); + +    result = PyLong_FromUnsignedLong(hash); + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : self    = objet Python concerné par l'appel.                 * +*                closure = non utilisé ici.                                   * +*                                                                             *  *  Description : Fournit le groupe d'appartenance d'un type donné.            *  *                                                                             *  *  Retour      : Eventuelle instance d'appartenance ou None.                  * @@ -913,6 +1011,7 @@ static PyObject *py_data_type_is_reference(PyObject *self, void *closure)  PyTypeObject *get_python_data_type_type(void)  {      static PyMethodDef py_data_type_methods[] = { +        DATA_TYPE_HASH_WRAPPER,          DATA_TYPE_DUP_WRAPPER,          DATA_TYPE_TO_STRING_WRAPPER,          DATA_TYPE_HANDLE_NAMESPACES_WRAPPER, @@ -922,6 +1021,7 @@ PyTypeObject *get_python_data_type_type(void)      };      static PyGetSetDef py_data_type_getseters[] = { +        DATA_TYPE_HASH_ATTRIB,          DATA_TYPE_NAMESPACE_ATTRIB,          DATA_TYPE_QUALIFIERS_ATTRIB,          DATA_TYPE_NAMESPACES_ATTRIB, | 
