Skip to content

feat: make Sapi work with ZTS builds #488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/embed/embed.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ void ext_php_rs_sapi_startup() {
zend_signal_startup();
}

SAPI_API void ext_php_rs_sapi_shutdown() {
#ifdef ZTS
tsrm_shutdown();
#endif
}

SAPI_API void ext_php_rs_sapi_per_thread_init() {
#ifdef ZTS
(void)ts_resource(0);
#ifdef PHP_WIN32
ZEND_TSRMLS_CACHE_UPDATE();
#endif
#endif
}

void ext_php_rs_php_error(int type, const char *format, ...) {
va_list args;
va_start(args, format);
Expand Down
2 changes: 2 additions & 0 deletions src/embed/embed.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
void* ext_php_rs_embed_callback(int argc, char** argv, void* (*callback)(void *), void *ctx);

void ext_php_rs_sapi_startup();
void ext_php_rs_sapi_shutdown();
void ext_php_rs_sapi_per_thread_init();

void ext_php_rs_php_error(int type, const char *format, ...);
3 changes: 3 additions & 0 deletions src/embed/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ extern "C" {
) -> *mut c_void;

pub fn ext_php_rs_sapi_startup();
pub fn ext_php_rs_sapi_shutdown();
pub fn ext_php_rs_sapi_per_thread_init();

pub fn ext_php_rs_php_error(
type_: ::std::os::raw::c_int,
error_msg: *const ::std::os::raw::c_char,
Expand Down
3 changes: 3 additions & 0 deletions src/embed/sapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ use crate::ffi::sapi_module_struct;
/// A Zend module entry, also known as an extension.
pub type SapiModule = sapi_module_struct;

unsafe impl Send for SapiModule {}
unsafe impl Sync for SapiModule {}

impl SapiModule {
/// Allocates the module entry on the heap, returning a pointer to the
/// memory location. The caller is responsible for the memory pointed to.
Expand Down
2 changes: 2 additions & 0 deletions src/zend/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ impl SapiGlobals {
}
}

/// Stores SAPI headers. Exposed through `SapiGlobals`.
pub type SapiHeaders = sapi_headers_struct;

impl<'a> SapiHeaders {
Expand All @@ -571,6 +572,7 @@ impl<'a> SapiHeaders {
}
}

/// Manage a key/value pair of SAPI headers.
pub type SapiHeader = sapi_header_struct;

impl<'a> SapiHeader {
Expand Down
2 changes: 2 additions & 0 deletions src/zend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub use globals::ExecutorGlobals;
pub use globals::FileGlobals;
pub use globals::ProcessGlobals;
pub use globals::SapiGlobals;
pub use globals::SapiHeader;
pub use globals::SapiHeaders;
pub use globals::SapiModule;
pub use handlers::ZendObjectHandlers;
pub use ini_entry_def::IniEntryDef;
Expand Down
Loading