cvs: php4(RAND_REDESIGN) /ext/standard basic_functions.c php_rand.h rand.c rand_mt.c rand_sys.c
| From: | Jeroen van Wolffelaar | Date: | Sun, 02 Sep 2001 23:39:46 +0000 |
| Subject: | cvs: php4(RAND_REDESIGN) /ext/standard basic_functions.c php_rand.h rand.c rand_mt.c rand_sys.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-7156@lists.php.net to get a copy of this message | ||
jeroen Sun Sep 2 19:39:46 2001 EDT
Modified files: (Branch: RAND_REDESIGN)
/php4/ext/standard basic_functions.c php_rand.h rand.c rand_mt.c
rand_sys.c
Log:
Fix the other 5% of the build - thanx to Zeev & Wez
Index: php4/ext/standard/basic_functions.c
diff -u php4/ext/standard/basic_functions.c:1.386.2.1 php4/ext/standard/basic_functions.c:1.386.2.2
--- php4/ext/standard/basic_functions.c:1.386.2.1 Fri Aug 24 19:47:27 2001
+++ php4/ext/standard/basic_functions.c Sun Sep 2 19:39:44 2001
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: basic_functions.c,v 1.386.2.1 2001/08/24 23:47:27 jeroen Exp $ */
+/* $Id: basic_functions.c,v 1.386.2.2 2001/09/02 23:39:44 jeroen Exp $ */
#include "php.h"
#include "php_main.h"
@@ -784,6 +784,7 @@
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
Index: php4/ext/standard/php_rand.h
diff -u php4/ext/standard/php_rand.h:1.8.8.4 php4/ext/standard/php_rand.h:1.8.8.5
--- php4/ext/standard/php_rand.h:1.8.8.4 Sun Sep 2 15:42:29 2001
+++ php4/ext/standard/php_rand.h Sun Sep 2 19:39:45 2001
@@ -20,7 +20,7 @@
| Based on code from: Shawn Cokus <Cokus@math.washington.edu> |
+----------------------------------------------------------------------+
*/
-/* $Id: php_rand.h,v 1.8.8.4 2001/09/02 19:42:29 jeroen Exp $ */
+/* $Id: php_rand.h,v 1.8.8.5 2001/09/02 23:39:45 jeroen Exp $ */
/* Layout implementation random functions
*
@@ -83,13 +83,16 @@
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
Index: php4/ext/standard/rand.c
diff -u php4/ext/standard/rand.c:1.31.4.4 php4/ext/standard/rand.c:1.31.4.5
--- php4/ext/standard/rand.c:1.31.4.4 Sun Sep 2 15:42:29 2001
+++ php4/ext/standard/rand.c Sun Sep 2 19:39:45 2001
@@ -17,7 +17,7 @@
| Pedro Melo <melo@ip.pt> |
+----------------------------------------------------------------------+
*/
-/* $Id: rand.c,v 1.31.4.4 2001/09/02 19:42:29 jeroen Exp $ */
+/* $Id: rand.c,v 1.31.4.5 2001/09/02 23:39:45 jeroen Exp $ */
#include <stdlib.h>
@@ -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
Index: php4/ext/standard/rand_mt.c
diff -u php4/ext/standard/rand_mt.c:1.1.2.2 php4/ext/standard/rand_mt.c:1.1.2.3
--- php4/ext/standard/rand_mt.c:1.1.2.2 Sun Aug 26 18:47:55 2001
+++ php4/ext/standard/rand_mt.c Sun Sep 2 19:39:45 2001
@@ -19,7 +19,7 @@
| Based on code from: Shawn Cokus <Cokus@math.washington.edu> |
+----------------------------------------------------------------------+
*/
-/* $Id: rand_mt.c,v 1.1.2.2 2001/08/26 22:47:55 jeroen Exp $ */
+/* $Id: rand_mt.c,v 1.1.2.3 2001/09/02 23:39:45 jeroen Exp $ */
#include <stdlib.h>
@@ -89,13 +89,16 @@
* 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 */
Index: php4/ext/standard/rand_sys.c
diff -u php4/ext/standard/rand_sys.c:1.1.2.3 php4/ext/standard/rand_sys.c:1.1.2.4
--- php4/ext/standard/rand_sys.c:1.1.2.3 Sun Sep 2 15:43:49 2001
+++ php4/ext/standard/rand_sys.c Sun Sep 2 19:39:45 2001
@@ -17,7 +17,7 @@
| Jeroen van Wolffelaar <jeroen@php.net> |
+----------------------------------------------------------------------+
*/
-/* $Id: rand_sys.c,v 1.1.2.3 2001/09/02 19:43:49 jeroen Exp $ */
+/* $Id: rand_sys.c,v 1.1.2.4 2001/09/02 23:39:45 jeroen Exp $ */
#include <stdlib.h>
@@ -40,41 +40,29 @@
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 @@
* 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
*/