cvs: php4(RAND_REDESIGN) /ext/standard array.c php_rand.h rand.c rand_sys.c
| From: | Jeroen van Wolffelaar | Date: | Sun, 02 Sep 2001 19:42:29 +0000 |
| Subject: | cvs: php4(RAND_REDESIGN) /ext/standard array.c php_rand.h rand.c rand_sys.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-7154@lists.php.net to get a copy of this message | ||
jeroen Sun Sep 2 15:42:29 2001 EDT
Modified files: (Branch: RAND_REDESIGN)
/php4/ext/standard array.c php_rand.h rand.c rand_sys.c
Log:
Fix build for 95%
Index: php4/ext/standard/array.c
diff -u php4/ext/standard/array.c:1.124 php4/ext/standard/array.c:1.124.2.1
--- php4/ext/standard/array.c:1.124 Tue Aug 21 08:57:51 2001
+++ php4/ext/standard/array.c Sun Sep 2 15:42:29 2001
@@ -21,7 +21,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: array.c,v 1.124 2001/08/21 12:57:51 zeev Exp $ */
+/* $Id: array.c,v 1.124.2.1 2001/09/02 19:42:29 jeroen Exp $ */
#include "php.h"
#include "php_ini.h"
@@ -2726,6 +2726,8 @@
ulong num_key;
HashPosition pos;
+ php_error(E_ERROR, "Function array_rand temporarily disabled");
+
if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 ||
zend_get_parameters_ex(ZEND_NUM_ARGS(), &input, &num_req) == FAILURE) {
WRONG_PARAM_COUNT;
@@ -2767,6 +2769,9 @@
randval = rand();
#endif
#endif
+
+ /* TEMPORARY HACK TO GET IT COMPILE */
+#define PHP_RAND_MAX 1
if ((double)(randval/(PHP_RAND_MAX+1.0)) < (double)num_req_val/(double)num_avail) {
/* If we are returning a single result, just do it. */
Index: php4/ext/standard/php_rand.h
diff -u php4/ext/standard/php_rand.h:1.8.8.3 php4/ext/standard/php_rand.h:1.8.8.4
--- php4/ext/standard/php_rand.h:1.8.8.3 Sun Aug 26 18:47:55 2001
+++ php4/ext/standard/php_rand.h Sun Sep 2 15:42:29 2001
@@ -20,7 +20,7 @@
| Based on code from: Shawn Cokus <Cokus@math.washington.edu> |
+----------------------------------------------------------------------+
*/
-/* $Id: php_rand.h,v 1.8.8.3 2001/08/26 22:47:55 jeroen Exp $ */
+/* $Id: php_rand.h,v 1.8.8.4 2001/09/02 19:42:29 jeroen Exp $ */
/* Layout implementation random functions
*
@@ -83,12 +83,13 @@
char *ini_str;
} php_randgen_entry;
-php_randgen_entry *php_randgen_entries;
+extern php_randgen_entry (*php_randgen_entries)[];
-#define PHP_SRAND(which,seed) (php_randgen_entry[which]->srand(seed))
-#define PHP_RAND(which) (php_randgen_entry[which]->rand())
-#define PHP_RANDMAX(which) (php_randgen_entry[which].randmax)
-#define PHP_RAND_INISTR(which) (php_randgen_entry[which].ini_str)
+#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 random generator constants */
#define PHP_RAND_SYS 0
Index: php4/ext/standard/rand.c
diff -u php4/ext/standard/rand.c:1.31.4.3 php4/ext/standard/rand.c:1.31.4.4
--- php4/ext/standard/rand.c:1.31.4.3 Sun Aug 26 18:47:55 2001
+++ php4/ext/standard/rand.c Sun Sep 2 15:42:29 2001
@@ -17,7 +17,7 @@
| Pedro Melo <melo@ip.pt> |
+----------------------------------------------------------------------+
*/
-/* $Id: rand.c,v 1.31.4.3 2001/08/26 22:47:55 jeroen Exp $ */
+/* $Id: rand.c,v 1.31.4.4 2001/09/02 19:42:29 jeroen Exp $ */
#include <stdlib.h>
@@ -42,9 +42,13 @@
};
#endif
-#define FOREACH_RANDGEN(var,i) for ( (var) = php_randgen_entry[(i)=0] ; (var) < PHP_RAND_NUMGENS
; (var) = php_randgen_entry[++(i)] )
+php_randgen_entry (*php_randgen_entries)[PHP_RAND_NUMRANDS];
-php_randgen_entry php_randgen_entries[PHP_RAND_NUMGENS];
+/* TODO: make sure this will be called */
+PHP_MINIT_FUNCTION(rand)
+{
+ /* call: rand_sys, rand_mt, etc */
+}
/* TODO: check that this function is called on the start of each script
* execution: not more often, not less often.
@@ -55,15 +59,14 @@
*/
PHP_RINIT_FUNCTION(rand)
{
- register php_randgen_entry *randgen;
register int i;
/* seed all number-generators */
/* FIXME: or seed relevant numgen on init/update ini-entry? */
- FOREACH_RANDGEN(randgen,i) {
- if (randgen.srand) {
+ for (i = 0 ; i < PHP_RAND_NUMRANDS ; i++) {
+ if (PHP_HAS_SRAND(i)) {
#define SRAND_A_RANDOM_SEED (time(0) * getpid() * (php_combined_lcg(TSRMLS_C) * 10000.0)) /*
something with microtime? */
- randgen->srand(SRAND_A_RANDOM_SEED);
+ PHP_SRAND(i,SRAND_A_RANDOM_SEED);
}
}
}
@@ -71,11 +74,10 @@
/* INI */
static int randgen_str_to_int(char *str, int strlen)
{
- register php_randgen_entry *randgen;
register int i;
- FOREACH_RANDGEN(randgen,i) {
- if (!strcasecmp(str, randgen.ini_str))
+ for (i = 0 ; i < PHP_RAND_NUMRANDS ; i++) {
+ if (!strcasecmp(str, PHP_RAND_INISTR(i)))
return i;
}
return -1;
@@ -93,7 +95,7 @@
* ini-parsing at startup? */
php_error(E_WARNING,"Invalid value for random_number_generator: \"%s\"",
new_value);
/* Fallback: */
- BG(rand_generator) = RAND_DEFAULT;
+ BG(rand_generator) = PHP_RAND_DEFAULT;
}
#ifdef DEBUG_RAND
printf("\nRAND-INI updated: %d\n",BG(rand_generator));
@@ -102,7 +104,8 @@
}
PHP_INI_BEGIN()
- PHP_INI_ENTRY("random_number_generator", PHP_RAND_INISTR(PHP_RAND_DEFAULT), PHP_INI_ALL,
OnUpdateRandGen)
+ /* FIXME: default is hardcoded here, this is the second place */
+ PHP_INI_ENTRY("random_number_generator", "mt", PHP_INI_ALL, OnUpdateRandGen)
PHP_INI_END()
/* srand */
@@ -273,5 +276,5 @@
* 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
*/
Index: php4/ext/standard/rand_sys.c
diff -u php4/ext/standard/rand_sys.c:1.1.2.1 php4/ext/standard/rand_sys.c:1.1.2.2
--- php4/ext/standard/rand_sys.c:1.1.2.1 Sun Aug 26 18:47:55 2001
+++ php4/ext/standard/rand_sys.c Sun Sep 2 15:42:29 2001
@@ -17,7 +17,7 @@
| Jeroen van Wolffelaar <jeroen@php.net> |
+----------------------------------------------------------------------+
*/
-/* $Id: rand_sys.c,v 1.1.2.1 2001/08/26 22:47:55 jeroen Exp $ */
+/* $Id: rand_sys.c,v 1.1.2.2 2001/09/02 19:42:29 jeroen Exp $ */
#include <stdlib.h>
@@ -38,33 +38,48 @@
return (long) rand_r(&BG(rand_sys_seed));
}
-php_randgen_entries[PHP_RAND_SYS] = {
- _php_srand_sys, /* void srand(long seed) */
- _php_rand_sys, /* long rand(void) */
+PHP_MINIT_FUNCTION(rand_sys)
+{
+ php_randgen_entries[PHP_RAND_SYS] = {
+ _php_srand_sys, /* void srand(long seed) */
+ _php_rand_sys, /* long rand(void) */
#ifdef RAND_MAX
- (long)RANDMAX, /* long randmax */
+ (long)RANDMAX, /* long randmax */
#else
- (long)(1<<15), /* long randmax */
+ (long)(1<<15), /* long randmax */
#endif
- "system" /* char *ini_str */
-}
+ "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
*/
-/* lrand48 (_not_ TS) */
+ /* lrand48 (_not_ TS) */
#if HAVE_LRAND48
-php_randgen_entries[PHP_RAND_LRAND48] = {
- srand48, /* void srand(long seed) */
- lrand48, /* long rand(void) */
- 2147483647L, /* long randmax */
- "lrand48" /* char *ini_str */
-}
+ php_randgen_entries[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;
+ php_randgen_entries[PHP_RAND_LRAND48] = NULL;
#endif
+
+}
/*
* Local variables: