Skip to content

Commit 0b59d96

Browse files
committed
Port fatal_error
1 parent eca2cf9 commit 0b59d96

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

crates/engine_xetex/src/c_api/errors.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use crate::c_api::engine::{
33
};
44
use crate::c_api::globals::Globals;
55
use crate::c_api::output::{
6-
rs_capture_to_diagnostic, rs_error_here_with_diagnostic, rs_print_char, rs_print_ln,
7-
rs_print_nl_bytes,
6+
rs_capture_to_diagnostic, rs_error_here_with_diagnostic, rs_print_bytes, rs_print_char,
7+
rs_print_ln, rs_print_nl_bytes,
88
};
99
use std::ffi::CStr;
1010

@@ -141,6 +141,27 @@ extern "C" fn post_error_message(need_to_print_it: i32) {
141141
});
142142
}
143143

144+
#[no_mangle]
145+
pub extern "C" fn fatal_error(s: *const libc::c_char) {
146+
let s = unsafe { CStr::from_ptr(s) }.to_bytes();
147+
Globals::with(|globals| {
148+
rs_pre_error_message(globals);
149+
rs_print_bytes(globals, b"Emergency stop");
150+
rs_print_nl_bytes(globals, s);
151+
rs_capture_to_diagnostic(globals, None);
152+
});
153+
154+
unsafe { close_files_and_terminate() };
155+
unsafe { tt_cleanup() };
156+
157+
Globals::with(|globals| {
158+
globals
159+
.out
160+
.rust_stdout
161+
.map(|stdout| globals.state.output_flush(stdout))
162+
});
163+
}
164+
144165
// TODO: Use the Rust versions directly once they're ported. These just rely indirectly on this
145166
// function, making it easier to port piecemeal.
146167
extern "C" {

crates/engine_xetex/xetex/xetex-errors.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,6 @@
1111

1212
/* WEBby error-handling code: */
1313

14-
void
15-
fatal_error(const char* s)
16-
{
17-
pre_error_message();
18-
print_cstr("Emergency stop");
19-
print_nl_cstr(s);
20-
capture_to_diagnostic(NULL); // started in pre_error_message
21-
22-
close_files_and_terminate();
23-
tt_cleanup();
24-
ttstub_output_flush(rust_stdout());
25-
_tt_abort("%s", s);
26-
}
27-
28-
2914
void
3015
overflow(const char* s, int32_t n)
3116
{

crates/engine_xetex/xetex/xetex_bindings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ void error(void);
764764

765765
void post_error_message(int32_t need_to_print_it);
766766

767+
void fatal_error(void);
768+
767769
extern void close_files_and_terminate(void);
768770

769771
extern void tt_cleanup(void);

0 commit comments

Comments
 (0)