Skip to content

Commit 21a70ce

Browse files
authored
force using extern "C-unwind" for functions marked with #[pg_guard] (#2014)
`pgrx` is switched from "C" to "C-unwind" in #1934 so it's fine to emit an error here Without this error, someone who updates dependencies without reading changelog, would break extensions silently, if their only usage of `#[pg_guard]` is `_PG_init`. It's bad.
1 parent f0e8512 commit 21a70ce

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

pgrx-macros/src/rewriter.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ pub fn item_fn_without_rewrite(mut func: ItemFn) -> syn::Result<proc_macro2::Tok
4747
let attrs = mem::take(&mut func.attrs);
4848
let generics = func.sig.generics.clone();
4949

50+
if !sig.abi.clone().and_then(|abi| abi.name).is_some_and(|name| name.value() == "C-unwind") {
51+
panic!("#[pg_guard] must be combined with extern \"C-unwind\"");
52+
}
53+
5054
if attrs.iter().any(|attr| attr.path().is_ident("no_mangle"))
5155
&& generics.params.iter().any(|p| match p {
5256
GenericParam::Type(_) => true,

pgrx/src/datum/datetime_support/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,8 @@ const DATE_EXTRACT: unsafe fn(fcinfo: pg_sys::FunctionCallInfo) -> pg_sys::Datum
401401

402402
#[cfg(any(feature = "pg12", feature = "pg13"))]
403403
mod pg12_13 {
404-
use crate as pgrx; // for [pg_guard]
405404
use crate::prelude::*;
406405

407-
#[pg_guard]
408406
pub(super) unsafe fn date_part(fcinfo: pg_sys::FunctionCallInfo) -> pg_sys::Datum {
409407
// we need to first convert the `date` value into a `timestamp` value
410408
// then call the `timestamp_part` function.

0 commit comments

Comments
 (0)