From 4b867ec899a621ac4bdf73ec9feea75222029a4d Mon Sep 17 00:00:00 2001 From: "Eric B. Ridge" Date: Wed, 30 Mar 2022 10:11:31 -0400 Subject: [PATCH 01/17] Remove FromDatum::NEEDS_TYPID const This constant was set to false in all every `FromDatum` implementation, and simply isn't necessary. Further changes to `FromDatum` are going to change how this idea worked in the first place. --- pgx/src/datum/date.rs | 1 - pgx/src/datum/from.rs | 19 ------------------- pgx/src/datum/geo.rs | 1 - pgx/src/datum/tuples.rs | 2 -- pgx/src/datum/varlena.rs | 1 - pgx/src/fcinfo.rs | 12 ++---------- pgx/src/rel.rs | 1 - 7 files changed, 2 insertions(+), 35 deletions(-) diff --git a/pgx/src/datum/date.rs b/pgx/src/datum/date.rs index 08983acef..b580b8b14 100644 --- a/pgx/src/datum/date.rs +++ b/pgx/src/datum/date.rs @@ -14,7 +14,6 @@ use time::format_description::FormatItem; #[derive(Debug)] pub struct Date(time::Date); impl FromDatum for Date { - const NEEDS_TYPID: bool = false; #[inline] unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _typoid: u32) -> Option { if is_null { diff --git a/pgx/src/datum/from.rs b/pgx/src/datum/from.rs index 6b6f02e4f..53a00c98f 100644 --- a/pgx/src/datum/from.rs +++ b/pgx/src/datum/from.rs @@ -22,7 +22,6 @@ use std::ffi::CStr; /// If implementing this, also implement `IntoDatum` for the reverse /// conversion. pub trait FromDatum { - const NEEDS_TYPID: bool = true; /// ## Safety /// /// This method is inherently unsafe as the `datum` argument can represent an arbitrary @@ -66,7 +65,6 @@ pub trait FromDatum { /// for pg_sys::Datum impl FromDatum for pg_sys::Datum { - const NEEDS_TYPID: bool = false; #[inline] unsafe fn from_datum( datum: pg_sys::Datum, @@ -83,7 +81,6 @@ impl FromDatum for pg_sys::Datum { /// for bool impl FromDatum for bool { - const NEEDS_TYPID: bool = false; #[inline] unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _: pg_sys::Oid) -> Option { if is_null { @@ -96,7 +93,6 @@ impl FromDatum for bool { /// for `"char"` impl FromDatum for i8 { - const NEEDS_TYPID: bool = false; #[inline] unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _: pg_sys::Oid) -> Option { if is_null { @@ -109,7 +105,6 @@ impl FromDatum for i8 { /// for smallint impl FromDatum for i16 { - const NEEDS_TYPID: bool = false; #[inline] unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _: pg_sys::Oid) -> Option { if is_null { @@ -122,7 +117,6 @@ impl FromDatum for i16 { /// for integer impl FromDatum for i32 { - const NEEDS_TYPID: bool = false; #[inline] unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _: pg_sys::Oid) -> Option { if is_null { @@ -135,7 +129,6 @@ impl FromDatum for i32 { /// for oid impl FromDatum for u32 { - const NEEDS_TYPID: bool = false; #[inline] unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _: pg_sys::Oid) -> Option { if is_null { @@ -148,7 +141,6 @@ impl FromDatum for u32 { /// for bigint impl FromDatum for i64 { - const NEEDS_TYPID: bool = false; #[inline] unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _: pg_sys::Oid) -> Option { if is_null { @@ -161,7 +153,6 @@ impl FromDatum for i64 { /// for real impl FromDatum for f32 { - const NEEDS_TYPID: bool = false; #[inline] unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _: pg_sys::Oid) -> Option { if is_null { @@ -174,7 +165,6 @@ impl FromDatum for f32 { /// for double precision impl FromDatum for f64 { - const NEEDS_TYPID: bool = false; #[inline] unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _: pg_sys::Oid) -> Option { if is_null { @@ -187,7 +177,6 @@ impl FromDatum for f64 { /// for text, varchar impl<'a> FromDatum for &'a str { - const NEEDS_TYPID: bool = false; #[inline] unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _: pg_sys::Oid) -> Option<&'a str> { if is_null { @@ -232,7 +221,6 @@ impl<'a> FromDatum for &'a str { /// /// This returns a **copy**, allocated and managed by Rust, of the underlying `varlena` Datum impl FromDatum for String { - const NEEDS_TYPID: bool = false; #[inline] unsafe fn from_datum( datum: pg_sys::Datum, @@ -248,7 +236,6 @@ impl FromDatum for String { } impl FromDatum for char { - const NEEDS_TYPID: bool = false; #[inline] unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, typoid: pg_sys::Oid) -> Option { let refstr: Option<&str> = FromDatum::from_datum(datum, is_null, typoid); @@ -261,7 +248,6 @@ impl FromDatum for char { /// for cstring impl<'a> FromDatum for &'a std::ffi::CStr { - const NEEDS_TYPID: bool = false; #[inline] unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _: pg_sys::Oid) -> Option<&'a CStr> { if is_null { @@ -277,7 +263,6 @@ impl<'a> FromDatum for &'a std::ffi::CStr { } impl<'a> FromDatum for &'a crate::cstr_core::CStr { - const NEEDS_TYPID: bool = false; #[inline] unsafe fn from_datum( datum: pg_sys::Datum, @@ -298,7 +283,6 @@ impl<'a> FromDatum for &'a crate::cstr_core::CStr { /// for bytea impl<'a> FromDatum for &'a [u8] { - const NEEDS_TYPID: bool = false; #[inline] unsafe fn from_datum(datum: usize, is_null: bool, _typoid: u32) -> Option<&'a [u8]> { if is_null { @@ -340,7 +324,6 @@ impl<'a> FromDatum for &'a [u8] { } impl FromDatum for Vec { - const NEEDS_TYPID: bool = false; #[inline] unsafe fn from_datum(datum: usize, is_null: bool, typoid: u32) -> Option> { if is_null { @@ -363,7 +346,6 @@ impl FromDatum for Vec { /// for NULL -- always converts to a `None`, even if the is_null argument is false impl FromDatum for () { - const NEEDS_TYPID: bool = false; #[inline] unsafe fn from_datum(_datum: pg_sys::Datum, _is_null: bool, _: pg_sys::Oid) -> Option<()> { None @@ -372,7 +354,6 @@ impl FromDatum for () { /// for user types impl FromDatum for PgBox { - const NEEDS_TYPID: bool = false; #[inline] unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _: pg_sys::Oid) -> Option { if is_null { diff --git a/pgx/src/datum/geo.rs b/pgx/src/datum/geo.rs index f17842056..c16d65647 100644 --- a/pgx/src/datum/geo.rs +++ b/pgx/src/datum/geo.rs @@ -10,7 +10,6 @@ Use of this source code is governed by the MIT license that can be found in the use crate::{direct_function_call_as_datum, pg_sys, FromDatum, IntoDatum}; impl FromDatum for pg_sys::BOX { - const NEEDS_TYPID: bool = false; unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _: pg_sys::Oid) -> Option where Self: Sized, diff --git a/pgx/src/datum/tuples.rs b/pgx/src/datum/tuples.rs index d0a719f33..a55792efc 100644 --- a/pgx/src/datum/tuples.rs +++ b/pgx/src/datum/tuples.rs @@ -49,7 +49,6 @@ where A: FromDatum + IntoDatum, B: FromDatum + IntoDatum, { - const NEEDS_TYPID: bool = A::NEEDS_TYPID || B::NEEDS_TYPID; unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, typoid: pg_sys::Oid) -> Option where Self: Sized, @@ -80,7 +79,6 @@ where B: FromDatum + IntoDatum, C: FromDatum + IntoDatum, { - const NEEDS_TYPID: bool = A::NEEDS_TYPID || B::NEEDS_TYPID || C::NEEDS_TYPID; unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, typoid: pg_sys::Oid) -> Option where Self: Sized, diff --git a/pgx/src/datum/varlena.rs b/pgx/src/datum/varlena.rs index df3a6a2c2..88d0c8b45 100644 --- a/pgx/src/datum/varlena.rs +++ b/pgx/src/datum/varlena.rs @@ -298,7 +298,6 @@ impl FromDatum for PgVarlena where T: Copy + Sized, { - const NEEDS_TYPID: bool = false; unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _typoid: u32) -> Option { if is_null { None diff --git a/pgx/src/fcinfo.rs b/pgx/src/fcinfo.rs index 1f693b101..8802cbb97 100644 --- a/pgx/src/fcinfo.rs +++ b/pgx/src/fcinfo.rs @@ -95,11 +95,7 @@ mod pg_10_11 { let datum = unsafe { fcinfo.as_ref() }.unwrap().arg[num]; let isnull = pg_arg_is_null(fcinfo, num); unsafe { - let typid = if T::NEEDS_TYPID { - crate::get_getarg_type(fcinfo, num) - } else { - pg_sys::InvalidOid - }; + let typid = pg_sys::InvalidOid; T::from_datum(datum, isnull, typid) } } @@ -138,11 +134,7 @@ mod pg_12_13_14 { pub fn pg_getarg(fcinfo: pg_sys::FunctionCallInfo, num: usize) -> Option { let datum = get_nullable_datum(fcinfo, num); unsafe { - let typid = if T::NEEDS_TYPID { - crate::get_getarg_type(fcinfo, num) - } else { - pg_sys::InvalidOid - }; + let typid = pg_sys::InvalidOid; T::from_datum(datum.value, datum.isnull, typid) } } diff --git a/pgx/src/rel.rs b/pgx/src/rel.rs index c376e1e3b..a0170ab1e 100644 --- a/pgx/src/rel.rs +++ b/pgx/src/rel.rs @@ -308,7 +308,6 @@ impl Clone for PgRelation { } impl FromDatum for PgRelation { - const NEEDS_TYPID: bool = false; unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _typoid: u32) -> Option { if is_null { None From cd50460db49a782ee8bfd60c8da4c264f9361d21 Mon Sep 17 00:00:00 2001 From: "Eric B. Ridge" Date: Wed, 30 Mar 2022 10:50:31 -0400 Subject: [PATCH 02/17] Remove the `typid` argument from `FromDatum::from_datum()`. This argument was never actually used, only passed around. And in many cases it was set to `pg_sys::InvalidOid` anyways. --- pgx-examples/bgworker/src/lib.rs | 2 +- pgx-macros/src/lib.rs | 2 +- pgx/src/datum/anyarray.rs | 15 ++---- pgx/src/datum/anyelement.rs | 15 ++---- pgx/src/datum/array.rs | 33 +++---------- pgx/src/datum/date.rs | 2 +- pgx/src/datum/from.rs | 57 +++++++++-------------- pgx/src/datum/geo.rs | 4 +- pgx/src/datum/inet.rs | 2 +- pgx/src/datum/internal.rs | 2 +- pgx/src/datum/item_pointer_data.rs | 6 +-- pgx/src/datum/json.rs | 10 ++-- pgx/src/datum/numeric.rs | 2 +- pgx/src/datum/time.rs | 2 +- pgx/src/datum/time_stamp.rs | 7 ++- pgx/src/datum/time_stamp_with_timezone.rs | 9 +--- pgx/src/datum/time_with_timezone.rs | 4 +- pgx/src/datum/tuples.rs | 18 +++---- pgx/src/datum/uuid.rs | 2 +- pgx/src/datum/varlena.rs | 6 +-- pgx/src/fcinfo.rs | 14 ++---- pgx/src/htup.rs | 14 ++---- pgx/src/rel.rs | 2 +- pgx/src/spi.rs | 6 +-- 24 files changed, 80 insertions(+), 156 deletions(-) diff --git a/pgx-examples/bgworker/src/lib.rs b/pgx-examples/bgworker/src/lib.rs index c3b23604e..9b7bdfa5a 100644 --- a/pgx-examples/bgworker/src/lib.rs +++ b/pgx-examples/bgworker/src/lib.rs @@ -40,7 +40,7 @@ pub extern "C" fn _PG_init() { #[pg_guard] #[no_mangle] pub extern "C" fn background_worker_main(arg: pg_sys::Datum) { - let arg = unsafe { i32::from_datum(arg, false, pg_sys::INT4OID) }; + let arg = unsafe { i32::from_datum(arg, false) }; // these are the signals we want to receive. If we don't attach the SIGTERM handler, then // we'll never be able to exit via an external notification diff --git a/pgx-macros/src/lib.rs b/pgx-macros/src/lib.rs index 4ca631db5..9dea84fd3 100644 --- a/pgx-macros/src/lib.rs +++ b/pgx-macros/src/lib.rs @@ -642,7 +642,7 @@ fn impl_postgres_enum(ast: DeriveInput) -> proc_macro2::TokenStream { stream.extend(quote! { impl pgx::FromDatum for #enum_ident { #[inline] - unsafe fn from_datum(datum: pgx::pg_sys::Datum, is_null: bool, typeoid: pgx::pg_sys::Oid) -> Option<#enum_ident> { + unsafe fn from_datum(datum: pgx::pg_sys::Datum, is_null: bool) -> Option<#enum_ident> { if is_null { None } else { diff --git a/pgx/src/datum/anyarray.rs b/pgx/src/datum/anyarray.rs index 12806bb1d..459c59b6c 100644 --- a/pgx/src/datum/anyarray.rs +++ b/pgx/src/datum/anyarray.rs @@ -12,7 +12,6 @@ use crate::{pg_sys, FromDatum, IntoDatum}; #[derive(Debug, Clone, Copy)] pub struct AnyArray { datum: pg_sys::Datum, - typoid: pg_sys::Oid, } impl AnyArray { @@ -20,27 +19,19 @@ impl AnyArray { self.datum } - pub fn oid(&self) -> pg_sys::Oid { - self.typoid - } - #[inline] pub fn into(&self) -> Option { - unsafe { T::from_datum(self.datum(), false, self.oid()) } + unsafe { T::from_datum(self.datum(), false) } } } impl FromDatum for AnyArray { #[inline] - unsafe fn from_datum( - datum: pg_sys::Datum, - is_null: bool, - typoid: pg_sys::Oid, - ) -> Option { + unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool) -> Option { if is_null { None } else { - Some(AnyArray { datum, typoid }) + Some(AnyArray { datum }) } } } diff --git a/pgx/src/datum/anyelement.rs b/pgx/src/datum/anyelement.rs index 3e3cc4fc7..d393a1d16 100644 --- a/pgx/src/datum/anyelement.rs +++ b/pgx/src/datum/anyelement.rs @@ -12,7 +12,6 @@ use crate::{pg_sys, FromDatum, IntoDatum}; #[derive(Debug, Clone, Copy)] pub struct AnyElement { datum: pg_sys::Datum, - typoid: pg_sys::Oid, } impl AnyElement { @@ -20,27 +19,19 @@ impl AnyElement { self.datum } - pub fn oid(&self) -> pg_sys::Oid { - self.typoid - } - #[inline] pub fn into(&self) -> Option { - unsafe { T::from_datum(self.datum(), false, self.oid()) } + unsafe { T::from_datum(self.datum(), false) } } } impl FromDatum for AnyElement { #[inline] - unsafe fn from_datum( - datum: pg_sys::Datum, - is_null: bool, - typoid: pg_sys::Oid, - ) -> Option { + unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool) -> Option { if is_null { None } else { - Some(AnyElement { datum, typoid }) + Some(AnyElement { datum }) } } } diff --git a/pgx/src/datum/array.rs b/pgx/src/datum/array.rs index 16525f9a9..25a7fbbcb 100644 --- a/pgx/src/datum/array.rs +++ b/pgx/src/datum/array.rs @@ -18,7 +18,6 @@ pub struct Array<'a, T: FromDatum> { array_type: *mut pg_sys::ArrayType, elements: *mut pg_sys::Datum, nulls: *mut bool, - typoid: pg_sys::Oid, nelems: usize, elem_slice: &'a [pg_sys::Datum], null_slice: &'a [bool], @@ -63,7 +62,6 @@ impl<'a, T: FromDatum> Array<'a, T> { array_type: std::ptr::null_mut(), elements, nulls, - typoid: pg_sys::InvalidOid, nelems, elem_slice: std::slice::from_raw_parts(elements, nelems), null_slice: std::slice::from_raw_parts(nulls, nelems), @@ -76,7 +74,6 @@ impl<'a, T: FromDatum> Array<'a, T> { array_type: *mut pg_sys::ArrayType, elements: *mut pg_sys::Datum, nulls: *mut bool, - typoid: pg_sys::Oid, nelems: usize, ) -> Self { Array:: { @@ -84,7 +81,6 @@ impl<'a, T: FromDatum> Array<'a, T> { array_type, elements, nulls, - typoid, nelems, elem_slice: std::slice::from_raw_parts(elements, nelems), null_slice: std::slice::from_raw_parts(nulls, nelems), @@ -153,7 +149,7 @@ impl<'a, T: FromDatum> Array<'a, T> { if i >= self.nelems { None } else { - Some(unsafe { T::from_datum(self.elem_slice[i], self.null_slice[i], self.typoid) }) + Some(unsafe { T::from_datum(self.elem_slice[i], self.null_slice[i]) }) } } } @@ -277,7 +273,7 @@ impl<'a, T: FromDatum> Drop for Array<'a, T> { impl<'a, T: FromDatum> FromDatum for Array<'a, T> { #[inline] - unsafe fn from_datum(datum: usize, is_null: bool, typoid: u32) -> Option> { + unsafe fn from_datum(datum: usize, is_null: bool) -> Option> { if is_null { None } else if datum == 0 { @@ -316,31 +312,20 @@ impl<'a, T: FromDatum> FromDatum for Array<'a, T> { &mut nelems, ); - Some(Array::from_pg( - ptr, - array, - elements, - nulls, - typoid, - nelems as usize, - )) + Some(Array::from_pg(ptr, array, elements, nulls, nelems as usize)) } } } impl FromDatum for Vec { #[inline] - unsafe fn from_datum( - datum: pg_sys::Datum, - is_null: bool, - typoid: pg_sys::Oid, - ) -> Option> { + unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool) -> Option> { if is_null { None } else if datum == 0 { panic!("array was flagged not null but datum is zero"); } else { - let array = Array::::from_datum(datum, is_null, typoid).unwrap(); + let array = Array::::from_datum(datum, is_null).unwrap(); let mut v = Vec::with_capacity(array.len()); for element in array.iter() { @@ -353,17 +338,13 @@ impl FromDatum for Vec { impl FromDatum for Vec> { #[inline] - unsafe fn from_datum( - datum: pg_sys::Datum, - is_null: bool, - typoid: pg_sys::Oid, - ) -> Option>> { + unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool) -> Option>> { if is_null { None } else if datum == 0 { panic!("array was flagged not null but datum is zero"); } else { - let array = Array::::from_datum(datum, is_null, typoid).unwrap(); + let array = Array::::from_datum(datum, is_null).unwrap(); let mut v = Vec::with_capacity(array.len()); for element in array.iter() { diff --git a/pgx/src/datum/date.rs b/pgx/src/datum/date.rs index b580b8b14..980681a8b 100644 --- a/pgx/src/datum/date.rs +++ b/pgx/src/datum/date.rs @@ -15,7 +15,7 @@ use time::format_description::FormatItem; pub struct Date(time::Date); impl FromDatum for Date { #[inline] - unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _typoid: u32) -> Option { + unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool) -> Option { if is_null { None } else { diff --git a/pgx/src/datum/from.rs b/pgx/src/datum/from.rs index 53a00c98f..567f0bc58 100644 --- a/pgx/src/datum/from.rs +++ b/pgx/src/datum/from.rs @@ -33,7 +33,7 @@ pub trait FromDatum { /// /// If, however, you're providing an arbitrary datum value, it needs to be considered unsafe /// and that unsafeness should be propagated through your API. - unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, typoid: pg_sys::Oid) -> Option + unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool) -> Option where Self: Sized; @@ -54,23 +54,18 @@ pub trait FromDatum { mut memory_context: PgMemoryContexts, datum: pg_sys::Datum, is_null: bool, - typoid: pg_sys::Oid, ) -> Option where Self: Sized, { - memory_context.switch_to(|_| FromDatum::from_datum(datum, is_null, typoid)) + memory_context.switch_to(|_| FromDatum::from_datum(datum, is_null)) } } /// for pg_sys::Datum impl FromDatum for pg_sys::Datum { #[inline] - unsafe fn from_datum( - datum: pg_sys::Datum, - is_null: bool, - _: pg_sys::Oid, - ) -> Option { + unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool) -> Option { if is_null { None } else { @@ -82,7 +77,7 @@ impl FromDatum for pg_sys::Datum { /// for bool impl FromDatum for bool { #[inline] - unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _: pg_sys::Oid) -> Option { + unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool) -> Option { if is_null { None } else { @@ -94,7 +89,7 @@ impl FromDatum for bool { /// for `"char"` impl FromDatum for i8 { #[inline] - unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _: pg_sys::Oid) -> Option { + unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool) -> Option { if is_null { None } else { @@ -106,7 +101,7 @@ impl FromDatum for i8 { /// for smallint impl FromDatum for i16 { #[inline] - unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _: pg_sys::Oid) -> Option { + unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool) -> Option { if is_null { None } else { @@ -118,7 +113,7 @@ impl FromDatum for i16 { /// for integer impl FromDatum for i32 { #[inline] - unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _: pg_sys::Oid) -> Option { + unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool) -> Option { if is_null { None } else { @@ -130,7 +125,7 @@ impl FromDatum for i32 { /// for oid impl FromDatum for u32 { #[inline] - unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _: pg_sys::Oid) -> Option { + unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool) -> Option { if is_null { None } else { @@ -142,7 +137,7 @@ impl FromDatum for u32 { /// for bigint impl FromDatum for i64 { #[inline] - unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _: pg_sys::Oid) -> Option { + unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool) -> Option { if is_null { None } else { @@ -154,7 +149,7 @@ impl FromDatum for i64 { /// for real impl FromDatum for f32 { #[inline] - unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _: pg_sys::Oid) -> Option { + unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool) -> Option { if is_null { None } else { @@ -166,7 +161,7 @@ impl FromDatum for f32 { /// for double precision impl FromDatum for f64 { #[inline] - unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _: pg_sys::Oid) -> Option { + unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool) -> Option { if is_null { None } else { @@ -178,7 +173,7 @@ impl FromDatum for f64 { /// for text, varchar impl<'a> FromDatum for &'a str { #[inline] - unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _: pg_sys::Oid) -> Option<&'a str> { + unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool) -> Option<&'a str> { if is_null { None } else if datum == 0 { @@ -193,7 +188,6 @@ impl<'a> FromDatum for &'a str { mut memory_context: PgMemoryContexts, datum: usize, is_null: bool, - _typoid: u32, ) -> Option where Self: Sized, @@ -222,12 +216,8 @@ impl<'a> FromDatum for &'a str { /// This returns a **copy**, allocated and managed by Rust, of the underlying `varlena` Datum impl FromDatum for String { #[inline] - unsafe fn from_datum( - datum: pg_sys::Datum, - is_null: bool, - typoid: pg_sys::Oid, - ) -> Option { - let refstr: Option<&str> = FromDatum::from_datum(datum, is_null, typoid); + unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool) -> Option { + let refstr: Option<&str> = FromDatum::from_datum(datum, is_null); match refstr { Some(refstr) => Some(refstr.to_owned()), None => None, @@ -237,8 +227,8 @@ impl FromDatum for String { impl FromDatum for char { #[inline] - unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, typoid: pg_sys::Oid) -> Option { - let refstr: Option<&str> = FromDatum::from_datum(datum, is_null, typoid); + unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool) -> Option { + let refstr: Option<&str> = FromDatum::from_datum(datum, is_null); match refstr { Some(refstr) => refstr.chars().next(), None => None, @@ -249,7 +239,7 @@ impl FromDatum for char { /// for cstring impl<'a> FromDatum for &'a std::ffi::CStr { #[inline] - unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _: pg_sys::Oid) -> Option<&'a CStr> { + unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool) -> Option<&'a CStr> { if is_null { None } else if datum == 0 { @@ -267,7 +257,6 @@ impl<'a> FromDatum for &'a crate::cstr_core::CStr { unsafe fn from_datum( datum: pg_sys::Datum, is_null: bool, - _: pg_sys::Oid, ) -> Option<&'a crate::cstr_core::CStr> { if is_null { None @@ -284,7 +273,7 @@ impl<'a> FromDatum for &'a crate::cstr_core::CStr { /// for bytea impl<'a> FromDatum for &'a [u8] { #[inline] - unsafe fn from_datum(datum: usize, is_null: bool, _typoid: u32) -> Option<&'a [u8]> { + unsafe fn from_datum(datum: usize, is_null: bool) -> Option<&'a [u8]> { if is_null { None } else if datum == 0 { @@ -299,7 +288,6 @@ impl<'a> FromDatum for &'a [u8] { mut memory_context: PgMemoryContexts, datum: usize, is_null: bool, - _typoid: u32, ) -> Option where Self: Sized, @@ -325,14 +313,14 @@ impl<'a> FromDatum for &'a [u8] { impl FromDatum for Vec { #[inline] - unsafe fn from_datum(datum: usize, is_null: bool, typoid: u32) -> Option> { + unsafe fn from_datum(datum: usize, is_null: bool) -> Option> { if is_null { None } else if datum == 0 { panic!("a bytea Datum as flagged as non-null but the datum is zero"); } else { // Vec conversion is initially the same as for &[u8] - let bytes: Option<&[u8]> = FromDatum::from_datum(datum, is_null, typoid); + let bytes: Option<&[u8]> = FromDatum::from_datum(datum, is_null); match bytes { // but then we need to convert it into an owned Vec where the backing @@ -347,7 +335,7 @@ impl FromDatum for Vec { /// for NULL -- always converts to a `None`, even if the is_null argument is false impl FromDatum for () { #[inline] - unsafe fn from_datum(_datum: pg_sys::Datum, _is_null: bool, _: pg_sys::Oid) -> Option<()> { + unsafe fn from_datum(_datum: pg_sys::Datum, _is_null: bool) -> Option<()> { None } } @@ -355,7 +343,7 @@ impl FromDatum for () { /// for user types impl FromDatum for PgBox { #[inline] - unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _: pg_sys::Oid) -> Option { + unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool) -> Option { if is_null { None } else if datum == 0 { @@ -372,7 +360,6 @@ impl FromDatum for PgBox { mut memory_context: PgMemoryContexts, datum: usize, is_null: bool, - _typoid: u32, ) -> Option where Self: Sized, diff --git a/pgx/src/datum/geo.rs b/pgx/src/datum/geo.rs index c16d65647..e2f56d8e0 100644 --- a/pgx/src/datum/geo.rs +++ b/pgx/src/datum/geo.rs @@ -10,7 +10,7 @@ Use of this source code is governed by the MIT license that can be found in the use crate::{direct_function_call_as_datum, pg_sys, FromDatum, IntoDatum}; impl FromDatum for pg_sys::BOX { - unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _: pg_sys::Oid) -> Option + unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool) -> Option where Self: Sized, { @@ -42,7 +42,7 @@ impl IntoDatum for pg_sys::BOX { } impl FromDatum for pg_sys::Point { - unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _: pg_sys::Oid) -> Option + unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool) -> Option where Self: Sized, { diff --git a/pgx/src/datum/inet.rs b/pgx/src/datum/inet.rs index 7247c5012..3b364cb59 100644 --- a/pgx/src/datum/inet.rs +++ b/pgx/src/datum/inet.rs @@ -84,7 +84,7 @@ impl<'de> Deserialize<'de> for Inet { } impl FromDatum for Inet { - unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _typoid: u32) -> Option { + unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool) -> Option { if is_null { None } else if datum == 0 { diff --git a/pgx/src/datum/internal.rs b/pgx/src/datum/internal.rs index 4eacfe860..20673db79 100644 --- a/pgx/src/datum/internal.rs +++ b/pgx/src/datum/internal.rs @@ -157,7 +157,7 @@ impl From> for Internal { impl FromDatum for Internal { #[inline] - unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _: pg_sys::Oid) -> Option { + unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool) -> Option { Some(Internal(if is_null { None } else { Some(datum) })) } } diff --git a/pgx/src/datum/item_pointer_data.rs b/pgx/src/datum/item_pointer_data.rs index e902f48ae..49eef05c3 100644 --- a/pgx/src/datum/item_pointer_data.rs +++ b/pgx/src/datum/item_pointer_data.rs @@ -13,11 +13,7 @@ use crate::{ impl FromDatum for pg_sys::ItemPointerData { #[inline] - unsafe fn from_datum( - datum: pg_sys::Datum, - is_null: bool, - _typoid: u32, - ) -> Option { + unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool) -> Option { if is_null { None } else { diff --git a/pgx/src/datum/json.rs b/pgx/src/datum/json.rs index 70cae4d1c..3f853103e 100644 --- a/pgx/src/datum/json.rs +++ b/pgx/src/datum/json.rs @@ -26,7 +26,7 @@ pub struct JsonString(pub String); /// for json impl FromDatum for Json { #[inline] - unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _: pg_sys::Oid) -> Option { + unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool) -> Option { if is_null { None } else if datum == 0 { @@ -44,7 +44,7 @@ impl FromDatum for Json { /// for jsonb impl FromDatum for JsonB { - unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _: pg_sys::Oid) -> Option { + unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool) -> Option { if is_null { None } else if datum == 0 { @@ -84,11 +84,7 @@ impl FromDatum for JsonB { /// This returns a **copy**, allocated and managed by Rust, of the underlying `varlena` Datum impl FromDatum for JsonString { #[inline] - unsafe fn from_datum( - datum: pg_sys::Datum, - is_null: bool, - _: pg_sys::Oid, - ) -> Option { + unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool) -> Option { if is_null { None } else if datum == 0 { diff --git a/pgx/src/datum/numeric.rs b/pgx/src/datum/numeric.rs index 4ecec5ae9..6db7751a9 100644 --- a/pgx/src/datum/numeric.rs +++ b/pgx/src/datum/numeric.rs @@ -152,7 +152,7 @@ impl Into for f64 { } impl FromDatum for Numeric { - unsafe fn from_datum(datum: usize, is_null: bool, _typoid: u32) -> Option + unsafe fn from_datum(datum: usize, is_null: bool) -> Option where Self: Sized, { diff --git a/pgx/src/datum/time.rs b/pgx/src/datum/time.rs index 72e37af99..23d357b4e 100644 --- a/pgx/src/datum/time.rs +++ b/pgx/src/datum/time.rs @@ -21,7 +21,7 @@ pub(crate) const SEC_PER_MIN: i64 = 60; pub struct Time(pub(crate) time::Time); impl FromDatum for Time { #[inline] - unsafe fn from_datum(datum: pg_sys::Datum, is_null: bool, _typoid: u32) -> Option