summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2020-12-11 14:36:09 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2020-12-11 14:36:09 (GMT)
commit4b5cf2c57553eaeb647090ba8d0ad862c46e6733 (patch)
treee52755b6cd408fb2f750364b01cf5c4560ff795c
parent57e3511bbc5fce4eedfad7b57e775338b3eed56a (diff)
Deleted the PyConstvalObject class from the Python API.
-rw-r--r--plugins/pychrysalide/Makefile.am1
-rw-r--r--plugins/pychrysalide/constval.c387
-rw-r--r--plugins/pychrysalide/constval.h45
-rw-r--r--plugins/pychrysalide/core.c2
-rw-r--r--plugins/pychrysalide/helpers.c65
-rw-r--r--plugins/pychrysalide/helpers.h13
6 files changed, 0 insertions, 513 deletions
diff --git a/plugins/pychrysalide/Makefile.am b/plugins/pychrysalide/Makefile.am
index 530a889..ede0047 100644
--- a/plugins/pychrysalide/Makefile.am
+++ b/plugins/pychrysalide/Makefile.am
@@ -7,7 +7,6 @@ libdir = $(pluginslibdir)
pychrysalide_la_SOURCES = \
access.h access.c \
constants.h constants.c \
- constval.h constval.c \
core.h core.c \
helpers.h helpers.c \
plugin.h plugin.c \
diff --git a/plugins/pychrysalide/constval.c b/plugins/pychrysalide/constval.c
deleted file mode 100644
index ab5b81f..0000000
--- a/plugins/pychrysalide/constval.c
+++ /dev/null
@@ -1,387 +0,0 @@
-
-/* Chrysalide - Outil d'analyse de fichiers binaires
- * constval.c - conversion de constantes C en équivalent Python
- *
- * Copyright (C) 2018 Cyrille Bagard
- *
- * This file is part of Chrysalide.
- *
- * Chrysalide is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * Chrysalide is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-
-#include "constval.h"
-
-
-#include <longintrepr.h>
-#include <malloc.h>
-#include <string.h>
-
-
-#include <i18n.h>
-
-
-#include "access.h"
-#include "helpers.h"
-
-
-
-/* Objet à vocation interne */
-typedef struct _PyConstvalObject
-{
- PyLongObject base; /* A laisser en premier */
-
- /**
- * Le champ suivant est rajouté à la fin de l'allocation
- * de l'objet PyLongObject, dont la taille est dynamique.
- */
-
- /*char *name;*/ /* Désignation de la valeur */
-
-} PyConstvalObject;
-
-
-
-/* Interdit la création d'une instance depuis Python. */
-static PyObject *py_constval_new(PyTypeObject *, PyObject *, PyObject *);
-
-/* Libère la mémoire occupée par la description en sortie. */
-static void py_constval_finalize(PyObject *);
-
-/* Calcule l'emplacement reservé pour une désignation de valeur. */
-static char **py_constval_compute_name_ptr(PyConstvalObject *);
-
-/* Construit une représentation textuelle de l'objet. */
-static PyObject *py_constval_str(PyObject *);
-
-/* Fournit une réduction de l'objet en vue d'une sérialisation. */
-static PyObject *py_constval_reduce(PyObject *, PyObject *);
-
-
-
-/******************************************************************************
-* *
-* Paramètres : type = type du nouvel objet à mettre en place. *
-* args = éventuelle liste d'arguments. *
-* kwds = éventuel dictionnaire de valeurs mises à disposition. *
-* *
-* Description : Interdit la création d'une instance depuis Python. *
-* *
-* Retour : NULL. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static PyObject *py_constval_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- PyObject *result; /* Instance à retourner */
- unsigned long value; /* Valeur entière */
- const char *name; /* Désignation humaine */
- int ret; /* Bilan de lecture des args. */
-
- ret = PyArg_ParseTuple(args, "ks", &value, &name);
- if (!ret) return NULL;
-
- result = build_constval_from_c_code(name, value);
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : self = valeur constante C convertie en Python. *
-* *
-* Description : Libère la mémoire occupée par la description en sortie. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static void py_constval_finalize(PyObject *self)
-{
- PyConstvalObject *constval; /* Autre version de l'objet */
- char **ptr; /* Désignation à convertir */
-
- constval = (PyConstvalObject *)self;
-
- ptr = py_constval_compute_name_ptr(constval);
-
- free(*ptr);
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : self = valeur constante C convertie en Python. *
-* *
-* Description : Calcule l'emplacement reservé pour une désignation de valeur.*
-* *
-* Retour : Pointeur vers l'adresse de désignation. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static char **py_constval_compute_name_ptr(PyConstvalObject *self)
-{
- digit *result; /* Adresse mémoire à retourner */
- Py_ssize_t size; /* Taille supplémentaire */
-
- size = Py_SIZE(&self->base);
-
- if (size < 0)
- size = -size;
-
- result = &self->base.ob_digit[size];
-
- return (char **)result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : self = valeur constante C convertie en Python. *
-* *
-* Description : Construit une représentation textuelle de l'objet. *
-* *
-* Retour : Chaîne de caractère Unicode. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static PyObject *py_constval_str(PyObject *self)
-{
- PyObject *result; /* Elément à retourner */
- PyConstvalObject *constval; /* Autre version de l'objet */
- char **ptr; /* Désignation à convertir */
-
- constval = (PyConstvalObject *)self;
-
- ptr = py_constval_compute_name_ptr(constval);
-
- result = PyUnicode_FromString(*ptr);
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : self = architecture concernée par la procédure. *
-* args = instruction représentant le point de départ. *
-* *
-* Description : Fournit une réduction de l'objet en vue d'une sérialisation. *
-* *
-* Retour : Données utiles à une reconstruction. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static PyObject *py_constval_reduce(PyObject *self, PyObject *args)
-{
- PyObject *result; /* Données à retourner */
- unsigned long value; /* Valeur entière */
- PyConstvalObject *constval; /* Autre version de l'objet */
- char **ptr; /* Désignation à convertir */
- PyObject *params; /* Paramètres de construction */
-
- value = PyLong_AsUnsignedLong(self);
-
- constval = (PyConstvalObject *)self;
-
- ptr = py_constval_compute_name_ptr(constval);
-
- params = Py_BuildValue("(ks)", value, *ptr);
-
- result = Py_BuildValue("(OO)", Py_TYPE(self), params);
-
- Py_DECREF(params);
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : - *
-* *
-* Description : Fournit un accès à une définition de type à diffuser. *
-* *
-* Retour : Définition d'objet pour Python. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-PyTypeObject *get_python_py_constval_type(void)
-{
- static PyMethodDef py_constval_methods[] = {
- {
- "__reduce__", py_constval_reduce,
- METH_NOARGS,
- "__reduce__($self, /)\n--\n\nProvide information to rebuild the object."
- },
- { NULL }
- };
-
- static PyGetSetDef py_constval_getseters[] = {
- { NULL }
- };
-
- static PyTypeObject py_constval_type = {
-
- PyVarObject_HEAD_INIT(NULL, 0)
-
- .tp_name = "pychrysalide.PyConstvalObject",
- .tp_basicsize = offsetof(PyLongObject, ob_digit),
- .tp_itemsize = sizeof(digit),
-
- .tp_str = py_constval_str,
-
- .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_FINALIZE,
-
- .tp_doc = "PyChrysalide object for C constant values",
-
- .tp_methods = py_constval_methods,
- .tp_getset = py_constval_getseters,
- .tp_base = &PyLong_Type,
-
- .tp_new = py_constval_new,
-
- .tp_finalize = py_constval_finalize,
-
- };
-
- return &py_constval_type;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : - *
-* *
-* Description : Prend en charge l'objet 'pychrysalide.PyConstvalObject'. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool ensure_python_py_constval_is_registered(void)
-{
- PyTypeObject *type; /* Type Python 'PyConstval...' */
- PyObject *module; /* Module à recompléter */
-
- type = get_python_py_constval_type();
-
- if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
- {
- module = get_access_to_python_module("pychrysalide");
-
- if (PyType_Ready(type) != 0)
- return false;
-
- if (!register_python_module_object(module, type))
- return false;
-
- }
-
- return true;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : name = désignation de la constante à représenter. *
-* value = valeur de la constante à représenter. *
-* *
-* Description : Construit un objet pour valeur constante en C. *
-* *
-* Retour : Object Python résultant de la construction opérée. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-PyObject *build_constval_from_c_code(const char *name, unsigned long value)
-{
- PyObject *result; /* Instance à retourner */
- PyLongObject *tmp; /* Construction temporaire */
- Py_ssize_t size; /* Taille supplémentaire */
- PyTypeObject *type; /* Type Python 'PyConstval...' */
- PyConstvalObject *constval; /* Autre version de l'objet */
- char **ptr; /* Désignation à convertir */
-
- /* Création d'une base de travail */
-
- tmp = (PyLongObject *)PyLong_FromUnsignedLong(value);
-
- size = Py_SIZE(tmp);
-
- if (size < 0)
- size = -size;
-
- /**
- * En allouant 2 éléments "digit" supplémentaires, on est assuré
- * de disposer de l'espace nécessaire pour la conservation
- * d'un pointeur.
- */
-
- result = PyObject_MALLOC(offsetof(PyLongObject, ob_digit) + (size + 2) * sizeof(digit));
-
- if (!result)
- {
- PyErr_NoMemory();
- return NULL;
- }
-
- type = get_python_py_constval_type();
-
- result = PyObject_INIT_VAR(result, type, size);
-
- /* Copie de la valeur */
-
- Py_SIZE(result) = Py_SIZE(tmp);
-
- constval = (PyConstvalObject *)result;
-
- while (--size >= 0)
- constval->base.ob_digit[size] = tmp->ob_digit[size];
-
- Py_DECREF(tmp);
-
- /* Copie de la désignation */
-
- ptr = py_constval_compute_name_ptr(constval);
-
- *ptr = strdup(name);
-
- return result;
-
-}
diff --git a/plugins/pychrysalide/constval.h b/plugins/pychrysalide/constval.h
deleted file mode 100644
index 1099ee5..0000000
--- a/plugins/pychrysalide/constval.h
+++ /dev/null
@@ -1,45 +0,0 @@
-
-/* Chrysalide - Outil d'analyse de fichiers binaires
- * constval.h - prototypes pour la conversion de constantes C en équivalent Python
- *
- * Copyright (C) 2018 Cyrille Bagard
- *
- * This file is part of Chrysalide.
- *
- * Chrysalide is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * Chrysalide is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-
-#ifndef _PLUGINS_PYCHRYSALIDE_CONSTVAL_H
-#define _PLUGINS_PYCHRYSALIDE_CONSTVAL_H
-
-
-#include <Python.h>
-#include <stdbool.h>
-
-
-
-/* Fournit un accès à une définition de type à diffuser. */
-PyTypeObject *get_python_py_constval_type(void);
-
-/* Prend en charge l'objet 'pychrysalide.PyConstvalObject'. */
-bool ensure_python_py_constval_is_registered(void);
-
-/* Construit un objet pour valeur constante en C. */
-PyObject *build_constval_from_c_code(const char *, unsigned long);
-
-
-
-#endif /* _PLUGINS_PYCHRYSALIDE_CONSTVAL_H */
diff --git a/plugins/pychrysalide/core.c b/plugins/pychrysalide/core.c
index 94fb899..ee88521 100644
--- a/plugins/pychrysalide/core.c
+++ b/plugins/pychrysalide/core.c
@@ -48,7 +48,6 @@
#include "access.h"
-#include "constval.h"
#include "helpers.h"
#include "plugin.h"
#include "star.h"
@@ -529,7 +528,6 @@ PyMODINIT_FUNC PyInit_pychrysalide(void)
if (status) status = add_mangling_module(result);
if (status) status = ensure_python_plugin_module_is_registered();
- if (status) status = ensure_python_py_constval_is_registered();
if (status) status = ensure_python_string_enum_is_registered();
if (status) status = ensure_python_py_struct_is_registered();
diff --git a/plugins/pychrysalide/helpers.c b/plugins/pychrysalide/helpers.c
index 894b600..f811ad3 100644
--- a/plugins/pychrysalide/helpers.c
+++ b/plugins/pychrysalide/helpers.c
@@ -40,7 +40,6 @@
#include "access.h"
-#include "constval.h"
#include "strenum.h"
@@ -280,70 +279,6 @@ PyObject *run_python_method(PyObject *module, const char *method, PyObject *args
}
-/******************************************************************************
-* *
-* Paramètres : dict = dictionnaire à compléter. *
-* key = désignation de la constante à intégrer. *
-* value = valeur de la constante à intégrer. *
-* *
-* Description : Ajoute une constante au dictionnaire d'un type Python donné. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool PyDict_AddULongConstant(PyObject *dict, const char *key, unsigned long value)
-{
- bool result; /* Bilan à retourner */
- PyObject *item; /* Nouvel élément à insérer */
- int ret; /* Bilan d'un ajout */
-
- item = build_constval_from_c_code(key, value);
-
- ret = PyDict_SetItemString(dict, key, item);
- result = (ret != -1);
-
- Py_DECREF(item);
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : dict = dictionnaire à compléter. *
-* key = désignation de la constante à intégrer. *
-* value = valeur de la constante à intégrer. *
-* *
-* Description : Ajoute une constante au dictionnaire d'un type Python donné. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool PyDict_AddStringConstant(PyObject *dict, const char *key, const char *value)
-{
- bool result; /* Bilan à retourner */
- PyObject *item; /* Nouvel élément à insérer */
- int ret; /* Bilan d'un ajout */
-
- item = PyUnicode_FromString(value);
-
- ret = PyDict_SetItemString(dict, key, item);
- result = (ret != -1);
-
- Py_DECREF(item);
-
- return result;
-
-}
-
-
/* ---------------------------------------------------------------------------------- */
/* MISE EN PLACE DE MODULES */
diff --git a/plugins/pychrysalide/helpers.h b/plugins/pychrysalide/helpers.h
index 522986f..226071c 100644
--- a/plugins/pychrysalide/helpers.h
+++ b/plugins/pychrysalide/helpers.h
@@ -47,19 +47,6 @@ bool has_python_method(PyObject *, const char *);
/* Appelle une routine Python. */
PyObject *run_python_method(PyObject *, const char *, PyObject *);
-/* Ajoute une constante au dictionnaire d'un type Python donné. */
-bool PyDict_AddULongConstant(PyObject *, const char *, unsigned long);
-
-/* Ajoute une constante au dictionnaire d'un type Python donné. */
-bool PyDict_AddStringConstant(PyObject *, const char *, const char *);
-
-
-#define PyDict_AddULongMacro(tp, c) PyDict_AddULongConstant(tp->tp_dict, #c, c)
-#define PyDict_AddStringMacro(tp, c) PyDict_AddStringConstant(tp->tp_dict, #c, c)
-
-#define PyModDict_AddULongMacro(d, c) PyDict_AddULongConstant(d, #c, c)
-#define PyModDict_AddStringMacro(d, c) PyDict_AddStringConstant(d, #c, c)
-
/* ---------------------------- MISE EN PLACE DE MODULES ---------------------------- */