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

fix: Workaround for mmap crash under Emscripten #20418

Merged
merged 1 commit into from
Dec 23, 2024
Merged
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
11 changes: 11 additions & 0 deletions crates/polars-io/src/utils/other.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#[cfg(any(feature = "ipc_streaming", feature = "parquet"))]
use std::borrow::Cow;
use std::io::Read;
#[cfg(target_os = "emscripten")]
use std::io::{Seek, SeekFrom};

use once_cell::sync::Lazy;
use polars_core::prelude::*;
Expand All @@ -23,6 +25,15 @@ pub fn get_reader_bytes<R: Read + MmapBytesReader + ?Sized>(
{
let mut options = memmap::MmapOptions::new();
options.offset(offset);

// Set mmap size based on seek to end when running under Emscripten
#[cfg(target_os = "emscripten")]
{
let mut file = file;
let size = file.seek(SeekFrom::End(0)).unwrap();
options.len((size - offset) as usize);
}

let mmap = MMapSemaphore::new_from_file_with_options(file, options)?;
Ok(ReaderBytes::Owned(MemSlice::from_mmap(Arc::new(mmap))))
} else {
Expand Down
Loading