Skip to content

Commit dce6ed3

Browse files
authored
random: Adjust status to state (#13521)
* random: Rename `status` local to `state` * random: Rename `php_random_algo_with_state`'s `status` member to `state`
1 parent ddcf5d7 commit dce6ed3

11 files changed

+99
-99
lines changed

ext/random/engine_combinedlcg.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@
3232
*/
3333
#define MODMULT(a, b, c, m, s) q = s / a; s = b * (s - a * q) - c * q; if (s < 0) s += m
3434

35-
static void seed(void *status, uint64_t seed)
35+
static void seed(void *state, uint64_t seed)
3636
{
37-
php_random_status_state_combinedlcg *s = status;
37+
php_random_status_state_combinedlcg *s = state;
3838

3939
s->state[0] = seed & 0xffffffffU;
4040
s->state[1] = seed >> 32;
4141
}
4242

43-
static php_random_result generate(void *status)
43+
static php_random_result generate(void *state)
4444
{
45-
php_random_status_state_combinedlcg *s = status;
45+
php_random_status_state_combinedlcg *s = state;
4646
int32_t q, z;
4747

4848
MODMULT(53668, 40014, 12211, 2147483563L, s->state[0]);
@@ -59,17 +59,17 @@ static php_random_result generate(void *status)
5959
};
6060
}
6161

62-
static zend_long range(void *status, zend_long min, zend_long max)
62+
static zend_long range(void *state, zend_long min, zend_long max)
6363
{
6464
return php_random_range((php_random_algo_with_state){
6565
.algo = &php_random_algo_combinedlcg,
66-
.status = status,
66+
.state = state,
6767
}, min, max);
6868
}
6969

70-
static bool serialize(void *status, HashTable *data)
70+
static bool serialize(void *state, HashTable *data)
7171
{
72-
php_random_status_state_combinedlcg *s = status;
72+
php_random_status_state_combinedlcg *s = state;
7373
zval t;
7474

7575
for (uint32_t i = 0; i < 2; i++) {
@@ -80,9 +80,9 @@ static bool serialize(void *status, HashTable *data)
8080
return true;
8181
}
8282

83-
static bool unserialize(void *status, HashTable *data)
83+
static bool unserialize(void *state, HashTable *data)
8484
{
85-
php_random_status_state_combinedlcg *s = status;
85+
php_random_status_state_combinedlcg *s = state;
8686
zval *t;
8787

8888
for (uint32_t i = 0; i < 2; i++) {

ext/random/engine_mt19937.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,14 @@ static inline void mt19937_seed_state(php_random_status_state_mt19937 *state, ui
139139
mt19937_reload(state);
140140
}
141141

142-
static void seed(void *status, uint64_t seed)
142+
static void seed(void *state, uint64_t seed)
143143
{
144-
mt19937_seed_state(status, seed);
144+
mt19937_seed_state(state, seed);
145145
}
146146

147-
static php_random_result generate(void *status)
147+
static php_random_result generate(void *state)
148148
{
149-
php_random_status_state_mt19937 *s = status;
149+
php_random_status_state_mt19937 *s = state;
150150
uint32_t s1;
151151

152152
if (s->count >= MT_N) {
@@ -164,17 +164,17 @@ static php_random_result generate(void *status)
164164
};
165165
}
166166

167-
static zend_long range(void *status, zend_long min, zend_long max)
167+
static zend_long range(void *state, zend_long min, zend_long max)
168168
{
169169
return php_random_range((php_random_algo_with_state){
170170
.algo = &php_random_algo_mt19937,
171-
.status = status,
171+
.state = state,
172172
}, min, max);
173173
}
174174

175-
static bool serialize(void *status, HashTable *data)
175+
static bool serialize(void *state, HashTable *data)
176176
{
177-
php_random_status_state_mt19937 *s = status;
177+
php_random_status_state_mt19937 *s = state;
178178
zval t;
179179

180180
for (uint32_t i = 0; i < MT_N; i++) {
@@ -189,9 +189,9 @@ static bool serialize(void *status, HashTable *data)
189189
return true;
190190
}
191191

192-
static bool unserialize(void *status, HashTable *data)
192+
static bool unserialize(void *state, HashTable *data)
193193
{
194-
php_random_status_state_mt19937 *s = status;
194+
php_random_status_state_mt19937 *s = state;
195195
zval *t;
196196

197197
/* Verify the expected number of elements, this implicitly ensures that no additional elements are present. */
@@ -255,7 +255,7 @@ PHPAPI void php_random_mt19937_seed_default(php_random_status_state_mt19937 *sta
255255
PHP_METHOD(Random_Engine_Mt19937, __construct)
256256
{
257257
php_random_algo_with_state engine = Z_RANDOM_ENGINE_P(ZEND_THIS)->engine;
258-
php_random_status_state_mt19937 *state = engine.status;
258+
php_random_status_state_mt19937 *state = engine.state;
259259
zend_long seed, mode = MT_RAND_MT19937;
260260
bool seed_is_null = true;
261261

@@ -298,7 +298,7 @@ PHP_METHOD(Random_Engine_Mt19937, generate)
298298

299299
ZEND_PARSE_PARAMETERS_NONE();
300300

301-
php_random_result generated = engine.algo->generate(engine.status);
301+
php_random_result generated = engine.algo->generate(engine.state);
302302
if (EG(exception)) {
303303
RETURN_THROWS();
304304
}
@@ -332,7 +332,7 @@ PHP_METHOD(Random_Engine_Mt19937, __serialize)
332332

333333
/* state */
334334
array_init(&t);
335-
if (!engine->engine.algo->serialize(engine->engine.status, Z_ARRVAL(t))) {
335+
if (!engine->engine.algo->serialize(engine->engine.state, Z_ARRVAL(t))) {
336336
zend_throw_exception(NULL, "Engine serialize failed", 0);
337337
RETURN_THROWS();
338338
}
@@ -375,7 +375,7 @@ PHP_METHOD(Random_Engine_Mt19937, __unserialize)
375375
zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(engine->std.ce->name));
376376
RETURN_THROWS();
377377
}
378-
if (!engine->engine.algo->unserialize(engine->engine.status, Z_ARRVAL_P(t))) {
378+
if (!engine->engine.algo->unserialize(engine->engine.state, Z_ARRVAL_P(t))) {
379379
zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(engine->std.ce->name));
380380
RETURN_THROWS();
381381
}
@@ -397,7 +397,7 @@ PHP_METHOD(Random_Engine_Mt19937, __debugInfo)
397397

398398
if (engine->engine.algo->serialize) {
399399
array_init(&t);
400-
if (!engine->engine.algo->serialize(engine->engine.status, Z_ARRVAL(t))) {
400+
if (!engine->engine.algo->serialize(engine->engine.state, Z_ARRVAL(t))) {
401401
zend_throw_exception(NULL, "Engine serialize failed", 0);
402402
RETURN_THROWS();
403403
}

ext/random/engine_pcgoneseq128xslrr64.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ static inline void seed128(php_random_status_state_pcgoneseq128xslrr64 *s, php_r
4343
step(s);
4444
}
4545

46-
static void seed(void *status, uint64_t seed)
46+
static void seed(void *state, uint64_t seed)
4747
{
48-
seed128(status, php_random_uint128_constant(0ULL, seed));
48+
seed128(state, php_random_uint128_constant(0ULL, seed));
4949
}
5050

51-
static php_random_result generate(void *status)
51+
static php_random_result generate(void *state)
5252
{
53-
php_random_status_state_pcgoneseq128xslrr64 *s = status;
53+
php_random_status_state_pcgoneseq128xslrr64 *s = state;
5454

5555
step(s);
5656

@@ -60,17 +60,17 @@ static php_random_result generate(void *status)
6060
};
6161
}
6262

63-
static zend_long range(void *status, zend_long min, zend_long max)
63+
static zend_long range(void *state, zend_long min, zend_long max)
6464
{
6565
return php_random_range((php_random_algo_with_state){
6666
.algo = &php_random_algo_pcgoneseq128xslrr64,
67-
.status = status,
67+
.state = state,
6868
}, min, max);
6969
}
7070

71-
static bool serialize(void *status, HashTable *data)
71+
static bool serialize(void *state, HashTable *data)
7272
{
73-
php_random_status_state_pcgoneseq128xslrr64 *s = status;
73+
php_random_status_state_pcgoneseq128xslrr64 *s = state;
7474
uint64_t u;
7575
zval z;
7676

@@ -85,9 +85,9 @@ static bool serialize(void *status, HashTable *data)
8585
return true;
8686
}
8787

88-
static bool unserialize(void *status, HashTable *data)
88+
static bool unserialize(void *state, HashTable *data)
8989
{
90-
php_random_status_state_pcgoneseq128xslrr64 *s = status;
90+
php_random_status_state_pcgoneseq128xslrr64 *s = state;
9191
uint64_t u[2];
9292
zval *t;
9393

@@ -146,7 +146,7 @@ PHPAPI void php_random_pcgoneseq128xslrr64_advance(php_random_status_state_pcgon
146146
PHP_METHOD(Random_Engine_PcgOneseq128XslRr64, __construct)
147147
{
148148
php_random_algo_with_state engine = Z_RANDOM_ENGINE_P(ZEND_THIS)->engine;
149-
php_random_status_state_pcgoneseq128xslrr64 *state = engine.status;
149+
php_random_status_state_pcgoneseq128xslrr64 *state = engine.state;
150150
zend_string *str_seed = NULL;
151151
zend_long int_seed = 0;
152152
bool seed_is_null = true;
@@ -195,7 +195,7 @@ PHP_METHOD(Random_Engine_PcgOneseq128XslRr64, __construct)
195195
PHP_METHOD(Random_Engine_PcgOneseq128XslRr64, jump)
196196
{
197197
php_random_algo_with_state engine = Z_RANDOM_ENGINE_P(ZEND_THIS)->engine;
198-
php_random_status_state_pcgoneseq128xslrr64 *state = engine.status;
198+
php_random_status_state_pcgoneseq128xslrr64 *state = engine.state;
199199
zend_long advance = 0;
200200

201201
ZEND_PARSE_PARAMETERS_START(1, 1)

ext/random/engine_secure.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
#include "Zend/zend_exceptions.h"
2727

28-
static php_random_result generate(void *status)
28+
static php_random_result generate(void *state)
2929
{
3030
zend_ulong r = 0;
3131

@@ -37,7 +37,7 @@ static php_random_result generate(void *status)
3737
};
3838
}
3939

40-
static zend_long range(void *status, zend_long min, zend_long max)
40+
static zend_long range(void *state, zend_long min, zend_long max)
4141
{
4242
zend_long result = 0;
4343

ext/random/engine_user.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
#include "php.h"
2222
#include "php_random.h"
2323

24-
static php_random_result generate(void *status)
24+
static php_random_result generate(void *state)
2525
{
26-
php_random_status_state_user *s = status;
26+
php_random_status_state_user *s = state;
2727
uint64_t result = 0;
2828
size_t size;
2929
zval retval;
@@ -65,11 +65,11 @@ static php_random_result generate(void *status)
6565
};
6666
}
6767

68-
static zend_long range(void *status, zend_long min, zend_long max)
68+
static zend_long range(void *state, zend_long min, zend_long max)
6969
{
7070
return php_random_range((php_random_algo_with_state){
7171
.algo = &php_random_algo_user,
72-
.status = status,
72+
.state = state,
7373
}, min, max);
7474
}
7575

ext/random/engine_xoshiro256starstar.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,30 +102,30 @@ static inline void seed64(php_random_status_state_xoshiro256starstar *state, uin
102102
seed256(state, s[0], s[1], s[2], s[3]);
103103
}
104104

105-
static void seed(void *status, uint64_t seed)
105+
static void seed(void *state, uint64_t seed)
106106
{
107-
seed64(status, seed);
107+
seed64(state, seed);
108108
}
109109

110-
static php_random_result generate(void *status)
110+
static php_random_result generate(void *state)
111111
{
112112
return (php_random_result){
113113
.size = sizeof(uint64_t),
114-
.result = generate_state(status),
114+
.result = generate_state(state),
115115
};
116116
}
117117

118-
static zend_long range(void *status, zend_long min, zend_long max)
118+
static zend_long range(void *state, zend_long min, zend_long max)
119119
{
120120
return php_random_range((php_random_algo_with_state){
121121
.algo = &php_random_algo_xoshiro256starstar,
122-
.status = status,
122+
.state = state,
123123
}, min, max);
124124
}
125125

126-
static bool serialize(void *status, HashTable *data)
126+
static bool serialize(void *state, HashTable *data)
127127
{
128-
php_random_status_state_xoshiro256starstar *s = status;
128+
php_random_status_state_xoshiro256starstar *s = state;
129129
zval t;
130130

131131
for (uint32_t i = 0; i < 4; i++) {
@@ -136,9 +136,9 @@ static bool serialize(void *status, HashTable *data)
136136
return true;
137137
}
138138

139-
static bool unserialize(void *status, HashTable *data)
139+
static bool unserialize(void *state, HashTable *data)
140140
{
141-
php_random_status_state_xoshiro256starstar *s = status;
141+
php_random_status_state_xoshiro256starstar *s = state;
142142
zval *t;
143143

144144
/* Verify the expected number of elements, this implicitly ensures that no additional elements are present. */
@@ -184,7 +184,7 @@ PHPAPI void php_random_xoshiro256starstar_jump_long(php_random_status_state_xosh
184184
PHP_METHOD(Random_Engine_Xoshiro256StarStar, jump)
185185
{
186186
php_random_algo_with_state engine = Z_RANDOM_ENGINE_P(ZEND_THIS)->engine;
187-
php_random_status_state_xoshiro256starstar *state = engine.status;
187+
php_random_status_state_xoshiro256starstar *state = engine.state;
188188

189189
ZEND_PARSE_PARAMETERS_NONE();
190190

@@ -196,7 +196,7 @@ PHP_METHOD(Random_Engine_Xoshiro256StarStar, jump)
196196
PHP_METHOD(Random_Engine_Xoshiro256StarStar, jumpLong)
197197
{
198198
php_random_algo_with_state engine = Z_RANDOM_ENGINE_P(ZEND_THIS)->engine;
199-
php_random_status_state_xoshiro256starstar *state = engine.status;
199+
php_random_status_state_xoshiro256starstar *state = engine.state;
200200

201201
ZEND_PARSE_PARAMETERS_NONE();
202202

@@ -208,7 +208,7 @@ PHP_METHOD(Random_Engine_Xoshiro256StarStar, jumpLong)
208208
PHP_METHOD(Random_Engine_Xoshiro256StarStar, __construct)
209209
{
210210
php_random_algo_with_state engine = Z_RANDOM_ENGINE_P(ZEND_THIS)->engine;
211-
php_random_status_state_xoshiro256starstar *state = engine.status;
211+
php_random_status_state_xoshiro256starstar *state = engine.state;
212212
zend_string *str_seed = NULL;
213213
zend_long int_seed = 0;
214214
bool seed_is_null = true;

ext/random/php_random.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,16 @@ typedef struct _php_random_result {
9696

9797
typedef struct _php_random_algo {
9898
const size_t state_size;
99-
void (*seed)(void *status, uint64_t seed);
100-
php_random_result (*generate)(void *status);
101-
zend_long (*range)(void *status, zend_long min, zend_long max);
102-
bool (*serialize)(void *status, HashTable *data);
103-
bool (*unserialize)(void *status, HashTable *data);
99+
void (*seed)(void *state, uint64_t seed);
100+
php_random_result (*generate)(void *state);
101+
zend_long (*range)(void *state, zend_long min, zend_long max);
102+
bool (*serialize)(void *state, HashTable *data);
103+
bool (*unserialize)(void *state, HashTable *data);
104104
} php_random_algo;
105105

106106
typedef struct _php_random_algo_with_state {
107107
const php_random_algo *algo;
108-
void *status;
108+
void *state;
109109
} php_random_algo_with_state;
110110

111111
extern PHPAPI const php_random_algo php_random_algo_combinedlcg;
@@ -170,7 +170,7 @@ static inline php_random_algo_with_state php_random_default_engine(void)
170170
{
171171
return (php_random_algo_with_state){
172172
.algo = php_random_default_algo(),
173-
.status = php_random_default_status(),
173+
.state = php_random_default_status(),
174174
};
175175
}
176176

0 commit comments

Comments
 (0)