Skip to content

Commit 5cf8609

Browse files
committed
Remove C code from engine_bibtex
1 parent ce0dd00 commit 5cf8609

12 files changed

Lines changed: 57 additions & 206 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/engine_bibtex/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,13 @@ repository = "https://github.com/tectonic-typesetting/tectonic/"
1616
readme = "README.md"
1717
license = "MIT"
1818
edition = "2018"
19-
links = "tectonic_engine_bibtex"
2019

2120
[dependencies]
2221
libc = "^0.2"
2322
tectonic_io_base = { path = "../io_base", version = '0.0.0-dev.0' }
2423
tectonic_bridge_core = { path = "../bridge_core", version = "0.0.0-dev.0" }
2524
tectonic_errors = { path = "../errors", version = "0.0.0-dev.0" }
2625

27-
[build-dependencies]
28-
cc = "^1.0.66"
29-
3026
[package.metadata.internal_dep_versions]
3127
tectonic_bridge_core = "thiscommit:2021-01-17:fohCh1sh"
3228
tectonic_errors = "5c9ba661edf5ef669f24f9904f99cca369d999e7"

crates/engine_bibtex/bibtex/bibtex.c

Lines changed: 0 additions & 25 deletions
This file was deleted.

crates/engine_bibtex/bibtex/bibtex_bindings.h

Lines changed: 0 additions & 70 deletions
This file was deleted.

crates/engine_bibtex/build.rs

Lines changed: 0 additions & 23 deletions
This file was deleted.

crates/engine_bibtex/cbindgen.toml

Lines changed: 0 additions & 14 deletions
This file was deleted.

crates/engine_bibtex/src/c_api/auxi.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ fn aux_bib_data_command(
146146

147147
let name = pool.get_str(bibs.cur_bib());
148148
let fname = CString::new(name).unwrap();
149-
let bib_in = peekable_open(&fname, FileFormat::Bib);
149+
let bib_in = peekable_open(ctx, &fname, FileFormat::Bib);
150150
if bib_in.is_null() {
151151
write_logs("I couldn't open database file ");
152152
print_bib_name(pool, bibs)?;
@@ -210,7 +210,7 @@ fn aux_bib_style_command(
210210

211211
let name = pool.get_str(ctx.bst_str);
212212
let fname = CString::new(name).unwrap();
213-
let ptr = peekable_open(&fname, FileFormat::Bst);
213+
let ptr = peekable_open(ctx, &fname, FileFormat::Bst);
214214
if ptr.is_null() {
215215
write_logs("I couldn't open style file ");
216216
print_bst_name(ctx, pool)?;
@@ -334,7 +334,7 @@ fn aux_citation_command(
334334
}
335335

336336
fn aux_input_command(
337-
ctx: &Bibtex,
337+
ctx: &mut Bibtex,
338338
buffers: &mut GlobalBuffer,
339339
aux: &mut AuxData,
340340
pool: &mut StringPool,
@@ -401,7 +401,7 @@ fn aux_input_command(
401401

402402
let name = pool.get_str(aux.at_ptr());
403403
let fname = CString::new(name).unwrap();
404-
let ptr = peekable_open(&fname, FileFormat::Tex);
404+
let ptr = peekable_open(ctx, &fname, FileFormat::Tex);
405405
if ptr.is_null() {
406406
write_logs("I couldn't open auxiliary file ");
407407
print_aux_name(aux, pool)?;
@@ -476,9 +476,9 @@ pub(crate) fn get_aux_command_and_process(
476476
Ok(())
477477
}
478478

479-
pub(crate) fn pop_the_aux_stack(aux: &mut AuxData) -> bool {
479+
pub(crate) fn pop_the_aux_stack(ctx: &mut Bibtex<'_, '_>, aux: &mut AuxData) -> bool {
480480
// SAFETY: Aux file at pointer guaranteed valid at this point
481-
unsafe { peekable_close(NonNull::new(aux.file_at_ptr())) };
481+
unsafe { peekable_close(ctx, NonNull::new(aux.file_at_ptr())) };
482482
aux.set_file_at_ptr(ptr::null_mut());
483483
if aux.ptr() == 0 {
484484
true

crates/engine_bibtex/src/c_api/bst.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ fn bst_read_command(ctx: &mut ExecCtx, globals: &mut GlobalItems<'_>) -> Result<
579579
)?;
580580
}
581581
// SAFETY: take_cur_bib_file returns reference to which we're the last owner
582-
unsafe { peekable_close(globals.bibs.take_cur_bib_file().map(NonNull::from)) };
582+
unsafe { peekable_close(ctx.glbl_ctx_mut(), globals.bibs.take_cur_bib_file().map(NonNull::from)) };
583583
globals.bibs.set_ptr(globals.bibs.ptr() + 1);
584584
}
585585

crates/engine_bibtex/src/c_api/exec.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ impl ExecVal {
6161
// SAFETY: We require our zero discriminant to be an integer, which is valid for any bit pattern, including 0
6262
unsafe impl SafelyZero for ExecVal {}
6363

64-
#[repr(C)]
65-
pub struct ExecCtx {
66-
pub glbl_ctx: *mut Bibtex,
64+
pub(crate) struct ExecCtx<'a, 'bib, 'cbs> {
65+
pub glbl_ctx: &'a mut Bibtex<'bib, 'cbs>,
6766
pub _default: HashPointer,
6867
pub(crate) lit_stack: Box<XBuf<ExecVal>>,
6968
pub lit_stk_ptr: usize,
@@ -72,8 +71,8 @@ pub struct ExecCtx {
7271
pub bib_str_ptr: StrNumber,
7372
}
7473

75-
impl ExecCtx {
76-
pub(crate) fn new(glbl_ctx: &mut Bibtex) -> ExecCtx {
74+
impl<'a, 'bib, 'cbs> ExecCtx<'a, 'bib, 'cbs> {
75+
pub(crate) fn new(glbl_ctx: &'a mut Bibtex<'bib, 'cbs>) -> ExecCtx<'a, 'bib, 'cbs> {
7776
ExecCtx {
7877
glbl_ctx,
7978
_default: 0,
@@ -125,14 +124,12 @@ impl ExecCtx {
125124
self.lit_stack.grow(LIT_STK_SIZE);
126125
}
127126

128-
pub(crate) fn glbl_ctx(&self) -> &Bibtex {
129-
// SAFETY: Contained pointer is always valid
130-
unsafe { &*self.glbl_ctx }
127+
pub(crate) fn glbl_ctx(&self) -> &Bibtex<'bib, 'cbs> {
128+
&*self.glbl_ctx
131129
}
132130

133-
pub(crate) fn glbl_ctx_mut(&mut self) -> &mut Bibtex {
134-
// SAFETY: Contained pointer is always valid
135-
unsafe { &mut *self.glbl_ctx }
131+
pub(crate) fn glbl_ctx_mut(&mut self) -> &mut Bibtex<'bib, 'cbs> {
132+
&mut *self.glbl_ctx
136133
}
137134
}
138135

crates/engine_bibtex/src/c_api/log.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
peekable::input_ln,
1313
pool::StringPool,
1414
scan::{Scan, ScanRes},
15-
ttstub_output_close, ttstub_output_open, ttstub_output_open_stdout, ASCIICode, Bibtex,
15+
ttbc_output_close, ttbc_output_open, ttbc_output_open_stdout, ASCIICode, Bibtex,
1616
CiteNumber, FieldLoc, HashPointer, StrNumber,
1717
},
1818
BibtexError,
@@ -79,12 +79,12 @@ pub(crate) fn write_log_file<B: ?Sized + AsBytes>(str: &B) {
7979
with_log(|log| log.write_all(str.as_bytes())).unwrap();
8080
}
8181

82-
pub(crate) fn init_log_file(file: &CStr) -> bool {
82+
pub(crate) fn init_log_file(ctx: &mut Bibtex<'_, '_>, file: &CStr) -> bool {
8383
LOG_FILE.with(|log| {
8484
let ptr = log.replace(None);
8585
if ptr.is_none() {
8686
// SAFETY: Our CStr is valid for the length of the call, so this can't access bad memory
87-
let new = unsafe { ttstub_output_open(file.as_ptr(), 0) };
87+
let new = unsafe { ttbc_output_open(ctx.engine, file.as_ptr(), 0) };
8888
// SAFETY: Return of ttstub_output_open should be valid if non-null
8989
log.set(unsafe { new.as_mut() });
9090
!new.is_null()
@@ -95,12 +95,12 @@ pub(crate) fn init_log_file(file: &CStr) -> bool {
9595
})
9696
}
9797

98-
pub fn init_standard_output() -> bool {
98+
pub(crate) fn init_standard_output(ctx: &mut Bibtex<'_, '_>) -> bool {
9999
STANDARD_OUTPUT.with(|out| {
100100
let ptr = out.replace(None);
101101
if ptr.is_none() {
102102
// SAFETY: This is actually fine to call, just extern
103-
let stdout = unsafe { ttstub_output_open_stdout() };
103+
let stdout = unsafe { ttbc_output_open_stdout(ctx.engine) };
104104
// SAFETY: Pointer from ttstub_output_open_stdout is valid if non-null
105105
out.set(unsafe { stdout.as_mut() });
106106
!stdout.is_null()
@@ -111,12 +111,12 @@ pub fn init_standard_output() -> bool {
111111
})
112112
}
113113

114-
pub fn bib_close_log() {
114+
pub(crate) fn bib_close_log(ctx: &mut Bibtex<'_, '_>) {
115115
LOG_FILE.with(|log| {
116116
let log = log.replace(None);
117117
if let Some(log) = log {
118118
// SAFETY: Log is valid due to being a mut ref
119-
unsafe { ttstub_output_close(log) };
119+
unsafe { ttbc_output_close(ctx.engine, log) };
120120
}
121121
})
122122
}

0 commit comments

Comments
 (0)