Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -395,10 +395,18 @@ ]) AC_MSG_RESULT($ac_cv_snprintf_useful_ret) ]) test x"$have_asprintf" != x"yes" -a x"$ac_cv_snprintf_useful_ret" != x"yes" && \ AC_MSG_ERROR(No asprintf and no snprintf returning required space!) + +AC_CHECK_FUNC(arc4random, [ + AC_DEFINE(OF_HAVE_ARC4RANDOM, 1, [Whether we have arc4random()]) +], [ + AC_CHECK_FUNC(random, [ + AC_DEFINE(OF_HAVE_RANDOM, 1, [Whether we have random()]) + ]) +]) AC_CHECK_LIB(dl, dlopen, LIBS="$LIBS -ldl") AC_ARG_ENABLE(threads, AS_HELP_STRING([--disable-threads], [disable thread support])) Index: src/OFObject.h ================================================================== --- src/OFObject.h +++ src/OFObject.h @@ -873,12 +873,13 @@ #import "OFObject+Serialization.h" #ifdef __cplusplus extern "C" { #endif +extern id of_alloc_object(Class class_, size_t extraSize, size_t extraAlignment, + void **extra); extern size_t of_pagesize; extern size_t of_num_cpus; -extern id of_alloc_object(Class class_, size_t extraSize, size_t extraAlignment, - void **extra); +extern uint32_t of_hash_seed; #ifdef __cplusplus } #endif Index: src/OFObject.m ================================================================== --- src/OFObject.m +++ src/OFObject.m @@ -24,10 +24,12 @@ #include #include +#include + #ifdef __QNX__ # include #endif #import "OFObject.h" @@ -97,10 +99,11 @@ Class isa; } alloc_failed_exception; size_t of_pagesize; size_t of_num_cpus; +uint32_t of_hash_seed; #if !defined(OF_APPLE_RUNTIME) || defined(__OBJC2__) static void uncaught_exception_handler(id exception) { @@ -273,10 +276,24 @@ # ifdef _SC_NPROCESSORS_CONF if ((of_num_cpus = sysconf(_SC_NPROCESSORS_CONF)) < 1) # endif of_num_cpus = 1; #endif + +#if defined(OF_HAVE_ARC4RANDOM) + of_hash_seed = arc4random(); +#elif defined(OF_HAVE_RANDOM) + struct timeval t; + gettimeofday(&t, NULL); + srandom(t.tv_usec); + of_hash_seed = random(); +#else + struct timeval t; + gettimeofday(&t, NULL); + srand(t.tv_usec); + of_hash_seed = rand(); +#endif } + (void)initialize { } Index: src/macros.h ================================================================== --- src/macros.h +++ src/macros.h @@ -324,11 +324,11 @@ #define OF_ROL(value, bits) \ (((value) << ((bits) % (sizeof(value) * 8))) | \ (value) >> (sizeof(value) * 8 - ((bits) % (sizeof(value) * 8)))) -#define OF_HASH_INIT(hash) hash = 0 +#define OF_HASH_INIT(hash) hash = of_hash_seed #define OF_HASH_ADD(hash, byte) \ { \ hash += (uint8_t)byte; \ hash += (hash << 10); \ hash ^= (hash >> 6); \ Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -27,11 +27,18 @@ # include # include PSP_MODULE_INFO("ObjFW Tests", 0, 0, 0); #endif -OF_APPLICATION_DELEGATE(TestsAppDelegate) +int +main(int argc, char *argv[]) +{ + /* We need deterministic hashes for tests */ + of_hash_seed = 0; + + return of_application_main(&argc, &argv, [TestsAppDelegate class]); +} @implementation TestsAppDelegate - (void)outputString: (OFString*)str withColor: (int)color {