Skip to content

Commit 5e45af4

Browse files
committed
merge revision(s) 37585,37587,37591,37592,37597,37599:
* 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
1 parent 7c9a4b2 commit 5e45af4

File tree

7 files changed

+570
-8
lines changed

7 files changed

+570
-8
lines changed

ChangeLog

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
Sat Nov 10 00:37:02 2012 NAKAMURA Usaku <usa@ruby-lang.org>
2+
3+
* siphash.h: check configure macros before include newer headers.
4+
5+
Sat Nov 10 00:37:02 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
6+
7+
* siphash.c (sip_init_state): use union to suppress warnings by gcc
8+
4.7.
9+
10+
Sat Nov 10 00:37:02 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
11+
12+
* random.c (rb_memhash): use siphash.
13+
114
Fri Nov 9 16:17:09 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
215

316
* file.c (append_fspath): revert a part of r37562.

common.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,8 @@ proc.$(OBJEXT): {$(VPATH)}proc.c {$(VPATH)}eval_intern.h \
671671
process.$(OBJEXT): {$(VPATH)}process.c $(RUBY_H_INCLUDES) \
672672
{$(VPATH)}util.h {$(VPATH)}io.h $(ENCODING_H_INCLUDES) {$(VPATH)}dln.h \
673673
$(VM_CORE_H_INCLUDES) {$(VPATH)}debug.h {$(VPATH)}internal.h
674-
random.$(OBJEXT): {$(VPATH)}random.c $(RUBY_H_INCLUDES)
674+
random.$(OBJEXT): {$(VPATH)}random.c $(RUBY_H_INCLUDES) \
675+
{$(VPATH)}siphash.c {$(VPATH)}siphash.h
675676
range.$(OBJEXT): {$(VPATH)}range.c $(RUBY_H_INCLUDES) \
676677
$(ENCODING_H_INCLUDES) {$(VPATH)}internal.h
677678
rational.$(OBJEXT): {$(VPATH)}rational.c $(RUBY_H_INCLUDES) {$(VPATH)}internal.h

random.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,15 @@ random_s_rand(int argc, VALUE *argv, VALUE obj)
12591259
return random_rand(argc, argv, rb_Random_DEFAULT);
12601260
}
12611261

1262+
#define SIP_HASH_STREAMING 0
1263+
#define sip_hash24 ruby_sip_hash24
1264+
#include "siphash.c"
1265+
12621266
static st_index_t hashseed;
1267+
static union {
1268+
uint8_t key[16];
1269+
uint32_t u32[(16 * sizeof(uint8_t) - 1) / sizeof(uint32_t)];
1270+
} sipseed;
12631271

12641272
static VALUE
12651273
init_randomseed(struct MT *mt, unsigned int initial[DEFAULT_SEED_CNT])
@@ -1279,6 +1287,7 @@ Init_RandomSeed(void)
12791287
unsigned int initial[DEFAULT_SEED_CNT];
12801288
struct MT *mt = &r->mt;
12811289
VALUE seed = init_randomseed(mt, initial);
1290+
int i;
12821291

12831292
hashseed = genrand_int32(mt);
12841293
#if SIZEOF_ST_INDEX_T*CHAR_BIT > 4*8
@@ -1294,6 +1303,9 @@ Init_RandomSeed(void)
12941303
hashseed |= genrand_int32(mt);
12951304
#endif
12961305

1306+
for (i = 0; i < numberof(sipseed.u32); ++i)
1307+
sipseed.u32[i] = genrand_int32(mt);
1308+
12971309
rb_global_variable(&r->seed);
12981310
r->seed = seed;
12991311
}
@@ -1304,6 +1316,17 @@ rb_hash_start(st_index_t h)
13041316
return st_hash_start(hashseed + h);
13051317
}
13061318

1319+
st_index_t
1320+
rb_memhash(const void *ptr, long len)
1321+
{
1322+
sip_uint64_t h = sip_hash24(sipseed.key, ptr, len);
1323+
#ifdef HAVE_UINT64_T
1324+
return (st_index_t)h;
1325+
#else
1326+
return (st_index_t)(h.u32[0] ^ h.u32[1]);
1327+
#endif
1328+
}
1329+
13071330
static void
13081331
Init_RandomSeed2(void)
13091332
{

0 commit comments

Comments
 (0)