Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix aarch64 build (fixes #279) #280

Merged
merged 3 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"]
edition = "2018"
categories = ["api-bindings"]
Expand Down
26 changes: 15 additions & 11 deletions src/embed/mod.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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
///
Expand Down Expand Up @@ -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
///
Expand All @@ -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 {
Expand Down Expand Up @@ -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
///
Expand Down
3 changes: 2 additions & 1 deletion src/types/class_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{
fmt::Debug,
mem,
ops::{Deref, DerefMut},
os::raw::c_char,
ptr::{self, NonNull},
};

Expand Down Expand Up @@ -161,7 +162,7 @@ impl<T: RegisteredClass> ZendClassObject<T> {
}

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()?
Expand Down
4 changes: 2 additions & 2 deletions src/types/object.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions src/zend/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub type Function = zend_function;
impl Function {
pub fn try_from_function(name: &str) -> Option<Self> {
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;
}
Expand All @@ -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() {
Expand Down
5 changes: 3 additions & 2 deletions src/zend/ini_entry_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 6 additions & 4 deletions src/zend/try_catch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down Expand Up @@ -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();
}
Expand Down