diff --git a/phper-macros/src/lib.rs b/phper-macros/src/lib.rs index f8387cfe..61cc54b9 100644 --- a/phper-macros/src/lib.rs +++ b/phper-macros/src/lib.rs @@ -24,34 +24,6 @@ mod utils; use proc_macro::TokenStream; -/// C style string end with '\0'. -/// -/// # Examples -/// -/// ```no_test -/// use std::ffi::CStr; -/// -/// assert_eq!(c_str!("foo"), unsafe { -/// CStr::from_ptr("foo\0".as_ptr().cast()) -/// }); -/// ``` -#[proc_macro] -pub fn c_str(input: TokenStream) -> TokenStream { - utils::c_str(input) -} - -/// C style string end with '\0'. -/// -/// # Examples -/// -/// ```no_test -/// assert_eq!(c_str_ptr!("foo"), "foo\0".as_ptr().cast()); -/// ``` -#[proc_macro] -pub fn c_str_ptr(input: TokenStream) -> TokenStream { - utils::c_str_ptr(input) -} - /// PHP module entry, wrap the `phper::modules::Module` write operation. /// /// # Examples diff --git a/phper-macros/src/utils.rs b/phper-macros/src/utils.rs index ca5f65c6..0efeeb85 100644 --- a/phper-macros/src/utils.rs +++ b/phper-macros/src/utils.rs @@ -7,23 +7,3 @@ // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO // NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. // See the Mulan PSL v2 for more details. - -use proc_macro::TokenStream; -use quote::quote; -use syn::{parse_macro_input, Expr}; - -pub(crate) fn c_str(input: TokenStream) -> TokenStream { - let input = parse_macro_input!(input as Expr); - let result = quote! { - unsafe { ::std::ffi::CStr::from_ptr(::core::concat!(#input, "\0").as_ptr().cast()) } - }; - result.into() -} - -pub(crate) fn c_str_ptr(input: TokenStream) -> TokenStream { - let input = parse_macro_input!(input as Expr); - let result = quote! { - ::core::concat!(#input, "\0").as_ptr() as *const ::std::os::raw::c_char - }; - result.into() -} diff --git a/phper-macros/tests/integration.rs b/phper-macros/tests/integration.rs index d3a0262c..0efeeb85 100644 --- a/phper-macros/tests/integration.rs +++ b/phper-macros/tests/integration.rs @@ -7,28 +7,3 @@ // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO // NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. // See the Mulan PSL v2 for more details. - -use phper_macros::*; -use std::ffi::CStr; - -#[test] -fn test_c_str() { - assert_eq!(c_str!("foo"), unsafe { - CStr::from_ptr("foo\0".as_ptr().cast()) - }); - - assert_eq!( - { - #[allow(unused_unsafe)] - unsafe { - c_str!("bar") - } - }, - unsafe { CStr::from_ptr("bar\0".as_ptr().cast()) } - ); -} - -#[test] -fn test_c_str_ptr() { - assert_eq!(c_str_ptr!("foo"), "foo\0".as_ptr().cast()); -} diff --git a/phper/src/ini.rs b/phper/src/ini.rs index 53bbeff0..c042a58e 100644 --- a/phper/src/ini.rs +++ b/phper/src/ini.rs @@ -10,7 +10,7 @@ //! Apis relate to [zend_ini_entry_def]. -use crate::{c_str, sys::*}; +use crate::sys::*; use std::{ ffi::{c_int, CStr}, mem::zeroed, @@ -100,13 +100,7 @@ impl FromIniValue for bool { #[allow(clippy::useless_conversion)] fn from_ini_value(name: &str) -> Self { let s = >::from_ini_value(name); - [ - Some(c_str!("1")), - Some(c_str!("true")), - Some(c_str!("on")), - Some(c_str!("On")), - ] - .contains(&s) + [Some(c"1"), Some(c"true"), Some(c"on"), Some(c"On")].contains(&s) } } diff --git a/phper/src/modules.rs b/phper/src/modules.rs index eb903a96..8d408fd9 100644 --- a/phper/src/modules.rs +++ b/phper/src/modules.rs @@ -11,7 +11,6 @@ //! Apis relate to [zend_module_entry]. use crate::{ - c_str_ptr, classes::{ClassEntity, InterfaceEntity}, constants::Constant, errors::Throwable, @@ -105,10 +104,10 @@ unsafe extern "C" fn module_info(zend_module: *mut zend_module_entry) { php_info_print_table_start(); if !module.version.as_bytes().is_empty() { - php_info_print_table_row(2, c_str_ptr!("version"), module.version.as_ptr()); + php_info_print_table_row(2, c"version", module.version.as_ptr()); } if !module.author.as_bytes().is_empty() { - php_info_print_table_row(2, c_str_ptr!("authors"), module.author.as_ptr()); + php_info_print_table_row(2, c"authors", module.author.as_ptr()); } for (key, value) in &module.infos { php_info_print_table_row(2, key.as_ptr(), value.as_ptr()); diff --git a/phper/src/types.rs b/phper/src/types.rs index d04e4ee2..4321127f 100644 --- a/phper/src/types.rs +++ b/phper/src/types.rs @@ -10,7 +10,7 @@ //! Apis relate to PHP types. -use crate::{c_str, sys::*}; +use crate::sys::*; use derive_more::From; use std::{ ffi::CStr, @@ -133,10 +133,10 @@ impl TypeInfo { let t = get_base_type_by_raw(self.t); if t == IS_UNDEF { - return c_str!("undef"); + return c"undef"; } if t == IS_REFERENCE { - return c_str!("reference"); + return c"reference"; } let s = zend_get_type_by_const(t as c_int); @@ -145,10 +145,10 @@ impl TypeInfo { // Compact with PHP7. let bs = s.to_bytes(); if bs == b"boolean" { - return c_str!("bool"); + return c"bool"; } if bs == b"integer" { - return c_str!("int"); + return c"int"; } s diff --git a/tests/integration/src/ini.rs b/tests/integration/src/ini.rs index b1f102b8..cf949833 100644 --- a/tests/integration/src/ini.rs +++ b/tests/integration/src/ini.rs @@ -9,7 +9,6 @@ // See the Mulan PSL v2 for more details. use phper::{ - c_str, ini::{ini_get, Policy}, modules::Module, }; @@ -33,7 +32,7 @@ pub fn integrate(module: &mut Module) { assert_eq!(ini_get::("INTEGRATE_INI_DOUBLE"), 200.); assert_eq!( ini_get::>("INTEGRATE_INI_STRING"), - Some(c_str!("something")) + Some(c"something") ); Ok::<_, Infallible>(()) });