fix output for #[pg_extern(no_guard)]
@@ -64,24 +64,6 @@ impl PgGuardRewriter {
let func_span = func.span().clone();
let rewritten_args = self.rewrite_args(func.clone(), is_raw);
let rewritten_return_type = self.rewrite_return_type(func.clone());
-
- if no_guard {
- quote_spanned! {func_span=>
- #[no_mangle]
- #[allow(unused_variables)]
- #vis fn #func_name(fcinfo: pg_sys::FunctionCallInfo) -> pg_sys::Datum {
- #func
-
- let result = {
- #rewritten_args
-
- #func_name(#arg_list)
- };
-
- #rewritten_return_type
- }
- }
- } else {
let func_name_wrapper = Ident::new(
&format!("{}_wrapper", &func.sig.ident.to_string()),
func_span,
@@ -95,24 +77,40 @@ impl PgGuardRewriter {
} else {
Ident::new("result", Span::call_site())
};
- quote_spanned! {func_span=>
- #func
- #[no_mangle]
- #[allow(unused_variables)]
- #vis fn #func_name_wrapper(fcinfo: pg_sys::FunctionCallInfo) -> pg_sys::Datum {
+ let func_call = if no_guard {
+ quote! {
+ let result = {
+ #rewritten_args
+ #func_name(#arg_list)
+ };
+ }
+ } else {
+ quote! {
let #result_var_name = pgx::guard( || {
#rewritten_args
#func_name(#arg_list)
} );
+ }
+ };
+
+ quote_spanned! {func_span=>
+
+ #[inline]
+ #func
+
+ #[no_mangle]
+ #[allow(unused_variables)]
+ #vis fn #func_name_wrapper(fcinfo: pg_sys::FunctionCallInfo) -> pg_sys::Datum {
+
+ #func_call
#rewritten_return_type
}
}
}
- }
fn item_fn_without_rewrite(&self, mut func: ItemFn) -> proc_macro2::TokenStream {
// remember the original visibility and signature classifications as we want
