bpo-1635741: Port _blake2 module to multi-phase init (GH-21856)

Port the _blake2 extension module to the multi-phase
initialization API (PEP 489).
This commit is contained in:
Mohamed Koubaa 2020-09-02 04:45:13 -05:00 committed by GitHub
parent 749ed85e44
commit a7f026870d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 121 additions and 120 deletions

View file

@ -33,8 +33,7 @@
#include "impl/blake2s-ref.c"
#endif
extern PyTypeObject PyBlake2_BLAKE2sType;
extern PyType_Spec blake2s_type_spec;
typedef struct {
PyObject_HEAD
@ -391,47 +390,24 @@ py_blake2s_dealloc(PyObject *self)
PyThread_free_lock(obj->lock);
obj->lock = NULL;
}
PyTypeObject *type = Py_TYPE(self);
PyObject_Del(self);
Py_DECREF(type);
}
PyTypeObject PyBlake2_BLAKE2sType = {
PyVarObject_HEAD_INIT(NULL, 0)
"_blake2.blake2s", /* tp_name */
sizeof(BLAKE2sObject), /* tp_basicsize */
0, /* tp_itemsize */
py_blake2s_dealloc, /* tp_dealloc */
0, /*tp_vectorcall_offset*/
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_as_async */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
py_blake2s_new__doc__, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
py_blake2s_methods, /* tp_methods */
0, /* tp_members */
py_blake2s_getsetters, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
py_blake2s_new, /* tp_new */
static PyType_Slot blake2s_type_slots[] = {
{Py_tp_dealloc, py_blake2s_dealloc},
{Py_tp_doc, (char *)py_blake2s_new__doc__},
{Py_tp_methods, py_blake2s_methods},
{Py_tp_getset, py_blake2s_getsetters},
{Py_tp_new, py_blake2s_new},
{0,0}
};
PyType_Spec blake2s_type_spec = {
.name = "_blake2.blake2s",
.basicsize = sizeof(BLAKE2sObject),
.flags = Py_TPFLAGS_DEFAULT,
.slots = blake2s_type_slots
};