Skip to content

Commit

Permalink
Merge pull request #2 from dmalusev/feat/ini-on-change
Browse files Browse the repository at this point in the history
Initial implementation for INI OnChange Callback
  • Loading branch information
Dusan Malusev authored Dec 3, 2023
2 parents 5eac1c0 + 868f74c commit 3877bab
Show file tree
Hide file tree
Showing 10 changed files with 293 additions and 134 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The framework that allows us to write PHP extensions using pure and safe Rust wh
### Necessary

- **rust** 1.74 or later
- **libclang** 9.0 or later
- **libclang** 14.0 or later
- **php** 8.1 or later

### Tested Support
Expand Down
4 changes: 1 addition & 3 deletions phper-alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ mod macros;
use phper_sys::*;
use std::{
borrow::Borrow,
convert::TryInto,
mem::{size_of, ManuallyDrop},
ops::{Deref, DerefMut},
};
Expand All @@ -37,11 +36,10 @@ impl<T> EBox<T> {
/// # Panic
///
/// Panic if `size_of::<T>()` equals zero.
#[allow(clippy::useless_conversion)]
pub fn new(x: T) -> Self {
unsafe {
assert_ne!(size_of::<T>(), 0);
let ptr: *mut T = phper_emalloc(size_of::<T>().try_into().unwrap()).cast();
let ptr: *mut T = phper_emalloc(size_of::<T>()).cast();
// TODO Deal with ptr is zero, when memory limit is reached.
ptr.write(x);
Self { ptr }
Expand Down
17 changes: 4 additions & 13 deletions phper-macros/src/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,26 @@

use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, ItemFn, Visibility};
use syn::{parse_macro_input, ItemFn};

pub(crate) fn php_get_module(_attr: TokenStream, input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as ItemFn);

let vis = &input.vis;
let ret = &input.sig.output;
let inputs = &input.sig.inputs;
let name = &input.sig.ident;
let body = &input.block;
let attrs = &input.attrs;

if name != "get_module" {
return quote! { compile_error!("function name with attribute `php_get_module` must be `get_module`") }.into();
}

if !matches!(vis, Visibility::Public(..)) {
return quote! { compile_error!("function `get_module` must be public"); }.into();
}

let result = quote! {
#[no_mangle]
#[doc(hidden)]
#(#attrs)*
#vis extern "C" fn #name() -> *const ::phper::sys::zend_module_entry {
fn internal(#inputs) #ret {
pub extern "C" fn get_module() -> *const ::phper::sys::zend_module_entry {
fn #name(#inputs) #ret {
#body
}
let internal: fn() -> ::phper::modules::Module = internal;
let internal: fn() -> ::phper::modules::Module = #name;
unsafe { internal().module_entry() }
}
};
Expand Down
13 changes: 13 additions & 0 deletions phper-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ fn main() {
// Block the `zend_ini_parse_quantity` because it's document causes the doc test to fail.
.blocklist_function("zend_ini_parse_quantity")
.clang_args(&includes)
.clang_args(&[
"-falign-functions",
"-flto=auto",
"-std=c17",
"-pedantic",
"-Wextra",
])
.derive_hash(true)
.derive_copy(true)
.derive_eq(true)
.derive_ord(true)
.derive_partialeq(true)
.derive_partialord(true)
.derive_default(true);

// iterate over the php include directories, and update the builder
Expand Down
11 changes: 4 additions & 7 deletions phper-sys/php_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@
#include <main/SAPI.h>
#include <zend_exceptions.h>
#include <zend_interfaces.h>

#include <zend_smart_str.h>

#if PHP_MAJOR_VERSION >= 8
#include <zend_observer.h>
#endif
#include <zend_smart_str.h>

typedef ZEND_INI_MH(phper_zend_ini_mh);

Expand Down Expand Up @@ -275,7 +271,7 @@ ZEND_FASTCALL void phper_smart_str_0(smart_str *str) {
}

ZEND_FASTCALL size_t phper_smart_str_get_len(const smart_str *str) {
return smart_str_get_len(str);
return smart_str_get_len((smart_str *)str);
}

ZEND_FASTCALL zend_string *phper_smart_str_extract(smart_str *str) {
Expand Down Expand Up @@ -556,7 +552,8 @@ ZEND_FASTCALL zend_internal_arg_info phper_zend_arg_info(bool pass_by_ref,
ZEND_FASTCALL zend_resource *
phper_register_persistent_resource(const zend_string *id, const void *ptr,
int le_id) {
return zend_register_persistent_resource_ex(id, ptr, le_id);
return zend_register_persistent_resource_ex((zend_string *)id, (void *)ptr,
le_id);
}

ZEND_FASTCALL int phper_zend_register_persistent_list_destructors(
Expand Down
Loading

0 comments on commit 3877bab

Please sign in to comment.