From bd54b3879f5b67ba0b43d1d0ecb7362b2b5f1974 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 17 Nov 2023 18:38:06 +0100 Subject: [PATCH 1/3] Fix #279 --- src/types/class_object.rs | 4 ++-- src/types/object.rs | 4 ++-- src/zend/function.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/types/class_object.rs b/src/types/class_object.rs index e9b116529..753933d39 100644 --- a/src/types/class_object.rs +++ b/src/types/class_object.rs @@ -5,7 +5,7 @@ use std::{ fmt::Debug, mem, ops::{Deref, DerefMut}, - ptr::{self, NonNull}, + ptr::{self, NonNull}, os::raw::c_char, }; use crate::{ @@ -161,7 +161,7 @@ impl ZendClassObject { } fn _from_zend_obj(std: &zend_object) -> Option<&mut Self> { - let std = std as *const zend_object as *const i8; + let std = std as *const zend_object as *const c_char; let ptr = unsafe { let ptr = std.offset(0 - Self::std_offset() as isize) as *const Self; (ptr as *mut Self).as_mut()? diff --git a/src/types/object.rs b/src/types/object.rs index ca8e526eb..f17b65fd2 100644 --- a/src/types/object.rs +++ b/src/types/object.rs @@ -1,7 +1,7 @@ //! Represents an object in PHP. Allows for overriding the internal object used //! by classes, allowing users to store Rust data inside a PHP object. -use std::{convert::TryInto, fmt::Debug, ops::DerefMut}; +use std::{convert::TryInto, fmt::Debug, ops::DerefMut, os::raw::c_char}; use crate::{ boxed::{ZBox, ZBoxable}, @@ -146,7 +146,7 @@ impl ZendObject { unsafe { let res = zend_hash_str_find_ptr_lc( &(*self.ce).function_table, - name.as_ptr() as *const i8, + name.as_ptr() as *const c_char, name.len(), ) as *mut zend_function; if res.is_null() { diff --git a/src/zend/function.rs b/src/zend/function.rs index a1ef8663c..fb5c4d4bd 100644 --- a/src/zend/function.rs +++ b/src/zend/function.rs @@ -52,7 +52,7 @@ pub type Function = zend_function; impl Function { pub fn try_from_function(name: &str) -> Option { unsafe { - let res = zend_fetch_function_str(name.as_ptr() as *const i8, name.len()); + let res = zend_fetch_function_str(name.as_ptr() as *const c_char, name.len()); if res.is_null() { return None; } @@ -65,7 +65,7 @@ impl Function { Some(ce) => unsafe { let res = zend_hash_str_find_ptr_lc( &ce.function_table, - name.as_ptr() as *const i8, + name.as_ptr() as *const c_char, name.len(), ) as *mut zend_function; if res.is_null() { From 602a5830ae19787e27f1e669ba02a897b4a88d94 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 17 Nov 2023 18:39:02 +0100 Subject: [PATCH 2/3] Bump --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index f2af9623a..a48417551 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ repository = "https://github.com/davidcole1340/ext-php-rs" homepage = "https://github.com/davidcole1340/ext-php-rs" license = "MIT OR Apache-2.0" keywords = ["php", "ffi", "zend"] -version = "0.10.3" +version = "0.10.4" authors = ["David Cole "] edition = "2018" categories = ["api-bindings"] From c87dc4b9d980e72eb760dcda3c869f7882c3c204 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 17 Nov 2023 18:42:03 +0100 Subject: [PATCH 3/3] Fmt --- src/embed/mod.rs | 26 +++++++++++++++----------- src/types/class_object.rs | 3 ++- src/zend/ini_entry_def.rs | 5 +++-- src/zend/try_catch.rs | 10 ++++++---- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/embed/mod.rs b/src/embed/mod.rs index 0ad64a615..d8f914ff7 100644 --- a/src/embed/mod.rs +++ b/src/embed/mod.rs @@ -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 /// diff --git a/src/types/class_object.rs b/src/types/class_object.rs index 753933d39..9b63b500c 100644 --- a/src/types/class_object.rs +++ b/src/types/class_object.rs @@ -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::{ diff --git a/src/zend/ini_entry_def.rs b/src/zend/ini_entry_def.rs index 881730031..d9c8f64d8 100644 --- a/src/zend/ini_entry_def.rs +++ b/src/zend/ini_entry_def.rs @@ -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)`. +/// 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)`. pub type IniEntryDef = zend_ini_entry_def; impl IniEntryDef { diff --git a/src/zend/try_catch.rs b/src/zend/try_catch.rs index f74b427a5..37cd89655 100644 --- a/src/zend/try_catch.rs +++ b/src/zend/try_catch.rs @@ -18,7 +18,8 @@ pub(crate) unsafe extern "C" fn panic_wrapper 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 + RefUnwindSafe>(func: F) -> Result ! { ext_php_rs_zend_bailout(); }