Move POD components of library_data_t to separate struct

This allows them to be accessed as regular fields from Rust, rather than having
to create setter/getter methods for each of them.
This commit is contained in:
Xiretza 2023-02-11 18:15:27 +01:00 committed by Johannes Altmanninger
parent 59fe124c40
commit 77a474ee37
5 changed files with 22 additions and 19 deletions

View file

@ -2,7 +2,7 @@ use libc::c_int;
use super::r#return::parse_return_value;
use super::shared::io_streams_t;
use crate::ffi::{parser_t, Repin};
use crate::ffi::parser_t;
use crate::wchar::wstr;
/// Function for handling the exit builtin.
@ -20,7 +20,7 @@ pub fn exit(
// TODO: in concurrent mode this won't successfully exit a pipeline, as there are other parsers
// involved. That is, `exit | sleep 1000` may not exit as hoped. Need to rationalize what
// behavior we want here.
parser.pin().libdata().set_exit_current_script(true);
parser.libdata_pod().exit_current_script = true;
return Some(retval);
}

View file

@ -8,7 +8,7 @@ use super::shared::{
BUILTIN_ERR_NOT_NUMBER, STATUS_CMD_OK, STATUS_INVALID_ARGS,
};
use crate::builtins::shared::BUILTIN_ERR_TOO_MANY_ARGUMENTS;
use crate::ffi::{parser_t, Repin};
use crate::ffi::parser_t;
use crate::wchar::{wstr, L};
use crate::wgetopt::{wgetopter_t, wopt, woption, woption_argument_t};
use crate::wutil::fish_wcstoi;
@ -79,14 +79,15 @@ pub fn r#return(
// If we're not in a function, exit the current script (but not an interactive shell).
if !has_function_block {
if !parser.is_interactive() {
parser.pin().libdata().set_exit_current_script(true);
let ld = parser.libdata_pod();
if !ld.is_interactive {
ld.exit_current_script = true;
}
return Some(retval);
}
// Mark a return in the libdata.
parser.pin().libdata().set_returning(true);
parser.libdata_pod().returning = true;
return Some(retval);
}

View file

@ -47,6 +47,7 @@ include_cpp! {
generate!("job_t")
generate!("process_t")
generate!("library_data_t")
generate_pod!("library_data_pod_t")
generate!("proc_wait_any")
@ -80,6 +81,12 @@ impl parser_t {
let ffi_jobs = self.ffi_jobs();
unsafe { slice::from_raw_parts(ffi_jobs.jobs, ffi_jobs.count) }
}
pub fn libdata_pod(&mut self) -> &mut library_data_pod_t {
let libdata = self.pin().ffi_libdata_pod();
unsafe { &mut *libdata }
}
}
impl job_t {

View file

@ -39,14 +39,6 @@ static wcstring user_presentable_path(const wcstring &path, const environment_t
return replace_home_directory_with_tilde(path, vars);
}
void library_data_t::set_exit_current_script(bool val) {
exit_current_script = val;
};
void library_data_t::set_returning(bool val) {
returning = val;
};
parser_t::parser_t(std::shared_ptr<env_stack_t> vars, bool is_principal)
: variables(std::move(vars)), is_principal_(is_principal) {
assert(variables.get() && "Null variables in parser initializer");
@ -497,6 +489,8 @@ job_t *parser_t::job_get_from_pid(pid_t pid) const {
return nullptr;
}
library_data_pod_t *parser_t::ffi_libdata_pod() { return &library_data; }
profile_item_t *parser_t::create_profile_item() {
if (g_profiling_active) {
profile_items.emplace_back();

View file

@ -146,8 +146,8 @@ struct profile_item_t {
class parse_execution_context_t;
/// Miscellaneous data used to avoid recursion and others.
struct library_data_t {
/// Plain-Old-Data components of `struct library_data_t` that can be shared over FFI
struct library_data_pod_t {
/// A counter incremented every time a command executes.
uint64_t exec_count{0};
@ -207,7 +207,10 @@ struct library_data_t {
/// The read limit to apply to captured subshell output, or 0 for none.
size_t read_limit{0};
};
/// Miscellaneous data used to avoid recursion and others.
struct library_data_t : public library_data_pod_t {
/// The current filename we are evaluating, either from builtin source or on the command line.
filename_ref_t current_filename{};
@ -231,9 +234,6 @@ struct library_data_t {
/// Used to get the full text of the current job for `status current-commandline`.
wcstring commandline;
} status_vars;
void set_exit_current_script(bool val);
void set_returning(bool val);
};
/// The result of parser_t::eval family.
@ -486,6 +486,7 @@ class parser_t : public std::enable_shared_from_this<parser_t> {
/// autocxx junk.
RustFFIJobList ffi_jobs() const;
library_data_pod_t *ffi_libdata_pod();
/// autocxx junk.
bool ffi_has_funtion_block() const;