ext/digest/murmurhash/murmurhash.h in digest-murmurhash-0.2.1 vs ext/digest/murmurhash/murmurhash.h in digest-murmurhash-0.2.2

- old
+ new

@@ -17,7 +17,45 @@ Data_Get_Struct(self, buffer_t, name); \ if (name == NULL) { \ rb_raise(rb_eArgError, "NULL found for " # name " when shouldn't be.'"); \ } +/* + * from https://github.com/ruby/ruby/blob/trunk/ext/digest/digest.c + * Copyright (C) 1995-2001 Yukihiro Matsumoto + * Copyright (C) 2001-2006 Akinori MUSHA + */ +static VALUE +hexencode_str_new(VALUE str_digest) +{ + char *digest; + size_t digest_len; + size_t i; + VALUE str; + char *p; + static const char hex[] = { + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'a', 'b', 'c', 'd', 'e', 'f' + }; + + StringValue(str_digest); + digest = RSTRING_PTR(str_digest); + digest_len = RSTRING_LEN(str_digest); + + if (LONG_MAX / 2 < digest_len) { + rb_raise(rb_eRuntimeError, "digest string too long"); + } + + str = rb_usascii_str_new(0, digest_len * 2); + + for (i = 0, p = RSTRING_PTR(str); i < digest_len; i++) { + unsigned char byte = digest[i]; + + p[i + i] = hex[byte >> 4]; + p[i + i + 1] = hex[byte & 0x0f]; + } + + return str; +} + #endif /* ifndef MURMURHASH_INCLUDED */