static PyObject *
_cffi_f_fuzzy_update(PyObject *self, PyObject *args)
{
  struct fuzzy_state * x0;
  unsigned char const * x1;
  size_t x2;
  Py_ssize_t datasize;
  int result;
  PyObject *arg0;
  PyObject *arg1;
  PyObject *arg2;

  if (!PyArg_ParseTuple(args, "OOO:fuzzy_update", &arg0, &arg1, &arg2))
    return NULL;

  datasize = _cffi_prepare_pointer_call_argument(
      _cffi_type(3), 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(3), arg0) < 0)
      return NULL;
  }

  datasize = _cffi_prepare_pointer_call_argument(
      _cffi_type(5), 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(5), arg1) < 0)
      return NULL;
  }

  x2 = _cffi_to_c_int(arg2, size_t);
  if (x2 == (size_t)-1 && PyErr_Occurred())
    return NULL;

  Py_BEGIN_ALLOW_THREADS
  _cffi_restore_errno();
  { result = fuzzy_update(x0, x1, x2); }
  _cffi_save_errno();
  Py_END_ALLOW_THREADS

  return _cffi_from_c_int(result, int);
}
Ejemplo n.º 2
0
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) ; 
}