static PyObject * _cffi_f_fuzzy_digest(PyObject *self, PyObject *args) { struct fuzzy_state const * x0; char * x1; unsigned int x2; Py_ssize_t datasize; int result; PyObject *arg0; PyObject *arg1; PyObject *arg2; if (!PyArg_ParseTuple(args, "OOO:fuzzy_digest", &arg0, &arg1, &arg2)) return NULL; datasize = _cffi_prepare_pointer_call_argument( _cffi_type(1), arg0, (char **)&x0); if (datasize != 0) { if (datasize < 0) return NULL; x0 = alloca(datasize); memset((void *)x0, 0, datasize); if (_cffi_convert_array_from_object((char *)x0, _cffi_type(1), arg0) < 0) return NULL; } datasize = _cffi_prepare_pointer_call_argument( _cffi_type(2), arg1, (char **)&x1); if (datasize != 0) { if (datasize < 0) return NULL; x1 = alloca(datasize); memset((void *)x1, 0, datasize); if (_cffi_convert_array_from_object((char *)x1, _cffi_type(2), arg1) < 0) return NULL; } x2 = _cffi_to_c_int(arg2, unsigned int); if (x2 == (unsigned int)-1 && PyErr_Occurred()) return NULL; Py_BEGIN_ALLOW_THREADS _cffi_restore_errno(); { result = fuzzy_digest(x0, x1, x2); } _cffi_save_errno(); Py_END_ALLOW_THREADS return _cffi_from_c_int(result, int); }
std::string fuzzy::calc_digest () { fuzzy_state * ctx = fuzzy_new () ; auto_fuzzy_state afs (ctx) ; if (ctx == 0) THROW_XDELTA_EXCEPTION_NO_ERRNO ("Out of memory") ; char_buffer<uchar_t> buff (BUFLEN); reader_.open_file () ; while (true ) { int bytes = reader_.read_file (buff.begin (), (uint32_t)buff.size ()); if (bytes == 0 ) break ; if (0 != fuzzy_update (afs.ctx, buff.begin (), bytes)) THROW_XDELTA_EXCEPTION ("fuzzy update failed.") ; } char result [FUZZY_MAX_RESULT]; if (0 != fuzzy_digest (afs.ctx, result, FUZZY_FLAG_ELIMSEQ)) THROW_XDELTA_EXCEPTION ("fuzzy digest failed."); reader_.close_file () ; return std::string(result) ; }