Skip to content

Commit

Permalink
Remove unsafeties for Oid conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
workingjubilee committed Nov 3, 2023
1 parent b6ce27f commit 5eb013f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pgrx/src/datum/from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl FromDatum for pg_sys::Oid {
.value()
.try_into()
.ok()
.map(|uint| unsafe { pg_sys::Oid::from_u32_unchecked(uint) })
.map(|uint: u32| pg_sys::Oid::from(uint))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pgrx/src/pgbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ use std::ptr::NonNull;
/// use pgrx::prelude::*;
///
/// pub fn do_something() {
/// # let example_rel_oid = |i| { unsafe { pg_sys::Oid::from_u32_unchecked(i) } };
/// # let example_rel_oid = |i| pg_sys::Oid::from(i);
/// // open a relation and project it as a pg_sys::Relation
/// let relid: pg_sys::Oid = example_rel_oid(42);
/// let lockmode = pg_sys::AccessShareLock as i32;
Expand Down
4 changes: 2 additions & 2 deletions pgrx/src/rel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ impl PgRelation {
///
/// ```rust,no_run
/// use pgrx::{PgRelation, pg_sys};
/// # let example_pg_class_oid = |i| { unsafe { pg_sys::Oid::from_u32_unchecked(i) } };
/// # let example_pg_class_oid = |i| pg_sys::Oid::from(i);
/// let oid = example_pg_class_oid(42); // a valid pg_class "oid" value
/// let relation = unsafe { PgRelation::from_pg(pg_sys::RelationIdGetRelation(oid) ) };
/// let tupdesc = relation.tuple_desc();
Expand Down Expand Up @@ -309,7 +309,7 @@ impl FromDatum for PgRelation {
None
} else {
Some(PgRelation::with_lock(
unsafe { pg_sys::Oid::from_u32_unchecked(u32::try_from(datum.value()).ok()?) },
pg_sys::Oid::from(u32::try_from(datum.value()).ok()?),
pg_sys::AccessShareLock as pg_sys::LOCKMODE,
))
}
Expand Down
2 changes: 1 addition & 1 deletion pgrx/src/tupdesc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl<'a> PgTupleDesc<'a> {
///
/// ```rust,no_run
/// use pgrx::{pg_sys, PgTupleDesc};
/// # let example_pg_type_oid = |i| { unsafe { pg_sys::Oid::from_u32_unchecked(i) } };
/// # let example_pg_type_oid = |i| pg_sys::Oid::from(i);
/// let typid = example_pg_type_oid(42); // a valid pg_type Oid
/// let typmod = 0; // its corresponding typemod value
/// let tupdesc = unsafe { PgTupleDesc::from_pg_is_copy(pg_sys::lookup_rowtype_tupdesc_copy(typid, typmod)) };
Expand Down

0 comments on commit 5eb013f

Please sign in to comment.