File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33use proc_macro2:: TokenStream ;
44use quote:: quote;
55
6- use crate :: helpers:: function_name;
7-
86/// Please see [`crate::export`] for documentation.
9- pub ( crate ) fn export ( _attr : TokenStream , ts : TokenStream ) -> TokenStream {
10- let Some ( name) = function_name ( ts. clone ( ) ) else {
11- return "::core::compile_error!(\" The #[export] attribute must be used on a function.\" );"
12- . parse :: < TokenStream > ( )
13- . unwrap ( ) ;
14- } ;
7+ pub ( crate ) fn export ( f : syn:: ItemFn ) -> TokenStream {
8+ let name = & f. sig . ident ;
159
16- // This verifies that the function has the same signature as the declaration generated by
17- // bindgen. It makes use of the fact that all branches of an if/else must have the same type.
18- let signature_check = quote ! (
10+ quote ! {
11+ // This verifies that the function has the same signature as the declaration generated by
12+ // bindgen. It makes use of the fact that all branches of an if/else must have the same
13+ // type.
1914 const _: ( ) = {
2015 if true {
2116 :: kernel:: bindings:: #name
2217 } else {
2318 #name
2419 } ;
2520 } ;
26- ) ;
27-
28- let no_mangle = quote ! ( #[ no_mangle] ) ;
2921
30- TokenStream :: from_iter ( [ signature_check, no_mangle, ts] )
22+ #[ no_mangle]
23+ #f
24+ }
3125}
Original file line number Diff line number Diff line change 22
33use proc_macro2:: {
44 token_stream,
5- Ident ,
65 TokenStream ,
76 TokenTree , //
87} ;
@@ -50,23 +49,6 @@ impl AsciiLitStr {
5049 }
5150}
5251
53- /// Given a function declaration, finds the name of the function.
54- pub ( crate ) fn function_name ( input : TokenStream ) -> Option < Ident > {
55- let mut input = input. into_iter ( ) ;
56- while let Some ( token) = input. next ( ) {
57- match token {
58- TokenTree :: Ident ( i) if i == "fn" => {
59- if let Some ( TokenTree :: Ident ( i) ) = input. next ( ) {
60- return Some ( i) ;
61- }
62- return None ;
63- }
64- _ => continue ,
65- }
66- }
67- None
68- }
69-
7052pub ( crate ) fn file ( ) -> String {
7153 #[ cfg( not( CONFIG_RUSTC_HAS_SPAN_FILE ) ) ]
7254 {
Original file line number Diff line number Diff line change @@ -234,8 +234,9 @@ pub fn vtable(attr: TokenStream, input: TokenStream) -> TokenStream {
234234/// This macro is *not* the same as the C macros `EXPORT_SYMBOL_*`. All Rust symbols are currently
235235/// automatically exported with `EXPORT_SYMBOL_GPL`.
236236#[ proc_macro_attribute]
237- pub fn export ( attr : TokenStream , ts : TokenStream ) -> TokenStream {
238- export:: export ( attr. into ( ) , ts. into ( ) ) . into ( )
237+ pub fn export ( attr : TokenStream , input : TokenStream ) -> TokenStream {
238+ parse_macro_input ! ( attr as syn:: parse:: Nothing ) ;
239+ export:: export ( parse_macro_input ! ( input) ) . into ( )
239240}
240241
241242/// Like [`core::format_args!`], but automatically wraps arguments in [`kernel::fmt::Adapter`].
You can’t perform that action at this time.
0 commit comments