Skip to content

Commit faf0efb

Browse files
committed
feat: make Sapi work with ZTS builds
1 parent e15de17 commit faf0efb

File tree

6 files changed

+27
-0
lines changed

6 files changed

+27
-0
lines changed

src/embed/embed.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ void ext_php_rs_sapi_startup() {
2929
zend_signal_startup();
3030
}
3131

32+
SAPI_API void ext_php_rs_sapi_shutdown() {
33+
#ifdef ZTS
34+
tsrm_shutdown();
35+
#endif
36+
}
37+
38+
SAPI_API void ext_php_rs_sapi_per_thread_init() {
39+
#ifdef ZTS
40+
(void)ts_resource(0);
41+
#ifdef PHP_WIN32
42+
ZEND_TSRMLS_CACHE_UPDATE();
43+
#endif
44+
#endif
45+
}
46+
3247
void ext_php_rs_php_error(int type, const char *format, ...) {
3348
va_list args;
3449
va_start(args, format);

src/embed/embed.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@
77
void* ext_php_rs_embed_callback(int argc, char** argv, void* (*callback)(void *), void *ctx);
88

99
void ext_php_rs_sapi_startup();
10+
void ext_php_rs_sapi_shutdown();
11+
void ext_php_rs_sapi_per_thread_init();
1012

1113
void ext_php_rs_php_error(int type, const char *format, ...);

src/embed/ffi.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ extern "C" {
1818
) -> *mut c_void;
1919

2020
pub fn ext_php_rs_sapi_startup();
21+
pub fn ext_php_rs_sapi_shutdown();
22+
pub fn ext_php_rs_sapi_per_thread_init();
23+
2124
pub fn ext_php_rs_php_error(
2225
type_: ::std::os::raw::c_int,
2326
error_msg: *const ::std::os::raw::c_char,

src/embed/sapi.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ use crate::ffi::sapi_module_struct;
66
/// A Zend module entry, also known as an extension.
77
pub type SapiModule = sapi_module_struct;
88

9+
unsafe impl Send for SapiModule {}
10+
unsafe impl Sync for SapiModule {}
11+
912
impl SapiModule {
1013
/// Allocates the module entry on the heap, returning a pointer to the
1114
/// memory location. The caller is responsible for the memory pointed to.

src/zend/globals.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ impl SapiGlobals {
562562
}
563563
}
564564

565+
/// Stores SAPI headers. Exposed through SapiGlobals.
565566
pub type SapiHeaders = sapi_headers_struct;
566567

567568
impl<'a> SapiHeaders {
@@ -571,6 +572,7 @@ impl<'a> SapiHeaders {
571572
}
572573
}
573574

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

576578
impl<'a> SapiHeader {

src/zend/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ pub use globals::ExecutorGlobals;
2828
pub use globals::FileGlobals;
2929
pub use globals::ProcessGlobals;
3030
pub use globals::SapiGlobals;
31+
pub use globals::SapiHeader;
32+
pub use globals::SapiHeaders;
3133
pub use globals::SapiModule;
3234
pub use handlers::ZendObjectHandlers;
3335
pub use ini_entry_def::IniEntryDef;

0 commit comments

Comments
 (0)