mirror of
https://github.com/danog/ext-php-rs.git
synced 2024-12-02 17:50:55 +01:00
Support ZTS
This commit is contained in:
parent
21c4bf68da
commit
01060ff08e
@ -26,6 +26,7 @@ extern "C" {
|
||||
pub fn ext_php_rs_zend_object_alloc(obj_size: usize, ce: *mut zend_class_entry) -> *mut c_void;
|
||||
pub fn ext_php_rs_zend_object_release(obj: *mut zend_object);
|
||||
pub fn ext_php_rs_executor_globals() -> *mut zend_executor_globals;
|
||||
pub fn ext_php_rs_process_globals() -> *mut php_core_globals;
|
||||
}
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
||||
|
@ -39,3 +39,15 @@ zend_executor_globals *ext_php_rs_executor_globals() {
|
||||
return &executor_globals;
|
||||
#endif
|
||||
}
|
||||
|
||||
php_core_globals *ext_php_rs_process_globals() {
|
||||
#ifdef ZTS
|
||||
#ifdef ZEND_ENABLE_STATIC_TSRMLS_CACHE
|
||||
return TSRMG_FAST_BULK_STATIC(core_globals_offset, php_core_globals);
|
||||
#else
|
||||
return TSRMG_FAST_BULK(core_globals_offset, php_core_globals *);
|
||||
#endif
|
||||
#else
|
||||
return &core_globals;
|
||||
#endif
|
||||
}
|
||||
|
@ -29,4 +29,5 @@ void ext_php_rs_set_known_valid_utf8(zend_string *zs);
|
||||
const char *ext_php_rs_php_build_id();
|
||||
void *ext_php_rs_zend_object_alloc(size_t obj_size, zend_class_entry *ce);
|
||||
void ext_php_rs_zend_object_release(zend_object *obj);
|
||||
zend_executor_globals *ext_php_rs_executor_globals();
|
||||
zend_executor_globals *ext_php_rs_executor_globals();
|
||||
php_core_globals *ext_php_rs_process_globals();
|
||||
|
@ -6,9 +6,9 @@ use parking_lot::{const_rwlock, RwLock, RwLockReadGuard, RwLockWriteGuard};
|
||||
|
||||
use crate::boxed::ZBox;
|
||||
use crate::ffi::{
|
||||
_zend_executor_globals, core_globals, ext_php_rs_executor_globals, php_core_globals,
|
||||
TRACK_VARS_COOKIE, TRACK_VARS_ENV, TRACK_VARS_FILES, TRACK_VARS_GET, TRACK_VARS_POST,
|
||||
TRACK_VARS_REQUEST, TRACK_VARS_SERVER,
|
||||
_zend_executor_globals, ext_php_rs_executor_globals, ext_php_rs_process_globals,
|
||||
php_core_globals, TRACK_VARS_COOKIE, TRACK_VARS_ENV, TRACK_VARS_FILES, TRACK_VARS_GET,
|
||||
TRACK_VARS_POST, TRACK_VARS_REQUEST, TRACK_VARS_SERVER,
|
||||
};
|
||||
|
||||
use crate::types::{ZendHashTable, ZendObject};
|
||||
@ -85,7 +85,7 @@ impl ProcessGlobals {
|
||||
pub fn get() -> GlobalReadGuard<Self> {
|
||||
// SAFETY: PHP executor globals are statically declared therefore should never
|
||||
// return an invalid pointer.
|
||||
let globals = unsafe { &core_globals };
|
||||
let globals = unsafe { &*ext_php_rs_process_globals() };
|
||||
let guard = PROCESS_GLOBALS_LOCK.read();
|
||||
GlobalReadGuard { globals, guard }
|
||||
}
|
||||
@ -100,7 +100,7 @@ impl ProcessGlobals {
|
||||
pub fn get_mut() -> GlobalWriteGuard<Self> {
|
||||
// SAFETY: PHP executor globals are statically declared therefore should never
|
||||
// return an invalid pointer.
|
||||
let globals = unsafe { &mut core_globals };
|
||||
let globals = unsafe { &mut *ext_php_rs_process_globals() };
|
||||
let guard = PROCESS_GLOBALS_LOCK.write();
|
||||
GlobalWriteGuard { globals, guard }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user