File tree 7 files changed +10
-91
lines changed
7 files changed +10
-91
lines changed Original file line number Diff line number Diff line change @@ -24,34 +24,6 @@ mod utils;
24
24
25
25
use proc_macro:: TokenStream ;
26
26
27
- /// C style string end with '\0'.
28
- ///
29
- /// # Examples
30
- ///
31
- /// ```no_test
32
- /// use std::ffi::CStr;
33
- ///
34
- /// assert_eq!(c_str!("foo"), unsafe {
35
- /// CStr::from_ptr("foo\0".as_ptr().cast())
36
- /// });
37
- /// ```
38
- #[ proc_macro]
39
- pub fn c_str ( input : TokenStream ) -> TokenStream {
40
- utils:: c_str ( input)
41
- }
42
-
43
- /// C style string end with '\0'.
44
- ///
45
- /// # Examples
46
- ///
47
- /// ```no_test
48
- /// assert_eq!(c_str_ptr!("foo"), "foo\0".as_ptr().cast());
49
- /// ```
50
- #[ proc_macro]
51
- pub fn c_str_ptr ( input : TokenStream ) -> TokenStream {
52
- utils:: c_str_ptr ( input)
53
- }
54
-
55
27
/// PHP module entry, wrap the `phper::modules::Module` write operation.
56
28
///
57
29
/// # Examples
Original file line number Diff line number Diff line change 7
7
// KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
8
8
// NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
9
9
// See the Mulan PSL v2 for more details.
10
-
11
- use proc_macro:: TokenStream ;
12
- use quote:: quote;
13
- use syn:: { parse_macro_input, Expr } ;
14
-
15
- pub ( crate ) fn c_str ( input : TokenStream ) -> TokenStream {
16
- let input = parse_macro_input ! ( input as Expr ) ;
17
- let result = quote ! {
18
- unsafe { :: std:: ffi:: CStr :: from_ptr( :: core:: concat!( #input, "\0 " ) . as_ptr( ) . cast( ) ) }
19
- } ;
20
- result. into ( )
21
- }
22
-
23
- pub ( crate ) fn c_str_ptr ( input : TokenStream ) -> TokenStream {
24
- let input = parse_macro_input ! ( input as Expr ) ;
25
- let result = quote ! {
26
- :: core:: concat!( #input, "\0 " ) . as_ptr( ) as * const :: std:: os:: raw:: c_char
27
- } ;
28
- result. into ( )
29
- }
Original file line number Diff line number Diff line change 7
7
// KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
8
8
// NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
9
9
// See the Mulan PSL v2 for more details.
10
-
11
- use phper_macros:: * ;
12
- use std:: ffi:: CStr ;
13
-
14
- #[ test]
15
- fn test_c_str ( ) {
16
- assert_eq ! ( c_str!( "foo" ) , unsafe {
17
- CStr :: from_ptr( "foo\0 " . as_ptr( ) . cast( ) )
18
- } ) ;
19
-
20
- assert_eq ! (
21
- {
22
- #[ allow( unused_unsafe) ]
23
- unsafe {
24
- c_str!( "bar" )
25
- }
26
- } ,
27
- unsafe { CStr :: from_ptr( "bar\0 " . as_ptr( ) . cast( ) ) }
28
- ) ;
29
- }
30
-
31
- #[ test]
32
- fn test_c_str_ptr ( ) {
33
- assert_eq ! ( c_str_ptr!( "foo" ) , "foo\0 " . as_ptr( ) . cast( ) ) ;
34
- }
Original file line number Diff line number Diff line change 10
10
11
11
//! Apis relate to [zend_ini_entry_def].
12
12
13
- use crate :: { c_str , sys:: * } ;
13
+ use crate :: sys:: * ;
14
14
use std:: {
15
15
ffi:: { c_int, CStr } ,
16
16
mem:: zeroed,
@@ -100,13 +100,7 @@ impl FromIniValue for bool {
100
100
#[ allow( clippy:: useless_conversion) ]
101
101
fn from_ini_value ( name : & str ) -> Self {
102
102
let s = <Option < & CStr > >:: from_ini_value ( name) ;
103
- [
104
- Some ( c_str ! ( "1" ) ) ,
105
- Some ( c_str ! ( "true" ) ) ,
106
- Some ( c_str ! ( "on" ) ) ,
107
- Some ( c_str ! ( "On" ) ) ,
108
- ]
109
- . contains ( & s)
103
+ [ Some ( c"1" ) , Some ( c"true" ) , Some ( c"on" ) , Some ( c"On" ) ] . contains ( & s)
110
104
}
111
105
}
112
106
Original file line number Diff line number Diff line change 11
11
//! Apis relate to [zend_module_entry].
12
12
13
13
use crate :: {
14
- c_str_ptr,
15
14
classes:: { ClassEntity , InterfaceEntity } ,
16
15
constants:: Constant ,
17
16
errors:: Throwable ,
@@ -105,10 +104,10 @@ unsafe extern "C" fn module_info(zend_module: *mut zend_module_entry) {
105
104
106
105
php_info_print_table_start ( ) ;
107
106
if !module. version . as_bytes ( ) . is_empty ( ) {
108
- php_info_print_table_row ( 2 , c_str_ptr ! ( "version" ) , module. version . as_ptr ( ) ) ;
107
+ php_info_print_table_row ( 2 , c "version", module. version . as_ptr ( ) ) ;
109
108
}
110
109
if !module. author . as_bytes ( ) . is_empty ( ) {
111
- php_info_print_table_row ( 2 , c_str_ptr ! ( "authors" ) , module. author . as_ptr ( ) ) ;
110
+ php_info_print_table_row ( 2 , c "authors", module. author . as_ptr ( ) ) ;
112
111
}
113
112
for ( key, value) in & module. infos {
114
113
php_info_print_table_row ( 2 , key. as_ptr ( ) , value. as_ptr ( ) ) ;
Original file line number Diff line number Diff line change 10
10
11
11
//! Apis relate to PHP types.
12
12
13
- use crate :: { c_str , sys:: * } ;
13
+ use crate :: sys:: * ;
14
14
use derive_more:: From ;
15
15
use std:: {
16
16
ffi:: CStr ,
@@ -133,10 +133,10 @@ impl TypeInfo {
133
133
let t = get_base_type_by_raw ( self . t ) ;
134
134
135
135
if t == IS_UNDEF {
136
- return c_str ! ( "undef" ) ;
136
+ return c "undef";
137
137
}
138
138
if t == IS_REFERENCE {
139
- return c_str ! ( "reference" ) ;
139
+ return c "reference";
140
140
}
141
141
142
142
let s = zend_get_type_by_const ( t as c_int ) ;
@@ -145,10 +145,10 @@ impl TypeInfo {
145
145
// Compact with PHP7.
146
146
let bs = s. to_bytes ( ) ;
147
147
if bs == b"boolean" {
148
- return c_str ! ( "bool" ) ;
148
+ return c "bool";
149
149
}
150
150
if bs == b"integer" {
151
- return c_str ! ( "int" ) ;
151
+ return c "int";
152
152
}
153
153
154
154
s
Original file line number Diff line number Diff line change 9
9
// See the Mulan PSL v2 for more details.
10
10
11
11
use phper:: {
12
- c_str,
13
12
ini:: { ini_get, Policy } ,
14
13
modules:: Module ,
15
14
} ;
@@ -33,7 +32,7 @@ pub fn integrate(module: &mut Module) {
33
32
assert_eq ! ( ini_get:: <f64 >( "INTEGRATE_INI_DOUBLE" ) , 200. ) ;
34
33
assert_eq ! (
35
34
ini_get:: <Option <& CStr >>( "INTEGRATE_INI_STRING" ) ,
36
- Some ( c_str! ( "something" ) )
35
+ Some ( c "something")
37
36
) ;
38
37
Ok :: < _ , Infallible > ( ( ) )
39
38
} ) ;
You can’t perform that action at this time.
0 commit comments