feat(zend): add ModuleGlobals for per-extension global state#715
Merged
ptondereau merged 1 commit intoextphprs:masterfrom Apr 3, 2026
Merged
feat(zend): add ModuleGlobals for per-extension global state#715ptondereau merged 1 commit intoextphprs:masterfrom
ptondereau merged 1 commit intoextphprs:masterfrom
Conversation
Add `ModuleGlobal` trait and `ModuleGlobals<T>` struct that integrate with PHP's TSRM to provide per-extension module globals. In ZTS builds, PHP allocates per-thread storage via `ts_allocate_id`; in NTS builds, the globals live inline in a user-declared static. API surface: - `ModuleGlobal` trait: `Default + 'static` with optional `ginit`/`gshutdown` - `ModuleGlobals<T>::new()`: const constructor for static declaration - `ModuleGlobals<T>::get()`: safe shared access (PHP single-threaded request model) - `ModuleGlobals<T>::get_mut()`: unsafe mutable access - `ModuleGlobals<T>::as_ptr()`: raw pointer escape hatch - `ModuleBuilder::globals()`: registration via existing builder pattern C layer: `ext_php_rs_tsrmg_bulk()` wraps `TSRMG_BULK` macro for ZTS access, matching the existing pattern for executor/compiler/process globals.
035230d to
80cf959
Compare
Pull Request Test Coverage Report for Build 23946027973Details
💛 - Coveralls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add
ModuleGlobaltrait andModuleGlobals<T>struct for per-extension module globals with full TSRM integration.Problem: ext-php-rs had no support for PHP module globals —
zend_module_entryalways setglobals_size: 0. Extensions needing request-isolated mutable state in ZTS builds had to drop to raw FFI.Solution: A two-layer API inspired by dd-trace-php's
profiling/src/module_globals.rs:ModuleGlobals<T>with safeget(), unsafeget_mut(), andas_ptr()escape hatch. Registers viaModuleBuilder::globals(&MY_GLOBALS).Checklist