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

Bibtex cleanups / type improvements #1163

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4a9156d
Preamble from XBuf to Vec
CraftSpider Sep 26, 2023
2baac5a
Box up peekable, Vec in BibData
CraftSpider Sep 26, 2023
73a3ad0
Don't bother boxing peekable
CraftSpider Sep 26, 2023
6c5f390
Simplify all files into `File` type
CraftSpider Sep 26, 2023
0d70cb7
Fns use Vec now
CraftSpider Sep 26, 2023
0883e38
Migrate fully to Vec, remove XBuf
CraftSpider Feb 21, 2024
866b845
Add +1 to vec constructors
CraftSpider Feb 21, 2024
711ba57
Remove history thread-local, make history part of Bibtex
CraftSpider Feb 21, 2024
996c4a3
Remove logs thread_local, making bibtex engine fully re-entrant, asid…
CraftSpider Feb 21, 2024
c7985ad
Make direct CoreBridgeLauncher API, use it to remove most remaining u…
CraftSpider Feb 21, 2024
64fe73c
Step 1 of improving hash - simplify arrays, remove set_ilk_info, etc
CraftSpider Feb 26, 2024
b1514c8
Make ExecCtx deref
CraftSpider Feb 26, 2024
1daf79b
Minor dead-code cleanup
CraftSpider Feb 27, 2024
199cf43
No longer use ilk_info - always use HashExtra, and make HashExtra dat…
CraftSpider Feb 28, 2024
6dd89b0
Fix clippy
CraftSpider Feb 28, 2024
0acb0d1
Fix multi-file logging, add test
CraftSpider Feb 28, 2024
69f0f45
Comment out pool test for now
CraftSpider Feb 28, 2024
effef64
Fix control sequence bug
CraftSpider Mar 7, 2024
9b49d01
Clean up some clippy annotations
CraftSpider Mar 7, 2024
bfa1371
Fix test_pool
CraftSpider Mar 31, 2024
47261d8
Add tectonic_status_base commit
CraftSpider Apr 1, 2024
4f6a428
Fix tests
CraftSpider Aug 11, 2024
2617e26
Re-add clippy fixes
CraftSpider Sep 29, 2024
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 Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

143 changes: 93 additions & 50 deletions crates/bridge_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@
};
use tectonic_status_base::{tt_error, tt_warning, MessageKind, StatusBackend};

/// The ID of an InputHandle, used for Rust core state
#[derive(Copy, Clone, PartialEq)]
pub struct InputId(*mut InputHandle);

Check warning on line 59 in crates/bridge_core/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/bridge_core/src/lib.rs#L58-L59

Added lines #L58 - L59 were not covered by tests

/// The ID of an OutputHandle, used for Rust core state
#[derive(Copy, Clone, PartialEq)]
pub struct OutputId(*mut OutputHandle);

Check warning on line 63 in crates/bridge_core/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/bridge_core/src/lib.rs#L62-L63

Added lines #L62 - L63 were not covered by tests

/// Possible failures for "system request" calls to the driver.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum SystemRequestError {
Expand Down Expand Up @@ -473,16 +481,29 @@
error_occurred
}

fn output_open(&mut self, name: &str, is_gz: bool) -> *mut OutputHandle {
fn output_to_id(&self, output: *mut OutputHandle) -> OutputId {
OutputId(output)
}

/// Get a mutable reference to an [`OutputHandle`] associated with an [`OutputId`]
pub fn get_output(&mut self, id: OutputId) -> &mut OutputHandle {
self.output_handles
.iter_mut()
.find(|o| ptr::addr_eq(&***o, id.0))
.unwrap()
}

/// Open a new output, provided the output name and whether it is gzipped.
pub fn output_open(&mut self, name: &str, is_gz: bool) -> Option<OutputId> {
let io = self.hooks.io();
let name = normalize_tex_path(name);

let mut oh = match io.output_open_name(&name) {
OpenResult::Ok(oh) => oh,
OpenResult::NotAvailable => return ptr::null_mut(),
OpenResult::NotAvailable => return None,

Check warning on line 503 in crates/bridge_core/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/bridge_core/src/lib.rs#L503

Added line #L503 was not covered by tests
OpenResult::Err(e) => {
tt_warning!(self.status, "open of output {} failed", name; e);
return ptr::null_mut();
return None;

Check warning on line 506 in crates/bridge_core/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/bridge_core/src/lib.rs#L506

Added line #L506 was not covered by tests
}
};

Expand All @@ -495,23 +516,24 @@
}

self.output_handles.push(Box::new(oh));
&mut **self.output_handles.last_mut().unwrap()
Some(OutputId(&mut **self.output_handles.last_mut().unwrap()))
}

fn output_open_stdout(&mut self) -> *mut OutputHandle {
/// Open a new stdout output.
pub fn output_open_stdout(&mut self) -> Option<OutputId> {
let io = self.hooks.io();

let oh = match io.output_open_stdout() {
OpenResult::Ok(oh) => oh,
OpenResult::NotAvailable => return ptr::null_mut(),
OpenResult::NotAvailable => return None,

Check warning on line 528 in crates/bridge_core/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/bridge_core/src/lib.rs#L528

Added line #L528 was not covered by tests
OpenResult::Err(e) => {
tt_warning!(self.status, "open of stdout failed"; e);
return ptr::null_mut();
return None;

Check warning on line 531 in crates/bridge_core/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/bridge_core/src/lib.rs#L531

Added line #L531 was not covered by tests
}
};

self.output_handles.push(Box::new(oh));
&mut **self.output_handles.last_mut().unwrap()
Some(OutputId(&mut **self.output_handles.last_mut().unwrap()))
}

fn output_write(&mut self, handle: *mut OutputHandle, buf: &[u8]) -> bool {
Expand Down Expand Up @@ -540,45 +562,57 @@
}
}

fn output_close(&mut self, handle: *mut OutputHandle) -> bool {
let len = self.output_handles.len();
/// Close the provided output, flushing it and performing any necessary handling.
pub fn output_close(&mut self, id: OutputId) -> bool {
let mut rv = false;

for i in 0..len {
let p: *const OutputHandle = &*self.output_handles[i];

if p == handle {
let mut oh = self.output_handles.swap_remove(i);
if let Err(e) = oh.flush() {
tt_warning!(self.status, "error when closing output {}", oh.name(); e.into());
rv = true;
}
let (name, digest) = oh.into_name_digest();
self.hooks.event_output_closed(name, digest);
break;
let pos = self
.output_handles
.iter()
.position(|o| ptr::addr_eq(&**o, id.0));
if let Some(pos) = pos {
let mut oh = self.output_handles.swap_remove(pos);
if let Err(e) = oh.flush() {
tt_warning!(self.status, "error when closing output {}", oh.name(); e.into());
rv = true;

Check warning on line 577 in crates/bridge_core/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/bridge_core/src/lib.rs#L576-L577

Added lines #L576 - L577 were not covered by tests
}
let (name, digest) = oh.into_name_digest();
self.hooks.event_output_closed(name, digest);
}

rv
}

fn input_open(&mut self, name: &str, format: FileFormat, is_gz: bool) -> *mut InputHandle {
fn input_to_id(&self, input: *mut InputHandle) -> InputId {
InputId(input)
}

/// Get a mutable reference to an [`InputHandle`] associated with an [`InputId`]
pub fn get_input(&mut self, input: InputId) -> &mut InputHandle {
self.input_handles
.iter_mut()
.find(|i| ptr::addr_eq(&***i, input.0))
.unwrap()
}

/// Open a new input, provided the input name, the file format, and whether it is gzipped.
pub fn input_open(&mut self, name: &str, format: FileFormat, is_gz: bool) -> Option<InputId> {
let name = normalize_tex_path(name);

let (ih, path) = match self.input_open_name_format_gz(&name, format, is_gz) {
OpenResult::Ok(tup) => tup,
OpenResult::NotAvailable => {
return ptr::null_mut();
return None;
}
OpenResult::Err(e) => {
tt_warning!(self.status, "open of input {} failed", name; e);
return ptr::null_mut();
return None;

Check warning on line 609 in crates/bridge_core/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/bridge_core/src/lib.rs#L609

Added line #L609 was not covered by tests
}
};

self.input_handles.push(Box::new(ih));
self.latest_input_path = path;
&mut **self.input_handles.last_mut().unwrap()
Some(InputId(&mut **self.input_handles.last_mut().unwrap()))
}

fn input_open_primary(&mut self) -> *mut InputHandle {
Expand Down Expand Up @@ -650,32 +684,31 @@
rhandle.ungetc(byte)
}

fn input_close(&mut self, handle: *mut InputHandle) -> bool {
let len = self.input_handles.len();

for i in 0..len {
let p: *const InputHandle = &*self.input_handles[i];

if p == handle {
let mut ih = self.input_handles.swap_remove(i);
let mut rv = false;

if let Err(e) = ih.scan_remainder() {
tt_warning!(self.status, "error closing out input {}", ih.name(); e);
rv = true;
}

let (name, digest_opt) = ih.into_name_digest();
self.hooks.event_input_closed(name, digest_opt, self.status);
return rv;
/// Close the provided output, performing any necessary handling.
pub fn input_close(&mut self, id: InputId) -> bool {
let pos = self
.input_handles
.iter()
.position(|i| ptr::addr_eq(&**i, id.0));
if let Some(pos) = pos {
let mut ih = self.input_handles.swap_remove(pos);
let mut rv = false;

if let Err(e) = ih.scan_remainder() {
tt_warning!(self.status, "error closing out input {}", ih.name(); e);
rv = true;

Check warning on line 699 in crates/bridge_core/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/bridge_core/src/lib.rs#L698-L699

Added lines #L698 - L699 were not covered by tests
}

let (name, digest_opt) = ih.into_name_digest();
self.hooks.event_input_closed(name, digest_opt, self.status);
return rv;
}

// TODO: Handle the error better. This indicates a bug in the engine.
tt_error!(
self.status,
"serious internal bug: unexpected handle in input close: {:?}",
handle
id.0
);

true
Expand Down Expand Up @@ -900,13 +933,19 @@
let rname = CStr::from_ptr(name).to_string_lossy();
let ris_gz = is_gz != 0;

es.output_open(&rname, ris_gz)
match es.output_open(&rname, ris_gz) {
Some(id) => es.get_output(id),
None => ptr::null_mut(),

Check warning on line 938 in crates/bridge_core/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/bridge_core/src/lib.rs#L938

Added line #L938 was not covered by tests
}
}

/// Open the general user output stream as a Tectonic output file.
#[no_mangle]
pub extern "C" fn ttbc_output_open_stdout(es: &mut CoreBridgeState) -> *mut OutputHandle {
es.output_open_stdout()
match es.output_open_stdout() {
Some(id) => es.get_output(id),
None => ptr::null_mut(),

Check warning on line 947 in crates/bridge_core/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/bridge_core/src/lib.rs#L947

Added line #L947 was not covered by tests
}
}

/// Write a single character to a Tectonic output file.
Expand Down Expand Up @@ -967,7 +1006,7 @@
return 0; // This is/was the behavior of close_file() in C.
}

libc::c_int::from(es.output_close(handle))
libc::c_int::from(es.output_close(es.output_to_id(handle)))
}

/// Open a Tectonic file for input.
Expand All @@ -984,7 +1023,11 @@
) -> *mut InputHandle {
let rname = CStr::from_ptr(name).to_string_lossy();
let ris_gz = is_gz != 0;
es.input_open(&rname, format, ris_gz)
let id = es.input_open(&rname, format, ris_gz);
match id {
Some(id) => es.get_input(id),
None => ptr::null_mut(),
}
}

/// Open the "primary input" file.
Expand Down Expand Up @@ -1169,7 +1212,7 @@
return 0; // This is/was the behavior of close_file() in C.
}

libc::c_int::from(es.input_close(handle))
libc::c_int::from(es.input_close(es.input_to_id(handle)))
}

/// A buffer for diagnostic messages. Rust code does not need to use this type.
Expand Down
4 changes: 4 additions & 0 deletions crates/engine_bibtex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ tectonic_io_base = { path = "../io_base", version = '0.0.0-dev.0' }
tectonic_bridge_core = { path = "../bridge_core", version = "0.0.0-dev.0" }
tectonic_errors = { path = "../errors", version = "0.0.0-dev.0" }

[dev-dependencies]
tectonic_status_base = { path = "../status_base", version = "0.0.0-dev.0" }

[package.metadata.internal_dep_versions]
tectonic_bridge_core = "thiscommit:2021-01-17:fohCh1sh"
tectonic_errors = "5c9ba661edf5ef669f24f9904f99cca369d999e7"
tectonic_io_base = "0d9169ef44b2652d6d70308a83022bfd60358e71"
tectonic_status_base = "0d9169ef44b2652d6d70308a83022bfd60358e71"
Loading
Loading