Skip to main content

SubshellSnapshot

Struct SubshellSnapshot 

Source
pub struct SubshellSnapshot {
Show 15 fields pub paramtab: HashMap<String, Param>, pub paramtab_hashed_storage: HashMap<String, IndexMap<String, String>>, pub positional_params: Vec<String>, pub env_vars: HashMap<String, String>, pub cwd: Option<PathBuf>, pub umask: u32, pub traps: HashMap<String, String>, pub opts: HashMap<String, bool>, pub aliases: Vec<(String, String)>, pub shfuncs: HashMap<String, Box<shfunc>>, pub functions_compiled: HashMap<String, Chunk>, pub function_source: HashMap<String, String>, pub modules: HashMap<String, i32>, pub thingytab: HashMap<String, Thingy>, pub keymapnamtab: HashMap<String, KeymapName>,
}
Expand description

Snapshot of subshell-isolated state. Captured at ( entry, restored at ) exit. zsh subshell semantics: assignments inside (…) don’t leak to the outer scope — and that includes export. zsh forks a child for the subshell so the child’s env::set_var dies with the child; without a fork (zshrs runs subshells in-process for perf), we snapshot+restore the OS env table around the subshell. Otherwise (export y=v) would leak y to the parent shell, breaking every script that uses a subshell to scope an env override. Snapshot of mutable executor state across a subshell boundary. Port of the entersubsh() save/restore Src/exec.c does at line 1084 — captures everything that must be replaced when a (...) group fires.

Fields§

§paramtab: HashMap<String, Param>

Snapshot of paramtab (the C-canonical parameter store) at subshell entry. Step 1 of the unification mirrors writes to paramtab, so subshell-scoped assignments now show up there too — without this snapshot, restoring only variables / arrays / assoc_arrays leaks the subshell’s writes to the parent via paramtab (e.g. x=outer; (x=inner); echo $x returned inner because paramsubst reads through paramtab).

§paramtab_hashed_storage: HashMap<String, IndexMap<String, String>>

paramtab_hashed_storage field.

§positional_params: Vec<String>

positional_params field.

§env_vars: HashMap<String, String>

env_vars field.

§cwd: Option<PathBuf>

Process working directory at subshell entry. cd inside the subshell shouldn’t leak to the parent; we restore on End.

§umask: u32

File-creation mask at subshell entry. zsh forks for (...) so umask set inside dies with the child; we run subshells in process so we must restore the mask on End. Otherwise umask 022; (umask 077); umask shows 077 in the parent.

§traps: HashMap<String, String>

Parent’s traps at subshell entry. zsh’s (trap "echo X" EXIT; true) runs the trap when the subshell exits — BEFORE the parent continues. Without this snapshot, the trap inherited from parent would fire, OR a trap set inside the subshell would leak to the parent’s process exit. Restored on subshell_end after the subshell’s own EXIT trap (if any) has fired. Stores a snapshot of crate::ported::builtin::traps_table() (canonical).

§opts: HashMap<String, bool>

Parent’s shell options at subshell entry. (set -e) / (setopt extendedglob) mustn’t leak; zsh forks the subshell so child options die with the child. We run in-process, so we must restore the option store on subshell_end.

§aliases: Vec<(String, String)>

Parent’s alias entries at subshell entry. zsh forks for (...) so (alias x=y) inside a subshell dies with the child and doesn’t leak to the parent. zshrs runs subshells in-process, so we must restore the alias table on subshell_end. Bug #209 in docs/BUGS.md. Stored as a flat Vec<(name, text)> snapshot — the underlying alias_table holds an IndexMap<String, alias> but alias carries hashnode metadata we don’t need to round-trip; only name + text are observable via alias NAME lookup.

§shfuncs: HashMap<String, Box<shfunc>>

Parent’s shell-function table at subshell entry. C zsh’s entersubsh (Src/exec.c) forks before running the subshell body so (f() { ... }) defining a function dies with the child and never leaks to the parent. zshrs runs subshells in-process, so we must clone shfunctab on entry and restore on exit. Bug #208 in docs/BUGS.md. Stored as the full HashMap<String, Box<shfunc>> clone — shfunc is Clone and the table snapshot is bounded by the user’s declared function set.

§functions_compiled: HashMap<String, Chunk>

Parent’s compiled-function chunks at subshell entry. Companion to shfuncs above — ShellExecutor.functions_compiled is the runtime dispatch table that Op::CallFunction reads through; without restoring it, a subshell (g() { override; }) leaves the override bytecode chunk in place so the parent’s g call still runs the override after subshell_end restored shfunctab. Bug #208 in docs/BUGS.md.

§function_source: HashMap<String, String>

Parent’s function source map at subshell entry. Companion to functions_compiled so typeset -f / whence show the parent’s source after subshell exit, not the subshell’s overridden body. Bug #208 in docs/BUGS.md.

§modules: HashMap<String, i32>

Parent’s modulestab modules map at subshell entry. zsh forks for (...) so a (zmodload zsh/X) inside the subshell sets MOD_INIT_B on the child’s modulestab; when the child exits the flag dies with it and the parent’s modulestab is untouched. zshrs runs subshells in-process, so a subshell zmodload would otherwise flip the parent’s ${modules[zsh/X]} from unset to “loaded”. Snapshot here and restore on subshell_end. Bug #210 in docs/BUGS.md. Stored as (name → flags) since module struct doesn’t derive Clone (LinkList/ Linkedmod) — and the only thing zmodload mutates that affects introspection is the flags bitmask (MOD_INIT_B for loaded, MOD_UNLOAD for unloaded).

§thingytab: HashMap<String, Thingy>

Parent’s THINGYTAB (ZLE widget registry) at subshell entry. zsh forks for (...) so zle -N w f / zle -D w inside the subshell flip widget bindings only in the child; when the child exits the parent’s widget table is untouched. zshrs runs subshells in-process so a subshell’s zle -D w would otherwise unbind the parent’s widget. Bug #453 in docs/BUGS.md.

§keymapnamtab: HashMap<String, KeymapName>

Parent’s KEYMAPNAMTAB (named keymap registry) at subshell entry. Same fork-copy semantics as THINGYTAB — a subshell’s bindkey -N km / bindkey -D km mutates only the child’s keymap registry in C zsh. Bug #454 in docs/BUGS.md.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

Source§

fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Gets the layout of the type.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The type for metadata in pointers and references to Self.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more