Skip to content

Commit

Permalink
merge revision(s) 37585,37587,37591,37592,37597,37599:
Browse files Browse the repository at this point in the history
	* random.c (rb_memhash): use siphash.

	* siphash.c (sip_init_state): use union to suppress warnings by gcc
	  4.7.

	* siphash.h: include inttypes.h only when HAVE_INTTYPES_H is defined.

	* siphash.h: check configure macros before include newer headers.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@37600 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
unak committed Nov 9, 2012
1 parent 7c9a4b2 commit 5e45af4
Show file tree
Hide file tree
Showing 7 changed files with 570 additions and 8 deletions.
13 changes: 13 additions & 0 deletions ChangeLog
@@ -1,3 +1,16 @@
Sat Nov 10 00:37:02 2012 NAKAMURA Usaku <usa@ruby-lang.org>

* siphash.h: check configure macros before include newer headers.

Sat Nov 10 00:37:02 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>

* siphash.c (sip_init_state): use union to suppress warnings by gcc
4.7.

Sat Nov 10 00:37:02 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>

* random.c (rb_memhash): use siphash.

Fri Nov 9 16:17:09 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>

* file.c (append_fspath): revert a part of r37562.
Expand Down
3 changes: 2 additions & 1 deletion common.mk
Expand Up @@ -671,7 +671,8 @@ proc.$(OBJEXT): {$(VPATH)}proc.c {$(VPATH)}eval_intern.h \
process.$(OBJEXT): {$(VPATH)}process.c $(RUBY_H_INCLUDES) \
{$(VPATH)}util.h {$(VPATH)}io.h $(ENCODING_H_INCLUDES) {$(VPATH)}dln.h \
$(VM_CORE_H_INCLUDES) {$(VPATH)}debug.h {$(VPATH)}internal.h
random.$(OBJEXT): {$(VPATH)}random.c $(RUBY_H_INCLUDES)
random.$(OBJEXT): {$(VPATH)}random.c $(RUBY_H_INCLUDES) \
{$(VPATH)}siphash.c {$(VPATH)}siphash.h
range.$(OBJEXT): {$(VPATH)}range.c $(RUBY_H_INCLUDES) \
$(ENCODING_H_INCLUDES) {$(VPATH)}internal.h
rational.$(OBJEXT): {$(VPATH)}rational.c $(RUBY_H_INCLUDES) {$(VPATH)}internal.h
Expand Down
23 changes: 23 additions & 0 deletions random.c
Expand Up @@ -1259,7 +1259,15 @@ random_s_rand(int argc, VALUE *argv, VALUE obj)
return random_rand(argc, argv, rb_Random_DEFAULT);
}

#define SIP_HASH_STREAMING 0
#define sip_hash24 ruby_sip_hash24
#include "siphash.c"

static st_index_t hashseed;
static union {
uint8_t key[16];
uint32_t u32[(16 * sizeof(uint8_t) - 1) / sizeof(uint32_t)];
} sipseed;

static VALUE
init_randomseed(struct MT *mt, unsigned int initial[DEFAULT_SEED_CNT])
Expand All @@ -1279,6 +1287,7 @@ Init_RandomSeed(void)
unsigned int initial[DEFAULT_SEED_CNT];
struct MT *mt = &r->mt;
VALUE seed = init_randomseed(mt, initial);
int i;

hashseed = genrand_int32(mt);
#if SIZEOF_ST_INDEX_T*CHAR_BIT > 4*8
Expand All @@ -1294,6 +1303,9 @@ Init_RandomSeed(void)
hashseed |= genrand_int32(mt);
#endif

for (i = 0; i < numberof(sipseed.u32); ++i)
sipseed.u32[i] = genrand_int32(mt);

rb_global_variable(&r->seed);
r->seed = seed;
}
Expand All @@ -1304,6 +1316,17 @@ rb_hash_start(st_index_t h)
return st_hash_start(hashseed + h);
}

st_index_t
rb_memhash(const void *ptr, long len)
{
sip_uint64_t h = sip_hash24(sipseed.key, ptr, len);
#ifdef HAVE_UINT64_T
return (st_index_t)h;
#else
return (st_index_t)(h.u32[0] ^ h.u32[1]);
#endif
}

static void
Init_RandomSeed2(void)
{
Expand Down

0 comments on commit 5e45af4

Please sign in to comment.