Skip to content

Commit

Permalink
Ensure PostgreSQL 16 compatibility
Browse files Browse the repository at this point in the history
DateTimeParseError: PostgreSQL source code documents that we can pass
null pointers here:

 > extra can be NULL if not needed for the particular dterr value.
 > [...]
 > If escontext points to an ErrorSaveContext node, that is filled instead
 > of throwing an error

DecodeDateTime however does not allow us to pass a null pointer, reading
the source code, it is expected that extra is not null. Therefore, in
order for us to get this thing to compile, we create an empty
DateTimeErrorExtra, which gets passed along.
  • Loading branch information
feikesteenbergen committed Oct 3, 2023
1 parent 75cb639 commit 0b86f83
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion extension/src/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
os::raw::{c_char, c_int},
};

use pgrx::pg_sys;
use pgrx::pg_sys::{self, DateTimeErrorExtra};
use std::ffi::CStr;

pub(crate) mod collations;
Expand Down Expand Up @@ -75,6 +75,13 @@ pub extern "C" fn _ts_toolkit_decode_timestamptz(text: &str) -> i64 {
pg_sys::MAXDATEFIELDS as i32,
&mut nf,
);
#[cfg(any(
feature = "pg11",
feature = "pg12",
feature = "pg13",
feature = "pg14",
feature = "pg15"
))]
if dterr == 0 {
dterr = pg_sys::DecodeDateTime(
field.as_mut_ptr(),
Expand All @@ -86,11 +93,45 @@ pub extern "C" fn _ts_toolkit_decode_timestamptz(text: &str) -> i64 {
&mut tz,
)
}
#[cfg(feature = "pg16")]
if dterr == 0 {
let mut extra = DateTimeErrorExtra::default();
dterr = pg_sys::DecodeDateTime(
field.as_mut_ptr(),
ftype.as_mut_ptr(),
nf,
&mut dtype,
tm,
&mut fsec,
&mut tz,
&mut extra as *mut DateTimeErrorExtra
)
}

#[cfg(any(
feature = "pg11",
feature = "pg12",
feature = "pg13",
feature = "pg14",
feature = "pg15"
))]
if dterr != 0 {
pg_sys::DateTimeParseError(
dterr,
str.as_ptr(),
b"timestamptz\0".as_ptr().cast::<c_char>(),
str.as_ptr(),
str.as_ptr(),
);
}
#[cfg(feature = "pg16")]
if dterr != 0 {
pg_sys::DateTimeParseError(
dterr,
core::ptr::null_mut(),
str.as_ptr(),
b"timestamptz\0".as_ptr().cast::<c_char>(),
core::ptr::null_mut(),
);
}

Expand Down

0 comments on commit 0b86f83

Please sign in to comment.