Skip to content

Commit 183cf93

Browse files
author
Jeroen van Wolffelaar
committed
Fix the other 5% of the build - thanx to Zeev & Wez
1 parent 736bdf7 commit 183cf93

File tree

5 files changed

+41
-49
lines changed

5 files changed

+41
-49
lines changed

ext/standard/basic_functions.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,7 @@ PHP_MINIT_FUNCTION(basic)
784784
PHP_MINIT(crypt)(INIT_FUNC_ARGS_PASSTHRU);
785785
#endif
786786

787+
PHP_MINIT(rand)(INIT_FUNC_ARGS_PASSTHRU);
787788
#ifdef ZTS
788789
PHP_MINIT(lcg)(INIT_FUNC_ARGS_PASSTHRU);
789790
#endif

ext/standard/php_rand.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,16 @@ typedef struct _php_randgen_entry {
8383
char *ini_str;
8484
} php_randgen_entry;
8585

86-
extern php_randgen_entry (*php_randgen_entries)[];
86+
/* an ARRAY of POINTERS, not vice versa */
87+
extern php_randgen_entry *php_randgen_entries[];
8788

88-
#define PHP_HAS_SRAND(which) (php_randgen_entries[which]->srand)
89-
#define PHP_SRAND(which,seed) ((*(php_randgen_entries[which]->srand))(seed))
90-
#define PHP_RAND(which) ((*(php_randgen_entries[which]->rand))())
91-
#define PHP_RANDMAX(which) (php_randgen_entries[which]->randmax)
92-
#define PHP_RAND_INISTR(which) (php_randgen_entries[which]->ini_str)
89+
#define PHP_RANDGEN_ENTRY(which, nsrand, nrand, nrandmax, nini_str) { \
90+
php_randgen_entries[which] = emalloc(sizeof(php_randgen_entry)); \
91+
php_randgen_entries[which]->srand = nsrand; \
92+
php_randgen_entries[which]->rand = nrand; \
93+
php_randgen_entries[which]->randmax = nrandmax; \
94+
php_randgen_entries[which]->ini_str = nini_str; \
95+
}
9396

9497
/* Define random generator constants */
9598
#define PHP_RAND_SYS 0

ext/standard/rand.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,19 @@
3232

3333
/* See php_rand.h for information about layout */
3434

35-
#if 0
36-
#define RANDGEN_ENTRY(intval, lower, upper, has_seed) \
37-
php_randgen_entry[intval] = { \
38-
(has_seed) ? php_rand_##lower : NULL, \
39-
php_rand_##lower, \
40-
PHP_RANDMAX_##upper, \
41-
"lower" \
42-
};
43-
#endif
35+
/* an ARRAY of POINTERS, not vice versa */
36+
php_randgen_entry *php_randgen_entries[PHP_RAND_NUMRANDS];
4437

45-
php_randgen_entry (*php_randgen_entries)[PHP_RAND_NUMRANDS];
38+
#define PHP_HAS_SRAND(which) (php_randgen_entries[which]->srand)
39+
#define PHP_SRAND(which,seed) ((*(php_randgen_entries[which]->srand))(seed))
40+
#define PHP_RAND(which) ((*(php_randgen_entries[which]->rand))())
41+
#define PHP_RANDMAX(which) (php_randgen_entries[which]->randmax)
42+
#define PHP_RAND_INISTR(which) (php_randgen_entries[which]->ini_str)
4643

47-
/* TODO: make sure this will be called */
4844
PHP_MINIT_FUNCTION(rand)
4945
{
50-
/* call: rand_sys, rand_mt, etc */
46+
PHP_MINIT(rand_sys)(INIT_FUNC_ARGS_PASSTHRU);
47+
PHP_MINIT(rand_mt)(INIT_FUNC_ARGS_PASSTHRU);
5148
}
5249

5350
/* TODO: check that this function is called on the start of each script

ext/standard/rand_mt.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,16 @@ static long _php_rand_mt(void);
8989
* Melo: it could be 2^^32 but we only use 2^^31 to maintain
9090
* compatibility with the previous php_rand
9191
*/
92-
#define _PHP_RANDMAX_MT ((long)(0x7FFFFFFF)) /* 2^^31 - 1 */
92+
#define PHP_RANDMAX_MT ((long)(0x7FFFFFFF)) /* 2^^31 - 1 */
9393

94-
php_randgen_entries[PHP_RAND_MT] = {
95-
_php_srand_mt, /* void srand(long seed) */
96-
_php_rand_mt, /* long rand(void) */
97-
PHP_RANDMAX_MT, /* long randmax */
98-
"mt" /* char *ini_str */
94+
PHP_MINIT_FUNCTION(rand_mt)
95+
{
96+
PHP_RANDGEN_ENTRY(PHP_RAND_MT,
97+
_php_srand_mt, /* void srand(long seed) */
98+
_php_rand_mt, /* long rand(void) */
99+
PHP_RANDMAX_MT, /* long randmax */
100+
"mt" /* char *ini_str */
101+
);
99102
}
100103

101104
#define N MT_N /* length of state vector */

ext/standard/rand_sys.c

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,41 +40,29 @@ static long _php_rand_sys(void)
4040

4141
PHP_MINIT_FUNCTION(rand_sys)
4242
{
43-
php_randgen_entries[PHP_RAND_SYS] = {
43+
#ifndef RAND_MAX
44+
#define RAND_MAX (1<<15)
45+
#endif
46+
PHP_RANDGEN_ENTRY(PHP_RAND_SYS,
4447
_php_srand_sys, /* void srand(long seed) */
4548
_php_rand_sys, /* long rand(void) */
46-
#ifdef RAND_MAX
47-
(long)RANDMAX, /* long randmax */
48-
#else
49-
(long)(1<<15), /* long randmax */
50-
#endif
49+
(long)RAND_MAX, /* long randmax */
5150
"system" /* char *ini_str */
52-
};
51+
);
5352

54-
/*
55-
php_randgen_entries[PHP_RAND_SYS]->srand = _php_srand_sys;
56-
php_randgen_entries[PHP_RAND_SYS].rand = _php_rand_sys;
57-
#ifdef RAND_MAX
58-
php_randgen_entries[PHP_RAND_SYS].randmax = (long)RAND_MAX;
59-
#else
60-
php_randgen_entries[PHP_RAND_SYS].randmax = (long)(1<<15);
61-
#endif
62-
php_randgen_entries[PHP_RAND_SYS].ini_str = "system";
63-
*/
64-
65-
/* random() is left away, no manual page on my system, no bigger range than
66-
* rand()
67-
* --jeroen
68-
*/
53+
/* random() is left away, no manual page on my system, no bigger range than
54+
* rand()
55+
* --jeroen
56+
*/
6957

7058
/* lrand48 (_not_ TS) */
7159
#if HAVE_LRAND48
72-
php_randgen_entries[PHP_RAND_LRAND48] = {
60+
PHP_RANDGEN_ENTRY(PHP_RAND_LRAND48,
7361
srand48, /* void srand(long seed) */
7462
lrand48, /* long rand(void) */
7563
2147483647L, /* long randmax */
7664
"lrand48" /* char *ini_str */
77-
};
65+
);
7866
#else
7967
php_randgen_entries[PHP_RAND_LRAND48] = NULL;
8068
#endif
@@ -87,5 +75,5 @@ PHP_MINIT_FUNCTION(rand_sys)
8775
* c-basic-offset: 4
8876
* End:
8977
* vim600: sw=4 ts=4 tw=78 fdm=marker
90-
* vim<600: sw=4 ts=4 tw=78
78+
* vim: sw=4 ts=4 tw=78
9179
*/

0 commit comments

Comments
 (0)