diff --git a/pgrx-macros/src/lib.rs b/pgrx-macros/src/lib.rs index 4e6291efc..14163d070 100644 --- a/pgrx-macros/src/lib.rs +++ b/pgrx-macros/src/lib.rs @@ -944,9 +944,9 @@ fn impl_postgres_type(ast: DeriveInput) -> syn::Result stream.extend(quote! { #[doc(hidden)] #[::pgrx::pgrx_macros::pg_extern(immutable,parallel_safe)] - pub fn #funcname_in #generics(input: Option<&#lifetime ::core::ffi::CStr>) -> Option<#name #generics> { + pub fn #funcname_in #generics(input: &#lifetime ::core::ffi::CStr) -> Option<#name #generics> { use ::pgrx::inoutfuncs::json_from_slice; - input.map(|cstr| json_from_slice(cstr.to_bytes()).ok()).flatten() + json_from_slice(input.to_bytes()).ok() } #[doc(hidden)] @@ -963,13 +963,8 @@ fn impl_postgres_type(ast: DeriveInput) -> syn::Result stream.extend(quote! { #[doc(hidden)] #[::pgrx::pgrx_macros::pg_extern(immutable,parallel_safe)] - pub fn #funcname_in #generics(input: Option<&::core::ffi::CStr>) -> Option<#name #generics> { - input.map_or_else(|| { - for m in <#name as ::pgrx::inoutfuncs::InOutFuncs>::NULL_ERROR_MESSAGE { - ::pgrx::pg_sys::error!("{m}"); - } - None - }, |i| Some(<#name as ::pgrx::inoutfuncs::InOutFuncs>::input(i))) + pub fn #funcname_in #generics(input: &::core::ffi::CStr) -> Option<#name #generics> { + Some(<#name as ::pgrx::inoutfuncs::InOutFuncs>::input(input)) } #[doc(hidden)] @@ -986,13 +981,8 @@ fn impl_postgres_type(ast: DeriveInput) -> syn::Result stream.extend(quote! { #[doc(hidden)] #[::pgrx::pgrx_macros::pg_extern(immutable,parallel_safe)] - pub fn #funcname_in #generics(input: Option<&::core::ffi::CStr>) -> Option<::pgrx::datum::PgVarlena<#name #generics>> { - input.map_or_else(|| { - for m in <#name as ::pgrx::inoutfuncs::PgVarlenaInOutFuncs>::NULL_ERROR_MESSAGE { - ::pgrx::pg_sys::error!("{m}"); - } - None - }, |i| Some(<#name as ::pgrx::inoutfuncs::PgVarlenaInOutFuncs>::input(i))) + pub fn #funcname_in #generics(input: &::core::ffi::CStr) -> Option<::pgrx::datum::PgVarlena<#name #generics>> { + Some(<#name as ::pgrx::inoutfuncs::PgVarlenaInOutFuncs>::input(input)) } #[doc(hidden)] diff --git a/pgrx-tests/src/tests/fcinfo_tests.rs b/pgrx-tests/src/tests/fcinfo_tests.rs index eb07adc31..7948053e5 100644 --- a/pgrx-tests/src/tests/fcinfo_tests.rs +++ b/pgrx-tests/src/tests/fcinfo_tests.rs @@ -141,30 +141,13 @@ impl InOutFuncs for NullStrict { // doesn't define a NULL_ERROR_MESSAGE } -#[derive(PostgresType, Serialize, Deserialize, Debug, PartialEq)] -#[inoutfuncs] -pub struct NullError {} - -impl InOutFuncs for NullError { - fn input(_input: &core::ffi::CStr) -> Self - where - Self: Sized, - { - NullError {} - } - - fn output(&self, _buffer: &mut StringInfo) {} - - const NULL_ERROR_MESSAGE: Option<&'static str> = Some("An error message"); -} - #[cfg(any(test, feature = "pg_test"))] #[pgrx::pg_schema] mod tests { #[allow(unused_imports)] use crate as pgrx_tests; - use super::{NullError, NullStrict}; + use super::NullStrict; use crate::tests::fcinfo_tests::same_name; use pgrx::prelude::*; use pgrx::{direct_pg_extern_function_call, IntoDatum}; @@ -319,10 +302,4 @@ mod tests { fn test_null_strict_type() { assert_eq!(Ok(None), Spi::get_one::("SELECT null::NullStrict")); } - - #[pg_test] - #[should_panic(expected = "An error message")] - fn test_null_error_type() { - Spi::get_one::("SELECT null::NullError").unwrap(); - } }