Skip to content

Commit fc467dc

Browse files
authored
random: Use ->default_object_handlers for engines (php#19625)
1 parent 84b78c0 commit fc467dc

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

UPGRADING.INTERNALS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ PHP 8.5 INTERNALS UPGRADE NOTES
3939
. Hash functions now use proper hash_spec_result enum for return values
4040
instead of using SUCCESS and FAILURE.
4141

42+
- Random
43+
. The handlers parameter of php_random_engine_common_init() has been
44+
removed. Use the default_object_handlers field on the CE instead.
45+
4246
- Zend
4347
. Added zend_safe_assign_to_variable_noref() function to safely assign
4448
a value to a non-reference zval.

ext/random/php_random.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ static inline php_random_randomizer *php_random_randomizer_from_obj(zend_object
151151
PHPAPI void *php_random_status_alloc(const php_random_algo *algo, const bool persistent);
152152
PHPAPI void *php_random_status_copy(const php_random_algo *algo, void *old_status, void *new_status);
153153
PHPAPI void php_random_status_free(void *status, const bool persistent);
154-
PHPAPI php_random_engine *php_random_engine_common_init(zend_class_entry *ce, zend_object_handlers *handlers, const php_random_algo *algo);
154+
PHPAPI php_random_engine *php_random_engine_common_init(zend_class_entry *ce, const php_random_algo *algo);
155155
PHPAPI void php_random_engine_common_free_object(zend_object *object);
156156
PHPAPI zend_object *php_random_engine_common_clone_object(zend_object *object);
157157
PHPAPI uint32_t php_random_range32(php_random_algo_with_state engine, uint32_t umax);

ext/random/random.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,22 +197,22 @@ PHPAPI uint64_t php_random_range64(php_random_algo_with_state engine, uint64_t u
197197

198198
static zend_object *php_random_engine_mt19937_new(zend_class_entry *ce)
199199
{
200-
return &php_random_engine_common_init(ce, &random_engine_mt19937_object_handlers, &php_random_algo_mt19937)->std;
200+
return &php_random_engine_common_init(ce, &php_random_algo_mt19937)->std;
201201
}
202202

203203
static zend_object *php_random_engine_pcgoneseq128xslrr64_new(zend_class_entry *ce)
204204
{
205-
return &php_random_engine_common_init(ce, &random_engine_pcgoneseq128xslrr64_object_handlers, &php_random_algo_pcgoneseq128xslrr64)->std;
205+
return &php_random_engine_common_init(ce, &php_random_algo_pcgoneseq128xslrr64)->std;
206206
}
207207

208208
static zend_object *php_random_engine_xoshiro256starstar_new(zend_class_entry *ce)
209209
{
210-
return &php_random_engine_common_init(ce, &random_engine_xoshiro256starstar_object_handlers, &php_random_algo_xoshiro256starstar)->std;
210+
return &php_random_engine_common_init(ce, &php_random_algo_xoshiro256starstar)->std;
211211
}
212212

213213
static zend_object *php_random_engine_secure_new(zend_class_entry *ce)
214214
{
215-
return &php_random_engine_common_init(ce, &random_engine_secure_object_handlers, &php_random_algo_secure)->std;
215+
return &php_random_engine_common_init(ce, &php_random_algo_secure)->std;
216216
}
217217

218218
static zend_object *php_random_randomizer_new(zend_class_entry *ce)
@@ -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 php_random_algo *algo)
254254
{
255255
php_random_engine *engine = zend_object_alloc(sizeof(php_random_engine), ce);
256256

@@ -261,7 +261,6 @@ PHPAPI php_random_engine *php_random_engine_common_init(zend_class_entry *ce, ze
261261
.algo = algo,
262262
.state = php_random_status_alloc(algo, false)
263263
};
264-
engine->std.handlers = handlers;
265264

266265
return engine;
267266
}
@@ -746,6 +745,7 @@ PHP_MINIT_FUNCTION(random)
746745
/* Random\Engine\Mt19937 */
747746
random_ce_Random_Engine_Mt19937 = register_class_Random_Engine_Mt19937(random_ce_Random_Engine);
748747
random_ce_Random_Engine_Mt19937->create_object = php_random_engine_mt19937_new;
748+
random_ce_Random_Engine_Mt19937->default_object_handlers = &random_engine_mt19937_object_handlers;
749749
memcpy(&random_engine_mt19937_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
750750
random_engine_mt19937_object_handlers.offset = XtOffsetOf(php_random_engine, std);
751751
random_engine_mt19937_object_handlers.free_obj = php_random_engine_common_free_object;
@@ -754,6 +754,7 @@ PHP_MINIT_FUNCTION(random)
754754
/* Random\Engine\PcgOnseq128XslRr64 */
755755
random_ce_Random_Engine_PcgOneseq128XslRr64 = register_class_Random_Engine_PcgOneseq128XslRr64(random_ce_Random_Engine);
756756
random_ce_Random_Engine_PcgOneseq128XslRr64->create_object = php_random_engine_pcgoneseq128xslrr64_new;
757+
random_ce_Random_Engine_PcgOneseq128XslRr64->default_object_handlers = &random_engine_pcgoneseq128xslrr64_object_handlers;
757758
memcpy(&random_engine_pcgoneseq128xslrr64_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
758759
random_engine_pcgoneseq128xslrr64_object_handlers.offset = XtOffsetOf(php_random_engine, std);
759760
random_engine_pcgoneseq128xslrr64_object_handlers.free_obj = php_random_engine_common_free_object;
@@ -762,6 +763,7 @@ PHP_MINIT_FUNCTION(random)
762763
/* Random\Engine\Xoshiro256StarStar */
763764
random_ce_Random_Engine_Xoshiro256StarStar = register_class_Random_Engine_Xoshiro256StarStar(random_ce_Random_Engine);
764765
random_ce_Random_Engine_Xoshiro256StarStar->create_object = php_random_engine_xoshiro256starstar_new;
766+
random_ce_Random_Engine_Xoshiro256StarStar->default_object_handlers = &random_engine_xoshiro256starstar_object_handlers;
765767
memcpy(&random_engine_xoshiro256starstar_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
766768
random_engine_xoshiro256starstar_object_handlers.offset = XtOffsetOf(php_random_engine, std);
767769
random_engine_xoshiro256starstar_object_handlers.free_obj = php_random_engine_common_free_object;
@@ -770,6 +772,7 @@ PHP_MINIT_FUNCTION(random)
770772
/* Random\Engine\Secure */
771773
random_ce_Random_Engine_Secure = register_class_Random_Engine_Secure(random_ce_Random_CryptoSafeEngine);
772774
random_ce_Random_Engine_Secure->create_object = php_random_engine_secure_new;
775+
random_ce_Random_Engine_Secure->default_object_handlers = &random_engine_secure_object_handlers;
773776
memcpy(&random_engine_secure_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
774777
random_engine_secure_object_handlers.offset = XtOffsetOf(php_random_engine, std);
775778
random_engine_secure_object_handlers.free_obj = php_random_engine_common_free_object;

0 commit comments

Comments
 (0)