Skip to content

Commit 79f648a

Browse files
committed
random: Narrow the parameter types of seed128/seed256
These internal-only functions accepted a `php_random_status`, just to extract the internal state from the `state` pointer. Make them take the state struct directly to improve type safety.
1 parent 453f5ab commit 79f648a

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

ext/random/engine_pcgoneseq128xslrr64.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ static inline void step(php_random_status_state_pcgoneseq128xslrr64 *s)
3434
);
3535
}
3636

37-
static inline void seed128(php_random_status *status, php_random_uint128_t seed)
37+
static inline void seed128(php_random_status_state_pcgoneseq128xslrr64 *s, php_random_uint128_t seed)
3838
{
39-
php_random_status_state_pcgoneseq128xslrr64 *s = status->state;
4039
s->state = php_random_uint128_constant(0ULL, 0ULL);
4140
step(s);
4241
s->state = php_random_uint128_add(s->state, seed);
@@ -45,7 +44,7 @@ static inline void seed128(php_random_status *status, php_random_uint128_t seed)
4544

4645
static void seed(php_random_status *status, uint64_t seed)
4746
{
48-
seed128(status, php_random_uint128_constant(0ULL, seed));
47+
seed128(status->state, php_random_uint128_constant(0ULL, seed));
4948
}
5049

5150
static php_random_result generate(php_random_status *status)
@@ -172,7 +171,7 @@ PHP_METHOD(Random_Engine_PcgOneseq128XslRr64, __construct)
172171
}
173172
}
174173

175-
seed128(engine->status, php_random_uint128_constant(t[0], t[1]));
174+
seed128(state, php_random_uint128_constant(t[0], t[1]));
176175
} else {
177176
zend_argument_value_error(1, "must be a 16 byte (128 bit) string");
178177
RETURN_THROWS();

ext/random/engine_xoshiro256starstar.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,8 @@ static inline void jump(php_random_status_state_xoshiro256starstar *state, const
8181
state->state[3] = s3;
8282
}
8383

84-
static inline void seed256(php_random_status *status, uint64_t s0, uint64_t s1, uint64_t s2, uint64_t s3)
84+
static inline void seed256(php_random_status_state_xoshiro256starstar *s, uint64_t s0, uint64_t s1, uint64_t s2, uint64_t s3)
8585
{
86-
php_random_status_state_xoshiro256starstar *s = status->state;
87-
8886
s->state[0] = s0;
8987
s->state[1] = s1;
9088
s->state[2] = s2;
@@ -100,7 +98,7 @@ static void seed(php_random_status *status, uint64_t seed)
10098
s[2] = splitmix64(&seed);
10199
s[3] = splitmix64(&seed);
102100

103-
seed256(status, s[0], s[1], s[2], s[3]);
101+
seed256(status->state, s[0], s[1], s[2], s[3]);
104102
}
105103

106104
static php_random_result generate(php_random_status *status)
@@ -237,7 +235,7 @@ PHP_METHOD(Random_Engine_Xoshiro256StarStar, __construct)
237235
RETURN_THROWS();
238236
}
239237

240-
seed256(engine->status, t[0], t[1], t[2], t[3]);
238+
seed256(state, t[0], t[1], t[2], t[3]);
241239
} else {
242240
zend_argument_value_error(1, "must be a 32 byte (256 bit) string");
243241
RETURN_THROWS();

0 commit comments

Comments
 (0)