Skip to content

Stdlib: register mt_getrandmax() beside getrandmax() (#17228) - #17235

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-17228-mt-getrandmax
Jul 7, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/issue-17228-mt-getrandmax

Conversation

@PurHur

@PurHur PurHur commented Jul 7, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add ext/standard/mt_getrandmax.php — thin builtin returning VmMt19937::PHP_MT_RAND_MAX (2147483647), matching php-src ext/random/random.c PHP_FUNCTION(mt_getrandmax).
  • Register in ext/standard/Module.php beside getrandmax(); spine + bootstrap inventory updated.
  • Compliance .phpt (VM + JIT) and issue repro under test/repro/.

Closes #17228

php-src reference

  • ext/random/random.c — PHP_FUNCTION(mt_getrandmax)

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php test/repro/maintainer_gap_mt_getrandmax_missing.php
vendor/bin/phpunit --filter mt_getrandmax
php bin/compile.php -l test/repro/maintainer_gap_mt_getrandmax_missing.php
OUT=$(mktemp -d)
php bin/compile.php -o "$OUT/repro" test/repro/maintainer_gap_mt_getrandmax_missing.php
"$OUT/repro"
php script/bootstrap-inventory.php --check
php script/check-selfhost-spine-coverage-sync.php
'

VM repro:

mt_rand=yes
mt_getrandmax=yes
2147483647
mt_getrandmax() expects exactly 0 arguments, 1 given

PHPUnit: OK (4 tests, 4 assertions) (VM + JIT compliance)

AOT compile + run:

mt_rand=yes
mt_getrandmax=yes
2147483647

(ArgumentCountError on surplus args is VM/JIT-only today — same as existing getrandmax().)

Made with Cursor

Portable code and vendor patches call mt_getrandmax() for the MT19937
upper bound; register the PHP builtin with VM/JIT/AOT constexpr lowering.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit f416abd into master Jul 7, 2026
1 check failed
@PurHur
PurHur deleted the agent/issue-17228-mt-getrandmax branch July 7, 2026 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stdlib: mt_getrandmax() missing while mt_rand()/getrandmax() registered (ext/random/random.c)

1 participant