Skip to content

Commit bc4a8d2

Browse files
committed
Adjust macros.
1 parent cbfa3af commit bc4a8d2

File tree

14 files changed

+160
-208
lines changed

14 files changed

+160
-208
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
- "7.2"
2727
- "7.3"
2828
- "7.4"
29+
- "8.0"
2930

3031
runs-on: ${{ matrix.os }}
3132
steps:

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ members = [
99

1010
# internal
1111
"examples/hello",
12-
"examples/hello-class",
13-
"examples/mini-curl",
12+
# "examples/hello-class",
13+
# "examples/mini-curl",
1414
]

examples/hello-class/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use phper::{
2-
c_str_ptr, php_fn, php_function, php_minfo, php_minfo_function, php_minit, php_minit_function,
3-
php_mshutdown, php_mshutdown_function, php_rinit, php_rinit_function, php_rshutdown,
2+
c_str_ptr, php_minfo_function, php_minit_function,
3+
php_mshutdown_function, php_rinit_function,
44
php_rshutdown_function,
55
sys::{
66
php_info_print_table_end, php_info_print_table_row, php_info_print_table_start,
@@ -13,7 +13,7 @@ use phper::{
1313
modules::{ModuleArgs, ModuleEntry, ModuleEntryBuilder},
1414
types::{ClassEntry, ExecuteData, SetVal, Value},
1515
},
16-
zend_get_module,
16+
php_get_module,
1717
};
1818
use std::{os::raw::c_char, ptr::null};
1919

@@ -142,7 +142,7 @@ static MODULE_ENTRY: ModuleEntry = ModuleEntryBuilder::new(
142142
.info_func(php_minfo!(module_info))
143143
.build();
144144

145-
#[zend_get_module]
145+
#[php_get_module]
146146
pub fn get_module() -> &'static ModuleEntry {
147147
&MODULE_ENTRY
148148
}

examples/hello/src/lib.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use phper::{
2-
c_str_ptr, php_fn, php_function, php_minfo, php_minfo_function, php_minit, php_minit_function,
3-
php_mshutdown, php_mshutdown_function, php_rinit, php_rinit_function, php_rshutdown,
4-
php_rshutdown_function,
2+
c_str_ptr, php_function, php_get_module, php_minfo_function, php_minit_function,
3+
php_mshutdown_function, php_rinit_function, php_rshutdown_function,
54
sys::{
65
php_info_print_table_end, php_info_print_table_row, php_info_print_table_start,
76
zend_function_entry, OnUpdateBool, PHP_INI_SYSTEM,
@@ -13,7 +12,6 @@ use phper::{
1312
modules::{ModuleArgs, ModuleEntry, ModuleEntryBuilder},
1413
types::{ExecuteData, SetVal},
1514
},
16-
zend_get_module,
1715
};
1816

1917
static SIMPLE_ENABLE: ModuleGlobals<bool> = ModuleGlobals::new(false);
@@ -77,7 +75,7 @@ static ARG_INFO_SAY_HELLO: MultiInternalArgInfo<1> =
7775

7876
static FUNCTION_ENTRIES: FunctionEntries<1> = FunctionEntries::new([zend_function_entry {
7977
fname: c_str_ptr!("say_hello"),
80-
handler: Some(php_fn!(say_hello)),
78+
handler: Some(say_hello),
8179
arg_info: ARG_INFO_SAY_HELLO.as_ptr(),
8280
num_args: 2,
8381
flags: 0,
@@ -88,14 +86,14 @@ static MODULE_ENTRY: ModuleEntry = ModuleEntryBuilder::new(
8886
c_str_ptr!(env!("CARGO_PKG_VERSION")),
8987
)
9088
.functions(FUNCTION_ENTRIES.as_ptr())
91-
.module_startup_func(php_minit!(module_init))
92-
.module_shutdown_func(php_mshutdown!(module_shutdown))
93-
.request_startup_func(php_rinit!(request_init))
94-
.request_shutdown_func(php_rshutdown!(request_shutdown))
95-
.info_func(php_minfo!(module_info))
89+
.module_startup_func(module_init)
90+
.module_shutdown_func(module_shutdown)
91+
.request_startup_func(request_init)
92+
.request_shutdown_func(request_shutdown)
93+
.info_func(module_info)
9694
.build();
9795

98-
#[zend_get_module]
96+
#[php_get_module]
9997
pub fn get_module() -> &'static ModuleEntry {
10098
&MODULE_ENTRY
10199
}

examples/mini-curl/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use phper::{
1414
modules::{ModuleArgs, ModuleEntry, ModuleEntryBuilder},
1515
types::{ClassEntry, ExecuteData, ReturnValue, SetVal, Value},
1616
},
17-
zend_get_module,
17+
php_get_module,
1818
};
1919

2020
static MINI_CURL_CE: ClassEntry = ClassEntry::new();
@@ -155,7 +155,7 @@ static MODULE_ENTRY: ModuleEntry = ModuleEntryBuilder::new(
155155
.info_func(php_minfo!(module_info))
156156
.build();
157157

158-
#[zend_get_module]
158+
#[php_get_module]
159159
pub fn get_module() -> &'static ModuleEntry {
160160
&MODULE_ENTRY
161161
}

phper-alloc/src/lib.rs

Lines changed: 74 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,78 @@
1-
#![feature(allocator_api)]
21
#![warn(rust_2018_idioms, clippy::dbg_macro, clippy::print_stdout)]
32

4-
use phper_sys::{_efree, _emalloc};
5-
use std::{
6-
alloc::{AllocError, AllocRef, Layout},
7-
ptr::{slice_from_raw_parts_mut, NonNull},
8-
};
3+
/// The Box which use php `emalloc` and `efree` to manage memory.
4+
/// TODO now feature `allocator_api` is still unstable, using global allocator instead.
5+
pub type EBox<T> = Box<T>;
96

10-
pub type EBox<T> = Box<T, Allocator>;
11-
pub type EVec<T> = Vec<T, Allocator>;
7+
/// The Vec which use php `emalloc` and `efree` to manage memory.
8+
/// TODO now feature `allocator_api` is still unstable, using global allocator instead.
9+
pub type EVec<T> = Vec<T>;
1210

13-
pub struct Allocator {
14-
#[cfg(phper_debug)]
15-
zend_filename: *const std::os::raw::c_char,
16-
#[cfg(phper_debug)]
17-
zend_lineno: u32,
18-
#[cfg(phper_debug)]
19-
zend_orig_filename: *const std::os::raw::c_char,
20-
#[cfg(phper_debug)]
21-
zend_orig_lineno: u32,
22-
}
23-
24-
impl Allocator {
25-
pub const fn new(
26-
#[cfg(phper_debug)] zend_filename: *const std::os::raw::c_char,
27-
#[cfg(phper_debug)] zend_lineno: u32,
28-
#[cfg(phper_debug)] zend_orig_filename: *const std::os::raw::c_char,
29-
#[cfg(phper_debug)] zend_orig_lineno: u32,
30-
) -> Self {
31-
Self {
32-
#[cfg(phper_debug)]
33-
zend_filename,
34-
#[cfg(phper_debug)]
35-
zend_lineno,
36-
#[cfg(phper_debug)]
37-
zend_orig_filename,
38-
#[cfg(phper_debug)]
39-
zend_orig_lineno,
40-
}
41-
}
42-
}
43-
44-
unsafe impl AllocRef for Allocator {
45-
fn alloc(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
46-
unsafe {
47-
#[cfg(phper_debug)]
48-
let ptr = _emalloc(
49-
layout.size(),
50-
self.zend_filename,
51-
self.zend_lineno,
52-
self.zend_orig_filename,
53-
self.zend_orig_lineno,
54-
);
55-
#[cfg(not(phper_debug))]
56-
let ptr = _emalloc(layout.size());
57-
58-
if ptr.is_null() {
59-
Err(AllocError)
60-
} else {
61-
let ptr = slice_from_raw_parts_mut(ptr.cast(), layout.size());
62-
Ok(NonNull::new_unchecked(ptr))
63-
}
64-
}
65-
}
66-
67-
unsafe fn dealloc(&self, ptr: NonNull<u8>, _layout: Layout) {
68-
// Not the correct position of `efree`, but can work!.
69-
#[cfg(phper_debug)]
70-
_efree(
71-
ptr.as_ptr().cast(),
72-
self.zend_filename,
73-
self.zend_lineno,
74-
self.zend_orig_filename,
75-
self.zend_orig_lineno,
76-
);
77-
#[cfg(not(phper_debug))]
78-
_efree(ptr.as_ptr().cast());
79-
}
80-
}
11+
// pub struct Allocator {
12+
// #[cfg(phper_debug)]
13+
// zend_filename: *const std::os::raw::c_char,
14+
// #[cfg(phper_debug)]
15+
// zend_lineno: u32,
16+
// #[cfg(phper_debug)]
17+
// zend_orig_filename: *const std::os::raw::c_char,
18+
// #[cfg(phper_debug)]
19+
// zend_orig_lineno: u32,
20+
// }
21+
//
22+
// impl Allocator {
23+
// pub const fn new(
24+
// #[cfg(phper_debug)] zend_filename: *const std::os::raw::c_char,
25+
// #[cfg(phper_debug)] zend_lineno: u32,
26+
// #[cfg(phper_debug)] zend_orig_filename: *const std::os::raw::c_char,
27+
// #[cfg(phper_debug)] zend_orig_lineno: u32,
28+
// ) -> Self {
29+
// Self {
30+
// #[cfg(phper_debug)]
31+
// zend_filename,
32+
// #[cfg(phper_debug)]
33+
// zend_lineno,
34+
// #[cfg(phper_debug)]
35+
// zend_orig_filename,
36+
// #[cfg(phper_debug)]
37+
// zend_orig_lineno,
38+
// }
39+
// }
40+
// }
41+
//
42+
// unsafe impl AllocRef for Allocator {
43+
// fn alloc(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
44+
// unsafe {
45+
// #[cfg(phper_debug)]
46+
// let ptr = _emalloc(
47+
// layout.size(),
48+
// self.zend_filename,
49+
// self.zend_lineno,
50+
// self.zend_orig_filename,
51+
// self.zend_orig_lineno,
52+
// );
53+
// #[cfg(not(phper_debug))]
54+
// let ptr = _emalloc(layout.size());
55+
//
56+
// if ptr.is_null() {
57+
// Err(AllocError)
58+
// } else {
59+
// let ptr = slice_from_raw_parts_mut(ptr.cast(), layout.size());
60+
// Ok(NonNull::new_unchecked(ptr))
61+
// }
62+
// }
63+
// }
64+
//
65+
// unsafe fn dealloc(&self, ptr: NonNull<u8>, _layout: Layout) {
66+
// // Not the correct position of `efree`, but can work!.
67+
// #[cfg(phper_debug)]
68+
// _efree(
69+
// ptr.as_ptr().cast(),
70+
// self.zend_filename,
71+
// self.zend_lineno,
72+
// self.zend_orig_filename,
73+
// self.zend_orig_lineno,
74+
// );
75+
// #[cfg(not(phper_debug))]
76+
// _efree(ptr.as_ptr().cast());
77+
// }
78+
// }

phper-macros/src/inner.rs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,16 @@ pub(crate) fn rename(input: TokenStream, prefix: impl ToString) -> TokenStream {
1010
result.into()
1111
}
1212

13-
pub(crate) fn hook_fn(input: TokenStream, prefix: impl ToString) -> TokenStream {
13+
pub(crate) fn hook_fn(input: TokenStream) -> TokenStream {
1414
let input = parse_macro_input!(input as ItemFn);
1515

16-
let name = prefix.to_string() + &input.sig.ident.to_string();
17-
let name = Ident::new(&name, input.sig.ident.span());
16+
let name = &input.sig.ident;
1817
let inputs = &input.sig.inputs;
1918
let ret = &input.sig.output;
2019
let body = &input.block;
2120
let attrs = &input.attrs;
2221

2322
let result = quote! {
24-
#[allow(dead_code)]
25-
#input
26-
2723
#(#attrs)*
2824
extern "C" fn #name(type_: ::std::os::raw::c_int, module_number: ::std::os::raw::c_int) -> ::std::os::raw::c_int {
2925
fn internal(#inputs) #ret {
@@ -43,20 +39,16 @@ pub(crate) fn hook_fn(input: TokenStream, prefix: impl ToString) -> TokenStream
4339
result.into()
4440
}
4541

46-
pub(crate) fn info_fn(input: TokenStream, prefix: impl ToString) -> TokenStream {
42+
pub(crate) fn info_fn(input: TokenStream) -> TokenStream {
4743
let input = parse_macro_input!(input as ItemFn);
4844

49-
let name = prefix.to_string() + &input.sig.ident.to_string();
50-
let name = Ident::new(&name, input.sig.ident.span());
45+
let name = &input.sig.ident;
5146
let inputs = &input.sig.inputs;
5247
let ret = &input.sig.output;
5348
let body = &input.block;
5449
let attrs = &input.attrs;
5550

5651
let result = quote! {
57-
#[allow(dead_code)]
58-
#input
59-
6052
#(#attrs)*
6153
extern "C" fn #name(zend_module: *mut ::phper::sys::zend_module_entry) {
6254
fn internal(#inputs) #ret {
@@ -77,17 +69,11 @@ pub(crate) fn php_function(_attr: TokenStream, input: TokenStream) -> TokenStrea
7769
let vis = &input.vis;
7870
let ret = &input.sig.output;
7971
let inputs = &input.sig.inputs;
80-
let name = Ident::new(
81-
&format!("zif_{}", &input.sig.ident.to_string()),
82-
input.sig.ident.span().clone(),
83-
);
72+
let name = &input.sig.ident;
8473
let body = &input.block;
8574
let attrs = &input.attrs;
8675

8776
let result = quote! {
88-
#[allow(dead_code)]
89-
#input
90-
9177
#(#attrs)*
9278
#vis extern "C" fn #name(
9379
execute_data: *mut ::phper::sys::zend_execute_data,
@@ -107,7 +93,7 @@ pub(crate) fn php_function(_attr: TokenStream, input: TokenStream) -> TokenStrea
10793
result.into()
10894
}
10995

110-
pub(crate) fn zend_get_module(_attr: TokenStream, input: TokenStream) -> TokenStream {
96+
pub(crate) fn php_get_module(_attr: TokenStream, input: TokenStream) -> TokenStream {
11197
let input = parse_macro_input!(input as ItemFn);
11298

11399
let vis = &input.vis;

0 commit comments

Comments
 (0)