Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions pgrx-bindgen/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ fn run_bindgen(
eprintln!("pg_target_includes = {pg_target_includes:?}");
let (autodetect, includes) = clang::detect_include_paths_for(preferred_clang);
let mut binder = bindgen::Builder::default();
binder = add_blocklists(binder, major_version);
binder = add_blocklists(binder, major_version, enable_cshim);
binder = add_allowlists(binder, pg_target_includes.iter().map(|x| x.as_str()));
binder = add_derives(binder);
if !autodetect {
Expand Down Expand Up @@ -800,14 +800,25 @@ fn run_bindgen(
Ok(bindings.to_string())
}

fn add_blocklists(bind: bindgen::Builder, major_version: u16) -> bindgen::Builder {
fn add_blocklists(
bind: bindgen::Builder,
major_version: u16,
enable_cshim: bool,
) -> bindgen::Builder {
let bind = if major_version >= 19 {
// Postgres 19 turned these into `static inline` functions, so without the cshim there's
// no symbol to link against. We implement them ourselves, in Rust, in `port.rs`
bind.blocklist_function("TransactionId(Precedes|PrecedesOrEquals|Follows|FollowsOrEquals)")
} else {
bind
};
let bind = if major_version < 16 || !enable_cshim {
// Before Postgres 16 these are macros. Without cshim, Postgres 16+ static inline
// functions have no symbol to link against. Use the Rust fallback in both cases.
bind.blocklist_function("BufferGetBlock").blocklist_function("BufferGetPage")
} else {
bind
};
bind.blocklist_type("Datum") // manually wrapping datum for correctness
.blocklist_type("Oid") // "Oid" is not just any u32
.blocklist_type("TransactionId") // "TransactionId" is not just any u32
Expand All @@ -820,8 +831,6 @@ fn add_blocklists(bind: bindgen::Builder, major_version: u16) -> bindgen::Builde
.blocklist_function("err(start|code|msg|detail|context_msg|hint|finish)")
// These functions are already ported in Rust
.blocklist_function("heap_getattr")
.blocklist_function("BufferGetBlock")
.blocklist_function("BufferGetPage")
.blocklist_function("BufferIsLocal")
.blocklist_function("GetMemoryChunkContext")
.blocklist_function("GETSTRUCT")
Expand Down
4 changes: 4 additions & 0 deletions pgrx-pg-sys/src/include/pg16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39199,8 +39199,12 @@ unsafe extern "C-unwind" {
pub fn FreeAccessStrategy(strategy: BufferAccessStrategy);
#[link_name = "BufferIsValid__pgrx_cshim"]
pub fn BufferIsValid(bufnum: Buffer) -> bool;
#[link_name = "BufferGetBlock__pgrx_cshim"]
pub fn BufferGetBlock(buffer: Buffer) -> Block;
#[link_name = "BufferGetPageSize__pgrx_cshim"]
pub fn BufferGetPageSize(buffer: Buffer) -> Size;
#[link_name = "BufferGetPage__pgrx_cshim"]
pub fn BufferGetPage(buffer: Buffer) -> Page;
#[link_name = "TestForOldSnapshot__pgrx_cshim"]
pub fn TestForOldSnapshot(snapshot: Snapshot, relation: Relation, page: Page);
pub static mut InRecovery: bool;
Expand Down
4 changes: 4 additions & 0 deletions pgrx-pg-sys/src/include/pg17.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39120,8 +39120,12 @@ unsafe extern "C-unwind" {
pub fn FreeAccessStrategy(strategy: BufferAccessStrategy);
#[link_name = "BufferIsValid__pgrx_cshim"]
pub fn BufferIsValid(bufnum: Buffer) -> bool;
#[link_name = "BufferGetBlock__pgrx_cshim"]
pub fn BufferGetBlock(buffer: Buffer) -> Block;
#[link_name = "BufferGetPageSize__pgrx_cshim"]
pub fn BufferGetPageSize(buffer: Buffer) -> Size;
#[link_name = "BufferGetPage__pgrx_cshim"]
pub fn BufferGetPage(buffer: Buffer) -> Page;
pub fn read_stream_begin_relation(
flags: ::core::ffi::c_int,
strategy: BufferAccessStrategy,
Expand Down
4 changes: 4 additions & 0 deletions pgrx-pg-sys/src/include/pg18.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41091,8 +41091,12 @@ unsafe extern "C-unwind" {
pub fn FreeAccessStrategy(strategy: BufferAccessStrategy);
#[link_name = "BufferIsValid__pgrx_cshim"]
pub fn BufferIsValid(bufnum: Buffer) -> bool;
#[link_name = "BufferGetBlock__pgrx_cshim"]
pub fn BufferGetBlock(buffer: Buffer) -> Block;
#[link_name = "BufferGetPageSize__pgrx_cshim"]
pub fn BufferGetPageSize(buffer: Buffer) -> Size;
#[link_name = "BufferGetPage__pgrx_cshim"]
pub fn BufferGetPage(buffer: Buffer) -> Page;
pub fn block_range_read_stream_cb(
stream: *mut ReadStream,
callback_private_data: *mut ::core::ffi::c_void,
Expand Down
4 changes: 4 additions & 0 deletions pgrx-pg-sys/src/include/pg19.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40932,8 +40932,12 @@ unsafe extern "C-unwind" {
pub fn FreeAccessStrategy(strategy: BufferAccessStrategy);
#[link_name = "BufferIsValid__pgrx_cshim"]
pub fn BufferIsValid(bufnum: Buffer) -> bool;
#[link_name = "BufferGetBlock__pgrx_cshim"]
pub fn BufferGetBlock(buffer: Buffer) -> Block;
#[link_name = "BufferGetPageSize__pgrx_cshim"]
pub fn BufferGetPageSize(buffer: Buffer) -> Size;
#[link_name = "BufferGetPage__pgrx_cshim"]
pub fn BufferGetPage(buffer: Buffer) -> Page;
pub fn block_range_read_stream_cb(
stream: *mut ReadStream,
callback_private_data: *mut ::core::ffi::c_void,
Expand Down
18 changes: 18 additions & 0 deletions pgrx-pg-sys/src/port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,15 @@ pub unsafe fn type_is_array(typoid: super::Oid) -> bool {

/// #define BufferGetPage(buffer) ((Page)BufferGetBlock(buffer))
#[inline]
#[cfg(any(
feature = "pg13",
feature = "pg14",
feature = "pg15",
all(
not(feature = "cshim"),
any(feature = "pg16", feature = "pg17", feature = "pg18", feature = "pg19")
)
))]
pub unsafe fn BufferGetPage(buffer: crate::Buffer) -> crate::Page {
BufferGetBlock(buffer) as crate::Page
}
Expand All @@ -353,6 +362,15 @@ pub unsafe fn BufferGetPage(buffer: crate::Buffer) -> crate::Page {
/// (Block) (BufferBlocks + ((Size) ((buffer) - 1)) * BLCKSZ) \
/// )
#[inline]
#[cfg(any(
feature = "pg13",
feature = "pg14",
feature = "pg15",
all(
not(feature = "cshim"),
any(feature = "pg16", feature = "pg17", feature = "pg18", feature = "pg19")
)
))]
pub unsafe fn BufferGetBlock(buffer: crate::Buffer) -> crate::Block {
if BufferIsLocal(buffer) {
*crate::LocalBufferBlockPointers.offset(((-buffer) - 1) as isize)
Expand Down
Loading