Skip to content

Commit

Permalink
Drop support for error messages via the InOutFuncs trait
Browse files Browse the repository at this point in the history
  • Loading branch information
workingjubilee committed Jun 25, 2024
1 parent 1a09c8d commit 3721045
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 40 deletions.
22 changes: 6 additions & 16 deletions pgrx-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -944,9 +944,9 @@ fn impl_postgres_type(ast: DeriveInput) -> syn::Result<proc_macro2::TokenStream>
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)]
Expand All @@ -963,13 +963,8 @@ fn impl_postgres_type(ast: DeriveInput) -> syn::Result<proc_macro2::TokenStream>
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)]
Expand All @@ -986,13 +981,8 @@ fn impl_postgres_type(ast: DeriveInput) -> syn::Result<proc_macro2::TokenStream>
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)]
Expand Down
25 changes: 1 addition & 24 deletions pgrx-tests/src/tests/fcinfo_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -319,10 +302,4 @@ mod tests {
fn test_null_strict_type() {
assert_eq!(Ok(None), Spi::get_one::<NullStrict>("SELECT null::NullStrict"));
}

#[pg_test]
#[should_panic(expected = "An error message")]
fn test_null_error_type() {
Spi::get_one::<NullError>("SELECT null::NullError").unwrap();
}
}

0 comments on commit 3721045

Please sign in to comment.