Skip to content

Commit

Permalink
Merge pull request #216 from zombodb/unsafe-is_a
Browse files Browse the repository at this point in the history
fix: Mark is_a unsafe
  • Loading branch information
Hoverbear committed Sep 24, 2021
2 parents 31c000b + 1b27c2c commit 742136d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
6 changes: 3 additions & 3 deletions pgx/src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl<T> PgList<T> {

#[inline]
pub fn get_ptr(&self, i: usize) -> Option<*mut T> {
if !self.is_empty() && !is_a(self.list as *mut pg_sys::Node, pg_sys::NodeTag_T_List) {
if !self.is_empty() && unsafe { !is_a(self.list as *mut pg_sys::Node, pg_sys::NodeTag_T_List) } {
panic!("PgList does not contain pointers")
}
if self.list.is_null() || i >= self.len() {
Expand All @@ -92,7 +92,7 @@ impl<T> PgList<T> {

#[inline]
pub fn get_int(&self, i: usize) -> Option<i32> {
if !self.is_empty() && !is_a(self.list as *mut pg_sys::Node, pg_sys::NodeTag_T_IntList) {
if !self.is_empty() && unsafe { !is_a(self.list as *mut pg_sys::Node, pg_sys::NodeTag_T_IntList) } {
panic!("PgList does not contain ints")
}

Expand All @@ -105,7 +105,7 @@ impl<T> PgList<T> {

#[inline]
pub fn get_oid(&self, i: usize) -> Option<pg_sys::Oid> {
if !self.is_empty() && !is_a(self.list as *mut pg_sys::Node, pg_sys::NodeTag_T_OidList) {
if !self.is_empty() && unsafe { !is_a(self.list as *mut pg_sys::Node, pg_sys::NodeTag_T_OidList) } {
panic!("PgList does not contain oids")
}

Expand Down
5 changes: 2 additions & 3 deletions pgx/src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
use crate::pg_sys;

/// #define IsA(nodeptr,_type_) (nodeTag(nodeptr) == T_##_type_)
#[allow(clippy::not_unsafe_ptr_arg_deref)] // ok b/c we check that nodeptr isn't null
#[inline]
pub fn is_a(nodeptr: *mut pg_sys::Node, tag: pg_sys::NodeTag) -> bool {
!nodeptr.is_null() && unsafe { nodeptr.as_ref().unwrap().type_ == tag }
pub unsafe fn is_a(nodeptr: *mut pg_sys::Node, tag: pg_sys::NodeTag) -> bool {
!nodeptr.is_null() && nodeptr.as_ref().unwrap().type_ == tag
}

pub fn node_to_string<'a>(nodeptr: *mut pg_sys::Node) -> Option<&'a str> {
Expand Down
2 changes: 1 addition & 1 deletion pgx/src/trigger_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{is_a, pg_sys};
#[inline]
pub fn called_as_trigger(fcinfo: pg_sys::FunctionCallInfo) -> bool {
let fcinfo = unsafe { fcinfo.as_ref() }.expect("fcinfo was null");
!fcinfo.context.is_null() && is_a(fcinfo.context, pg_sys::NodeTag_T_TriggerData)
!fcinfo.context.is_null() && unsafe { is_a(fcinfo.context, pg_sys::NodeTag_T_TriggerData) }
}

#[inline]
Expand Down

0 comments on commit 742136d

Please sign in to comment.