diff options
author | Jeroen van Wolffelaar <jeroen@php.net> | 2001-09-02 23:39:45 +0000 |
---|---|---|
committer | Jeroen van Wolffelaar <jeroen@php.net> | 2001-09-02 23:39:45 +0000 |
commit | 183cf93bcad5a106a33f52a763e02470808bfaf8 (patch) | |
tree | 6133a96bbd9ea2361762879970004a58ce51a877 | |
parent | 736bdf7117b735ae163b9eb4ad621fb166abc8ac (diff) | |
download | php-git-183cf93bcad5a106a33f52a763e02470808bfaf8.tar.gz |
Fix the other 5% of the build - thanx to Zeev & Wez
-rw-r--r-- | ext/standard/basic_functions.c | 1 | ||||
-rw-r--r-- | ext/standard/php_rand.h | 15 | ||||
-rw-r--r-- | ext/standard/rand.c | 21 | ||||
-rw-r--r-- | ext/standard/rand_mt.c | 15 | ||||
-rw-r--r-- | ext/standard/rand_sys.c | 38 |
5 files changed, 41 insertions, 49 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 59ef384aa2..467d5c0959 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -784,6 +784,7 @@ PHP_MINIT_FUNCTION(basic) PHP_MINIT(crypt)(INIT_FUNC_ARGS_PASSTHRU); #endif + PHP_MINIT(rand)(INIT_FUNC_ARGS_PASSTHRU); #ifdef ZTS PHP_MINIT(lcg)(INIT_FUNC_ARGS_PASSTHRU); #endif diff --git a/ext/standard/php_rand.h b/ext/standard/php_rand.h index 8ad83e8e2f..01225ca760 100644 --- a/ext/standard/php_rand.h +++ b/ext/standard/php_rand.h @@ -83,13 +83,16 @@ typedef struct _php_randgen_entry { char *ini_str; } php_randgen_entry; -extern php_randgen_entry (*php_randgen_entries)[]; +/* an ARRAY of POINTERS, not vice versa */ +extern php_randgen_entry *php_randgen_entries[]; -#define PHP_HAS_SRAND(which) (php_randgen_entries[which]->srand) -#define PHP_SRAND(which,seed) ((*(php_randgen_entries[which]->srand))(seed)) -#define PHP_RAND(which) ((*(php_randgen_entries[which]->rand))()) -#define PHP_RANDMAX(which) (php_randgen_entries[which]->randmax) -#define PHP_RAND_INISTR(which) (php_randgen_entries[which]->ini_str) +#define PHP_RANDGEN_ENTRY(which, nsrand, nrand, nrandmax, nini_str) { \ + php_randgen_entries[which] = emalloc(sizeof(php_randgen_entry)); \ + php_randgen_entries[which]->srand = nsrand; \ + php_randgen_entries[which]->rand = nrand; \ + php_randgen_entries[which]->randmax = nrandmax; \ + php_randgen_entries[which]->ini_str = nini_str; \ +} /* Define random generator constants */ #define PHP_RAND_SYS 0 diff --git a/ext/standard/rand.c b/ext/standard/rand.c index e5d4a05bfa..4232e08b11 100644 --- a/ext/standard/rand.c +++ b/ext/standard/rand.c @@ -32,22 +32,19 @@ /* See php_rand.h for information about layout */ -#if 0 -#define RANDGEN_ENTRY(intval, lower, upper, has_seed) \ - php_randgen_entry[intval] = { \ - (has_seed) ? php_rand_##lower : NULL, \ - php_rand_##lower, \ - PHP_RANDMAX_##upper, \ - "lower" \ - }; -#endif +/* an ARRAY of POINTERS, not vice versa */ +php_randgen_entry *php_randgen_entries[PHP_RAND_NUMRANDS]; -php_randgen_entry (*php_randgen_entries)[PHP_RAND_NUMRANDS]; +#define PHP_HAS_SRAND(which) (php_randgen_entries[which]->srand) +#define PHP_SRAND(which,seed) ((*(php_randgen_entries[which]->srand))(seed)) +#define PHP_RAND(which) ((*(php_randgen_entries[which]->rand))()) +#define PHP_RANDMAX(which) (php_randgen_entries[which]->randmax) +#define PHP_RAND_INISTR(which) (php_randgen_entries[which]->ini_str) -/* TODO: make sure this will be called */ PHP_MINIT_FUNCTION(rand) { - /* call: rand_sys, rand_mt, etc */ + PHP_MINIT(rand_sys)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(rand_mt)(INIT_FUNC_ARGS_PASSTHRU); } /* TODO: check that this function is called on the start of each script diff --git a/ext/standard/rand_mt.c b/ext/standard/rand_mt.c index a044c8fb0d..e7512a867b 100644 --- a/ext/standard/rand_mt.c +++ b/ext/standard/rand_mt.c @@ -89,13 +89,16 @@ static long _php_rand_mt(void); * Melo: it could be 2^^32 but we only use 2^^31 to maintain * compatibility with the previous php_rand */ -#define _PHP_RANDMAX_MT ((long)(0x7FFFFFFF)) /* 2^^31 - 1 */ +#define PHP_RANDMAX_MT ((long)(0x7FFFFFFF)) /* 2^^31 - 1 */ -php_randgen_entries[PHP_RAND_MT] = { - _php_srand_mt, /* void srand(long seed) */ - _php_rand_mt, /* long rand(void) */ - PHP_RANDMAX_MT, /* long randmax */ - "mt" /* char *ini_str */ +PHP_MINIT_FUNCTION(rand_mt) +{ + PHP_RANDGEN_ENTRY(PHP_RAND_MT, + _php_srand_mt, /* void srand(long seed) */ + _php_rand_mt, /* long rand(void) */ + PHP_RANDMAX_MT, /* long randmax */ + "mt" /* char *ini_str */ + ); } #define N MT_N /* length of state vector */ diff --git a/ext/standard/rand_sys.c b/ext/standard/rand_sys.c index 3805fe5b1d..fcb52fb365 100644 --- a/ext/standard/rand_sys.c +++ b/ext/standard/rand_sys.c @@ -40,41 +40,29 @@ static long _php_rand_sys(void) PHP_MINIT_FUNCTION(rand_sys) { - php_randgen_entries[PHP_RAND_SYS] = { +#ifndef RAND_MAX +#define RAND_MAX (1<<15) +#endif + PHP_RANDGEN_ENTRY(PHP_RAND_SYS, _php_srand_sys, /* void srand(long seed) */ _php_rand_sys, /* long rand(void) */ -#ifdef RAND_MAX - (long)RANDMAX, /* long randmax */ -#else - (long)(1<<15), /* long randmax */ -#endif + (long)RAND_MAX, /* long randmax */ "system" /* char *ini_str */ - }; + ); - /* - php_randgen_entries[PHP_RAND_SYS]->srand = _php_srand_sys; - php_randgen_entries[PHP_RAND_SYS].rand = _php_rand_sys; -#ifdef RAND_MAX - php_randgen_entries[PHP_RAND_SYS].randmax = (long)RAND_MAX; -#else - php_randgen_entries[PHP_RAND_SYS].randmax = (long)(1<<15); -#endif - php_randgen_entries[PHP_RAND_SYS].ini_str = "system"; - */ - -/* random() is left away, no manual page on my system, no bigger range than - * rand() - * --jeroen - */ + /* random() is left away, no manual page on my system, no bigger range than + * rand() + * --jeroen + */ /* lrand48 (_not_ TS) */ #if HAVE_LRAND48 - php_randgen_entries[PHP_RAND_LRAND48] = { + PHP_RANDGEN_ENTRY(PHP_RAND_LRAND48, srand48, /* void srand(long seed) */ lrand48, /* long rand(void) */ 2147483647L, /* long randmax */ "lrand48" /* char *ini_str */ - }; + ); #else php_randgen_entries[PHP_RAND_LRAND48] = NULL; #endif @@ -87,5 +75,5 @@ PHP_MINIT_FUNCTION(rand_sys) * c-basic-offset: 4 * End: * vim600: sw=4 ts=4 tw=78 fdm=marker - * vim<600: sw=4 ts=4 tw=78 + * vim: sw=4 ts=4 tw=78 */ |