Skip to content

Augment error message when opening files for external tools #899

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

Merged
merged 9 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
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
413 changes: 224 additions & 189 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions crates/bridge_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
//!
//! [cbindgen]: https://github.com/eqrion/cbindgen
//!
//! If you change the interfaces here, rerun cbindgen as described in the README!
//!
//! In order to provide access to a C/C++ engine in Rust, you should create some
//! kind of interface that expects to be given a reference to a
//! [`CoreBridgeLauncher`] struct. You should use that struct's
Expand Down Expand Up @@ -589,7 +591,7 @@ impl<'a> CoreBridgeState<'a> {
}
}

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

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

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

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

Expand Down
7 changes: 6 additions & 1 deletion crates/bridge_core/support/support.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,12 @@ ttstub_input_get_size(rust_input_handle_t handle)
time_t
ttstub_input_get_mtime(rust_input_handle_t handle)
{
return ttbc_input_get_mtime(tectonic_global_bridge_core, handle);
/* Due to the Musl 1.2 "time64" transition, we can't safely bridge time_t
* between Rust and C code. And formally, ISO C provides nearly no
* guarantees about what the type time_t actually is. So let's just cast and
* hope for the best. */
int64_t ti = ttbc_input_get_mtime(tectonic_global_bridge_core, handle);
return (time_t) ti;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ size_t ttbc_input_get_size(ttbc_state_t *es, ttbc_input_handle_t *handle);
/**
* Get the modification time of a Tectonic input file.
*/
time_t ttbc_input_get_mtime(ttbc_state_t *es, ttbc_input_handle_t *handle);
int64_t ttbc_input_get_mtime(ttbc_state_t *es, ttbc_input_handle_t *handle);

/**
* Seek in a Tectonic input stream.
Expand Down
2 changes: 2 additions & 0 deletions crates/bridge_flate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//! This crate provides a few extern "C" functions that expose the functionality
//! of the flate2 crate in a C API that can be consumed by other C/C++ code in
//! the Tectonic codebase.
//!
//! If you change the interfaces here, rerun cbindgen as described in the README!

use flate2::{Compress, Compression, Decompress, FlushCompress, FlushDecompress, Status};
use std::{
Expand Down
2 changes: 2 additions & 0 deletions crates/engine_bibtex/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
//!
//! [Tectonic]: https://tectonic-typesetting.github.io/
//! [`tectonic`]: https://docs.rs/tectonic/
//!
//! If you change the interfaces here, rerun cbindgen as described in the README!

use std::ffi::CString;
use tectonic_bridge_core::{CoreBridgeLauncher, EngineAbortedError};
Expand Down
6 changes: 4 additions & 2 deletions crates/engine_xdvipdfmx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl XdvipdfmxEngine {
.build_date
.duration_since(SystemTime::UNIX_EPOCH)
.expect("invalid build date")
.as_secs() as libc::time_t,
.as_secs(),
};

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

#[doc(hidden)]
pub mod c_api {
// If you change the interfaces here, rerun cbindgen as described in the README!

use tectonic_bridge_core::CoreBridgeState;

#[derive(Debug)]
Expand All @@ -155,7 +157,7 @@ pub mod c_api {
pub paperspec: *const libc::c_char,
pub enable_compression: libc::c_uchar,
pub deterministic_tags: libc::c_uchar,
pub build_date: libc::time_t,
pub build_date: u64,
}

#[allow(improper_ctypes)] // for CoreBridgeState
Expand Down
5 changes: 4 additions & 1 deletion crates/engine_xdvipdfmx/xdvipdfmx/dvipdfmx.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,9 @@ tt_engine_xdvipdfmx_main(
return 99;
}

/* See ttstub_input_get_mtime() in tectonic_bridge_core about bridging time_t
* over FFI. */

rv = dvipdfmx_main(
pdfname,
dviname,
Expand All @@ -509,7 +512,7 @@ tt_engine_xdvipdfmx_main(
(bool) config->deterministic_tags,
false, /* quiet */
0, /* verbose */
config->build_date,
(time_t) config->build_date,
config->paperspec
);

Expand Down
2 changes: 1 addition & 1 deletion crates/engine_xdvipdfmx/xdvipdfmx/xdvipdfmx_bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ typedef struct {
const char *paperspec;
unsigned char enable_compression;
unsigned char deterministic_tags;
time_t build_date;
uint64_t build_date;
} XdvipdfmxConfig;

#ifdef __cplusplus
Expand Down
6 changes: 4 additions & 2 deletions crates/engine_xetex/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ impl TexEngine {
self.build_date
.duration_since(SystemTime::UNIX_EPOCH)
.expect("invalid build date")
.as_secs() as libc::time_t,
.as_secs(),
)
};

Expand All @@ -245,6 +245,8 @@ impl TexEngine {

#[doc(hidden)]
pub mod c_api {
// If you change the interfaces here, rerun cbindgen as described in the README!

use tectonic_bridge_core::CoreBridgeState;

#[allow(improper_ctypes)] // for CoreBridgeState
Expand All @@ -258,7 +260,7 @@ pub mod c_api {
api: &mut CoreBridgeState,
dump_name: *const libc::c_char,
input_file_name: *const libc::c_char,
build_date: libc::time_t,
build_date: u64,
) -> libc::c_int;
}
}
Expand Down
8 changes: 5 additions & 3 deletions crates/engine_xetex/xetex/xetex-engine-interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ int tt_engine_xetex_main(
ttbc_state_t *api,
const char *dump_name,
const char *input_file_name,
time_t build_date
uint64_t build_date
);

/* These functions aren't used within the C/C++ library, but are called
Expand Down Expand Up @@ -53,7 +53,7 @@ tt_engine_xetex_main(
ttbc_state_t *api,
const char *dump_name,
const char *input_file_name,
time_t build_date
uint64_t build_date
) {
int rv;

Expand All @@ -62,7 +62,9 @@ tt_engine_xetex_main(
return HISTORY_FATAL_ERROR;
}

rv = tt_run_engine(dump_name, input_file_name, build_date);
/* See ttstub_input_get_mtime() in tectonic_bridge_core about bridging time_t
* over FFI. */
rv = tt_run_engine(dump_name, input_file_name, (time_t) build_date);
ttbc_global_engine_exit();
return rv;
}
2 changes: 1 addition & 1 deletion crates/engine_xetex/xetex/xetex_bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extern int tt_xetex_set_int_variable(const char *var_name, int value);
extern int tt_engine_xetex_main(ttbc_state_t *api,
const char *dump_name,
const char *input_file_name,
time_t build_date);
uint64_t build_date);

#ifdef __cplusplus
} // extern "C"
Expand Down
4 changes: 2 additions & 2 deletions crates/pdf_io/pdf_io/dpx-pdfobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,11 +675,11 @@ pdf_out_flush (void)

if (dpx_conf.verbose_level > 0) {
if (p->options.compression.level > 0) {
dpx_message("Compression saved %ld bytes\n", p->output.compression_saved);
dpx_message("Compression saved %"PRIuZ" bytes\n", p->output.compression_saved);
}
}

dpx_message("%ld bytes written", p->output.file_position);
dpx_message("%"PRIuZ" bytes written", p->output.file_position);

ttstub_output_close(p->output.handle);
p->output.handle = NULL;
Expand Down
12 changes: 6 additions & 6 deletions crates/xetex_format/src/enums/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ macro_rules! inner_declare_primitive_value {
///
/// Usage:
///
/// ```
/// ```text
/// {
/// var $VARNAME1 $SYMNAME1 $SINCE1 [$VALUESOURCE1],
/// var $VARNAME2 $SYMNAME2 $SINCE2 [$VALUESOURCE2],
Expand All @@ -163,7 +163,7 @@ macro_rules! inner_declare_primitive_value {
///
/// basically becomes
///
/// ```
/// ```text
/// pub enum Enumeration {
/// $VARNAME1,
/// $VARNAME2,
Expand Down Expand Up @@ -207,14 +207,14 @@ macro_rules! inner_declare_enum {
///
/// Usage:
///
/// ```
/// ```text
/// (var $VARNAME $SYMNAME $SINCE [$VALUESOURCE])
/// ```
///
/// becomes a `DynamicEnumItemDescription` initializer with `absval`
/// of `Some(Enumeration::$VARNAME)`, while
///
/// ```
/// ```text
/// (not ....)
/// ```
///
Expand Down Expand Up @@ -259,7 +259,7 @@ macro_rules! inner_declare_desc {
///
/// Usage:
///
/// ```
/// ```text
/// declare! {
/// EnumName enum_name {
/// var First FIRST_CODE 10 [Next],
Expand All @@ -271,7 +271,7 @@ macro_rules! inner_declare_desc {
///
/// evaluates to something along the lines of
///
/// ```
/// ```text
/// pub mod enum_name {
/// pub enum Enumeration {
/// First,
Expand Down
16 changes: 14 additions & 2 deletions crates/xetex_layout/layout/xetex-XeTeXFontMgr_FC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ XeTeXFontMgr_FC::readNames(FcPattern* pat)
case kPreferredSubfamilyName:
{
bool preferredName = false;
if (nameRec.platform_id == TT_PLATFORM_MACINTOSH
/* Tectonic: macRomanConv may not be available; see comment below */
if (macRomanConv != NULL && nameRec.platform_id == TT_PLATFORM_MACINTOSH
&& nameRec.encoding_id == TT_MAC_ID_ROMAN && nameRec.language_id == 0) {
utf8name = convertToUtf8(macRomanConv, nameRec.string, nameRec.string_len);
preferredName = true;
Expand Down Expand Up @@ -319,10 +320,21 @@ XeTeXFontMgr_FC::initialize()
_tt_abort("FreeType initialization failed");

UErrorCode err = U_ZERO_ERROR;

/* Tectonic: Alpine >=3.16 splits the ICU data in a way that seems to make
* the "macintosh" converter unavailable in our MUSL static builds. I don't
* see a workaround: installing `icu-data-full` doesn't help, I think
* because the static libraries don't access the data file that it provides.
*/
macRomanConv = ucnv_open("macintosh", &err);
if (!U_SUCCESS(err)) {
err = U_ZERO_ERROR;
macRomanConv = NULL;
}

utf16beConv = ucnv_open("UTF16BE", &err);
utf8Conv = ucnv_open("UTF8", &err);
if (err)
if (!U_SUCCESS(err))
_tt_abort("cannot read font names");

FcPattern* pat = FcNameParse((const FcChar8*)":outline=true");
Expand Down
5 changes: 4 additions & 1 deletion src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,10 @@ impl BridgeState {
));
}

let mut ih = self.input_open_name(name, status).must_exist()?;
let mut ih = ctry!(
self.input_open_name(name, status).must_exist();
"can't open path `{}`", name
);

// If the input path is absolute, we don't need to create a
// version in the tempdir, and in fact the current
Expand Down