From 8b686a6f68545d19765bd79452842403cce4af38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Lambert?= Date: Mon, 19 Oct 2020 13:50:00 +0700 Subject: [PATCH] match `hashlib` behavior: - enable `update` after `digest` - add `copy` method - add `digest_size`, `block_size` and `name` readonly attributes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Aurélien Lambert ... --- metrohash.cpp | 2294 +++++++++++++++++++++++++++++++++---------------- metrohash.pyx | 94 +- test.py | 52 ++ 3 files changed, 1661 insertions(+), 779 deletions(-) diff --git a/metrohash.cpp b/metrohash.cpp index 8cf9199..10fefb0 100644 --- a/metrohash.cpp +++ b/metrohash.cpp @@ -1,4 +1,4 @@ -/* Generated by Cython 0.29.5 */ +/* Generated by Cython 0.29.21 */ /* BEGIN: Cython Metadata { @@ -7,6 +7,7 @@ "MetroHash/src/metrohash.h" ], "extra_compile_args": [ + "-O3", "-msse4.2" ], "include_dirs": [ @@ -31,8 +32,8 @@ END: Cython Metadata */ #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000) #error Cython requires Python 2.6+ or Python 3.3+. #else -#define CYTHON_ABI "0_29_5" -#define CYTHON_HEX_VERSION 0x001D05F0 +#define CYTHON_ABI "0_29_21" +#define CYTHON_HEX_VERSION 0x001D15F0 #define CYTHON_FUTURE_DIVISION 0 #include #ifndef offsetof @@ -348,8 +349,13 @@ class __Pyx_FakeReference { #define __Pyx_DefaultClassType PyClass_Type #else #define __Pyx_BUILTIN_MODULE_NAME "builtins" +#if PY_VERSION_HEX >= 0x030800A4 && PY_VERSION_HEX < 0x030800B2 + #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) +#else #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) +#endif #define __Pyx_DefaultClassType PyType_Type #endif #ifndef Py_TPFLAGS_CHECKTYPES @@ -468,7 +474,11 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) { #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u) #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) #define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, ch) + #if defined(PyUnicode_IS_READY) && defined(PyUnicode_GET_SIZE) #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) + #else + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_LENGTH(u)) + #endif #else #define CYTHON_PEP393_ENABLED 0 #define PyUnicode_1BYTE_KIND 1 @@ -517,8 +527,10 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) { #define PyString_Type PyUnicode_Type #define PyString_Check PyUnicode_Check #define PyString_CheckExact PyUnicode_CheckExact +#ifndef PyObject_Unicode #define PyObject_Unicode PyObject_Str #endif +#endif #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj) #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj) @@ -529,6 +541,13 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) { #ifndef PySet_CheckExact #define PySet_CheckExact(obj) (Py_TYPE(obj) == &PySet_Type) #endif +#if PY_VERSION_HEX >= 0x030900A4 + #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt) + #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size) +#else + #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt) + #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size) +#endif #if CYTHON_ASSUME_SAFE_MACROS #define __Pyx_PySequence_SIZE(seq) Py_SIZE(seq) #else @@ -568,7 +587,7 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) { #define __Pyx_PyInt_AsHash_t PyInt_AsSsize_t #endif #if PY_MAJOR_VERSION >= 3 - #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : (Py_INCREF(func), func)) + #define __Pyx_PyMethod_New(func, self, klass) ((self) ? ((void)(klass), PyMethod_New(func, self)) : __Pyx_NewRef(func)) #else #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass) #endif @@ -609,11 +628,10 @@ static CYTHON_INLINE float __PYX_NAN() { #define __Pyx_truncl truncl #endif - +#define __PYX_MARK_ERR_POS(f_index, lineno) \ + { __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__; (void)__pyx_clineno; } #define __PYX_ERR(f_index, lineno, Ln_error) \ -{ \ - __pyx_filename = __pyx_f[f_index]; __pyx_lineno = lineno; __pyx_clineno = __LINE__; goto Ln_error; \ -} + { __PYX_MARK_ERR_POS(f_index, lineno) goto Ln_error; } #ifndef __PYX_EXTERN_C #ifdef __cplusplus @@ -640,7 +658,8 @@ typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* enc const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; #define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0 -#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 0 +#define __PYX_DEFAULT_STRING_ENCODING_IS_UTF8 0 +#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT (PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8) #define __PYX_DEFAULT_STRING_ENCODING "" #define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString #define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize @@ -845,7 +864,7 @@ struct __pyx_obj_9metrohash_MetroHash128; struct __pyx_opt_args_9metrohash_metrohash64; struct __pyx_opt_args_9metrohash_metrohash128; -/* "metrohash.pyx":51 +/* "metrohash.pyx":54 * return b.hex() * * cpdef bytes metrohash64(bytes data, uint64_t seed=0ULL): # <<<<<<<<<<<<<< @@ -857,7 +876,7 @@ struct __pyx_opt_args_9metrohash_metrohash64 { uint64_t seed; }; -/* "metrohash.pyx":57 +/* "metrohash.pyx":60 * return bytes(out) * * cpdef bytes metrohash128(bytes data, uint64_t seed=0ULL): # <<<<<<<<<<<<<< @@ -869,7 +888,7 @@ struct __pyx_opt_args_9metrohash_metrohash128 { uint64_t seed; }; -/* "metrohash.pyx":63 +/* "metrohash.pyx":66 * return bytes(out) * * cdef class MetroHash64(object): # <<<<<<<<<<<<<< @@ -878,14 +897,13 @@ struct __pyx_opt_args_9metrohash_metrohash128 { */ struct __pyx_obj_9metrohash_MetroHash64 { PyObject_HEAD + struct __pyx_vtabstruct_9metrohash_MetroHash64 *__pyx_vtab; MetroHash64 *_hasher; - PyObject *_hash; - bool _notfinal; }; -/* "metrohash.pyx":98 - * return bytes2hex(self.digest()) +/* "metrohash.pyx":114 + * return MetroHash64(self) * * cdef class MetroHash128(object): # <<<<<<<<<<<<<< * @@ -893,12 +911,39 @@ struct __pyx_obj_9metrohash_MetroHash64 { */ struct __pyx_obj_9metrohash_MetroHash128 { PyObject_HEAD + struct __pyx_vtabstruct_9metrohash_MetroHash128 *__pyx_vtab; MetroHash128 *_hasher; - PyObject *_hash; - bool _notfinal; }; + +/* "metrohash.pyx":66 + * return bytes(out) + * + * cdef class MetroHash64(object): # <<<<<<<<<<<<<< + * + * cdef CMetroHash64* _hasher + */ + +struct __pyx_vtabstruct_9metrohash_MetroHash64 { + PyObject *(*digest)(struct __pyx_obj_9metrohash_MetroHash64 *, int __pyx_skip_dispatch); +}; +static struct __pyx_vtabstruct_9metrohash_MetroHash64 *__pyx_vtabptr_9metrohash_MetroHash64; + + +/* "metrohash.pyx":114 + * return MetroHash64(self) + * + * cdef class MetroHash128(object): # <<<<<<<<<<<<<< + * + * cdef CMetroHash128* _hasher + */ + +struct __pyx_vtabstruct_9metrohash_MetroHash128 { + PyObject *(*digest)(struct __pyx_obj_9metrohash_MetroHash128 *, int __pyx_skip_dispatch); +}; +static struct __pyx_vtabstruct_9metrohash_MetroHash128 *__pyx_vtabptr_9metrohash_MetroHash128; + /* --- Runtime support code (head) --- */ /* Refnanny.proto */ #ifndef CYTHON_REFNANNY @@ -985,7 +1030,7 @@ static CYTHON_INLINE PyObject *__Pyx_PyCFunction_FastCall(PyObject *func, PyObje #define __Pyx_PyFunction_FastCall(func, args, nargs)\ __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL) #if 1 || PY_VERSION_HEX < 0x030600B1 -static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwargs); +static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs); #else #define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs) #endif @@ -1046,47 +1091,8 @@ static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, __Pyx__ArgTypeTest(obj, type, name, exact)) static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact); -/* PyThreadStateGet.proto */ -#if CYTHON_FAST_THREAD_STATE -#define __Pyx_PyThreadState_declare PyThreadState *__pyx_tstate; -#define __Pyx_PyThreadState_assign __pyx_tstate = __Pyx_PyThreadState_Current; -#define __Pyx_PyErr_Occurred() __pyx_tstate->curexc_type -#else -#define __Pyx_PyThreadState_declare -#define __Pyx_PyThreadState_assign -#define __Pyx_PyErr_Occurred() PyErr_Occurred() -#endif - -/* PyErrFetchRestore.proto */ -#if CYTHON_FAST_THREAD_STATE -#define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL) -#define __Pyx_ErrRestoreWithState(type, value, tb) __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb) -#define __Pyx_ErrFetchWithState(type, value, tb) __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb) -#define __Pyx_ErrRestore(type, value, tb) __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb) -#define __Pyx_ErrFetch(type, value, tb) __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb) -static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); -static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); -#if CYTHON_COMPILING_IN_CPYTHON -#define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL)) -#else -#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc) -#endif -#else -#define __Pyx_PyErr_Clear() PyErr_Clear() -#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc) -#define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb) -#define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb) -#define __Pyx_ErrRestoreInState(tstate, type, value, tb) PyErr_Restore(type, value, tb) -#define __Pyx_ErrFetchInState(tstate, type, value, tb) PyErr_Fetch(type, value, tb) -#define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb) -#define __Pyx_ErrFetch(type, value, tb) PyErr_Fetch(type, value, tb) -#endif - -/* RaiseException.proto */ -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); - /* PyDictVersioning.proto */ -#if CYTHON_USE_DICT_VERSIONS +#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS #define __PYX_DICT_VERSION_INIT ((PY_UINT64_T) -1) #define __PYX_GET_DICT_VERSION(dict) (((PyDictObject*)(dict))->ma_version_tag) #define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\ @@ -1132,6 +1138,45 @@ static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_ve static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name); #endif +/* PyThreadStateGet.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyThreadState_declare PyThreadState *__pyx_tstate; +#define __Pyx_PyThreadState_assign __pyx_tstate = __Pyx_PyThreadState_Current; +#define __Pyx_PyErr_Occurred() __pyx_tstate->curexc_type +#else +#define __Pyx_PyThreadState_declare +#define __Pyx_PyThreadState_assign +#define __Pyx_PyErr_Occurred() PyErr_Occurred() +#endif + +/* PyErrFetchRestore.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL) +#define __Pyx_ErrRestoreWithState(type, value, tb) __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb) +#define __Pyx_ErrFetchWithState(type, value, tb) __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb) +#define __Pyx_ErrRestore(type, value, tb) __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb) +#define __Pyx_ErrFetch(type, value, tb) __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); +static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#if CYTHON_COMPILING_IN_CPYTHON +#define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL)) +#else +#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc) +#endif +#else +#define __Pyx_PyErr_Clear() PyErr_Clear() +#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc) +#define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb) +#define __Pyx_ErrRestoreInState(tstate, type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetchInState(tstate, type, value, tb) PyErr_Fetch(type, value, tb) +#define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetch(type, value, tb) PyErr_Fetch(type, value, tb) +#endif + +/* RaiseException.proto */ +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); + /* PyObject_GenericGetAttrNoDict.proto */ #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name); @@ -1146,6 +1191,20 @@ static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_nam #define __Pyx_PyObject_GenericGetAttr PyObject_GenericGetAttr #endif +/* SetVTable.proto */ +static int __Pyx_SetVtable(PyObject *dict, void *vtable); + +/* PyErrExceptionMatches.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyErr_ExceptionMatches(err) __Pyx_PyErr_ExceptionMatchesInState(__pyx_tstate, err) +static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err); +#else +#define __Pyx_PyErr_ExceptionMatches(err) PyErr_ExceptionMatches(err) +#endif + +/* PyObjectGetAttrStrNoError.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name); + /* SetupReduce.proto */ static int __Pyx_setup_reduce(PyObject* type_obj); @@ -1209,6 +1268,8 @@ static int __Pyx_check_binary_version(void); /* InitStrings.proto */ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); +static PyObject *__pyx_f_9metrohash_11MetroHash64_digest(struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self, int __pyx_skip_dispatch); /* proto*/ +static PyObject *__pyx_f_9metrohash_12MetroHash128_digest(struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self, int __pyx_skip_dispatch); /* proto*/ /* Module declarations from 'libcpp' */ @@ -1225,7 +1286,6 @@ int __pyx_module_is_main_metrohash = 0; /* Implementation of 'metrohash' */ static PyObject *__pyx_builtin_MemoryError; -static PyObject *__pyx_builtin_RuntimeError; static PyObject *__pyx_builtin_TypeError; static const char __pyx_k_[] = "\000\000\000\000\000\000\000\000"; static const char __pyx_k_b[] = "b"; @@ -1248,25 +1308,22 @@ static const char __pyx_k_TypeError[] = "TypeError"; static const char __pyx_k_bytes2hex[] = "bytes2hex"; static const char __pyx_k_metrohash[] = "metrohash"; static const char __pyx_k_reduce_ex[] = "__reduce_ex__"; +static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__"; static const char __pyx_k_MemoryError[] = "MemoryError"; static const char __pyx_k_MetroHash64[] = "MetroHash64"; static const char __pyx_k_metrohash64[] = "metrohash64"; static const char __pyx_k_MetroHash128[] = "MetroHash128"; -static const char __pyx_k_RuntimeError[] = "RuntimeError"; static const char __pyx_k_metrohash128[] = "metrohash128"; static const char __pyx_k_version_info[] = "version_info"; static const char __pyx_k_metrohash_pyx[] = "metrohash.pyx"; static const char __pyx_k_reduce_cython[] = "__reduce_cython__"; static const char __pyx_k_setstate_cython[] = "__setstate_cython__"; static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; -static const char __pyx_k_Hash_already_finalized[] = "Hash already finalized."; static const char __pyx_k_no_default___reduce___due_to_non[] = "no default __reduce__ due to non-trivial __cinit__"; static PyObject *__pyx_kp_b_; -static PyObject *__pyx_kp_s_Hash_already_finalized; static PyObject *__pyx_n_s_MemoryError; static PyObject *__pyx_n_s_MetroHash128; static PyObject *__pyx_n_s_MetroHash64; -static PyObject *__pyx_n_s_RuntimeError; static PyObject *__pyx_n_s_TypeError; static PyObject *__pyx_kp_b__3; static PyObject *__pyx_n_s_all; @@ -1286,6 +1343,7 @@ static PyObject *__pyx_n_s_metrohash64; static PyObject *__pyx_kp_s_metrohash_pyx; static PyObject *__pyx_n_s_name; static PyObject *__pyx_kp_s_no_default___reduce___due_to_non; +static PyObject *__pyx_n_s_pyx_vtable; static PyObject *__pyx_n_s_reduce; static PyObject *__pyx_n_s_reduce_cython; static PyObject *__pyx_n_s_reduce_ex; @@ -1299,23 +1357,36 @@ static PyObject *__pyx_pf_9metrohash_bytes2hex(CYTHON_UNUSED PyObject *__pyx_sel static PyObject *__pyx_pf_9metrohash_2bytes2hex(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_b); /* proto */ static PyObject *__pyx_pf_9metrohash_4metrohash64(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_data, uint64_t __pyx_v_seed); /* proto */ static PyObject *__pyx_pf_9metrohash_6metrohash128(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_data, uint64_t __pyx_v_seed); /* proto */ -static int __pyx_pf_9metrohash_11MetroHash64___cinit__(struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self, uint64_t __pyx_v_seed); /* proto */ +static PyObject *__pyx_pf_9metrohash_11MetroHash64_11digest_size___get__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_9metrohash_11MetroHash64_10block_size___get__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_9metrohash_11MetroHash64_4name___get__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self); /* proto */ +static int __pyx_pf_9metrohash_11MetroHash64___cinit__(struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self, PyObject *__pyx_v_seed); /* proto */ static void __pyx_pf_9metrohash_11MetroHash64_2__dealloc__(struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_9metrohash_11MetroHash64_4update(struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self, PyObject *__pyx_v_data); /* proto */ static PyObject *__pyx_pf_9metrohash_11MetroHash64_6digest(struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_9metrohash_11MetroHash64_8hexdigest(struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_9metrohash_11MetroHash64_10__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_9metrohash_11MetroHash64_12__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ -static int __pyx_pf_9metrohash_12MetroHash128___cinit__(struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self, uint64_t __pyx_v_seed); /* proto */ +static PyObject *__pyx_pf_9metrohash_11MetroHash64_10copy(struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_9metrohash_11MetroHash64_12__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_9metrohash_11MetroHash64_14__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_9metrohash_12MetroHash128_11digest_size___get__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_9metrohash_12MetroHash128_10block_size___get__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_9metrohash_12MetroHash128_4name___get__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self); /* proto */ +static int __pyx_pf_9metrohash_12MetroHash128___cinit__(struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self, PyObject *__pyx_v_seed); /* proto */ static void __pyx_pf_9metrohash_12MetroHash128_2__dealloc__(struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_9metrohash_12MetroHash128_4update(struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self, PyObject *__pyx_v_data); /* proto */ static PyObject *__pyx_pf_9metrohash_12MetroHash128_6digest(struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_9metrohash_12MetroHash128_8hexdigest(struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_9metrohash_12MetroHash128_10__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_9metrohash_12MetroHash128_12__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_9metrohash_12MetroHash128_10copy(struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_9metrohash_12MetroHash128_12__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_9metrohash_12MetroHash128_14__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ static PyObject *__pyx_tp_new_9metrohash_MetroHash64(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static PyObject *__pyx_tp_new_9metrohash_MetroHash128(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_int_0; static PyObject *__pyx_int_3; +static PyObject *__pyx_int_8; +static PyObject *__pyx_int_16; +static PyObject *__pyx_int_32; +static PyObject *__pyx_int_64; static PyObject *__pyx_tuple__2; static PyObject *__pyx_tuple__4; static PyObject *__pyx_tuple__5; @@ -1325,12 +1396,13 @@ static PyObject *__pyx_tuple__8; static PyObject *__pyx_tuple__9; static PyObject *__pyx_tuple__10; static PyObject *__pyx_tuple__11; -static PyObject *__pyx_tuple__13; -static PyObject *__pyx_codeobj__12; -static PyObject *__pyx_codeobj__14; +static PyObject *__pyx_tuple__12; +static PyObject *__pyx_tuple__14; +static PyObject *__pyx_codeobj__13; +static PyObject *__pyx_codeobj__15; /* Late includes */ -/* "metrohash.pyx":45 +/* "metrohash.pyx":48 * * if sys.version_info < (3, ): * def bytes2hex(b): # <<<<<<<<<<<<<< @@ -1358,9 +1430,12 @@ static PyObject *__pyx_pf_9metrohash_bytes2hex(CYTHON_UNUSED PyObject *__pyx_sel PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; __Pyx_RefNannySetupContext("bytes2hex", 0); - /* "metrohash.pyx":46 + /* "metrohash.pyx":49 * if sys.version_info < (3, ): * def bytes2hex(b): * return b.encode("hex") # <<<<<<<<<<<<<< @@ -1368,7 +1443,7 @@ static PyObject *__pyx_pf_9metrohash_bytes2hex(CYTHON_UNUSED PyObject *__pyx_sel * def bytes2hex(b): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_b, __pyx_n_s_encode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 46, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_b, __pyx_n_s_encode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 49, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -1382,14 +1457,14 @@ static PyObject *__pyx_pf_9metrohash_bytes2hex(CYTHON_UNUSED PyObject *__pyx_sel } __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_n_s_hex) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_n_s_hex); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 46, __pyx_L1_error) + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 49, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "metrohash.pyx":45 + /* "metrohash.pyx":48 * * if sys.version_info < (3, ): * def bytes2hex(b): # <<<<<<<<<<<<<< @@ -1410,7 +1485,7 @@ static PyObject *__pyx_pf_9metrohash_bytes2hex(CYTHON_UNUSED PyObject *__pyx_sel return __pyx_r; } -/* "metrohash.pyx":48 +/* "metrohash.pyx":51 * return b.encode("hex") * else: * def bytes2hex(b): # <<<<<<<<<<<<<< @@ -1438,9 +1513,12 @@ static PyObject *__pyx_pf_9metrohash_2bytes2hex(CYTHON_UNUSED PyObject *__pyx_se PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; __Pyx_RefNannySetupContext("bytes2hex", 0); - /* "metrohash.pyx":49 + /* "metrohash.pyx":52 * else: * def bytes2hex(b): * return b.hex() # <<<<<<<<<<<<<< @@ -1448,7 +1526,7 @@ static PyObject *__pyx_pf_9metrohash_2bytes2hex(CYTHON_UNUSED PyObject *__pyx_se * cpdef bytes metrohash64(bytes data, uint64_t seed=0ULL): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_b, __pyx_n_s_hex); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 49, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_b, __pyx_n_s_hex); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 52, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -1462,14 +1540,14 @@ static PyObject *__pyx_pf_9metrohash_2bytes2hex(CYTHON_UNUSED PyObject *__pyx_se } __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 49, __pyx_L1_error) + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 52, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "metrohash.pyx":48 + /* "metrohash.pyx":51 * return b.encode("hex") * else: * def bytes2hex(b): # <<<<<<<<<<<<<< @@ -1490,7 +1568,7 @@ static PyObject *__pyx_pf_9metrohash_2bytes2hex(CYTHON_UNUSED PyObject *__pyx_se return __pyx_r; } -/* "metrohash.pyx":51 +/* "metrohash.pyx":54 * return b.hex() * * cpdef bytes metrohash64(bytes data, uint64_t seed=0ULL): # <<<<<<<<<<<<<< @@ -1508,6 +1586,9 @@ static PyObject *__pyx_f_9metrohash_metrohash64(PyObject *__pyx_v_data, CYTHON_U uint8_t const *__pyx_t_2; Py_ssize_t __pyx_t_3; uint8_t *__pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; __Pyx_RefNannySetupContext("metrohash64", 0); if (__pyx_optional_args) { if (__pyx_optional_args->__pyx_n > 0) { @@ -1515,19 +1596,19 @@ static PyObject *__pyx_f_9metrohash_metrohash64(PyObject *__pyx_v_data, CYTHON_U } } - /* "metrohash.pyx":53 + /* "metrohash.pyx":56 * cpdef bytes metrohash64(bytes data, uint64_t seed=0ULL): * * cdef bytearray out = bytearray(b"\0"*8) # <<<<<<<<<<<<<< * CMetroHash64.Hash(data, len(data), out, seed) * return bytes(out) */ - __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)(&PyByteArray_Type)), __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 53, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)(&PyByteArray_Type)), __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 56, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_out = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "metrohash.pyx":54 + /* "metrohash.pyx":57 * * cdef bytearray out = bytearray(b"\0"*8) * CMetroHash64.Hash(data, len(data), out, seed) # <<<<<<<<<<<<<< @@ -1536,18 +1617,18 @@ static PyObject *__pyx_f_9metrohash_metrohash64(PyObject *__pyx_v_data, CYTHON_U */ if (unlikely(__pyx_v_data == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 54, __pyx_L1_error) + __PYX_ERR(0, 57, __pyx_L1_error) } - __pyx_t_2 = __Pyx_PyBytes_AsUString(__pyx_v_data); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(0, 54, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyBytes_AsUString(__pyx_v_data); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(0, 57, __pyx_L1_error) if (unlikely(__pyx_v_data == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(0, 54, __pyx_L1_error) + __PYX_ERR(0, 57, __pyx_L1_error) } - __pyx_t_3 = PyBytes_GET_SIZE(__pyx_v_data); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 54, __pyx_L1_error) - __pyx_t_4 = __Pyx_PyObject_AsWritableUString(__pyx_v_out); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 54, __pyx_L1_error) + __pyx_t_3 = PyBytes_GET_SIZE(__pyx_v_data); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 57, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_AsWritableUString(__pyx_v_out); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 57, __pyx_L1_error) MetroHash64::Hash(__pyx_t_2, __pyx_t_3, __pyx_t_4, __pyx_v_seed); - /* "metrohash.pyx":55 + /* "metrohash.pyx":58 * cdef bytearray out = bytearray(b"\0"*8) * CMetroHash64.Hash(data, len(data), out, seed) * return bytes(out) # <<<<<<<<<<<<<< @@ -1555,13 +1636,13 @@ static PyObject *__pyx_f_9metrohash_metrohash64(PyObject *__pyx_v_data, CYTHON_U * cpdef bytes metrohash128(bytes data, uint64_t seed=0ULL): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyBytes_Type)), __pyx_v_out); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 55, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyBytes_Type)), __pyx_v_out); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 58, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L0; - /* "metrohash.pyx":51 + /* "metrohash.pyx":54 * return b.hex() * * cpdef bytes metrohash64(bytes data, uint64_t seed=0ULL): # <<<<<<<<<<<<<< @@ -1586,6 +1667,9 @@ static PyObject *__pyx_pw_9metrohash_5metrohash64(PyObject *__pyx_self, PyObject static PyObject *__pyx_pw_9metrohash_5metrohash64(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_data = 0; uint64_t __pyx_v_seed; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("metrohash64 (wrapper)", 0); @@ -1616,7 +1700,7 @@ static PyObject *__pyx_pw_9metrohash_5metrohash64(PyObject *__pyx_self, PyObject } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "metrohash64") < 0)) __PYX_ERR(0, 51, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "metrohash64") < 0)) __PYX_ERR(0, 54, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -1629,20 +1713,20 @@ static PyObject *__pyx_pw_9metrohash_5metrohash64(PyObject *__pyx_self, PyObject } __pyx_v_data = ((PyObject*)values[0]); if (values[1]) { - __pyx_v_seed = __Pyx_PyInt_As_uint64_t(values[1]); if (unlikely((__pyx_v_seed == ((uint64_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 51, __pyx_L3_error) + __pyx_v_seed = __Pyx_PyInt_As_uint64_t(values[1]); if (unlikely((__pyx_v_seed == ((uint64_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 54, __pyx_L3_error) } else { __pyx_v_seed = ((uint64_t)0ULL); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("metrohash64", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 51, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("metrohash64", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 54, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("metrohash.metrohash64", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_data), (&PyBytes_Type), 1, "data", 1))) __PYX_ERR(0, 51, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_data), (&PyBytes_Type), 1, "data", 1))) __PYX_ERR(0, 54, __pyx_L1_error) __pyx_r = __pyx_pf_9metrohash_4metrohash64(__pyx_self, __pyx_v_data, __pyx_v_seed); /* function exit code */ @@ -1659,11 +1743,14 @@ static PyObject *__pyx_pf_9metrohash_4metrohash64(CYTHON_UNUSED PyObject *__pyx_ __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; struct __pyx_opt_args_9metrohash_metrohash64 __pyx_t_2; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; __Pyx_RefNannySetupContext("metrohash64", 0); __Pyx_XDECREF(__pyx_r); __pyx_t_2.__pyx_n = 1; __pyx_t_2.seed = __pyx_v_seed; - __pyx_t_1 = __pyx_f_9metrohash_metrohash64(__pyx_v_data, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 51, __pyx_L1_error) + __pyx_t_1 = __pyx_f_9metrohash_metrohash64(__pyx_v_data, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 54, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -1680,7 +1767,7 @@ static PyObject *__pyx_pf_9metrohash_4metrohash64(CYTHON_UNUSED PyObject *__pyx_ return __pyx_r; } -/* "metrohash.pyx":57 +/* "metrohash.pyx":60 * return bytes(out) * * cpdef bytes metrohash128(bytes data, uint64_t seed=0ULL): # <<<<<<<<<<<<<< @@ -1698,6 +1785,9 @@ static PyObject *__pyx_f_9metrohash_metrohash128(PyObject *__pyx_v_data, CYTHON_ uint8_t const *__pyx_t_2; Py_ssize_t __pyx_t_3; uint8_t *__pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; __Pyx_RefNannySetupContext("metrohash128", 0); if (__pyx_optional_args) { if (__pyx_optional_args->__pyx_n > 0) { @@ -1705,19 +1795,19 @@ static PyObject *__pyx_f_9metrohash_metrohash128(PyObject *__pyx_v_data, CYTHON_ } } - /* "metrohash.pyx":59 + /* "metrohash.pyx":62 * cpdef bytes metrohash128(bytes data, uint64_t seed=0ULL): * * cdef bytearray out = bytearray(b"\0"*16) # <<<<<<<<<<<<<< * CMetroHash128.Hash(data, len(data), out, seed) * return bytes(out) */ - __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)(&PyByteArray_Type)), __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 59, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)(&PyByteArray_Type)), __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 62, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_out = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "metrohash.pyx":60 + /* "metrohash.pyx":63 * * cdef bytearray out = bytearray(b"\0"*16) * CMetroHash128.Hash(data, len(data), out, seed) # <<<<<<<<<<<<<< @@ -1726,18 +1816,18 @@ static PyObject *__pyx_f_9metrohash_metrohash128(PyObject *__pyx_v_data, CYTHON_ */ if (unlikely(__pyx_v_data == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); - __PYX_ERR(0, 60, __pyx_L1_error) + __PYX_ERR(0, 63, __pyx_L1_error) } - __pyx_t_2 = __Pyx_PyBytes_AsUString(__pyx_v_data); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(0, 60, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyBytes_AsUString(__pyx_v_data); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(0, 63, __pyx_L1_error) if (unlikely(__pyx_v_data == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(0, 60, __pyx_L1_error) + __PYX_ERR(0, 63, __pyx_L1_error) } - __pyx_t_3 = PyBytes_GET_SIZE(__pyx_v_data); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 60, __pyx_L1_error) - __pyx_t_4 = __Pyx_PyObject_AsWritableUString(__pyx_v_out); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 60, __pyx_L1_error) + __pyx_t_3 = PyBytes_GET_SIZE(__pyx_v_data); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 63, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_AsWritableUString(__pyx_v_out); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 63, __pyx_L1_error) MetroHash128::Hash(__pyx_t_2, __pyx_t_3, __pyx_t_4, __pyx_v_seed); - /* "metrohash.pyx":61 + /* "metrohash.pyx":64 * cdef bytearray out = bytearray(b"\0"*16) * CMetroHash128.Hash(data, len(data), out, seed) * return bytes(out) # <<<<<<<<<<<<<< @@ -1745,13 +1835,13 @@ static PyObject *__pyx_f_9metrohash_metrohash128(PyObject *__pyx_v_data, CYTHON_ * cdef class MetroHash64(object): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyBytes_Type)), __pyx_v_out); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 61, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyBytes_Type)), __pyx_v_out); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 64, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L0; - /* "metrohash.pyx":57 + /* "metrohash.pyx":60 * return bytes(out) * * cpdef bytes metrohash128(bytes data, uint64_t seed=0ULL): # <<<<<<<<<<<<<< @@ -1776,6 +1866,9 @@ static PyObject *__pyx_pw_9metrohash_7metrohash128(PyObject *__pyx_self, PyObjec static PyObject *__pyx_pw_9metrohash_7metrohash128(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_data = 0; uint64_t __pyx_v_seed; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("metrohash128 (wrapper)", 0); @@ -1806,7 +1899,7 @@ static PyObject *__pyx_pw_9metrohash_7metrohash128(PyObject *__pyx_self, PyObjec } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "metrohash128") < 0)) __PYX_ERR(0, 57, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "metrohash128") < 0)) __PYX_ERR(0, 60, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -1819,20 +1912,20 @@ static PyObject *__pyx_pw_9metrohash_7metrohash128(PyObject *__pyx_self, PyObjec } __pyx_v_data = ((PyObject*)values[0]); if (values[1]) { - __pyx_v_seed = __Pyx_PyInt_As_uint64_t(values[1]); if (unlikely((__pyx_v_seed == ((uint64_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 57, __pyx_L3_error) + __pyx_v_seed = __Pyx_PyInt_As_uint64_t(values[1]); if (unlikely((__pyx_v_seed == ((uint64_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 60, __pyx_L3_error) } else { __pyx_v_seed = ((uint64_t)0ULL); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("metrohash128", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 57, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("metrohash128", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 60, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("metrohash.metrohash128", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_data), (&PyBytes_Type), 1, "data", 1))) __PYX_ERR(0, 57, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_data), (&PyBytes_Type), 1, "data", 1))) __PYX_ERR(0, 60, __pyx_L1_error) __pyx_r = __pyx_pf_9metrohash_6metrohash128(__pyx_self, __pyx_v_data, __pyx_v_seed); /* function exit code */ @@ -1849,11 +1942,14 @@ static PyObject *__pyx_pf_9metrohash_6metrohash128(CYTHON_UNUSED PyObject *__pyx __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; struct __pyx_opt_args_9metrohash_metrohash128 __pyx_t_2; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; __Pyx_RefNannySetupContext("metrohash128", 0); __Pyx_XDECREF(__pyx_r); __pyx_t_2.__pyx_n = 1; __pyx_t_2.seed = __pyx_v_seed; - __pyx_t_1 = __pyx_f_9metrohash_metrohash128(__pyx_v_data, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 57, __pyx_L1_error) + __pyx_t_1 = __pyx_f_9metrohash_metrohash128(__pyx_v_data, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 60, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -1870,24 +1966,187 @@ static PyObject *__pyx_pf_9metrohash_6metrohash128(CYTHON_UNUSED PyObject *__pyx return __pyx_r; } -/* "metrohash.pyx":69 - * cdef bool _notfinal +/* "metrohash.pyx":71 + * + * @property + * def digest_size(self): # <<<<<<<<<<<<<< + * return 8 + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_9metrohash_11MetroHash64_11digest_size_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_9metrohash_11MetroHash64_11digest_size_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_9metrohash_11MetroHash64_11digest_size___get__(((struct __pyx_obj_9metrohash_MetroHash64 *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_9metrohash_11MetroHash64_11digest_size___get__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + + /* "metrohash.pyx":72 + * @property + * def digest_size(self): + * return 8 # <<<<<<<<<<<<<< + * + * @property + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_int_8); + __pyx_r = __pyx_int_8; + goto __pyx_L0; + + /* "metrohash.pyx":71 + * + * @property + * def digest_size(self): # <<<<<<<<<<<<<< + * return 8 + * + */ + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "metrohash.pyx":75 + * + * @property + * def block_size(self): # <<<<<<<<<<<<<< + * return 32 + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_9metrohash_11MetroHash64_10block_size_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_9metrohash_11MetroHash64_10block_size_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_9metrohash_11MetroHash64_10block_size___get__(((struct __pyx_obj_9metrohash_MetroHash64 *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_9metrohash_11MetroHash64_10block_size___get__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + + /* "metrohash.pyx":76 + * @property + * def block_size(self): + * return 32 # <<<<<<<<<<<<<< + * + * @property + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_int_32); + __pyx_r = __pyx_int_32; + goto __pyx_L0; + + /* "metrohash.pyx":75 + * + * @property + * def block_size(self): # <<<<<<<<<<<<<< + * return 32 + * + */ + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "metrohash.pyx":79 + * + * @property + * def name(self): # <<<<<<<<<<<<<< + * return 'metrohash64' + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_9metrohash_11MetroHash64_4name_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_9metrohash_11MetroHash64_4name_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_9metrohash_11MetroHash64_4name___get__(((struct __pyx_obj_9metrohash_MetroHash64 *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_9metrohash_11MetroHash64_4name___get__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + + /* "metrohash.pyx":80 + * @property + * def name(self): + * return 'metrohash64' # <<<<<<<<<<<<<< + * + * def __cinit__(self, seed=0): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_n_s_metrohash64); + __pyx_r = __pyx_n_s_metrohash64; + goto __pyx_L0; + + /* "metrohash.pyx":79 + * + * @property + * def name(self): # <<<<<<<<<<<<<< + * return 'metrohash64' + * + */ + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "metrohash.pyx":82 + * return 'metrohash64' * - * def __cinit__(self, uint64_t seed=0ULL): # <<<<<<<<<<<<<< - * self._hasher = new CMetroHash64(seed) - * self._hash = bytearray(b"\0"*8) + * def __cinit__(self, seed=0): # <<<<<<<<<<<<<< + * cdef uint64_t _seed + * cdef MetroHash64 _copy */ /* Python wrapper */ static int __pyx_pw_9metrohash_11MetroHash64_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_pw_9metrohash_11MetroHash64_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - uint64_t __pyx_v_seed; + PyObject *__pyx_v_seed = 0; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_seed,0}; PyObject* values[1] = {0}; + values[0] = ((PyObject *)__pyx_int_0); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); @@ -1906,7 +2165,7 @@ static int __pyx_pw_9metrohash_11MetroHash64_1__cinit__(PyObject *__pyx_v_self, } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(0, 69, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(0, 82, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -1916,15 +2175,11 @@ static int __pyx_pw_9metrohash_11MetroHash64_1__cinit__(PyObject *__pyx_v_self, default: goto __pyx_L5_argtuple_error; } } - if (values[0]) { - __pyx_v_seed = __Pyx_PyInt_As_uint64_t(values[0]); if (unlikely((__pyx_v_seed == ((uint64_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 69, __pyx_L3_error) - } else { - __pyx_v_seed = ((uint64_t)0ULL); - } + __pyx_v_seed = values[0]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 69, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 82, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("metrohash.MetroHash64.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -1937,48 +2192,86 @@ static int __pyx_pw_9metrohash_11MetroHash64_1__cinit__(PyObject *__pyx_v_self, return __pyx_r; } -static int __pyx_pf_9metrohash_11MetroHash64___cinit__(struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self, uint64_t __pyx_v_seed) { +static int __pyx_pf_9metrohash_11MetroHash64___cinit__(struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self, PyObject *__pyx_v_seed) { + uint64_t __pyx_v__seed; + struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v__copy = 0; int __pyx_r; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; + int __pyx_t_1; int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + uint64_t __pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__cinit__", 0); - /* "metrohash.pyx":70 - * - * def __cinit__(self, uint64_t seed=0ULL): - * self._hasher = new CMetroHash64(seed) # <<<<<<<<<<<<<< - * self._hash = bytearray(b"\0"*8) - * self._notfinal = True + /* "metrohash.pyx":85 + * cdef uint64_t _seed + * cdef MetroHash64 _copy + * if isinstance(seed, MetroHash64): # <<<<<<<<<<<<<< + * _copy = seed + * self._hasher = new CMetroHash64(deref(_copy._hasher)) + */ + __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_seed, __pyx_ptype_9metrohash_MetroHash64); + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { + + /* "metrohash.pyx":86 + * cdef MetroHash64 _copy + * if isinstance(seed, MetroHash64): + * _copy = seed # <<<<<<<<<<<<<< + * self._hasher = new CMetroHash64(deref(_copy._hasher)) + * else: + */ + __pyx_t_3 = __pyx_v_seed; + __Pyx_INCREF(__pyx_t_3); + __pyx_v__copy = ((struct __pyx_obj_9metrohash_MetroHash64 *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "metrohash.pyx":87 + * if isinstance(seed, MetroHash64): + * _copy = seed + * self._hasher = new CMetroHash64(deref(_copy._hasher)) # <<<<<<<<<<<<<< + * else: + * _seed = seed + */ + __pyx_v_self->_hasher = new MetroHash64((*__pyx_v__copy->_hasher)); + + /* "metrohash.pyx":85 + * cdef uint64_t _seed + * cdef MetroHash64 _copy + * if isinstance(seed, MetroHash64): # <<<<<<<<<<<<<< + * _copy = seed + * self._hasher = new CMetroHash64(deref(_copy._hasher)) */ - __pyx_v_self->_hasher = new MetroHash64(__pyx_v_seed); + goto __pyx_L3; + } - /* "metrohash.pyx":71 - * def __cinit__(self, uint64_t seed=0ULL): - * self._hasher = new CMetroHash64(seed) - * self._hash = bytearray(b"\0"*8) # <<<<<<<<<<<<<< - * self._notfinal = True + /* "metrohash.pyx":89 + * self._hasher = new CMetroHash64(deref(_copy._hasher)) + * else: + * _seed = seed # <<<<<<<<<<<<<< + * self._hasher = new CMetroHash64(_seed) * */ - __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)(&PyByteArray_Type)), __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 71, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->_hash); - __Pyx_DECREF(__pyx_v_self->_hash); - __pyx_v_self->_hash = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; + /*else*/ { + __pyx_t_4 = __Pyx_PyInt_As_uint64_t(__pyx_v_seed); if (unlikely((__pyx_t_4 == ((uint64_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 89, __pyx_L1_error) + __pyx_v__seed = ((uint64_t)__pyx_t_4); - /* "metrohash.pyx":72 - * self._hasher = new CMetroHash64(seed) - * self._hash = bytearray(b"\0"*8) - * self._notfinal = True # <<<<<<<<<<<<<< + /* "metrohash.pyx":90 + * else: + * _seed = seed + * self._hasher = new CMetroHash64(_seed) # <<<<<<<<<<<<<< * * if self._hasher is NULL: */ - __pyx_v_self->_notfinal = 1; + __pyx_v_self->_hasher = new MetroHash64(__pyx_v__seed); + } + __pyx_L3:; - /* "metrohash.pyx":74 - * self._notfinal = True + /* "metrohash.pyx":92 + * self._hasher = new CMetroHash64(_seed) * * if self._hasher is NULL: # <<<<<<<<<<<<<< * raise MemoryError() @@ -1987,17 +2280,17 @@ static int __pyx_pf_9metrohash_11MetroHash64___cinit__(struct __pyx_obj_9metroha __pyx_t_2 = ((__pyx_v_self->_hasher == NULL) != 0); if (unlikely(__pyx_t_2)) { - /* "metrohash.pyx":75 + /* "metrohash.pyx":93 * * if self._hasher is NULL: * raise MemoryError() # <<<<<<<<<<<<<< * * def __dealloc__(self): */ - PyErr_NoMemory(); __PYX_ERR(0, 75, __pyx_L1_error) + PyErr_NoMemory(); __PYX_ERR(0, 93, __pyx_L1_error) - /* "metrohash.pyx":74 - * self._notfinal = True + /* "metrohash.pyx":92 + * self._hasher = new CMetroHash64(_seed) * * if self._hasher is NULL: # <<<<<<<<<<<<<< * raise MemoryError() @@ -2005,27 +2298,28 @@ static int __pyx_pf_9metrohash_11MetroHash64___cinit__(struct __pyx_obj_9metroha */ } - /* "metrohash.pyx":69 - * cdef bool _notfinal + /* "metrohash.pyx":82 + * return 'metrohash64' * - * def __cinit__(self, uint64_t seed=0ULL): # <<<<<<<<<<<<<< - * self._hasher = new CMetroHash64(seed) - * self._hash = bytearray(b"\0"*8) + * def __cinit__(self, seed=0): # <<<<<<<<<<<<<< + * cdef uint64_t _seed + * cdef MetroHash64 _copy */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("metrohash.MetroHash64.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v__copy); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "metrohash.pyx":77 +/* "metrohash.pyx":95 * raise MemoryError() * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -2049,7 +2343,7 @@ static void __pyx_pf_9metrohash_11MetroHash64_2__dealloc__(struct __pyx_obj_9met int __pyx_t_1; __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "metrohash.pyx":78 + /* "metrohash.pyx":96 * * def __dealloc__(self): * if self._hasher is not NULL: # <<<<<<<<<<<<<< @@ -2059,7 +2353,7 @@ static void __pyx_pf_9metrohash_11MetroHash64_2__dealloc__(struct __pyx_obj_9met __pyx_t_1 = ((__pyx_v_self->_hasher != NULL) != 0); if (__pyx_t_1) { - /* "metrohash.pyx":79 + /* "metrohash.pyx":97 * def __dealloc__(self): * if self._hasher is not NULL: * del self._hasher # <<<<<<<<<<<<<< @@ -2068,7 +2362,7 @@ static void __pyx_pf_9metrohash_11MetroHash64_2__dealloc__(struct __pyx_obj_9met */ delete __pyx_v_self->_hasher; - /* "metrohash.pyx":80 + /* "metrohash.pyx":98 * if self._hasher is not NULL: * del self._hasher * self._hasher = NULL # <<<<<<<<<<<<<< @@ -2077,7 +2371,7 @@ static void __pyx_pf_9metrohash_11MetroHash64_2__dealloc__(struct __pyx_obj_9met */ __pyx_v_self->_hasher = NULL; - /* "metrohash.pyx":78 + /* "metrohash.pyx":96 * * def __dealloc__(self): * if self._hasher is not NULL: # <<<<<<<<<<<<<< @@ -2086,7 +2380,7 @@ static void __pyx_pf_9metrohash_11MetroHash64_2__dealloc__(struct __pyx_obj_9met */ } - /* "metrohash.pyx":77 + /* "metrohash.pyx":95 * raise MemoryError() * * def __dealloc__(self): # <<<<<<<<<<<<<< @@ -2098,12 +2392,12 @@ static void __pyx_pf_9metrohash_11MetroHash64_2__dealloc__(struct __pyx_obj_9met __Pyx_RefNannyFinishContext(); } -/* "metrohash.pyx":82 +/* "metrohash.pyx":100 * self._hasher = NULL * * def update(self, data): # <<<<<<<<<<<<<< - * if self._notfinal: - * self._hasher.Update(data, len(data)) + * self._hasher.Update(data, len(data)) + * */ /* Python wrapper */ @@ -2122,72 +2416,36 @@ static PyObject *__pyx_pw_9metrohash_11MetroHash64_5update(PyObject *__pyx_v_sel static PyObject *__pyx_pf_9metrohash_11MetroHash64_4update(struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self, PyObject *__pyx_v_data) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - int __pyx_t_1; - uint8_t const *__pyx_t_2; - Py_ssize_t __pyx_t_3; - PyObject *__pyx_t_4 = NULL; + uint8_t const *__pyx_t_1; + Py_ssize_t __pyx_t_2; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; __Pyx_RefNannySetupContext("update", 0); - /* "metrohash.pyx":83 + /* "metrohash.pyx":101 * * def update(self, data): - * if self._notfinal: # <<<<<<<<<<<<<< - * self._hasher.Update(data, len(data)) - * else: - */ - __pyx_t_1 = (__pyx_v_self->_notfinal != 0); - if (likely(__pyx_t_1)) { - - /* "metrohash.pyx":84 - * def update(self, data): - * if self._notfinal: - * self._hasher.Update(data, len(data)) # <<<<<<<<<<<<<< - * else: - * raise RuntimeError("Hash already finalized.") - */ - __pyx_t_2 = __Pyx_PyObject_AsUString(__pyx_v_data); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(0, 84, __pyx_L1_error) - __pyx_t_3 = PyObject_Length(__pyx_v_data); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 84, __pyx_L1_error) - __pyx_v_self->_hasher->Update(__pyx_t_2, __pyx_t_3); - - /* "metrohash.pyx":83 + * self._hasher.Update(data, len(data)) # <<<<<<<<<<<<<< * - * def update(self, data): - * if self._notfinal: # <<<<<<<<<<<<<< - * self._hasher.Update(data, len(data)) - * else: + * cpdef digest(self): */ - goto __pyx_L3; - } + __pyx_t_1 = __Pyx_PyObject_AsUString(__pyx_v_data); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) __PYX_ERR(0, 101, __pyx_L1_error) + __pyx_t_2 = PyObject_Length(__pyx_v_data); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 101, __pyx_L1_error) + __pyx_v_self->_hasher->Update(__pyx_t_1, __pyx_t_2); - /* "metrohash.pyx":86 - * self._hasher.Update(data, len(data)) - * else: - * raise RuntimeError("Hash already finalized.") # <<<<<<<<<<<<<< - * - * def digest(self): - */ - /*else*/ { - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 86, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 86, __pyx_L1_error) - } - __pyx_L3:; - - /* "metrohash.pyx":82 + /* "metrohash.pyx":100 * self._hasher = NULL * * def update(self, data): # <<<<<<<<<<<<<< - * if self._notfinal: - * self._hasher.Update(data, len(data)) + * self._hasher.Update(data, len(data)) + * */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("metrohash.MetroHash64.update", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; @@ -2196,98 +2454,165 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_4update(struct __pyx_obj_9met return __pyx_r; } -/* "metrohash.pyx":88 - * raise RuntimeError("Hash already finalized.") +/* "metrohash.pyx":103 + * self._hasher.Update(data, len(data)) * - * def digest(self): # <<<<<<<<<<<<<< - * if self._notfinal: - * self._hasher.Finalize(self._hash) + * cpdef digest(self): # <<<<<<<<<<<<<< + * cdef bytearray _hash = bytearray(8) + * CMetroHash64(deref(self._hasher)).Finalize(_hash) */ -/* Python wrapper */ static PyObject *__pyx_pw_9metrohash_11MetroHash64_7digest(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_9metrohash_11MetroHash64_7digest(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("digest (wrapper)", 0); - __pyx_r = __pyx_pf_9metrohash_11MetroHash64_6digest(((struct __pyx_obj_9metrohash_MetroHash64 *)__pyx_v_self)); - - /* function exit code */ - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_9metrohash_11MetroHash64_6digest(struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self) { +static PyObject *__pyx_f_9metrohash_11MetroHash64_digest(struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self, int __pyx_skip_dispatch) { + PyObject *__pyx_v__hash = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - int __pyx_t_1; - uint8_t *__pyx_t_2; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + uint8_t *__pyx_t_5; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; __Pyx_RefNannySetupContext("digest", 0); + /* Check if called by wrapper */ + if (unlikely(__pyx_skip_dispatch)) ; + /* Check if overridden in Python */ + else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || (Py_TYPE(((PyObject *)__pyx_v_self))->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) { + #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS + static PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT; + if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) { + PY_UINT64_T __pyx_type_dict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self)); + #endif + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_digest); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 103, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_9metrohash_11MetroHash64_7digest)) { + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 103, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L0; + } + #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS + __pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self)); + __pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self)); + if (unlikely(__pyx_type_dict_guard != __pyx_tp_dict_version)) { + __pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT; + } + #endif + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS + } + #endif + } - /* "metrohash.pyx":89 - * - * def digest(self): - * if self._notfinal: # <<<<<<<<<<<<<< - * self._hasher.Finalize(self._hash) - * self._notfinal = False - */ - __pyx_t_1 = (__pyx_v_self->_notfinal != 0); - if (__pyx_t_1) { - - /* "metrohash.pyx":90 - * def digest(self): - * if self._notfinal: - * self._hasher.Finalize(self._hash) # <<<<<<<<<<<<<< - * self._notfinal = False - * - */ - __pyx_t_2 = __Pyx_PyObject_AsWritableUString(__pyx_v_self->_hash); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(0, 90, __pyx_L1_error) - __pyx_v_self->_hasher->Finalize(__pyx_t_2); - - /* "metrohash.pyx":91 - * if self._notfinal: - * self._hasher.Finalize(self._hash) - * self._notfinal = False # <<<<<<<<<<<<<< + /* "metrohash.pyx":104 * - * return bytes(self._hash) + * cpdef digest(self): + * cdef bytearray _hash = bytearray(8) # <<<<<<<<<<<<<< + * CMetroHash64(deref(self._hasher)).Finalize(_hash) + * return bytes(_hash) */ - __pyx_v_self->_notfinal = 0; + __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)(&PyByteArray_Type)), __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 104, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v__hash = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; - /* "metrohash.pyx":89 + /* "metrohash.pyx":105 + * cpdef digest(self): + * cdef bytearray _hash = bytearray(8) + * CMetroHash64(deref(self._hasher)).Finalize(_hash) # <<<<<<<<<<<<<< + * return bytes(_hash) * - * def digest(self): - * if self._notfinal: # <<<<<<<<<<<<<< - * self._hasher.Finalize(self._hash) - * self._notfinal = False */ - } + __pyx_t_5 = __Pyx_PyObject_AsWritableUString(__pyx_v__hash); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 105, __pyx_L1_error) + MetroHash64((*__pyx_v_self->_hasher)).Finalize(__pyx_t_5); - /* "metrohash.pyx":93 - * self._notfinal = False - * - * return bytes(self._hash) # <<<<<<<<<<<<<< + /* "metrohash.pyx":106 + * cdef bytearray _hash = bytearray(8) + * CMetroHash64(deref(self._hasher)).Finalize(_hash) + * return bytes(_hash) # <<<<<<<<<<<<<< * * def hexdigest(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyBytes_Type)), __pyx_v_self->_hash); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 93, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; + __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyBytes_Type)), __pyx_v__hash); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 106, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; goto __pyx_L0; - /* "metrohash.pyx":88 - * raise RuntimeError("Hash already finalized.") + /* "metrohash.pyx":103 + * self._hasher.Update(data, len(data)) * - * def digest(self): # <<<<<<<<<<<<<< - * if self._notfinal: - * self._hasher.Finalize(self._hash) + * cpdef digest(self): # <<<<<<<<<<<<<< + * cdef bytearray _hash = bytearray(8) + * CMetroHash64(deref(self._hasher)).Finalize(_hash) */ /* function exit code */ __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("metrohash.MetroHash64.digest", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v__hash); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_9metrohash_11MetroHash64_7digest(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_9metrohash_11MetroHash64_7digest(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("digest (wrapper)", 0); + __pyx_r = __pyx_pf_9metrohash_11MetroHash64_6digest(((struct __pyx_obj_9metrohash_MetroHash64 *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_9metrohash_11MetroHash64_6digest(struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("digest", 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __pyx_f_9metrohash_11MetroHash64_digest(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 103, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("metrohash.MetroHash64.digest", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; @@ -2296,8 +2621,8 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_6digest(struct __pyx_obj_9met return __pyx_r; } -/* "metrohash.pyx":95 - * return bytes(self._hash) +/* "metrohash.pyx":108 + * return bytes(_hash) * * def hexdigest(self): # <<<<<<<<<<<<<< * return bytes2hex(self.digest()) @@ -2324,36 +2649,23 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_8hexdigest(struct __pyx_obj_9 PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; __Pyx_RefNannySetupContext("hexdigest", 0); - /* "metrohash.pyx":96 + /* "metrohash.pyx":109 * * def hexdigest(self): * return bytes2hex(self.digest()) # <<<<<<<<<<<<<< * - * cdef class MetroHash128(object): + * def copy(self): */ __Pyx_XDECREF(__pyx_r); - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_bytes2hex); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 96, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_bytes2hex); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 109, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_digest); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 96, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 96, __pyx_L1_error) + __pyx_t_3 = ((struct __pyx_vtabstruct_9metrohash_MetroHash64 *)__pyx_v_self->__pyx_vtab)->digest(__pyx_v_self, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 109, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); @@ -2367,15 +2679,15 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_8hexdigest(struct __pyx_obj_9 __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 96, __pyx_L1_error) + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 109, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "metrohash.pyx":95 - * return bytes(self._hash) + /* "metrohash.pyx":108 + * return bytes(_hash) * * def hexdigest(self): # <<<<<<<<<<<<<< * return bytes2hex(self.digest()) @@ -2388,7 +2700,6 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_8hexdigest(struct __pyx_obj_9 __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("metrohash.MetroHash64.hexdigest", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; @@ -2397,6 +2708,69 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_8hexdigest(struct __pyx_obj_9 return __pyx_r; } +/* "metrohash.pyx":111 + * return bytes2hex(self.digest()) + * + * def copy(self): # <<<<<<<<<<<<<< + * return MetroHash64(self) + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_9metrohash_11MetroHash64_11copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_9metrohash_11MetroHash64_11copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("copy (wrapper)", 0); + __pyx_r = __pyx_pf_9metrohash_11MetroHash64_10copy(((struct __pyx_obj_9metrohash_MetroHash64 *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_9metrohash_11MetroHash64_10copy(struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("copy", 0); + + /* "metrohash.pyx":112 + * + * def copy(self): + * return MetroHash64(self) # <<<<<<<<<<<<<< + * + * cdef class MetroHash128(object): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_9metrohash_MetroHash64), ((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 112, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "metrohash.pyx":111 + * return bytes2hex(self.digest()) + * + * def copy(self): # <<<<<<<<<<<<<< + * return MetroHash64(self) + * + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("metrohash.MetroHash64.copy", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + /* "(tree fragment)":1 * def __reduce_cython__(self): # <<<<<<<<<<<<<< * raise TypeError("no default __reduce__ due to non-trivial __cinit__") @@ -2404,22 +2778,25 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_8hexdigest(struct __pyx_obj_9 */ /* Python wrapper */ -static PyObject *__pyx_pw_9metrohash_11MetroHash64_11__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_9metrohash_11MetroHash64_11__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_9metrohash_11MetroHash64_13__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_9metrohash_11MetroHash64_13__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_9metrohash_11MetroHash64_10__reduce_cython__(((struct __pyx_obj_9metrohash_MetroHash64 *)__pyx_v_self)); + __pyx_r = __pyx_pf_9metrohash_11MetroHash64_12__reduce_cython__(((struct __pyx_obj_9metrohash_MetroHash64 *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_9metrohash_11MetroHash64_10__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self) { +static PyObject *__pyx_pf_9metrohash_11MetroHash64_12__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__reduce_cython__", 0); /* "(tree fragment)":2 @@ -2458,22 +2835,25 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_10__reduce_cython__(CYTHON_UN */ /* Python wrapper */ -static PyObject *__pyx_pw_9metrohash_11MetroHash64_13__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static PyObject *__pyx_pw_9metrohash_11MetroHash64_13__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pw_9metrohash_11MetroHash64_15__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static PyObject *__pyx_pw_9metrohash_11MetroHash64_15__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_9metrohash_11MetroHash64_12__setstate_cython__(((struct __pyx_obj_9metrohash_MetroHash64 *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + __pyx_r = __pyx_pf_9metrohash_11MetroHash64_14__setstate_cython__(((struct __pyx_obj_9metrohash_MetroHash64 *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_9metrohash_11MetroHash64_12__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_9metrohash_11MetroHash64_14__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash64 *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__setstate_cython__", 0); /* "(tree fragment)":4 @@ -2504,24 +2884,187 @@ static PyObject *__pyx_pf_9metrohash_11MetroHash64_12__setstate_cython__(CYTHON_ return __pyx_r; } -/* "metrohash.pyx":104 - * cdef bool _notfinal +/* "metrohash.pyx":119 + * + * @property + * def digest_size(self): # <<<<<<<<<<<<<< + * return 16 + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_9metrohash_12MetroHash128_11digest_size_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_9metrohash_12MetroHash128_11digest_size_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_9metrohash_12MetroHash128_11digest_size___get__(((struct __pyx_obj_9metrohash_MetroHash128 *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_9metrohash_12MetroHash128_11digest_size___get__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + + /* "metrohash.pyx":120 + * @property + * def digest_size(self): + * return 16 # <<<<<<<<<<<<<< + * + * @property + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_int_16); + __pyx_r = __pyx_int_16; + goto __pyx_L0; + + /* "metrohash.pyx":119 + * + * @property + * def digest_size(self): # <<<<<<<<<<<<<< + * return 16 + * + */ + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "metrohash.pyx":123 + * + * @property + * def block_size(self): # <<<<<<<<<<<<<< + * return 64 + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_9metrohash_12MetroHash128_10block_size_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_9metrohash_12MetroHash128_10block_size_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_9metrohash_12MetroHash128_10block_size___get__(((struct __pyx_obj_9metrohash_MetroHash128 *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_9metrohash_12MetroHash128_10block_size___get__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + + /* "metrohash.pyx":124 + * @property + * def block_size(self): + * return 64 # <<<<<<<<<<<<<< + * + * @property + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_int_64); + __pyx_r = __pyx_int_64; + goto __pyx_L0; + + /* "metrohash.pyx":123 + * + * @property + * def block_size(self): # <<<<<<<<<<<<<< + * return 64 + * + */ + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "metrohash.pyx":127 + * + * @property + * def name(self): # <<<<<<<<<<<<<< + * return 'metrohash128' + * + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_9metrohash_12MetroHash128_4name_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_9metrohash_12MetroHash128_4name_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_9metrohash_12MetroHash128_4name___get__(((struct __pyx_obj_9metrohash_MetroHash128 *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_9metrohash_12MetroHash128_4name___get__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + + /* "metrohash.pyx":128 + * @property + * def name(self): + * return 'metrohash128' # <<<<<<<<<<<<<< + * + * def __cinit__(self, seed=0): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_n_s_metrohash128); + __pyx_r = __pyx_n_s_metrohash128; + goto __pyx_L0; + + /* "metrohash.pyx":127 + * + * @property + * def name(self): # <<<<<<<<<<<<<< + * return 'metrohash128' + * + */ + + /* function exit code */ + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "metrohash.pyx":130 + * return 'metrohash128' * - * def __cinit__(self, uint64_t seed=0ULL): # <<<<<<<<<<<<<< - * self._hasher = new CMetroHash128(seed) - * self._hash = bytearray(b"\0"*16) + * def __cinit__(self, seed=0): # <<<<<<<<<<<<<< + * cdef uint64_t _seed + * cdef MetroHash128 _copy */ /* Python wrapper */ static int __pyx_pw_9metrohash_12MetroHash128_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_pw_9metrohash_12MetroHash128_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - uint64_t __pyx_v_seed; + PyObject *__pyx_v_seed = 0; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_seed,0}; PyObject* values[1] = {0}; + values[0] = ((PyObject *)__pyx_int_0); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); @@ -2540,7 +3083,7 @@ static int __pyx_pw_9metrohash_12MetroHash128_1__cinit__(PyObject *__pyx_v_self, } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(0, 104, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(0, 130, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -2550,15 +3093,11 @@ static int __pyx_pw_9metrohash_12MetroHash128_1__cinit__(PyObject *__pyx_v_self, default: goto __pyx_L5_argtuple_error; } } - if (values[0]) { - __pyx_v_seed = __Pyx_PyInt_As_uint64_t(values[0]); if (unlikely((__pyx_v_seed == ((uint64_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 104, __pyx_L3_error) - } else { - __pyx_v_seed = ((uint64_t)0ULL); - } + __pyx_v_seed = values[0]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 104, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 130, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("metrohash.MetroHash128.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -2571,96 +3110,107 @@ static int __pyx_pw_9metrohash_12MetroHash128_1__cinit__(PyObject *__pyx_v_self, return __pyx_r; } -static int __pyx_pf_9metrohash_12MetroHash128___cinit__(struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self, uint64_t __pyx_v_seed) { +static int __pyx_pf_9metrohash_12MetroHash128___cinit__(struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self, PyObject *__pyx_v_seed) { + uint64_t __pyx_v__seed; + struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v__copy = 0; int __pyx_r; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; + int __pyx_t_1; int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + uint64_t __pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__cinit__", 0); - /* "metrohash.pyx":105 - * - * def __cinit__(self, uint64_t seed=0ULL): - * self._hasher = new CMetroHash128(seed) # <<<<<<<<<<<<<< - * self._hash = bytearray(b"\0"*16) - * self._notfinal = True + /* "metrohash.pyx":133 + * cdef uint64_t _seed + * cdef MetroHash128 _copy + * if isinstance(seed, MetroHash128): # <<<<<<<<<<<<<< + * _copy = seed + * self._hasher = new CMetroHash128(deref(_copy._hasher)) */ - __pyx_v_self->_hasher = new MetroHash128(__pyx_v_seed); - - /* "metrohash.pyx":106 - * def __cinit__(self, uint64_t seed=0ULL): - * self._hasher = new CMetroHash128(seed) - * self._hash = bytearray(b"\0"*16) # <<<<<<<<<<<<<< - * self._notfinal = True - * + __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_seed, __pyx_ptype_9metrohash_MetroHash128); + __pyx_t_2 = (__pyx_t_1 != 0); + if (__pyx_t_2) { + + /* "metrohash.pyx":134 + * cdef MetroHash128 _copy + * if isinstance(seed, MetroHash128): + * _copy = seed # <<<<<<<<<<<<<< + * self._hasher = new CMetroHash128(deref(_copy._hasher)) + * else: */ - __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)(&PyByteArray_Type)), __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 106, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->_hash); - __Pyx_DECREF(__pyx_v_self->_hash); - __pyx_v_self->_hash = ((PyObject*)__pyx_t_1); - __pyx_t_1 = 0; - - /* "metrohash.pyx":107 - * self._hasher = new CMetroHash128(seed) - * self._hash = bytearray(b"\0"*16) - * self._notfinal = True # <<<<<<<<<<<<<< - * - * if self._hasher is NULL: + __pyx_t_3 = __pyx_v_seed; + __Pyx_INCREF(__pyx_t_3); + __pyx_v__copy = ((struct __pyx_obj_9metrohash_MetroHash128 *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "metrohash.pyx":135 + * if isinstance(seed, MetroHash128): + * _copy = seed + * self._hasher = new CMetroHash128(deref(_copy._hasher)) # <<<<<<<<<<<<<< + * else: + * _seed = seed */ - __pyx_v_self->_notfinal = 1; - - /* "metrohash.pyx":109 - * self._notfinal = True - * - * if self._hasher is NULL: # <<<<<<<<<<<<<< - * raise MemoryError() - * + __pyx_v_self->_hasher = new MetroHash128((*__pyx_v__copy->_hasher)); + + /* "metrohash.pyx":133 + * cdef uint64_t _seed + * cdef MetroHash128 _copy + * if isinstance(seed, MetroHash128): # <<<<<<<<<<<<<< + * _copy = seed + * self._hasher = new CMetroHash128(deref(_copy._hasher)) */ - __pyx_t_2 = ((__pyx_v_self->_hasher == NULL) != 0); - if (unlikely(__pyx_t_2)) { + goto __pyx_L3; + } - /* "metrohash.pyx":110 - * - * if self._hasher is NULL: - * raise MemoryError() # <<<<<<<<<<<<<< + /* "metrohash.pyx":137 + * self._hasher = new CMetroHash128(deref(_copy._hasher)) + * else: + * _seed = seed # <<<<<<<<<<<<<< + * self._hasher = new CMetroHash128(_seed) * - * def __dealloc__(self): */ - PyErr_NoMemory(); __PYX_ERR(0, 110, __pyx_L1_error) + /*else*/ { + __pyx_t_4 = __Pyx_PyInt_As_uint64_t(__pyx_v_seed); if (unlikely((__pyx_t_4 == ((uint64_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 137, __pyx_L1_error) + __pyx_v__seed = ((uint64_t)__pyx_t_4); - /* "metrohash.pyx":109 - * self._notfinal = True - * - * if self._hasher is NULL: # <<<<<<<<<<<<<< - * raise MemoryError() + /* "metrohash.pyx":138 + * else: + * _seed = seed + * self._hasher = new CMetroHash128(_seed) # <<<<<<<<<<<<<< * + * def __dealloc__(self): */ + __pyx_v_self->_hasher = new MetroHash128(__pyx_v__seed); } + __pyx_L3:; - /* "metrohash.pyx":104 - * cdef bool _notfinal + /* "metrohash.pyx":130 + * return 'metrohash128' * - * def __cinit__(self, uint64_t seed=0ULL): # <<<<<<<<<<<<<< - * self._hasher = new CMetroHash128(seed) - * self._hash = bytearray(b"\0"*16) + * def __cinit__(self, seed=0): # <<<<<<<<<<<<<< + * cdef uint64_t _seed + * cdef MetroHash128 _copy */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("metrohash.MetroHash128.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v__copy); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "metrohash.pyx":112 - * raise MemoryError() +/* "metrohash.pyx":140 + * self._hasher = new CMetroHash128(_seed) * * def __dealloc__(self): # <<<<<<<<<<<<<< * if self._hasher is not NULL: @@ -2683,7 +3233,7 @@ static void __pyx_pf_9metrohash_12MetroHash128_2__dealloc__(struct __pyx_obj_9me int __pyx_t_1; __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "metrohash.pyx":113 + /* "metrohash.pyx":141 * * def __dealloc__(self): * if self._hasher is not NULL: # <<<<<<<<<<<<<< @@ -2693,7 +3243,7 @@ static void __pyx_pf_9metrohash_12MetroHash128_2__dealloc__(struct __pyx_obj_9me __pyx_t_1 = ((__pyx_v_self->_hasher != NULL) != 0); if (__pyx_t_1) { - /* "metrohash.pyx":114 + /* "metrohash.pyx":142 * def __dealloc__(self): * if self._hasher is not NULL: * del self._hasher # <<<<<<<<<<<<<< @@ -2702,7 +3252,7 @@ static void __pyx_pf_9metrohash_12MetroHash128_2__dealloc__(struct __pyx_obj_9me */ delete __pyx_v_self->_hasher; - /* "metrohash.pyx":115 + /* "metrohash.pyx":143 * if self._hasher is not NULL: * del self._hasher * self._hasher = NULL # <<<<<<<<<<<<<< @@ -2711,7 +3261,7 @@ static void __pyx_pf_9metrohash_12MetroHash128_2__dealloc__(struct __pyx_obj_9me */ __pyx_v_self->_hasher = NULL; - /* "metrohash.pyx":113 + /* "metrohash.pyx":141 * * def __dealloc__(self): * if self._hasher is not NULL: # <<<<<<<<<<<<<< @@ -2720,8 +3270,8 @@ static void __pyx_pf_9metrohash_12MetroHash128_2__dealloc__(struct __pyx_obj_9me */ } - /* "metrohash.pyx":112 - * raise MemoryError() + /* "metrohash.pyx":140 + * self._hasher = new CMetroHash128(_seed) * * def __dealloc__(self): # <<<<<<<<<<<<<< * if self._hasher is not NULL: @@ -2732,12 +3282,12 @@ static void __pyx_pf_9metrohash_12MetroHash128_2__dealloc__(struct __pyx_obj_9me __Pyx_RefNannyFinishContext(); } -/* "metrohash.pyx":117 +/* "metrohash.pyx":145 * self._hasher = NULL * * def update(self, data): # <<<<<<<<<<<<<< - * if self._notfinal: - * self._hasher.Update(data, len(data)) + * self._hasher.Update(data, len(data)) + * */ /* Python wrapper */ @@ -2756,72 +3306,36 @@ static PyObject *__pyx_pw_9metrohash_12MetroHash128_5update(PyObject *__pyx_v_se static PyObject *__pyx_pf_9metrohash_12MetroHash128_4update(struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self, PyObject *__pyx_v_data) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - int __pyx_t_1; - uint8_t const *__pyx_t_2; - Py_ssize_t __pyx_t_3; - PyObject *__pyx_t_4 = NULL; + uint8_t const *__pyx_t_1; + Py_ssize_t __pyx_t_2; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; __Pyx_RefNannySetupContext("update", 0); - /* "metrohash.pyx":118 - * - * def update(self, data): - * if self._notfinal: # <<<<<<<<<<<<<< - * self._hasher.Update(data, len(data)) - * else: - */ - __pyx_t_1 = (__pyx_v_self->_notfinal != 0); - if (likely(__pyx_t_1)) { - - /* "metrohash.pyx":119 - * def update(self, data): - * if self._notfinal: - * self._hasher.Update(data, len(data)) # <<<<<<<<<<<<<< - * else: - * raise RuntimeError("Hash already finalized.") - */ - __pyx_t_2 = __Pyx_PyObject_AsUString(__pyx_v_data); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(0, 119, __pyx_L1_error) - __pyx_t_3 = PyObject_Length(__pyx_v_data); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 119, __pyx_L1_error) - __pyx_v_self->_hasher->Update(__pyx_t_2, __pyx_t_3); - - /* "metrohash.pyx":118 + /* "metrohash.pyx":146 * * def update(self, data): - * if self._notfinal: # <<<<<<<<<<<<<< - * self._hasher.Update(data, len(data)) - * else: - */ - goto __pyx_L3; - } - - /* "metrohash.pyx":121 - * self._hasher.Update(data, len(data)) - * else: - * raise RuntimeError("Hash already finalized.") # <<<<<<<<<<<<<< + * self._hasher.Update(data, len(data)) # <<<<<<<<<<<<<< * - * def digest(self): + * cpdef digest(self): */ - /*else*/ { - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 121, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __Pyx_Raise(__pyx_t_4, 0, 0, 0); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 121, __pyx_L1_error) - } - __pyx_L3:; + __pyx_t_1 = __Pyx_PyObject_AsUString(__pyx_v_data); if (unlikely((!__pyx_t_1) && PyErr_Occurred())) __PYX_ERR(0, 146, __pyx_L1_error) + __pyx_t_2 = PyObject_Length(__pyx_v_data); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 146, __pyx_L1_error) + __pyx_v_self->_hasher->Update(__pyx_t_1, __pyx_t_2); - /* "metrohash.pyx":117 + /* "metrohash.pyx":145 * self._hasher = NULL * * def update(self, data): # <<<<<<<<<<<<<< - * if self._notfinal: - * self._hasher.Update(data, len(data)) + * self._hasher.Update(data, len(data)) + * */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("metrohash.MetroHash128.update", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; @@ -2830,14 +3344,134 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_4update(struct __pyx_obj_9me return __pyx_r; } -/* "metrohash.pyx":123 - * raise RuntimeError("Hash already finalized.") +/* "metrohash.pyx":148 + * self._hasher.Update(data, len(data)) * - * def digest(self): # <<<<<<<<<<<<<< - * if self._notfinal: - * self._hasher.Finalize(self._hash) + * cpdef digest(self): # <<<<<<<<<<<<<< + * cdef bytearray _hash = bytearray(16) + * CMetroHash128(deref(self._hasher)).Finalize(_hash) */ +static PyObject *__pyx_pw_9metrohash_12MetroHash128_7digest(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_f_9metrohash_12MetroHash128_digest(struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self, int __pyx_skip_dispatch) { + PyObject *__pyx_v__hash = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + uint8_t *__pyx_t_5; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("digest", 0); + /* Check if called by wrapper */ + if (unlikely(__pyx_skip_dispatch)) ; + /* Check if overridden in Python */ + else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || (Py_TYPE(((PyObject *)__pyx_v_self))->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) { + #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS + static PY_UINT64_T __pyx_tp_dict_version = __PYX_DICT_VERSION_INIT, __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT; + if (unlikely(!__Pyx_object_dict_version_matches(((PyObject *)__pyx_v_self), __pyx_tp_dict_version, __pyx_obj_dict_version))) { + PY_UINT64_T __pyx_type_dict_guard = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self)); + #endif + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_digest); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 148, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_9metrohash_12MetroHash128_7digest)) { + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + } + } + __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 148, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L0; + } + #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS + __pyx_tp_dict_version = __Pyx_get_tp_dict_version(((PyObject *)__pyx_v_self)); + __pyx_obj_dict_version = __Pyx_get_object_dict_version(((PyObject *)__pyx_v_self)); + if (unlikely(__pyx_type_dict_guard != __pyx_tp_dict_version)) { + __pyx_tp_dict_version = __pyx_obj_dict_version = __PYX_DICT_VERSION_INIT; + } + #endif + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS + } + #endif + } + + /* "metrohash.pyx":149 + * + * cpdef digest(self): + * cdef bytearray _hash = bytearray(16) # <<<<<<<<<<<<<< + * CMetroHash128(deref(self._hasher)).Finalize(_hash) + * return bytes(_hash) + */ + __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)(&PyByteArray_Type)), __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 149, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v__hash = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "metrohash.pyx":150 + * cpdef digest(self): + * cdef bytearray _hash = bytearray(16) + * CMetroHash128(deref(self._hasher)).Finalize(_hash) # <<<<<<<<<<<<<< + * return bytes(_hash) + * + */ + __pyx_t_5 = __Pyx_PyObject_AsWritableUString(__pyx_v__hash); if (unlikely((!__pyx_t_5) && PyErr_Occurred())) __PYX_ERR(0, 150, __pyx_L1_error) + MetroHash128((*__pyx_v_self->_hasher)).Finalize(__pyx_t_5); + + /* "metrohash.pyx":151 + * cdef bytearray _hash = bytearray(16) + * CMetroHash128(deref(self._hasher)).Finalize(_hash) + * return bytes(_hash) # <<<<<<<<<<<<<< + * + * def hexdigest(self): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyBytes_Type)), __pyx_v__hash); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 151, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + /* "metrohash.pyx":148 + * self._hasher.Update(data, len(data)) + * + * cpdef digest(self): # <<<<<<<<<<<<<< + * cdef bytearray _hash = bytearray(16) + * CMetroHash128(deref(self._hasher)).Finalize(_hash) + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("metrohash.MetroHash128.digest", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v__hash); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + /* Python wrapper */ static PyObject *__pyx_pw_9metrohash_12MetroHash128_7digest(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ static PyObject *__pyx_pw_9metrohash_12MetroHash128_7digest(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { @@ -2854,75 +3488,109 @@ static PyObject *__pyx_pw_9metrohash_12MetroHash128_7digest(PyObject *__pyx_v_se static PyObject *__pyx_pf_9metrohash_12MetroHash128_6digest(struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - int __pyx_t_1; - uint8_t *__pyx_t_2; - PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; __Pyx_RefNannySetupContext("digest", 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = __pyx_f_9metrohash_12MetroHash128_digest(__pyx_v_self, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 148, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "metrohash.pyx":124 - * - * def digest(self): - * if self._notfinal: # <<<<<<<<<<<<<< - * self._hasher.Finalize(self._hash) - * self._notfinal = False - */ - __pyx_t_1 = (__pyx_v_self->_notfinal != 0); - if (__pyx_t_1) { + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("metrohash.MetroHash128.digest", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "metrohash.pyx":125 - * def digest(self): - * if self._notfinal: - * self._hasher.Finalize(self._hash) # <<<<<<<<<<<<<< - * self._notfinal = False +/* "metrohash.pyx":153 + * return bytes(_hash) * - */ - __pyx_t_2 = __Pyx_PyObject_AsWritableUString(__pyx_v_self->_hash); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(0, 125, __pyx_L1_error) - __pyx_v_self->_hasher->Finalize(__pyx_t_2); - - /* "metrohash.pyx":126 - * if self._notfinal: - * self._hasher.Finalize(self._hash) - * self._notfinal = False # <<<<<<<<<<<<<< + * def hexdigest(self): # <<<<<<<<<<<<<< + * return bytes2hex(self.digest()) * - * return bytes(self._hash) */ - __pyx_v_self->_notfinal = 0; - /* "metrohash.pyx":124 - * - * def digest(self): - * if self._notfinal: # <<<<<<<<<<<<<< - * self._hasher.Finalize(self._hash) - * self._notfinal = False - */ - } +/* Python wrapper */ +static PyObject *__pyx_pw_9metrohash_12MetroHash128_9hexdigest(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_9metrohash_12MetroHash128_9hexdigest(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("hexdigest (wrapper)", 0); + __pyx_r = __pyx_pf_9metrohash_12MetroHash128_8hexdigest(((struct __pyx_obj_9metrohash_MetroHash128 *)__pyx_v_self)); - /* "metrohash.pyx":128 - * self._notfinal = False - * - * return bytes(self._hash) # <<<<<<<<<<<<<< + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_9metrohash_12MetroHash128_8hexdigest(struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("hexdigest", 0); + + /* "metrohash.pyx":154 * * def hexdigest(self): + * return bytes2hex(self.digest()) # <<<<<<<<<<<<<< + * + * def copy(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyBytes_Type)), __pyx_v_self->_hash); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 128, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_bytes2hex); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 154, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = ((struct __pyx_vtabstruct_9metrohash_MetroHash128 *)__pyx_v_self->__pyx_vtab)->digest(__pyx_v_self, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 154, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_r = __pyx_t_3; - __pyx_t_3 = 0; + __pyx_t_4 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 154, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; goto __pyx_L0; - /* "metrohash.pyx":123 - * raise RuntimeError("Hash already finalized.") + /* "metrohash.pyx":153 + * return bytes(_hash) + * + * def hexdigest(self): # <<<<<<<<<<<<<< + * return bytes2hex(self.digest()) * - * def digest(self): # <<<<<<<<<<<<<< - * if self._notfinal: - * self._hasher.Finalize(self._hash) */ /* function exit code */ __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("metrohash.MetroHash128.digest", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("metrohash.MetroHash128.hexdigest", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -2930,96 +3598,58 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_6digest(struct __pyx_obj_9me return __pyx_r; } -/* "metrohash.pyx":130 - * return bytes(self._hash) - * - * def hexdigest(self): # <<<<<<<<<<<<<< +/* "metrohash.pyx":156 * return bytes2hex(self.digest()) + * + * def copy(self): # <<<<<<<<<<<<<< + * return MetroHash128(self) */ /* Python wrapper */ -static PyObject *__pyx_pw_9metrohash_12MetroHash128_9hexdigest(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_9metrohash_12MetroHash128_9hexdigest(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_9metrohash_12MetroHash128_11copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_9metrohash_12MetroHash128_11copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("hexdigest (wrapper)", 0); - __pyx_r = __pyx_pf_9metrohash_12MetroHash128_8hexdigest(((struct __pyx_obj_9metrohash_MetroHash128 *)__pyx_v_self)); + __Pyx_RefNannySetupContext("copy (wrapper)", 0); + __pyx_r = __pyx_pf_9metrohash_12MetroHash128_10copy(((struct __pyx_obj_9metrohash_MetroHash128 *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_9metrohash_12MetroHash128_8hexdigest(struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self) { +static PyObject *__pyx_pf_9metrohash_12MetroHash128_10copy(struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - __Pyx_RefNannySetupContext("hexdigest", 0); + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("copy", 0); - /* "metrohash.pyx":131 + /* "metrohash.pyx":157 * - * def hexdigest(self): - * return bytes2hex(self.digest()) # <<<<<<<<<<<<<< + * def copy(self): + * return MetroHash128(self) # <<<<<<<<<<<<<< */ __Pyx_XDECREF(__pyx_r); - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_bytes2hex); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 131, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_digest); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 131, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = NULL; - if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_4, function); - } - } - __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 131, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = NULL; - if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_4)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_4); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 131, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_9metrohash_MetroHash128), ((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 157, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; - /* "metrohash.pyx":130 - * return bytes(self._hash) - * - * def hexdigest(self): # <<<<<<<<<<<<<< + /* "metrohash.pyx":156 * return bytes2hex(self.digest()) + * + * def copy(self): # <<<<<<<<<<<<<< + * return MetroHash128(self) */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_4); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_AddTraceback("metrohash.MetroHash128.hexdigest", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("metrohash.MetroHash128.copy", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -3034,22 +3664,25 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_8hexdigest(struct __pyx_obj_ */ /* Python wrapper */ -static PyObject *__pyx_pw_9metrohash_12MetroHash128_11__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_9metrohash_12MetroHash128_11__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_9metrohash_12MetroHash128_13__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_9metrohash_12MetroHash128_13__reduce_cython__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_9metrohash_12MetroHash128_10__reduce_cython__(((struct __pyx_obj_9metrohash_MetroHash128 *)__pyx_v_self)); + __pyx_r = __pyx_pf_9metrohash_12MetroHash128_12__reduce_cython__(((struct __pyx_obj_9metrohash_MetroHash128 *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_9metrohash_12MetroHash128_10__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self) { +static PyObject *__pyx_pf_9metrohash_12MetroHash128_12__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__reduce_cython__", 0); /* "(tree fragment)":2 @@ -3058,7 +3691,7 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_10__reduce_cython__(CYTHON_U * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 2, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -3088,22 +3721,25 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_10__reduce_cython__(CYTHON_U */ /* Python wrapper */ -static PyObject *__pyx_pw_9metrohash_12MetroHash128_13__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ -static PyObject *__pyx_pw_9metrohash_12MetroHash128_13__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pw_9metrohash_12MetroHash128_15__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state); /*proto*/ +static PyObject *__pyx_pw_9metrohash_12MetroHash128_15__setstate_cython__(PyObject *__pyx_v_self, PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); - __pyx_r = __pyx_pf_9metrohash_12MetroHash128_12__setstate_cython__(((struct __pyx_obj_9metrohash_MetroHash128 *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); + __pyx_r = __pyx_pf_9metrohash_12MetroHash128_14__setstate_cython__(((struct __pyx_obj_9metrohash_MetroHash128 *)__pyx_v_self), ((PyObject *)__pyx_v___pyx_state)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_9metrohash_12MetroHash128_12__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { +static PyObject *__pyx_pf_9metrohash_12MetroHash128_14__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_9metrohash_MetroHash128 *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__setstate_cython__", 0); /* "(tree fragment)":4 @@ -3111,7 +3747,7 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_12__setstate_cython__(CYTHON * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -3133,6 +3769,7 @@ static PyObject *__pyx_pf_9metrohash_12MetroHash128_12__setstate_cython__(CYTHON __Pyx_RefNannyFinishContext(); return __pyx_r; } +static struct __pyx_vtabstruct_9metrohash_MetroHash64 __pyx_vtable_9metrohash_MetroHash64; static PyObject *__pyx_tp_new_9metrohash_MetroHash64(PyTypeObject *t, PyObject *a, PyObject *k) { struct __pyx_obj_9metrohash_MetroHash64 *p; @@ -3144,7 +3781,7 @@ static PyObject *__pyx_tp_new_9metrohash_MetroHash64(PyTypeObject *t, PyObject * } if (unlikely(!o)) return 0; p = ((struct __pyx_obj_9metrohash_MetroHash64 *)o); - p->_hash = ((PyObject*)Py_None); Py_INCREF(Py_None); + p->__pyx_vtab = __pyx_vtabptr_9metrohash_MetroHash64; if (unlikely(__pyx_pw_9metrohash_11MetroHash64_1__cinit__(o, a, k) < 0)) goto bad; return o; bad: @@ -3153,7 +3790,6 @@ static PyObject *__pyx_tp_new_9metrohash_MetroHash64(PyTypeObject *t, PyObject * } static void __pyx_tp_dealloc_9metrohash_MetroHash64(PyObject *o) { - struct __pyx_obj_9metrohash_MetroHash64 *p = (struct __pyx_obj_9metrohash_MetroHash64 *)o; #if CYTHON_USE_TP_FINALIZE if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) { if (PyObject_CallFinalizerFromDealloc(o)) return; @@ -3162,31 +3798,55 @@ static void __pyx_tp_dealloc_9metrohash_MetroHash64(PyObject *o) { { PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); + __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1); __pyx_pw_9metrohash_11MetroHash64_3__dealloc__(o); - --Py_REFCNT(o); + __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1); PyErr_Restore(etype, eval, etb); } - Py_CLEAR(p->_hash); (*Py_TYPE(o)->tp_free)(o); } +static PyObject *__pyx_getprop_9metrohash_11MetroHash64_digest_size(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_9metrohash_11MetroHash64_11digest_size_1__get__(o); +} + +static PyObject *__pyx_getprop_9metrohash_11MetroHash64_block_size(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_9metrohash_11MetroHash64_10block_size_1__get__(o); +} + +static PyObject *__pyx_getprop_9metrohash_11MetroHash64_name(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_9metrohash_11MetroHash64_4name_1__get__(o); +} + static PyMethodDef __pyx_methods_9metrohash_MetroHash64[] = { {"update", (PyCFunction)__pyx_pw_9metrohash_11MetroHash64_5update, METH_O, 0}, {"digest", (PyCFunction)__pyx_pw_9metrohash_11MetroHash64_7digest, METH_NOARGS, 0}, {"hexdigest", (PyCFunction)__pyx_pw_9metrohash_11MetroHash64_9hexdigest, METH_NOARGS, 0}, - {"__reduce_cython__", (PyCFunction)__pyx_pw_9metrohash_11MetroHash64_11__reduce_cython__, METH_NOARGS, 0}, - {"__setstate_cython__", (PyCFunction)__pyx_pw_9metrohash_11MetroHash64_13__setstate_cython__, METH_O, 0}, + {"copy", (PyCFunction)__pyx_pw_9metrohash_11MetroHash64_11copy, METH_NOARGS, 0}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_9metrohash_11MetroHash64_13__reduce_cython__, METH_NOARGS, 0}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_9metrohash_11MetroHash64_15__setstate_cython__, METH_O, 0}, {0, 0, 0, 0} }; +static struct PyGetSetDef __pyx_getsets_9metrohash_MetroHash64[] = { + {(char *)"digest_size", __pyx_getprop_9metrohash_11MetroHash64_digest_size, 0, (char *)0, 0}, + {(char *)"block_size", __pyx_getprop_9metrohash_11MetroHash64_block_size, 0, (char *)0, 0}, + {(char *)"name", __pyx_getprop_9metrohash_11MetroHash64_name, 0, (char *)0, 0}, + {0, 0, 0, 0, 0} +}; + static PyTypeObject __pyx_type_9metrohash_MetroHash64 = { PyVarObject_HEAD_INIT(0, 0) "metrohash.MetroHash64", /*tp_name*/ sizeof(struct __pyx_obj_9metrohash_MetroHash64), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_9metrohash_MetroHash64, /*tp_dealloc*/ + #if PY_VERSION_HEX < 0x030800b4 0, /*tp_print*/ + #endif + #if PY_VERSION_HEX >= 0x030800b4 + 0, /*tp_vectorcall_offset*/ + #endif 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 @@ -3215,7 +3875,7 @@ static PyTypeObject __pyx_type_9metrohash_MetroHash64 = { 0, /*tp_iternext*/ __pyx_methods_9metrohash_MetroHash64, /*tp_methods*/ 0, /*tp_members*/ - 0, /*tp_getset*/ + __pyx_getsets_9metrohash_MetroHash64, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ @@ -3236,7 +3896,14 @@ static PyTypeObject __pyx_type_9metrohash_MetroHash64 = { #if PY_VERSION_HEX >= 0x030400a1 0, /*tp_finalize*/ #endif + #if PY_VERSION_HEX >= 0x030800b1 + 0, /*tp_vectorcall*/ + #endif + #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000 + 0, /*tp_print*/ + #endif }; +static struct __pyx_vtabstruct_9metrohash_MetroHash128 __pyx_vtable_9metrohash_MetroHash128; static PyObject *__pyx_tp_new_9metrohash_MetroHash128(PyTypeObject *t, PyObject *a, PyObject *k) { struct __pyx_obj_9metrohash_MetroHash128 *p; @@ -3248,7 +3915,7 @@ static PyObject *__pyx_tp_new_9metrohash_MetroHash128(PyTypeObject *t, PyObject } if (unlikely(!o)) return 0; p = ((struct __pyx_obj_9metrohash_MetroHash128 *)o); - p->_hash = ((PyObject*)Py_None); Py_INCREF(Py_None); + p->__pyx_vtab = __pyx_vtabptr_9metrohash_MetroHash128; if (unlikely(__pyx_pw_9metrohash_12MetroHash128_1__cinit__(o, a, k) < 0)) goto bad; return o; bad: @@ -3257,7 +3924,6 @@ static PyObject *__pyx_tp_new_9metrohash_MetroHash128(PyTypeObject *t, PyObject } static void __pyx_tp_dealloc_9metrohash_MetroHash128(PyObject *o) { - struct __pyx_obj_9metrohash_MetroHash128 *p = (struct __pyx_obj_9metrohash_MetroHash128 *)o; #if CYTHON_USE_TP_FINALIZE if (unlikely(PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE) && Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) { if (PyObject_CallFinalizerFromDealloc(o)) return; @@ -3266,31 +3932,55 @@ static void __pyx_tp_dealloc_9metrohash_MetroHash128(PyObject *o) { { PyObject *etype, *eval, *etb; PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); + __Pyx_SET_REFCNT(o, Py_REFCNT(o) + 1); __pyx_pw_9metrohash_12MetroHash128_3__dealloc__(o); - --Py_REFCNT(o); + __Pyx_SET_REFCNT(o, Py_REFCNT(o) - 1); PyErr_Restore(etype, eval, etb); } - Py_CLEAR(p->_hash); (*Py_TYPE(o)->tp_free)(o); } +static PyObject *__pyx_getprop_9metrohash_12MetroHash128_digest_size(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_9metrohash_12MetroHash128_11digest_size_1__get__(o); +} + +static PyObject *__pyx_getprop_9metrohash_12MetroHash128_block_size(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_9metrohash_12MetroHash128_10block_size_1__get__(o); +} + +static PyObject *__pyx_getprop_9metrohash_12MetroHash128_name(PyObject *o, CYTHON_UNUSED void *x) { + return __pyx_pw_9metrohash_12MetroHash128_4name_1__get__(o); +} + static PyMethodDef __pyx_methods_9metrohash_MetroHash128[] = { {"update", (PyCFunction)__pyx_pw_9metrohash_12MetroHash128_5update, METH_O, 0}, {"digest", (PyCFunction)__pyx_pw_9metrohash_12MetroHash128_7digest, METH_NOARGS, 0}, {"hexdigest", (PyCFunction)__pyx_pw_9metrohash_12MetroHash128_9hexdigest, METH_NOARGS, 0}, - {"__reduce_cython__", (PyCFunction)__pyx_pw_9metrohash_12MetroHash128_11__reduce_cython__, METH_NOARGS, 0}, - {"__setstate_cython__", (PyCFunction)__pyx_pw_9metrohash_12MetroHash128_13__setstate_cython__, METH_O, 0}, + {"copy", (PyCFunction)__pyx_pw_9metrohash_12MetroHash128_11copy, METH_NOARGS, 0}, + {"__reduce_cython__", (PyCFunction)__pyx_pw_9metrohash_12MetroHash128_13__reduce_cython__, METH_NOARGS, 0}, + {"__setstate_cython__", (PyCFunction)__pyx_pw_9metrohash_12MetroHash128_15__setstate_cython__, METH_O, 0}, {0, 0, 0, 0} }; +static struct PyGetSetDef __pyx_getsets_9metrohash_MetroHash128[] = { + {(char *)"digest_size", __pyx_getprop_9metrohash_12MetroHash128_digest_size, 0, (char *)0, 0}, + {(char *)"block_size", __pyx_getprop_9metrohash_12MetroHash128_block_size, 0, (char *)0, 0}, + {(char *)"name", __pyx_getprop_9metrohash_12MetroHash128_name, 0, (char *)0, 0}, + {0, 0, 0, 0, 0} +}; + static PyTypeObject __pyx_type_9metrohash_MetroHash128 = { PyVarObject_HEAD_INIT(0, 0) "metrohash.MetroHash128", /*tp_name*/ sizeof(struct __pyx_obj_9metrohash_MetroHash128), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_9metrohash_MetroHash128, /*tp_dealloc*/ + #if PY_VERSION_HEX < 0x030800b4 0, /*tp_print*/ + #endif + #if PY_VERSION_HEX >= 0x030800b4 + 0, /*tp_vectorcall_offset*/ + #endif 0, /*tp_getattr*/ 0, /*tp_setattr*/ #if PY_MAJOR_VERSION < 3 @@ -3319,7 +4009,7 @@ static PyTypeObject __pyx_type_9metrohash_MetroHash128 = { 0, /*tp_iternext*/ __pyx_methods_9metrohash_MetroHash128, /*tp_methods*/ 0, /*tp_members*/ - 0, /*tp_getset*/ + __pyx_getsets_9metrohash_MetroHash128, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ @@ -3340,6 +4030,12 @@ static PyTypeObject __pyx_type_9metrohash_MetroHash128 = { #if PY_VERSION_HEX >= 0x030400a1 0, /*tp_finalize*/ #endif + #if PY_VERSION_HEX >= 0x030800b1 + 0, /*tp_vectorcall*/ + #endif + #if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000 + 0, /*tp_print*/ + #endif }; static PyMethodDef __pyx_methods[] = { @@ -3391,11 +4087,9 @@ static struct PyModuleDef __pyx_moduledef = { static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_b_, __pyx_k_, sizeof(__pyx_k_), 0, 0, 0, 0}, - {&__pyx_kp_s_Hash_already_finalized, __pyx_k_Hash_already_finalized, sizeof(__pyx_k_Hash_already_finalized), 0, 0, 1, 0}, {&__pyx_n_s_MemoryError, __pyx_k_MemoryError, sizeof(__pyx_k_MemoryError), 0, 0, 1, 1}, {&__pyx_n_s_MetroHash128, __pyx_k_MetroHash128, sizeof(__pyx_k_MetroHash128), 0, 0, 1, 1}, {&__pyx_n_s_MetroHash64, __pyx_k_MetroHash64, sizeof(__pyx_k_MetroHash64), 0, 0, 1, 1}, - {&__pyx_n_s_RuntimeError, __pyx_k_RuntimeError, sizeof(__pyx_k_RuntimeError), 0, 0, 1, 1}, {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1}, {&__pyx_kp_b__3, __pyx_k__3, sizeof(__pyx_k__3), 0, 0, 0, 0}, {&__pyx_n_s_all, __pyx_k_all, sizeof(__pyx_k_all), 0, 0, 1, 1}, @@ -3415,6 +4109,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_metrohash_pyx, __pyx_k_metrohash_pyx, sizeof(__pyx_k_metrohash_pyx), 0, 0, 1, 0}, {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1}, {&__pyx_kp_s_no_default___reduce___due_to_non, __pyx_k_no_default___reduce___due_to_non, sizeof(__pyx_k_no_default___reduce___due_to_non), 0, 0, 1, 0}, + {&__pyx_n_s_pyx_vtable, __pyx_k_pyx_vtable, sizeof(__pyx_k_pyx_vtable), 0, 0, 1, 1}, {&__pyx_n_s_reduce, __pyx_k_reduce, sizeof(__pyx_k_reduce), 0, 0, 1, 1}, {&__pyx_n_s_reduce_cython, __pyx_k_reduce_cython, sizeof(__pyx_k_reduce_cython), 0, 0, 1, 1}, {&__pyx_n_s_reduce_ex, __pyx_k_reduce_ex, sizeof(__pyx_k_reduce_ex), 0, 0, 1, 1}, @@ -3427,8 +4122,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {0, 0, 0, 0, 0, 0, 0} }; static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) __PYX_ERR(0, 75, __pyx_L1_error) - __pyx_builtin_RuntimeError = __Pyx_GetBuiltinName(__pyx_n_s_RuntimeError); if (!__pyx_builtin_RuntimeError) __PYX_ERR(0, 86, __pyx_L1_error) + __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) __PYX_ERR(0, 93, __pyx_L1_error) __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(1, 2, __pyx_L1_error) return 0; __pyx_L1_error:; @@ -3439,36 +4133,36 @@ static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); - /* "metrohash.pyx":53 + /* "metrohash.pyx":56 * cpdef bytes metrohash64(bytes data, uint64_t seed=0ULL): * * cdef bytearray out = bytearray(b"\0"*8) # <<<<<<<<<<<<<< * CMetroHash64.Hash(data, len(data), out, seed) * return bytes(out) */ - __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_b_); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 53, __pyx_L1_error) + __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_b_); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 56, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__2); __Pyx_GIVEREF(__pyx_tuple__2); - /* "metrohash.pyx":59 + /* "metrohash.pyx":62 * cpdef bytes metrohash128(bytes data, uint64_t seed=0ULL): * * cdef bytearray out = bytearray(b"\0"*16) # <<<<<<<<<<<<<< * CMetroHash128.Hash(data, len(data), out, seed) * return bytes(out) */ - __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_b__3); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 59, __pyx_L1_error) + __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_b__3); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 62, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__4); __Pyx_GIVEREF(__pyx_tuple__4); - /* "metrohash.pyx":86 - * self._hasher.Update(data, len(data)) - * else: - * raise RuntimeError("Hash already finalized.") # <<<<<<<<<<<<<< + /* "metrohash.pyx":104 * - * def digest(self): + * cpdef digest(self): + * cdef bytearray _hash = bytearray(8) # <<<<<<<<<<<<<< + * CMetroHash64(deref(self._hasher)).Finalize(_hash) + * return bytes(_hash) */ - __pyx_tuple__5 = PyTuple_Pack(1, __pyx_kp_s_Hash_already_finalized); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 86, __pyx_L1_error) + __pyx_tuple__5 = PyTuple_Pack(1, __pyx_int_8); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 104, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__5); __Pyx_GIVEREF(__pyx_tuple__5); @@ -3491,59 +4185,70 @@ static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { __Pyx_GOTREF(__pyx_tuple__7); __Pyx_GIVEREF(__pyx_tuple__7); + /* "metrohash.pyx":149 + * + * cpdef digest(self): + * cdef bytearray _hash = bytearray(16) # <<<<<<<<<<<<<< + * CMetroHash128(deref(self._hasher)).Finalize(_hash) + * return bytes(_hash) + */ + __pyx_tuple__8 = PyTuple_Pack(1, __pyx_int_16); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 149, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__8); + __Pyx_GIVEREF(__pyx_tuple__8); + /* "(tree fragment)":2 * def __reduce_cython__(self): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") */ - __pyx_tuple__8 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(1, 2, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__8); - __Pyx_GIVEREF(__pyx_tuple__8); + __pyx_tuple__9 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(1, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__9); + __Pyx_GIVEREF(__pyx_tuple__9); /* "(tree fragment)":4 * raise TypeError("no default __reduce__ due to non-trivial __cinit__") * def __setstate_cython__(self, __pyx_state): * raise TypeError("no default __reduce__ due to non-trivial __cinit__") # <<<<<<<<<<<<<< */ - __pyx_tuple__9 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(1, 4, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__9); - __Pyx_GIVEREF(__pyx_tuple__9); + __pyx_tuple__10 = PyTuple_Pack(1, __pyx_kp_s_no_default___reduce___due_to_non); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__10); + __Pyx_GIVEREF(__pyx_tuple__10); - /* "metrohash.pyx":44 + /* "metrohash.pyx":47 * __all__ = ["MetroHash128", "MetroHash64", "metrohash128", "metrohash64"] * * if sys.version_info < (3, ): # <<<<<<<<<<<<<< * def bytes2hex(b): * return b.encode("hex") */ - __pyx_tuple__10 = PyTuple_Pack(1, __pyx_int_3); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 44, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__10); - __Pyx_GIVEREF(__pyx_tuple__10); + __pyx_tuple__11 = PyTuple_Pack(1, __pyx_int_3); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(0, 47, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__11); + __Pyx_GIVEREF(__pyx_tuple__11); - /* "metrohash.pyx":45 + /* "metrohash.pyx":48 * * if sys.version_info < (3, ): * def bytes2hex(b): # <<<<<<<<<<<<<< * return b.encode("hex") * else: */ - __pyx_tuple__11 = PyTuple_Pack(1, __pyx_n_s_b); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(0, 45, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__11); - __Pyx_GIVEREF(__pyx_tuple__11); - __pyx_codeobj__12 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__11, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_metrohash_pyx, __pyx_n_s_bytes2hex, 45, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__12)) __PYX_ERR(0, 45, __pyx_L1_error) + __pyx_tuple__12 = PyTuple_Pack(1, __pyx_n_s_b); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(0, 48, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__12); + __Pyx_GIVEREF(__pyx_tuple__12); + __pyx_codeobj__13 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__12, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_metrohash_pyx, __pyx_n_s_bytes2hex, 48, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__13)) __PYX_ERR(0, 48, __pyx_L1_error) - /* "metrohash.pyx":48 + /* "metrohash.pyx":51 * return b.encode("hex") * else: * def bytes2hex(b): # <<<<<<<<<<<<<< * return b.hex() * */ - __pyx_tuple__13 = PyTuple_Pack(1, __pyx_n_s_b); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(0, 48, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__13); - __Pyx_GIVEREF(__pyx_tuple__13); - __pyx_codeobj__14 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__13, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_metrohash_pyx, __pyx_n_s_bytes2hex, 48, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__14)) __PYX_ERR(0, 48, __pyx_L1_error) + __pyx_tuple__14 = PyTuple_Pack(1, __pyx_n_s_b); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(0, 51, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__14); + __Pyx_GIVEREF(__pyx_tuple__14); + __pyx_codeobj__15 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__14, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_metrohash_pyx, __pyx_n_s_bytes2hex, 51, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__15)) __PYX_ERR(0, 51, __pyx_L1_error) __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -3553,7 +4258,12 @@ static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) { if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error); + __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error) __pyx_int_3 = PyInt_FromLong(3); if (unlikely(!__pyx_int_3)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_8 = PyInt_FromLong(8); if (unlikely(!__pyx_int_8)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_16 = PyInt_FromLong(16); if (unlikely(!__pyx_int_16)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_32 = PyInt_FromLong(32); if (unlikely(!__pyx_int_32)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_64 = PyInt_FromLong(64); if (unlikely(!__pyx_int_64)) __PYX_ERR(0, 1, __pyx_L1_error) return 0; __pyx_L1_error:; return -1; @@ -3593,23 +4303,36 @@ static int __Pyx_modinit_function_export_code(void) { static int __Pyx_modinit_type_init_code(void) { __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0); /*--- Type init code ---*/ - if (PyType_Ready(&__pyx_type_9metrohash_MetroHash64) < 0) __PYX_ERR(0, 63, __pyx_L1_error) + __pyx_vtabptr_9metrohash_MetroHash64 = &__pyx_vtable_9metrohash_MetroHash64; + __pyx_vtable_9metrohash_MetroHash64.digest = (PyObject *(*)(struct __pyx_obj_9metrohash_MetroHash64 *, int __pyx_skip_dispatch))__pyx_f_9metrohash_11MetroHash64_digest; + if (PyType_Ready(&__pyx_type_9metrohash_MetroHash64) < 0) __PYX_ERR(0, 66, __pyx_L1_error) + #if PY_VERSION_HEX < 0x030800B1 __pyx_type_9metrohash_MetroHash64.tp_print = 0; + #endif if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_9metrohash_MetroHash64.tp_dictoffset && __pyx_type_9metrohash_MetroHash64.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_9metrohash_MetroHash64.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (PyObject_SetAttr(__pyx_m, __pyx_n_s_MetroHash64, (PyObject *)&__pyx_type_9metrohash_MetroHash64) < 0) __PYX_ERR(0, 63, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_9metrohash_MetroHash64) < 0) __PYX_ERR(0, 63, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_9metrohash_MetroHash64.tp_dict, __pyx_vtabptr_9metrohash_MetroHash64) < 0) __PYX_ERR(0, 66, __pyx_L1_error) + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_MetroHash64, (PyObject *)&__pyx_type_9metrohash_MetroHash64) < 0) __PYX_ERR(0, 66, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_9metrohash_MetroHash64) < 0) __PYX_ERR(0, 66, __pyx_L1_error) __pyx_ptype_9metrohash_MetroHash64 = &__pyx_type_9metrohash_MetroHash64; - if (PyType_Ready(&__pyx_type_9metrohash_MetroHash128) < 0) __PYX_ERR(0, 98, __pyx_L1_error) + __pyx_vtabptr_9metrohash_MetroHash128 = &__pyx_vtable_9metrohash_MetroHash128; + __pyx_vtable_9metrohash_MetroHash128.digest = (PyObject *(*)(struct __pyx_obj_9metrohash_MetroHash128 *, int __pyx_skip_dispatch))__pyx_f_9metrohash_12MetroHash128_digest; + if (PyType_Ready(&__pyx_type_9metrohash_MetroHash128) < 0) __PYX_ERR(0, 114, __pyx_L1_error) + #if PY_VERSION_HEX < 0x030800B1 __pyx_type_9metrohash_MetroHash128.tp_print = 0; + #endif if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_type_9metrohash_MetroHash128.tp_dictoffset && __pyx_type_9metrohash_MetroHash128.tp_getattro == PyObject_GenericGetAttr)) { __pyx_type_9metrohash_MetroHash128.tp_getattro = __Pyx_PyObject_GenericGetAttr; } - if (PyObject_SetAttr(__pyx_m, __pyx_n_s_MetroHash128, (PyObject *)&__pyx_type_9metrohash_MetroHash128) < 0) __PYX_ERR(0, 98, __pyx_L1_error) - if (__Pyx_setup_reduce((PyObject*)&__pyx_type_9metrohash_MetroHash128) < 0) __PYX_ERR(0, 98, __pyx_L1_error) + if (__Pyx_SetVtable(__pyx_type_9metrohash_MetroHash128.tp_dict, __pyx_vtabptr_9metrohash_MetroHash128) < 0) __PYX_ERR(0, 114, __pyx_L1_error) + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_MetroHash128, (PyObject *)&__pyx_type_9metrohash_MetroHash128) < 0) __PYX_ERR(0, 114, __pyx_L1_error) + if (__Pyx_setup_reduce((PyObject*)&__pyx_type_9metrohash_MetroHash128) < 0) __PYX_ERR(0, 114, __pyx_L1_error) __pyx_ptype_9metrohash_MetroHash128 = &__pyx_type_9metrohash_MetroHash128; __Pyx_RefNannyFinishContext(); return 0; @@ -3643,17 +4366,19 @@ static int __Pyx_modinit_function_import_code(void) { } -#if PY_MAJOR_VERSION < 3 -#ifdef CYTHON_NO_PYINIT_EXPORT -#define __Pyx_PyMODINIT_FUNC void -#else +#ifndef CYTHON_NO_PYINIT_EXPORT #define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC +#elif PY_MAJOR_VERSION < 3 +#ifdef __cplusplus +#define __Pyx_PyMODINIT_FUNC extern "C" void +#else +#define __Pyx_PyMODINIT_FUNC void #endif #else -#ifdef CYTHON_NO_PYINIT_EXPORT -#define __Pyx_PyMODINIT_FUNC PyObject * +#ifdef __cplusplus +#define __Pyx_PyMODINIT_FUNC extern "C" PyObject * #else -#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC +#define __Pyx_PyMODINIT_FUNC PyObject * #endif #endif @@ -3737,6 +4462,9 @@ static CYTHON_SMALL_CODE int __pyx_pymod_exec_metrohash(PyObject *__pyx_pyinit_m PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; int __pyx_t_3; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; __Pyx_RefNannyDeclarations #if CYTHON_PEP489_MULTI_PHASE_INIT if (__pyx_m) { @@ -3804,10 +4532,9 @@ if (!__Pyx_RefNanny) { __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error) Py_INCREF(__pyx_d); __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error) - __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error) - #if CYTHON_COMPILING_IN_PYPY Py_INCREF(__pyx_b); - #endif + __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error) + Py_INCREF(__pyx_cython_runtime); if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error); /*--- Initialize various global constants etc. ---*/ if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error) @@ -3833,7 +4560,7 @@ if (!__Pyx_RefNanny) { (void)__Pyx_modinit_global_init_code(); (void)__Pyx_modinit_variable_export_code(); (void)__Pyx_modinit_function_export_code(); - if (unlikely(__Pyx_modinit_type_init_code() != 0)) goto __pyx_L1_error; + if (unlikely(__Pyx_modinit_type_init_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error) (void)__Pyx_modinit_type_import_code(); (void)__Pyx_modinit_variable_import_code(); (void)__Pyx_modinit_function_import_code(); @@ -3854,14 +4581,14 @@ if (!__Pyx_RefNanny) { if (PyDict_SetItem(__pyx_d, __pyx_n_s_sys, __pyx_t_1) < 0) __PYX_ERR(0, 3, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "metrohash.pyx":42 + /* "metrohash.pyx":45 * void Hash(const uint8_t* buffer, const uint64_t length, uint8_t* const hash, const uint64_t seed) * * __all__ = ["MetroHash128", "MetroHash64", "metrohash128", "metrohash64"] # <<<<<<<<<<<<<< * * if sys.version_info < (3, ): */ - __pyx_t_1 = PyList_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 42, __pyx_L1_error) + __pyx_t_1 = PyList_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 45, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_n_s_MetroHash128); __Pyx_GIVEREF(__pyx_n_s_MetroHash128); @@ -3875,40 +4602,40 @@ if (!__Pyx_RefNanny) { __Pyx_INCREF(__pyx_n_s_metrohash64); __Pyx_GIVEREF(__pyx_n_s_metrohash64); PyList_SET_ITEM(__pyx_t_1, 3, __pyx_n_s_metrohash64); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_all, __pyx_t_1) < 0) __PYX_ERR(0, 42, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_all, __pyx_t_1) < 0) __PYX_ERR(0, 45, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "metrohash.pyx":44 + /* "metrohash.pyx":47 * __all__ = ["MetroHash128", "MetroHash64", "metrohash128", "metrohash64"] * * if sys.version_info < (3, ): # <<<<<<<<<<<<<< * def bytes2hex(b): * return b.encode("hex") */ - __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_sys); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 44, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_sys); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 47, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_version_info); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 44, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_version_info); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 47, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_tuple__10, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 44, __pyx_L1_error) + __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_tuple__11, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 47, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 44, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 47, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_3) { - /* "metrohash.pyx":45 + /* "metrohash.pyx":48 * * if sys.version_info < (3, ): * def bytes2hex(b): # <<<<<<<<<<<<<< * return b.encode("hex") * else: */ - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_9metrohash_1bytes2hex, NULL, __pyx_n_s_metrohash); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 45, __pyx_L1_error) + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_9metrohash_1bytes2hex, NULL, __pyx_n_s_metrohash); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 48, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_bytes2hex, __pyx_t_1) < 0) __PYX_ERR(0, 45, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_bytes2hex, __pyx_t_1) < 0) __PYX_ERR(0, 48, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "metrohash.pyx":44 + /* "metrohash.pyx":47 * __all__ = ["MetroHash128", "MetroHash64", "metrohash128", "metrohash64"] * * if sys.version_info < (3, ): # <<<<<<<<<<<<<< @@ -3918,7 +4645,7 @@ if (!__Pyx_RefNanny) { goto __pyx_L2; } - /* "metrohash.pyx":48 + /* "metrohash.pyx":51 * return b.encode("hex") * else: * def bytes2hex(b): # <<<<<<<<<<<<<< @@ -3926,9 +4653,9 @@ if (!__Pyx_RefNanny) { * */ /*else*/ { - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_9metrohash_3bytes2hex, NULL, __pyx_n_s_metrohash); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 48, __pyx_L1_error) + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_9metrohash_3bytes2hex, NULL, __pyx_n_s_metrohash); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 51, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_bytes2hex, __pyx_t_1) < 0) __PYX_ERR(0, 48, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_bytes2hex, __pyx_t_1) < 0) __PYX_ERR(0, 51, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } __pyx_L2:; @@ -4068,7 +4795,7 @@ static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args return result; } #if 1 || PY_VERSION_HEX < 0x030600B1 -static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwargs) { +static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs) { PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func); PyObject *globals = PyFunction_GET_GLOBALS(func); PyObject *argdefs = PyFunction_GET_DEFAULTS(func); @@ -4139,12 +4866,12 @@ static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, } #if PY_MAJOR_VERSION >= 3 result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL, - args, nargs, + args, (int)nargs, k, (int)nk, d, (int)nd, kwdefs, closure); #else result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL, - args, nargs, + args, (int)nargs, k, (int)nk, d, (int)nd, closure); #endif @@ -4323,7 +5050,7 @@ static int __Pyx_ParseOptionalKeywords( } name = first_kw_arg; #if PY_MAJOR_VERSION < 3 - if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) { + if (likely(PyString_Check(key))) { while (*name) { if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key)) && _PyString_Eq(**name, key)) { @@ -4350,7 +5077,7 @@ static int __Pyx_ParseOptionalKeywords( while (*name) { int cmp = (**name == key) ? 0 : #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 - (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 : + (__Pyx_PyUnicode_GET_LENGTH(**name) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 : #endif PyUnicode_Compare(**name, key); if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; @@ -4366,7 +5093,7 @@ static int __Pyx_ParseOptionalKeywords( while (argname != first_kw_arg) { int cmp = (**argname == key) ? 0 : #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 - (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 : + (__Pyx_PyUnicode_GET_LENGTH(**argname) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 : #endif PyUnicode_Compare(**argname, key); if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; @@ -4450,6 +5177,67 @@ static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *nam return 0; } +/* PyDictVersioning */ +#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) { + PyObject *dict = Py_TYPE(obj)->tp_dict; + return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0; +} +static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) { + PyObject **dictptr = NULL; + Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset; + if (offset) { +#if CYTHON_COMPILING_IN_CPYTHON + dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj); +#else + dictptr = _PyObject_GetDictPtr(obj); +#endif + } + return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0; +} +static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) { + PyObject *dict = Py_TYPE(obj)->tp_dict; + if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict))) + return 0; + return obj_dict_version == __Pyx_get_object_dict_version(obj); +} +#endif + +/* GetModuleGlobalName */ +#if CYTHON_USE_DICT_VERSIONS +static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value) +#else +static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name) +#endif +{ + PyObject *result; +#if !CYTHON_AVOID_BORROWED_REFS +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 + result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } else if (unlikely(PyErr_Occurred())) { + return NULL; + } +#else + result = PyDict_GetItem(__pyx_d, name); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } +#endif +#else + result = PyObject_GetItem(__pyx_d, name); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } + PyErr_Clear(); +#endif + return __Pyx_GetBuiltinName(name); +} + /* PyErrFetchRestore */ #if CYTHON_FAST_THREAD_STATE static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { @@ -4633,63 +5421,6 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject } #endif -/* PyDictVersioning */ -#if CYTHON_USE_DICT_VERSIONS -static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) { - PyObject *dict = Py_TYPE(obj)->tp_dict; - return dict ? __PYX_GET_DICT_VERSION(dict) : 0; -} -static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) { - PyObject **dictptr = NULL; - Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset; - if (offset) { - dictptr = (offset > 0) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj); - } - return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0; -} -static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) { - PyObject *dict = Py_TYPE(obj)->tp_dict; - if (!dict || tp_dict_version != __PYX_GET_DICT_VERSION(dict)) - return 0; - return obj_dict_version == __Pyx_get_object_dict_version(obj); -} -#endif - -/* GetModuleGlobalName */ -#if CYTHON_USE_DICT_VERSIONS -static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value) -#else -static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name) -#endif -{ - PyObject *result; -#if !CYTHON_AVOID_BORROWED_REFS -#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 - result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash); - __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) - if (likely(result)) { - return __Pyx_NewRef(result); - } else if (unlikely(PyErr_Occurred())) { - return NULL; - } -#else - result = PyDict_GetItem(__pyx_d, name); - __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) - if (likely(result)) { - return __Pyx_NewRef(result); - } -#endif -#else - result = PyObject_GetItem(__pyx_d, name); - __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) - if (likely(result)) { - return __Pyx_NewRef(result); - } - PyErr_Clear(); -#endif - return __Pyx_GetBuiltinName(name); -} - /* PyObject_GenericGetAttrNoDict */ #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 static PyObject *__Pyx_RaiseGenericGetAttributeError(PyTypeObject *tp, PyObject *attr_name) { @@ -4740,6 +5471,71 @@ static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_nam } #endif +/* SetVTable */ +static int __Pyx_SetVtable(PyObject *dict, void *vtable) { +#if PY_VERSION_HEX >= 0x02070000 + PyObject *ob = PyCapsule_New(vtable, 0, 0); +#else + PyObject *ob = PyCObject_FromVoidPtr(vtable, 0); +#endif + if (!ob) + goto bad; + if (PyDict_SetItem(dict, __pyx_n_s_pyx_vtable, ob) < 0) + goto bad; + Py_DECREF(ob); + return 0; +bad: + Py_XDECREF(ob); + return -1; +} + +/* PyErrExceptionMatches */ +#if CYTHON_FAST_THREAD_STATE +static int __Pyx_PyErr_ExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { + Py_ssize_t i, n; + n = PyTuple_GET_SIZE(tuple); +#if PY_MAJOR_VERSION >= 3 + for (i=0; icurexc_type; + if (exc_type == err) return 1; + if (unlikely(!exc_type)) return 0; + if (unlikely(PyTuple_Check(err))) + return __Pyx_PyErr_ExceptionMatchesTuple(exc_type, err); + return __Pyx_PyErr_GivenExceptionMatches(exc_type, err); +} +#endif + +/* PyObjectGetAttrStrNoError */ +static void __Pyx_PyObject_GetAttrStr_ClearAttributeError(void) { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + if (likely(__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError))) + __Pyx_PyErr_Clear(); +} +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name) { + PyObject *result; +#if CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_TYPE_SLOTS && PY_VERSION_HEX >= 0x030700B1 + PyTypeObject* tp = Py_TYPE(obj); + if (likely(tp->tp_getattro == PyObject_GenericGetAttr)) { + return _PyObject_GenericGetAttrWithDict(obj, attr_name, NULL, 1); + } +#endif + result = __Pyx_PyObject_GetAttrStr(obj, attr_name); + if (unlikely(!result)) { + __Pyx_PyObject_GetAttrStr_ClearAttributeError(); + } + return result; +} + /* SetupReduce */ static int __Pyx_setup_reduce_is_named(PyObject* meth, PyObject* name) { int ret; @@ -4767,43 +5563,51 @@ static int __Pyx_setup_reduce(PyObject* type_obj) { PyObject *setstate = NULL; PyObject *setstate_cython = NULL; #if CYTHON_USE_PYTYPE_LOOKUP - if (_PyType_Lookup((PyTypeObject*)type_obj, __pyx_n_s_getstate)) goto GOOD; + if (_PyType_Lookup((PyTypeObject*)type_obj, __pyx_n_s_getstate)) goto __PYX_GOOD; #else - if (PyObject_HasAttr(type_obj, __pyx_n_s_getstate)) goto GOOD; + if (PyObject_HasAttr(type_obj, __pyx_n_s_getstate)) goto __PYX_GOOD; #endif #if CYTHON_USE_PYTYPE_LOOKUP - object_reduce_ex = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto BAD; + object_reduce_ex = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD; #else - object_reduce_ex = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto BAD; + object_reduce_ex = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD; #endif - reduce_ex = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_ex); if (unlikely(!reduce_ex)) goto BAD; + reduce_ex = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_ex); if (unlikely(!reduce_ex)) goto __PYX_BAD; if (reduce_ex == object_reduce_ex) { #if CYTHON_USE_PYTYPE_LOOKUP - object_reduce = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto BAD; + object_reduce = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto __PYX_BAD; #else - object_reduce = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto BAD; + object_reduce = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto __PYX_BAD; #endif - reduce = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce); if (unlikely(!reduce)) goto BAD; + reduce = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce); if (unlikely(!reduce)) goto __PYX_BAD; if (reduce == object_reduce || __Pyx_setup_reduce_is_named(reduce, __pyx_n_s_reduce_cython)) { - reduce_cython = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_cython); if (unlikely(!reduce_cython)) goto BAD; - ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce, reduce_cython); if (unlikely(ret < 0)) goto BAD; - ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce_cython); if (unlikely(ret < 0)) goto BAD; + reduce_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_reduce_cython); + if (likely(reduce_cython)) { + ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce, reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD; + ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD; + } else if (reduce == object_reduce || PyErr_Occurred()) { + goto __PYX_BAD; + } setstate = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_setstate); if (!setstate) PyErr_Clear(); if (!setstate || __Pyx_setup_reduce_is_named(setstate, __pyx_n_s_setstate_cython)) { - setstate_cython = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_setstate_cython); if (unlikely(!setstate_cython)) goto BAD; - ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate, setstate_cython); if (unlikely(ret < 0)) goto BAD; - ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate_cython); if (unlikely(ret < 0)) goto BAD; + setstate_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_setstate_cython); + if (likely(setstate_cython)) { + ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate, setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD; + ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD; + } else if (!setstate || PyErr_Occurred()) { + goto __PYX_BAD; + } } PyType_Modified((PyTypeObject*)type_obj); } } - goto GOOD; -BAD: + goto __PYX_GOOD; +__PYX_BAD: if (!PyErr_Occurred()) PyErr_Format(PyExc_RuntimeError, "Unable to initialize pickling for %s", ((PyTypeObject*)type_obj)->tp_name); ret = -1; -GOOD: +__PYX_GOOD: #if !CYTHON_USE_PYTYPE_LOOKUP Py_XDECREF(object_reduce); Py_XDECREF(object_reduce_ex); @@ -4846,7 +5650,7 @@ static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) { { #if PY_MAJOR_VERSION >= 3 if (level == -1) { - if (strchr(__Pyx_MODULE_NAME, '.')) { + if ((1) && (strchr(__Pyx_MODULE_NAME, '.'))) { module = PyImport_ImportModuleLevelObject( name, global_dict, empty_dict, list, 1); if (!module) { @@ -4883,7 +5687,7 @@ static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) { /* CLineInTraceback */ #ifndef CYTHON_CLINE_IN_TRACEBACK -static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line) { +static int __Pyx_CLineForTraceback(CYTHON_NCP_UNUSED PyThreadState *tstate, int c_line) { PyObject *use_cline; PyObject *ptype, *pvalue, *ptraceback; #if CYTHON_COMPILING_IN_CPYTHON @@ -4987,7 +5791,7 @@ static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { if (__pyx_code_cache.count == __pyx_code_cache.max_count) { int new_max = __pyx_code_cache.max_count + 64; entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc( - __pyx_code_cache.entries, (size_t)new_max*sizeof(__Pyx_CodeObjectCacheEntry)); + __pyx_code_cache.entries, ((size_t)new_max) * sizeof(__Pyx_CodeObjectCacheEntry)); if (unlikely(!entries)) { return; } diff --git a/metrohash.pyx b/metrohash.pyx index 7bca78a..3f720f1 100644 --- a/metrohash.pyx +++ b/metrohash.pyx @@ -3,6 +3,7 @@ import sys from libcpp cimport bool from libc.stdint cimport uint64_t, uint8_t +from cython.operator cimport dereference as deref """ h = MetroHash128() @@ -25,6 +26,7 @@ cdef extern from "metrohash.h" nogil: cdef cppclass CMetroHash64 "MetroHash64": CMetroHash64(const uint64_t seed) + CMetroHash64(const CMetroHash64& copy) void Initialize(const uint64_t seed) void Update(const uint8_t* buffer, const uint64_t length) void Finalize(uint8_t* const result) @@ -33,6 +35,7 @@ cdef extern from "metrohash.h" nogil: cdef cppclass CMetroHash128 "MetroHash128": CMetroHash128(const uint64_t seed) + CMetroHash128(const CMetroHash128& copy) void Initialize(const uint64_t seed) void Update(const uint8_t* buffer, const uint64_t length) void Finalize(uint8_t* const result) @@ -63,13 +66,28 @@ cpdef bytes metrohash128(bytes data, uint64_t seed=0ULL): cdef class MetroHash64(object): cdef CMetroHash64* _hasher - cdef bytearray _hash - cdef bool _notfinal - def __cinit__(self, uint64_t seed=0ULL): - self._hasher = new CMetroHash64(seed) - self._hash = bytearray(b"\0"*8) - self._notfinal = True + @property + def digest_size(self): + return 8 + + @property + def block_size(self): + return 32 + + @property + def name(self): + return 'metrohash64' + + def __cinit__(self, seed=0): + cdef uint64_t _seed + cdef MetroHash64 _copy + if isinstance(seed, MetroHash64): + _copy = seed + self._hasher = new CMetroHash64(deref(_copy._hasher)) + else: + _seed = seed + self._hasher = new CMetroHash64(_seed) if self._hasher is NULL: raise MemoryError() @@ -80,34 +98,44 @@ cdef class MetroHash64(object): self._hasher = NULL def update(self, data): - if self._notfinal: - self._hasher.Update(data, len(data)) - else: - raise RuntimeError("Hash already finalized.") - - def digest(self): - if self._notfinal: - self._hasher.Finalize(self._hash) - self._notfinal = False + self._hasher.Update(data, len(data)) - return bytes(self._hash) + cpdef digest(self): + cdef bytearray _hash = bytearray(8) + CMetroHash64(deref(self._hasher)).Finalize(_hash) + return bytes(_hash) def hexdigest(self): return bytes2hex(self.digest()) + def copy(self): + return MetroHash64(self) + cdef class MetroHash128(object): cdef CMetroHash128* _hasher - cdef bytearray _hash - cdef bool _notfinal - def __cinit__(self, uint64_t seed=0ULL): - self._hasher = new CMetroHash128(seed) - self._hash = bytearray(b"\0"*16) - self._notfinal = True + @property + def digest_size(self): + return 16 - if self._hasher is NULL: - raise MemoryError() + @property + def block_size(self): + return 64 + + @property + def name(self): + return 'metrohash128' + + def __cinit__(self, seed=0): + cdef uint64_t _seed + cdef MetroHash128 _copy + if isinstance(seed, MetroHash128): + _copy = seed + self._hasher = new CMetroHash128(deref(_copy._hasher)) + else: + _seed = seed + self._hasher = new CMetroHash128(_seed) def __dealloc__(self): if self._hasher is not NULL: @@ -115,17 +143,15 @@ cdef class MetroHash128(object): self._hasher = NULL def update(self, data): - if self._notfinal: - self._hasher.Update(data, len(data)) - else: - raise RuntimeError("Hash already finalized.") - - def digest(self): - if self._notfinal: - self._hasher.Finalize(self._hash) - self._notfinal = False + self._hasher.Update(data, len(data)) - return bytes(self._hash) + cpdef digest(self): + cdef bytearray _hash = bytearray(16) + CMetroHash128(deref(self._hasher)).Finalize(_hash) + return bytes(_hash) def hexdigest(self): return bytes2hex(self.digest()) + + def copy(self): + return MetroHash128(self) diff --git a/test.py b/test.py index 0b147ee..d6333ec 100644 --- a/test.py +++ b/test.py @@ -16,6 +16,32 @@ def test_metrohash64(self): self.assertEqual(truth, bytes2hex(h.digest())) self.assertEqual(truth, h.hexdigest()) + def test_metrohash64_update(self): + for cls, input, seed, truth in [ + (MetroHash64, self.test_key_63, 0, "6b753dae06704bad"), + (MetroHash64, self.test_key_63, 1, "3b0d481cf4b9b8df"), + ]: + h = cls(seed) + for i in range(0, len(input), 4): + h.digest() + h.update(input[i:i+4]) + + self.assertEqual(truth, bytes2hex(h.digest())) + self.assertEqual(truth, h.hexdigest()) + + def test_metrohash64_copy(self): + for cls, input, seed, truth in [ + (MetroHash64, self.test_key_63, 0, "6b753dae06704bad"), + (MetroHash64, self.test_key_63, 1, "3b0d481cf4b9b8df"), + ]: + h = cls(seed) + for i in range(0, len(input), 4): + h.update(input[i:i+4]) + h = h.copy() + + self.assertEqual(truth, bytes2hex(h.digest())) + self.assertEqual(truth, h.hexdigest()) + def test_metrohash64_convenience(self): for func, input, seed, truth in [ (metrohash64, self.test_key_63, 0, "6b753dae06704bad"), @@ -35,6 +61,32 @@ def test_metrohash128(self): self.assertEqual(truth, bytes2hex(h.digest())) self.assertEqual(truth, h.hexdigest()) + def test_metrohash128_update(self): + for cls, input, seed, truth in [ + (MetroHash128, self.test_key_63, 0, "c77ce2bfa4ed9f9b0548b2ac5074a297"), + (MetroHash128, self.test_key_63, 1, "45a3cdb838199d7fbdd68d867a14ecef"), + ]: + h = cls(seed) + for i in range(0, len(input), 4): + h.digest() + h.update(input[i:i+4]) + + self.assertEqual(truth, bytes2hex(h.digest())) + self.assertEqual(truth, h.hexdigest()) + + def test_metrohash128_copy(self): + for cls, input, seed, truth in [ + (MetroHash128, self.test_key_63, 0, "c77ce2bfa4ed9f9b0548b2ac5074a297"), + (MetroHash128, self.test_key_63, 1, "45a3cdb838199d7fbdd68d867a14ecef"), + ]: + h = cls(seed) + for i in range(0, len(input), 4): + h.update(input[i:i+4]) + h = h.copy() + + self.assertEqual(truth, bytes2hex(h.digest())) + self.assertEqual(truth, h.hexdigest()) + def test_metrohash128_convenience(self): for func, input, seed, truth in [ (metrohash128, self.test_key_63, 0, "c77ce2bfa4ed9f9b0548b2ac5074a297"),