Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PG function declerations that are not generated by pgrx yet #18

Merged
merged 1 commit into from
Sep 27, 2024
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
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use pgrx::prelude::*;

mod pgrx_missing_declerations;
mod pgrx_utils;

pgrx::pg_module_magic!();
Expand Down
54 changes: 54 additions & 0 deletions src/pgrx_missing_declerations.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use pgrx::{
pg_sys::{self, Alias, Oid, ParseNamespaceItem, ParseState, Relation, TupleTableSlot},
PgBox,
prelude::*,
};

#[allow(improper_ctypes)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per #16, do you need the pg_guard annotation?

#[pg_guard]
extern "C" {
pub(crate) fn get_extension_oid(name: *const i8, missing_ok: bool) -> Oid;

pub(crate) fn get_extension_schema(ext_oid: Oid) -> Oid;

pub(crate) fn addRangeTableEntryForRelation(
pstate: *mut ParseState,
rel: Relation,
lockmode: i32,
alias: *mut Alias,
inh: bool,
inFromCl: bool,
) -> *mut ParseNamespaceItem;

pub(crate) fn addNSItemToQuery(
pstate: *mut ParseState,
nsitem: *mut ParseNamespaceItem,
add_to_join_list: bool,
add_to_rel_namespace: bool,
add_to_var_namespace: bool,
);

pub(crate) fn assign_expr_collations(
pstate: *mut ParseState,
expr: *mut pg_sys::Node,
) -> *mut pg_sys::Node;
}

/*
* slot_getallattrs
* This function forces all the entries of the slot's Datum/isnull
* arrays to be valid. The caller may then extract data directly
* from those arrays instead of using slot_getattr.
*/
pub(crate) fn slot_getallattrs(slot: *mut TupleTableSlot) {
// copied from Postgres since this method was inlined in the original code
// (not found in pg_sys)
// handles select * from table
unsafe {
let slot = PgBox::from_pg(slot);
let tts_tupledesc = PgBox::from_pg(slot.tts_tupleDescriptor);
if (slot.tts_nvalid as i32) < tts_tupledesc.natts {
pg_sys::slot_getsomeattrs_int(slot.as_ptr(), tts_tupledesc.natts);
}
};
}
Loading