summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/common/fnv1a.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysalide/common/fnv1a.c')
-rw-r--r--plugins/pychrysalide/common/fnv1a.c91
1 files changed, 20 insertions, 71 deletions
diff --git a/plugins/pychrysalide/common/fnv1a.c b/plugins/pychrysalide/common/fnv1a.c
index 510b531..4103c86 100644
--- a/plugins/pychrysalide/common/fnv1a.c
+++ b/plugins/pychrysalide/common/fnv1a.c
@@ -36,16 +36,8 @@
-#define FNV1A_DOC \
- "Python version for Chrysalide of the Fowler-Noll-Vo" \
- " hash function.\n" \
- "\n" \
- "There is no constructor for this class: its methods" \
- " are static methods only."
-
-
/* Détermine l'empreinte FNV1a d'une chaîne de caractères. */
-static PyObject *py_fnv1a_hash(PyObject *, PyObject *);
+static PyObject *py_fnv1a(PyObject *, PyObject *);
@@ -62,18 +54,21 @@ static PyObject *py_fnv1a_hash(PyObject *, PyObject *);
* *
******************************************************************************/
-static PyObject *py_fnv1a_hash(PyObject *self, PyObject *args)
+static PyObject *py_fnv1a(PyObject *self, PyObject *args)
{
PyObject *result; /* Instance à retourner */
const char *str; /* Chaîne à traiter. */
int ret; /* Bilan de lecture des args. */
fnv64_t value; /* Empreinte calculée */
-#define FNV1A_HASH_METHOD PYTHON_METHOD_DEF \
-( \
- hash, "str, /", \
- METH_VARARGS | METH_STATIC, py_fnv1a, \
- "Compute the FNV-1a hash from a given string." \
+#define FNV1A_METHOD PYTHON_METHOD_DEF \
+( \
+ fnv1a, "str, /", \
+ METH_VARARGS, py, \
+ "Compute the Fowler-Noll-Vo hash (version 1a) of a" \
+ " given string." \
+ "\n" \
+ "The result is 64-bit integer value." \
)
ret = PyArg_ParseTuple(args, "s", &str);
@@ -92,48 +87,7 @@ static PyObject *py_fnv1a_hash(PyObject *self, PyObject *args)
* *
* Paramètres : - *
* *
-* Description : Fournit un accès à une définition de type à diffuser. *
-* *
-* Retour : Définition d'objet pour Python. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-PyTypeObject *get_python_fnv1a_type(void)
-{
- static PyMethodDef py_fnv1a_methods[] = {
- FNV1A_HASH_METHOD,
- { NULL }
- };
-
- static PyTypeObject py_fnv1a_type = {
-
- PyVarObject_HEAD_INIT(NULL, 0)
-
- .tp_name = "pychrysalide.common.fnv1a",
- .tp_basicsize = sizeof(PyObject),
-
- .tp_flags = Py_TPFLAGS_DEFAULT,
-
- .tp_doc = FNV1A_DOC,
-
- .tp_methods = py_fnv1a_methods,
-
- .tp_new = no_python_constructor_allowed,
-
- };
-
- return &py_fnv1a_type;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : module = module dont la définition est à compléter. *
-* *
-* Description : Prend en charge l'objet 'pychrysalide.core.fnv1a'. *
+* Description : Définit une extension du module 'common' à compléter. *
* *
* Retour : Bilan de l'opération. *
* *
@@ -141,25 +95,20 @@ PyTypeObject *get_python_fnv1a_type(void)
* *
******************************************************************************/
-bool ensure_python_fnv1a_is_registered(void)
+bool populate_common_module_with_fnv1a(void)
{
- PyTypeObject *type; /* Type Python pour 'fnv1a' */
+ bool result; /* Bilan à retourner */
PyObject *module; /* Module à recompléter */
- type = get_python_fnv1a_type();
-
- if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
- {
- if (PyType_Ready(type) != 0)
- return false;
-
- module = get_access_to_python_module("pychrysalide.common");
+ static PyMethodDef py_fnv1a_methods[] = {
+ FNV1A_METHOD,
+ { NULL }
+ };
- if (!register_python_module_object(module, type))
- return false;
+ module = get_access_to_python_module("pychrysalide.common");
- }
+ result = register_python_module_methods(module, py_fnv1a_methods);
- return true;
+ return result;
}