Skip to content

Commit a1d1212

Browse files
authored
Merge pull request #899 from matz-e/better-external-tool-errors
Augment error message when opening files for external tools
2 parents c77ef78 + 1493593 commit a1d1212

File tree

16 files changed

+285
-218
lines changed

16 files changed

+285
-218
lines changed

Cargo.lock

Lines changed: 224 additions & 189 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bridge_core/src/lib.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
//!
1515
//! [cbindgen]: https://github.com/eqrion/cbindgen
1616
//!
17+
//! If you change the interfaces here, rerun cbindgen as described in the README!
18+
//!
1719
//! In order to provide access to a C/C++ engine in Rust, you should create some
1820
//! kind of interface that expects to be given a reference to a
1921
//! [`CoreBridgeLauncher`] struct. You should use that struct's
@@ -589,7 +591,7 @@ impl<'a> CoreBridgeState<'a> {
589591
}
590592
}
591593

592-
fn input_get_mtime(&mut self, handle: *mut InputHandle) -> libc::time_t {
594+
fn input_get_mtime(&mut self, handle: *mut InputHandle) -> i64 {
593595
let rhandle: &mut InputHandle = unsafe { &mut *handle };
594596

595597
let maybe_time = match rhandle.get_unix_mtime() {
@@ -601,7 +603,7 @@ impl<'a> CoreBridgeState<'a> {
601603
};
602604

603605
if let Some(t) = maybe_time {
604-
t as libc::time_t
606+
t
605607
} else {
606608
1 // Intentionally make this distinguishable from the error value 0
607609
}
@@ -1020,10 +1022,7 @@ pub extern "C" fn ttbc_input_get_size(
10201022

10211023
/// Get the modification time of a Tectonic input file.
10221024
#[no_mangle]
1023-
pub extern "C" fn ttbc_input_get_mtime(
1024-
es: &mut CoreBridgeState,
1025-
handle: *mut InputHandle,
1026-
) -> libc::time_t {
1025+
pub extern "C" fn ttbc_input_get_mtime(es: &mut CoreBridgeState, handle: *mut InputHandle) -> i64 {
10271026
es.input_get_mtime(handle)
10281027
}
10291028

crates/bridge_core/support/support.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,12 @@ ttstub_input_get_size(rust_input_handle_t handle)
254254
time_t
255255
ttstub_input_get_mtime(rust_input_handle_t handle)
256256
{
257-
return ttbc_input_get_mtime(tectonic_global_bridge_core, handle);
257+
/* Due to the Musl 1.2 "time64" transition, we can't safely bridge time_t
258+
* between Rust and C code. And formally, ISO C provides nearly no
259+
* guarantees about what the type time_t actually is. So let's just cast and
260+
* hope for the best. */
261+
int64_t ti = ttbc_input_get_mtime(tectonic_global_bridge_core, handle);
262+
return (time_t) ti;
258263
}
259264

260265

crates/bridge_core/support/tectonic_bridge_core_generated.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ size_t ttbc_input_get_size(ttbc_state_t *es, ttbc_input_handle_t *handle);
262262
/**
263263
* Get the modification time of a Tectonic input file.
264264
*/
265-
time_t ttbc_input_get_mtime(ttbc_state_t *es, ttbc_input_handle_t *handle);
265+
int64_t ttbc_input_get_mtime(ttbc_state_t *es, ttbc_input_handle_t *handle);
266266

267267
/**
268268
* Seek in a Tectonic input stream.

crates/bridge_flate/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
//! This crate provides a few extern "C" functions that expose the functionality
77
//! of the flate2 crate in a C API that can be consumed by other C/C++ code in
88
//! the Tectonic codebase.
9+
//!
10+
//! If you change the interfaces here, rerun cbindgen as described in the README!
911
1012
use flate2::{Compress, Compression, Decompress, FlushCompress, FlushDecompress, Status};
1113
use std::{

crates/engine_bibtex/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
//!
1717
//! [Tectonic]: https://tectonic-typesetting.github.io/
1818
//! [`tectonic`]: https://docs.rs/tectonic/
19+
//!
20+
//! If you change the interfaces here, rerun cbindgen as described in the README!
1921
2022
use std::ffi::CString;
2123
use tectonic_bridge_core::{CoreBridgeLauncher, EngineAbortedError};

crates/engine_xdvipdfmx/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl XdvipdfmxEngine {
124124
.build_date
125125
.duration_since(SystemTime::UNIX_EPOCH)
126126
.expect("invalid build date")
127-
.as_secs() as libc::time_t,
127+
.as_secs(),
128128
};
129129

130130
let cdvi = CString::new(dvi)?;
@@ -147,6 +147,8 @@ impl XdvipdfmxEngine {
147147

148148
#[doc(hidden)]
149149
pub mod c_api {
150+
// If you change the interfaces here, rerun cbindgen as described in the README!
151+
150152
use tectonic_bridge_core::CoreBridgeState;
151153

152154
#[derive(Debug)]
@@ -155,7 +157,7 @@ pub mod c_api {
155157
pub paperspec: *const libc::c_char,
156158
pub enable_compression: libc::c_uchar,
157159
pub deterministic_tags: libc::c_uchar,
158-
pub build_date: libc::time_t,
160+
pub build_date: u64,
159161
}
160162

161163
#[allow(improper_ctypes)] // for CoreBridgeState

crates/engine_xdvipdfmx/xdvipdfmx/dvipdfmx.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,9 @@ tt_engine_xdvipdfmx_main(
499499
return 99;
500500
}
501501

502+
/* See ttstub_input_get_mtime() in tectonic_bridge_core about bridging time_t
503+
* over FFI. */
504+
502505
rv = dvipdfmx_main(
503506
pdfname,
504507
dviname,
@@ -509,7 +512,7 @@ tt_engine_xdvipdfmx_main(
509512
(bool) config->deterministic_tags,
510513
false, /* quiet */
511514
0, /* verbose */
512-
config->build_date,
515+
(time_t) config->build_date,
513516
config->paperspec
514517
);
515518

crates/engine_xdvipdfmx/xdvipdfmx/xdvipdfmx_bindings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ typedef struct {
1010
const char *paperspec;
1111
unsigned char enable_compression;
1212
unsigned char deterministic_tags;
13-
time_t build_date;
13+
uint64_t build_date;
1414
} XdvipdfmxConfig;
1515

1616
#ifdef __cplusplus

crates/engine_xetex/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ impl TexEngine {
228228
self.build_date
229229
.duration_since(SystemTime::UNIX_EPOCH)
230230
.expect("invalid build date")
231-
.as_secs() as libc::time_t,
231+
.as_secs(),
232232
)
233233
};
234234

@@ -245,6 +245,8 @@ impl TexEngine {
245245

246246
#[doc(hidden)]
247247
pub mod c_api {
248+
// If you change the interfaces here, rerun cbindgen as described in the README!
249+
248250
use tectonic_bridge_core::CoreBridgeState;
249251

250252
#[allow(improper_ctypes)] // for CoreBridgeState
@@ -258,7 +260,7 @@ pub mod c_api {
258260
api: &mut CoreBridgeState,
259261
dump_name: *const libc::c_char,
260262
input_file_name: *const libc::c_char,
261-
build_date: libc::time_t,
263+
build_date: u64,
262264
) -> libc::c_int;
263265
}
264266
}

0 commit comments

Comments
 (0)