#![cfg_attr(feature = "nightly", feature(allocator_api))]
#[macro_use]
extern crate bitflags;
extern crate alloc;
use std::sync::LazyLock as Lazy;
pub use pgrx_macros;
pub use pgrx_macros::*;
#[doc(inline)]
pub use pgrx_sql_entity_graph::metadata::impl_sql_translatable;
pub use pgrx_sql_entity_graph::pgrx_resolved_type;
pub mod prelude;
pub mod aggregate;
pub mod array;
pub mod atomics;
pub mod bgworkers;
pub mod callbacks;
pub mod callconv;
pub mod datetime;
pub mod datum;
pub mod enum_helper;
pub mod fcinfo;
pub mod ffi;
pub mod fn_call;
pub mod guc;
pub mod heap_tuple;
pub mod htup;
pub mod inoutfuncs;
pub mod itemptr;
pub mod iter;
pub mod layout;
pub mod list;
pub mod lwlock;
pub mod memcx;
pub mod memcxt;
pub mod misc;
#[cfg(feature = "cshim")]
pub mod namespace;
pub mod nodes;
pub mod nullable;
pub mod palloc;
pub mod pg_catalog;
pub mod pgbox;
pub mod rel;
pub mod shmem;
pub mod spi;
#[cfg(feature = "cshim")]
pub mod spinlock;
pub mod stringinfo;
pub mod trigger_support;
pub mod tupdesc;
pub mod varlena;
pub mod wrappers;
pub mod xid;
mod ptr;
mod slice;
mod toast;
pub use aggregate::*;
pub use atomics::*;
pub use callbacks::*;
pub use datum::{
AnyArray, AnyElement, AnyNumeric, Array, FromDatum, Inet, Internal, IntoDatum, Json, JsonB,
Numeric, Range, Uuid, VariadicArray, numeric,
};
pub use enum_helper::*;
pub use fcinfo::*;
pub use guc::*;
pub use htup::*;
pub use inoutfuncs::*;
#[cfg(feature = "cshim")]
pub use list::old_list::*;
pub use lwlock::*;
pub use memcxt::*;
#[cfg(feature = "cshim")]
pub use namespace::*;
pub use nodes::*;
pub use pgbox::*;
pub use rel::*;
pub use shmem::*;
pub use spi::Spi; pub use stringinfo::*;
pub use trigger_support::*;
pub use tupdesc::*;
pub use varlena::*;
pub use wrappers::*;
pub use xid::*;
pub mod pg_sys;
pub use pg_sys::PgBuiltInOids;
pub use pg_sys::elog::PgLogLevel;
pub use pg_sys::errcodes::PgSqlErrorCode;
pub use pg_sys::oids::PgOid;
pub use pg_sys::panic::pgrx_extern_c_guard;
pub use pg_sys::pg_try::PgTryBuilder;
pub use pg_sys::utils::name_data_to_str;
pub use pg_sys::{
FATAL, PANIC, check_for_interrupts, debug1, debug2, debug3, debug4, debug5, ereport,
ereport_domain, error, function_name, info, log, notice, warning,
};
#[doc(hidden)]
pub use pgrx_sql_entity_graph;
mod seal {
pub trait Sealed {}
}
#[cfg(all(
any(feature = "pg15", feature = "pg16", feature = "pg17", feature = "pg18"),
not(feature = "unsafe-postgres")
))]
const _: () = {
use core::ffi::CStr;
const fn same_cstr(a: &CStr, b: &CStr) -> bool {
if a.to_bytes().len() != b.to_bytes().len() {
return false;
}
let mut i = 0;
while i < a.to_bytes().len() {
if a.to_bytes()[i] != b.to_bytes()[i] {
return false;
}
i += 1;
}
true
}
assert!(
same_cstr(pg_sys::FMGR_ABI_EXTRA, c"PostgreSQL"),
"Unsupported Postgres ABI. Perhaps you need `--features unsafe-postgres`?",
);
};
#[macro_export]
macro_rules! pg_module_magic {
($($key:ident $(= $value:expr)?),*) => {
$crate::pg_magic_func!($($key $(= $value)?),*);
};
}
#[macro_export]
macro_rules! pg_magic_func {
($($key:ident $(= $value: expr)?),*) => {
::pgrx::pgrx_sql_entity_graph::__pgrx_schema_entry!(
__PGRX_SCHEMA_SECTION_SENTINEL,
::pgrx::pgrx_sql_entity_graph::section::SECTION_SENTINEL_ENTRY_LEN,
::pgrx::pgrx_sql_entity_graph::section::schema_section_sentinel_entry()
);
#[unsafe(no_mangle)]
#[allow(non_snake_case, unexpected_cfgs)]
#[doc(hidden)]
pub extern "C" fn Pg_magic_func() -> &'static ::pgrx::pg_sys::Pg_magic_struct {
#[repr(transparent)]
struct AssertSync<T>(T);
unsafe impl<T> Sync for AssertSync<T> {}
::pgrx::pg_sys::panic::register_pg_guard_panic_hook();
static MY_MAGIC: AssertSync<::pgrx::pg_sys::Pg_magic_struct> = {
let len = ::core::mem::size_of::<::pgrx::pg_sys::Pg_magic_struct>() as i32;
let version = ::pgrx::pg_sys::PG_VERSION_NUM as i32 / 100;
let funcmaxargs = ::pgrx::pg_sys::FUNC_MAX_ARGS as i32;
let indexmaxkeys = ::pgrx::pg_sys::INDEX_MAX_KEYS as i32;
let namedatalen = ::pgrx::pg_sys::NAMEDATALEN as i32;
let float8byval = cfg!(target_pointer_width = "64") as i32;
#[cfg(not(any(feature = "pg13", feature = "pg14")))]
let abi_extra = {
let magic = ::pgrx::pg_sys::FMGR_ABI_EXTRA.to_bytes_with_nul();
let mut abi = [0 as ::pgrx::ffi::c_char; 32];
let mut i = 0;
while i < magic.len() {
abi[i] = magic[i] as ::pgrx::ffi::c_char;
i += 1;
}
abi
};
let mut magic = ::pgrx::pg_sys::Pg_magic_struct {
len,
#[cfg(not(feature = "pg18"))]
version,
#[cfg(not(feature = "pg18"))]
funcmaxargs,
#[cfg(not(feature = "pg18"))]
indexmaxkeys,
#[cfg(not(feature = "pg18"))]
namedatalen,
#[cfg(not(feature = "pg18"))]
float8byval,
#[cfg(any(feature = "pg15", feature = "pg16", feature = "pg17"))]
abi_extra,
#[cfg(feature = "pg18")]
abi_fields: ::pgrx::pg_sys::Pg_abi_values {
version,
funcmaxargs,
indexmaxkeys,
namedatalen,
float8byval,
abi_extra,
},
#[cfg(feature = "pg18")]
name: ::core::ptr::null(),
#[cfg(feature = "pg18")]
version: ::core::ptr::null(),
};
#[allow(unused_macros)]
macro_rules! field_update {
(name) => {
field_update!(name = {
const RAW: &str = env!("CARGO_PKG_NAME");
const BUFFER: [u8; RAW.len() + 1] = {
let mut buffer = [0u8; RAW.len() + 1];
let mut i = 0_usize;
while i < RAW.len() {
buffer[i] = RAW.as_bytes()[i];
i += 1;
}
buffer
};
const STR: &::core::ffi::CStr =
if let Ok(s) = ::core::ffi::CStr::from_bytes_with_nul(&BUFFER) {
s
} else {
panic!("there are null characters in CARGO_PKG_NAME")
};
const { STR }
});
};
(version) => {
field_update!(name = {
const RAW: &str = env!("CARGO_PKG_VERSION");
const BUFFER: [u8; RAW.len() + 1] = {
let mut buffer = [0u8; RAW.len() + 1];
let mut i = 0_usize;
while i < RAW.len() {
buffer[i] = RAW.as_bytes()[i];
i += 1;
}
buffer
};
const STR: &::core::ffi::CStr =
if let Ok(s) = ::core::ffi::CStr::from_bytes_with_nul(&BUFFER) {
s
} else {
panic!("there are null characters in CARGO_CRATE_VERSION")
};
const { STR }
});
};
(name = $name:expr) => {
let name: &'static ::core::ffi::CStr = $name;
#[cfg(feature = "pg18")]
{
magic.name = ::core::ffi::CStr::as_ptr($name);
}
};
(version = $version:expr) => {
let version: &'static ::core::ffi::CStr = $version;
#[cfg(feature = "pg18")]
{
magic.version = ::core::ffi::CStr::as_ptr($version);
}
};
}
$(field_update!($key $(= $value)?);)*
AssertSync(magic)
};
&MY_MAGIC.0
}
};
}
pub(crate) static UTF8DATABASE: Lazy<Utf8Compat> = Lazy::new(|| {
use pg_sys::pg_enc::*;
let encoding_int = unsafe { pg_sys::GetDatabaseEncoding() };
match encoding_int as _ {
PG_UTF8 => Utf8Compat::Yes,
PG_SQL_ASCII => Utf8Compat::Maybe,
PG_SJIS | PG_SHIFT_JIS_2004
| PG_BIG5
| PG_JOHAB => unreachable!("impossible? unsupported non-ASCII-compatible database encoding is not a server encoding"),
1..=41=> Utf8Compat::Ascii,
_ => Utf8Compat::Maybe,
}
});
#[derive(Debug, Clone, Copy)]
pub(crate) enum Utf8Compat {
Yes,
Maybe,
Ascii,
}