This commit is contained in:
Daniil Gentili 2023-11-17 18:42:03 +01:00
parent 602a5830ae
commit c87dc4b9d9
4 changed files with 26 additions and 18 deletions

View File

@ -1,8 +1,9 @@
//! Provides implementations for running php code from rust.
//! 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
//! You should only use this crate for test purpose, it's not production ready
//! This crate was only test with PHP 8.2 please report any issue with other
//! version You should only use this crate for test purpose, it's not production
//! ready
mod ffi;
@ -43,13 +44,14 @@ static RUN_FN_LOCK: RwLock<()> = const_rwlock(());
impl Embed {
/// Run a php script from a file
///
/// This function will only work correctly when used inside the `Embed::run` function
/// otherwise behavior is unexpected
/// This function will only work correctly when used inside the `Embed::run`
/// function otherwise behavior is unexpected
///
/// # Returns
///
/// * `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
///
@ -97,10 +99,10 @@ impl Embed {
/// Start and run embed sapi engine
///
/// This function will allow to run php code from rust, the same PHP context 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
/// variables defined in previous calls
/// This function will allow to run php code from rust, the same PHP context
/// 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 variables defined in previous calls
///
/// # Returns
///
@ -127,7 +129,8 @@ impl Embed {
// @TODO handle php thread safe
//
// 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 panic = unsafe {
@ -155,7 +158,8 @@ impl Embed {
/// 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
///

View File

@ -5,7 +5,8 @@ use std::{
fmt::Debug,
mem,
ops::{Deref, DerefMut},
ptr::{self, NonNull}, os::raw::c_char,
os::raw::c_char,
ptr::{self, NonNull},
};
use crate::{

View File

@ -7,8 +7,9 @@ use crate::{ffi::zend_ini_entry_def, ffi::zend_register_ini_entries, flags::IniE
/// A Zend ini entry definition.
///
/// To register ini definitions for extensions, the IniEntryDef builder should be used. Ini
/// entries should be registered in your module's startup_function via `IniEntryDef::register(Vec<IniEntryDef>)`.
/// To register ini definitions for extensions, the IniEntryDef builder should
/// 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;
impl IniEntryDef {

View File

@ -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)
/// 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
///
@ -60,10 +61,11 @@ pub fn try_catch<R, F: FnMut() -> R + RefUnwindSafe>(func: F) -> Result<R, Catch
/// # Safety
///
/// 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
///
/// When using this function you should ensure that all the memory allocated in the current scope is released
/// 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
pub unsafe fn bailout() -> ! {
ext_php_rs_zend_bailout();
}