Skip to content

Commit 8238c8e

Browse files
committed
ext/random: Add const qualifier
1 parent be844f9 commit 8238c8e

File tree

5 files changed

+21
-20
lines changed

5 files changed

+21
-20
lines changed

ext/random/engine_mt19937.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static bool serialize(void *state, HashTable *data)
188188
return true;
189189
}
190190

191-
static bool unserialize(void *state, HashTable *data)
191+
static bool unserialize(void *state, const HashTable *data)
192192
{
193193
php_random_status_state_mt19937 *s = state;
194194
zval *t;

ext/random/engine_pcgoneseq128xslrr64.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static bool serialize(void *state, HashTable *data)
8080
return true;
8181
}
8282

83-
static bool unserialize(void *state, HashTable *data)
83+
static bool unserialize(void *state, const HashTable *data)
8484
{
8585
php_random_status_state_pcgoneseq128xslrr64 *s = state;
8686
uint64_t u[2];

ext/random/engine_xoshiro256starstar.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ static bool serialize(void *state, HashTable *data)
131131
return true;
132132
}
133133

134-
static bool unserialize(void *state, HashTable *data)
134+
static bool unserialize(void *state, const HashTable *data)
135135
{
136136
php_random_status_state_xoshiro256starstar *s = state;
137137

ext/random/random.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ PHPAPI void *php_random_status_alloc(const php_random_algo *algo, const bool per
240240
return algo->state_size > 0 ? pecalloc(1, algo->state_size, persistent) : NULL;
241241
}
242242

243-
PHPAPI void *php_random_status_copy(const php_random_algo *algo, void *old_status, void *new_status)
243+
PHPAPI void *php_random_status_copy(const php_random_algo *algo, const void *old_status, void *new_status)
244244
{
245245
return memcpy(new_status, old_status, algo->state_size);
246246
}
@@ -250,7 +250,7 @@ PHPAPI void php_random_status_free(void *status, const bool persistent)
250250
pefree(status, persistent);
251251
}
252252

253-
PHPAPI php_random_engine *php_random_engine_common_init(zend_class_entry *ce, zend_object_handlers *handlers, const php_random_algo *algo)
253+
PHPAPI php_random_engine *php_random_engine_common_init(zend_class_entry *ce, const zend_object_handlers *handlers, const php_random_algo *algo)
254254
{
255255
php_random_engine *engine = zend_object_alloc(sizeof(php_random_engine), ce);
256256

@@ -355,10 +355,11 @@ PHPAPI zend_string *php_random_bin2hex_le(const void *ptr, const size_t len)
355355

356356
/* {{{ php_random_hex2bin_le */
357357
/* stolen from standard/string.c */
358-
PHPAPI bool php_random_hex2bin_le(zend_string *hexstr, void *dest)
358+
PHPAPI bool php_random_hex2bin_le(const zend_string *hexstr, void *dest)
359359
{
360360
size_t len = hexstr->len >> 1;
361-
unsigned char *str = (unsigned char *) hexstr->val, c, l, d;
361+
const unsigned char *str = (unsigned char *) hexstr->val;
362+
unsigned char c, l, d;
362363
unsigned char *ptr = (unsigned char *) dest;
363364
int is_letter, i = 0;
364365

@@ -462,7 +463,7 @@ PHPAPI zend_long php_mt_rand_range(zend_long min, zend_long max)
462463
* rand() allows min > max, mt_rand does not */
463464
PHPAPI zend_long php_mt_rand_common(zend_long min, zend_long max)
464465
{
465-
php_random_status_state_mt19937 *s = php_random_default_status();
466+
const php_random_status_state_mt19937 *s = php_random_default_status();
466467

467468
if (s->mode == MT_RAND_MT19937) {
468469
return php_mt_rand_range(min, max);
@@ -633,7 +634,7 @@ PHP_FUNCTION(random_int)
633634
}
634635
/* }}} */
635636

636-
static inline void fallback_seed_add(PHP_SHA1_CTX *c, void *p, size_t l){
637+
static inline void fallback_seed_add(PHP_SHA1_CTX *c, const void *p, size_t l){
637638
/* Wrapper around PHP_SHA1Update allowing to pass
638639
* arbitrary pointers without (unsigned char*) casts
639640
* everywhere.

ext/random/randomizer.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ PHP_METHOD(Random_Randomizer, __construct)
9393
/* {{{ Generate a float in [0, 1) */
9494
PHP_METHOD(Random_Randomizer, nextFloat)
9595
{
96-
php_random_randomizer *randomizer = Z_RANDOM_RANDOMIZER_P(ZEND_THIS);
96+
const php_random_randomizer *randomizer = Z_RANDOM_RANDOMIZER_P(ZEND_THIS);
9797
php_random_algo_with_state engine = randomizer->engine;
9898

9999
uint64_t result;
@@ -136,7 +136,7 @@ PHP_METHOD(Random_Randomizer, nextFloat)
136136
*/
137137
PHP_METHOD(Random_Randomizer, getFloat)
138138
{
139-
php_random_randomizer *randomizer = Z_RANDOM_RANDOMIZER_P(ZEND_THIS);
139+
const php_random_randomizer *randomizer = Z_RANDOM_RANDOMIZER_P(ZEND_THIS);
140140
double min, max;
141141
zend_object *bounds = NULL;
142142
int bounds_type = 'C' + sizeof("ClosedOpen") - 1;
@@ -159,8 +159,8 @@ PHP_METHOD(Random_Randomizer, getFloat)
159159
}
160160

161161
if (bounds) {
162-
zval *case_name = zend_enum_fetch_case_name(bounds);
163-
zend_string *bounds_name = Z_STR_P(case_name);
162+
const zval *case_name = zend_enum_fetch_case_name(bounds);
163+
const zend_string *bounds_name = Z_STR_P(case_name);
164164

165165
bounds_type = ZSTR_VAL(bounds_name)[0] + ZSTR_LEN(bounds_name);
166166
}
@@ -210,7 +210,7 @@ PHP_METHOD(Random_Randomizer, getFloat)
210210
/* {{{ Generate positive random number */
211211
PHP_METHOD(Random_Randomizer, nextInt)
212212
{
213-
php_random_randomizer *randomizer = Z_RANDOM_RANDOMIZER_P(ZEND_THIS);
213+
const php_random_randomizer *randomizer = Z_RANDOM_RANDOMIZER_P(ZEND_THIS);
214214
php_random_algo_with_state engine = randomizer->engine;
215215

216216
ZEND_PARSE_PARAMETERS_NONE();
@@ -231,7 +231,7 @@ PHP_METHOD(Random_Randomizer, nextInt)
231231
/* {{{ Generate random number in range */
232232
PHP_METHOD(Random_Randomizer, getInt)
233233
{
234-
php_random_randomizer *randomizer = Z_RANDOM_RANDOMIZER_P(ZEND_THIS);
234+
const php_random_randomizer *randomizer = Z_RANDOM_RANDOMIZER_P(ZEND_THIS);
235235
php_random_algo_with_state engine = randomizer->engine;
236236

237237
uint64_t result;
@@ -274,7 +274,7 @@ PHP_METHOD(Random_Randomizer, getInt)
274274
/* {{{ Generate random bytes string in ordered length */
275275
PHP_METHOD(Random_Randomizer, getBytes)
276276
{
277-
php_random_randomizer *randomizer = Z_RANDOM_RANDOMIZER_P(ZEND_THIS);
277+
const php_random_randomizer *randomizer = Z_RANDOM_RANDOMIZER_P(ZEND_THIS);
278278
php_random_algo_with_state engine = randomizer->engine;
279279

280280
zend_string *retval;
@@ -349,7 +349,7 @@ PHP_METHOD(Random_Randomizer, getBytes)
349349
/* {{{ Shuffling array */
350350
PHP_METHOD(Random_Randomizer, shuffleArray)
351351
{
352-
php_random_randomizer *randomizer = Z_RANDOM_RANDOMIZER_P(ZEND_THIS);
352+
const php_random_randomizer *randomizer = Z_RANDOM_RANDOMIZER_P(ZEND_THIS);
353353
zval *array;
354354

355355
ZEND_PARSE_PARAMETERS_START(1, 1)
@@ -366,7 +366,7 @@ PHP_METHOD(Random_Randomizer, shuffleArray)
366366
/* {{{ Shuffling binary */
367367
PHP_METHOD(Random_Randomizer, shuffleBytes)
368368
{
369-
php_random_randomizer *randomizer = Z_RANDOM_RANDOMIZER_P(ZEND_THIS);
369+
const php_random_randomizer *randomizer = Z_RANDOM_RANDOMIZER_P(ZEND_THIS);
370370
zend_string *bytes;
371371

372372
ZEND_PARSE_PARAMETERS_START(1, 1)
@@ -387,7 +387,7 @@ PHP_METHOD(Random_Randomizer, shuffleBytes)
387387
/* {{{ Pick keys */
388388
PHP_METHOD(Random_Randomizer, pickArrayKeys)
389389
{
390-
php_random_randomizer *randomizer = Z_RANDOM_RANDOMIZER_P(ZEND_THIS);
390+
const php_random_randomizer *randomizer = Z_RANDOM_RANDOMIZER_P(ZEND_THIS);
391391
zval *input;
392392
zend_long num_req;
393393

@@ -419,7 +419,7 @@ PHP_METHOD(Random_Randomizer, pickArrayKeys)
419419
/* {{{ Get Random Bytes for String */
420420
PHP_METHOD(Random_Randomizer, getBytesFromString)
421421
{
422-
php_random_randomizer *randomizer = Z_RANDOM_RANDOMIZER_P(ZEND_THIS);
422+
const php_random_randomizer *randomizer = Z_RANDOM_RANDOMIZER_P(ZEND_THIS);
423423
php_random_algo_with_state engine = randomizer->engine;
424424

425425
zend_long user_length;

0 commit comments

Comments
 (0)