Skip to content

Commit

Permalink
Use flatbuffers::follow instead of init_from_table (#1878)
Browse files Browse the repository at this point in the history
  • Loading branch information
robert3005 authored Jan 9, 2025
1 parent 24ce4fd commit d76e945
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 18 deletions.
6 changes: 2 additions & 4 deletions vortex-array/src/data/viewed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::fmt::{Debug, Formatter};
use std::sync::Arc;

use enum_iterator::all;
use flatbuffers::Follow;
use itertools::Itertools;
use vortex_buffer::ByteBuffer;
use vortex_dtype::{DType, Nullability, PType};
Expand Down Expand Up @@ -42,10 +43,7 @@ impl Debug for ViewedArrayData {

impl ViewedArrayData {
pub fn flatbuffer(&self) -> fb::Array {
unsafe {
let tab = flatbuffers::Table::new(self.flatbuffer.as_ref(), self.flatbuffer_loc);
fb::Array::init_from_table(tab)
}
unsafe { fb::Array::follow(self.flatbuffer.as_ref(), self.flatbuffer_loc) }
}

pub fn metadata_bytes(&self) -> Option<&[u8]> {
Expand Down
9 changes: 2 additions & 7 deletions vortex-dtype/src/dtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fmt::{Debug, Display, Formatter};
use std::hash::Hash;
use std::sync::Arc;

use flatbuffers::root;
use flatbuffers::{root, Follow};
use itertools::Itertools;
use vortex_error::{
vortex_bail, vortex_err, vortex_panic, VortexExpect, VortexResult, VortexUnwrap,
Expand Down Expand Up @@ -205,12 +205,7 @@ impl ViewedDType {

/// The viewed [`fbd::DType`] instance.
pub fn flatbuffer(&self) -> fbd::DType<'_> {
unsafe {
fbd::DType::init_from_table(flatbuffers::Table::new(
self.flatbuffer.as_ref(),
self.flatbuffer_loc,
))
}
unsafe { fbd::DType::follow(self.flatbuffer.as_ref(), self.flatbuffer_loc) }
}

/// Returns the underlying shared buffer
Expand Down
10 changes: 3 additions & 7 deletions vortex-layout/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::ops::Deref;
use std::sync::Arc;

use bytes::Bytes;
use flatbuffers::{FlatBufferBuilder, Table, Verifiable, Verifier, VerifierOptions, WIPOffset};
use flatbuffers::{FlatBufferBuilder, Follow, Verifiable, Verifier, VerifierOptions, WIPOffset};
use vortex_array::ContextRef;
use vortex_buffer::ByteBuffer;
use vortex_dtype::DType;
Expand Down Expand Up @@ -50,10 +50,7 @@ struct ViewedLayoutData {
impl ViewedLayoutData {
/// Return the flatbuffer layout message.
fn flatbuffer(&self) -> layout::Layout<'_> {
unsafe {
let tab = Table::new(self.flatbuffer.as_ref(), self.flatbuffer_loc);
layout::Layout::init_from_table(tab)
}
unsafe { layout::Layout::follow(self.flatbuffer.as_ref(), self.flatbuffer_loc) }
}
}

Expand Down Expand Up @@ -91,8 +88,7 @@ impl LayoutData {
fb::Layout::run_verifier(&mut v, flatbuffer_loc)?;

// SAFETY: we just verified the buffer contains a valid layout message.
let fb_layout =
unsafe { fb::Layout::init_from_table(Table::new(flatbuffer.as_ref(), flatbuffer_loc)) };
let fb_layout = unsafe { fb::Layout::follow(flatbuffer.as_ref(), flatbuffer_loc) };
if fb_layout.encoding() != encoding.id().0 {
vortex_bail!(
"Mismatched encoding, flatbuffer contains {}, given {}",
Expand Down

0 comments on commit d76e945

Please sign in to comment.