mirror of
https://github.com/danog/ext-php-rs.git
synced 2024-12-14 10:08:25 +01:00
ZTS support for file globals
This commit is contained in:
parent
06e190e08a
commit
a616c4b4db
@ -28,6 +28,7 @@ extern "C" {
|
|||||||
pub fn ext_php_rs_executor_globals() -> *mut zend_executor_globals;
|
pub fn ext_php_rs_executor_globals() -> *mut zend_executor_globals;
|
||||||
pub fn ext_php_rs_process_globals() -> *mut php_core_globals;
|
pub fn ext_php_rs_process_globals() -> *mut php_core_globals;
|
||||||
pub fn ext_php_rs_sapi_globals() -> *mut sapi_globals_struct;
|
pub fn ext_php_rs_sapi_globals() -> *mut sapi_globals_struct;
|
||||||
|
pub fn ext_php_rs_file_globals() -> *mut php_file_globals;
|
||||||
}
|
}
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
||||||
|
@ -64,3 +64,12 @@ sapi_globals_struct *ext_php_rs_sapi_globals() {
|
|||||||
return &sapi_globals;
|
return &sapi_globals;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
php_file_globals *ext_php_rs_file_globals() {
|
||||||
|
#ifdef ZTS
|
||||||
|
return TSRMG_FAST_BULK(file_globals_id, php_file_globals *);
|
||||||
|
#else
|
||||||
|
return &file_globals;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
@ -8,11 +8,11 @@ use parking_lot::{const_rwlock, RwLock, RwLockReadGuard, RwLockWriteGuard};
|
|||||||
|
|
||||||
use crate::boxed::ZBox;
|
use crate::boxed::ZBox;
|
||||||
use crate::ffi::{
|
use crate::ffi::{
|
||||||
_zend_executor_globals, ext_php_rs_executor_globals, ext_php_rs_process_globals,
|
_zend_executor_globals, ext_php_rs_executor_globals, ext_php_rs_file_globals,
|
||||||
ext_php_rs_sapi_globals, file_globals, php_core_globals, php_file_globals, sapi_globals_struct,
|
ext_php_rs_process_globals, ext_php_rs_sapi_globals, php_core_globals, php_file_globals,
|
||||||
sapi_header_struct, sapi_headers_struct, sapi_request_info, zend_is_auto_global,
|
sapi_globals_struct, sapi_header_struct, sapi_headers_struct, sapi_request_info,
|
||||||
TRACK_VARS_COOKIE, TRACK_VARS_ENV, TRACK_VARS_FILES, TRACK_VARS_GET, TRACK_VARS_POST,
|
zend_is_auto_global, TRACK_VARS_COOKIE, TRACK_VARS_ENV, TRACK_VARS_FILES, TRACK_VARS_GET,
|
||||||
TRACK_VARS_REQUEST, TRACK_VARS_SERVER,
|
TRACK_VARS_POST, TRACK_VARS_REQUEST, TRACK_VARS_SERVER,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::types::{ZendHashTable, ZendObject, ZendStr};
|
use crate::types::{ZendHashTable, ZendObject, ZendStr};
|
||||||
@ -378,7 +378,8 @@ impl FileGlobals {
|
|||||||
pub fn get() -> GlobalReadGuard<Self> {
|
pub fn get() -> GlobalReadGuard<Self> {
|
||||||
// SAFETY: PHP executor globals are statically declared therefore should never
|
// SAFETY: PHP executor globals are statically declared therefore should never
|
||||||
// return an invalid pointer.
|
// return an invalid pointer.
|
||||||
let globals = unsafe { &file_globals };
|
let globals = unsafe { ext_php_rs_file_globals().as_ref() }
|
||||||
|
.expect("Static file globals were invalid");
|
||||||
let guard = FILE_GLOBALS_LOCK.read();
|
let guard = FILE_GLOBALS_LOCK.read();
|
||||||
GlobalReadGuard { globals, guard }
|
GlobalReadGuard { globals, guard }
|
||||||
}
|
}
|
||||||
@ -393,7 +394,7 @@ impl FileGlobals {
|
|||||||
pub fn get_mut() -> GlobalWriteGuard<Self> {
|
pub fn get_mut() -> GlobalWriteGuard<Self> {
|
||||||
// SAFETY: PHP executor globals are statically declared therefore should never
|
// SAFETY: PHP executor globals are statically declared therefore should never
|
||||||
// return an invalid pointer.
|
// return an invalid pointer.
|
||||||
let globals = unsafe { &mut file_globals };
|
let globals = unsafe { &mut *ext_php_rs_file_globals() };
|
||||||
let guard = SAPI_GLOBALS_LOCK.write();
|
let guard = SAPI_GLOBALS_LOCK.write();
|
||||||
GlobalWriteGuard { globals, guard }
|
GlobalWriteGuard { globals, guard }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user