mirror of
https://github.com/danog/ext-php-rs.git
synced 2024-11-30 04:39:04 +01:00
Fmt
This commit is contained in:
parent
602a5830ae
commit
c87dc4b9d9
@ -1,8 +1,9 @@
|
|||||||
//! Provides implementations for running php code from rust.
|
//! Provides implementations for running php code from rust.
|
||||||
//! It only works on linux for now and you should have `php-embed` installed
|
//! It only works on linux for now and you should have `php-embed` installed
|
||||||
//!
|
//!
|
||||||
//! This crate was only test with PHP 8.2 please report any issue with other version
|
//! This crate was only test with PHP 8.2 please report any issue with other
|
||||||
//! You should only use this crate for test purpose, it's not production ready
|
//! version You should only use this crate for test purpose, it's not production
|
||||||
|
//! ready
|
||||||
|
|
||||||
mod ffi;
|
mod ffi;
|
||||||
|
|
||||||
@ -43,13 +44,14 @@ static RUN_FN_LOCK: RwLock<()> = const_rwlock(());
|
|||||||
impl Embed {
|
impl Embed {
|
||||||
/// Run a php script from a file
|
/// Run a php script from a file
|
||||||
///
|
///
|
||||||
/// This function will only work correctly when used inside the `Embed::run` function
|
/// This function will only work correctly when used inside the `Embed::run`
|
||||||
/// otherwise behavior is unexpected
|
/// function otherwise behavior is unexpected
|
||||||
///
|
///
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
/// * `Ok(())` - The script was executed successfully
|
/// * `Ok(())` - The script was executed successfully
|
||||||
/// * `Err(EmbedError)` - An error occured during the execution of the script
|
/// * `Err(EmbedError)` - An error occured during the execution of the
|
||||||
|
/// script
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
@ -97,10 +99,10 @@ impl Embed {
|
|||||||
|
|
||||||
/// Start and run embed sapi engine
|
/// Start and run embed sapi engine
|
||||||
///
|
///
|
||||||
/// This function will allow to run php code from rust, the same PHP context is keep between calls
|
/// This function will allow to run php code from rust, the same PHP context
|
||||||
/// inside the function passed to this method.
|
/// is keep between calls inside the function passed to this method.
|
||||||
/// Which means subsequent calls to `Embed::eval` or `Embed::run_script` will be able to access
|
/// Which means subsequent calls to `Embed::eval` or `Embed::run_script`
|
||||||
/// variables defined in previous calls
|
/// will be able to access variables defined in previous calls
|
||||||
///
|
///
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
@ -127,7 +129,8 @@ impl Embed {
|
|||||||
// @TODO handle php thread safe
|
// @TODO handle php thread safe
|
||||||
//
|
//
|
||||||
// This is to prevent multiple threads from running php at the same time
|
// This is to prevent multiple threads from running php at the same time
|
||||||
// At some point we should detect if php is compiled with thread safety and avoid doing that in this case
|
// At some point we should detect if php is compiled with thread safety and
|
||||||
|
// avoid doing that in this case
|
||||||
let _guard = RUN_FN_LOCK.write();
|
let _guard = RUN_FN_LOCK.write();
|
||||||
|
|
||||||
let panic = unsafe {
|
let panic = unsafe {
|
||||||
@ -155,7 +158,8 @@ impl Embed {
|
|||||||
|
|
||||||
/// Evaluate a php code
|
/// Evaluate a php code
|
||||||
///
|
///
|
||||||
/// This function will only work correctly when used inside the `Embed::run` function
|
/// This function will only work correctly when used inside the `Embed::run`
|
||||||
|
/// function
|
||||||
///
|
///
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
|
@ -5,7 +5,8 @@ use std::{
|
|||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
mem,
|
mem,
|
||||||
ops::{Deref, DerefMut},
|
ops::{Deref, DerefMut},
|
||||||
ptr::{self, NonNull}, os::raw::c_char,
|
os::raw::c_char,
|
||||||
|
ptr::{self, NonNull},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -7,8 +7,9 @@ use crate::{ffi::zend_ini_entry_def, ffi::zend_register_ini_entries, flags::IniE
|
|||||||
|
|
||||||
/// A Zend ini entry definition.
|
/// A Zend ini entry definition.
|
||||||
///
|
///
|
||||||
/// To register ini definitions for extensions, the IniEntryDef builder should be used. Ini
|
/// To register ini definitions for extensions, the IniEntryDef builder should
|
||||||
/// entries should be registered in your module's startup_function via `IniEntryDef::register(Vec<IniEntryDef>)`.
|
/// be used. Ini entries should be registered in your module's startup_function
|
||||||
|
/// via `IniEntryDef::register(Vec<IniEntryDef>)`.
|
||||||
pub type IniEntryDef = zend_ini_entry_def;
|
pub type IniEntryDef = zend_ini_entry_def;
|
||||||
|
|
||||||
impl IniEntryDef {
|
impl IniEntryDef {
|
||||||
|
@ -18,7 +18,8 @@ pub(crate) unsafe extern "C" fn panic_wrapper<R, F: FnMut() -> R + RefUnwindSafe
|
|||||||
|
|
||||||
/// PHP propose a try catch mechanism in C using setjmp and longjmp (bailout)
|
/// PHP propose a try catch mechanism in C using setjmp and longjmp (bailout)
|
||||||
/// It store the arg of setjmp into the bailout field of the global executor
|
/// It store the arg of setjmp into the bailout field of the global executor
|
||||||
/// If a bailout is triggered, the executor will jump to the setjmp and restore the previous setjmp
|
/// If a bailout is triggered, the executor will jump to the setjmp and restore
|
||||||
|
/// the previous setjmp
|
||||||
///
|
///
|
||||||
/// try_catch allow to use this mechanism
|
/// try_catch allow to use this mechanism
|
||||||
///
|
///
|
||||||
@ -60,10 +61,11 @@ pub fn try_catch<R, F: FnMut() -> R + RefUnwindSafe>(func: F) -> Result<R, Catch
|
|||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// This function is unsafe because it can cause memory leaks
|
/// This function is unsafe because it can cause memory leaks
|
||||||
/// Since it will jump to the last try catch block, it will not call the destructor of the current scope
|
/// Since it will jump to the last try catch block, it will not call the
|
||||||
///
|
/// destructor of the current scope
|
||||||
/// When using this function you should ensure that all the memory allocated in the current scope is released
|
|
||||||
///
|
///
|
||||||
|
/// When using this function you should ensure that all the memory allocated in
|
||||||
|
/// the current scope is released
|
||||||
pub unsafe fn bailout() -> ! {
|
pub unsafe fn bailout() -> ! {
|
||||||
ext_php_rs_zend_bailout();
|
ext_php_rs_zend_bailout();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user