pub struct shfunc_table { /* private fields */ }Expand description
Shell function hash table
$shfunctab shell function table.
Port of the shfunctab HashTable Src/hashtable.c builds —
printshfuncnode / freeshfuncnode (Src/builtin.c) hang off
the same shape.
Faithful port of C’s HashTable shfunctab (Src/zsh.h, declared
mod_export HashTable shfunctab). Stores Box<shfunc> so that
raw *mut shfunc handed to C-style call sites stays stable
across map rehashes — mirrors C’s HashNode semantics where
the table owns the heap allocation and hands out pointers.
Owned-value accessors (add, get, get_mut) coexist with
C-faithful pointer accessors (addnode, getnode) so both
the Rust-idiomatic bytecode function-def path
(fusevm_bridge.rs:8378) and the C-style bin_functions
port (builtin.rs:3689+) write to the same canonical table.
Implementations§
Source§impl shfunc_table
impl shfunc_table
Sourcepub fn new() -> Self
pub fn new() -> Self
new — shfunctab = newhashtable(7, "shfunctab", NULL)
(Src/hashtable.c:814). The initial bucket count is part of the
observable scan order, so it must be C’s 7 and grow only through
expandhashtable’s x4 rule.
Sourcepub fn snapshot(&self) -> Arc<shfunc_table> ⓘ
pub fn snapshot(&self) -> Arc<shfunc_table> ⓘ
snapshot — clone the whole bucket array for subshell
save/restore. Used by subshell_begin to capture the parent’s
function set before the subshell body runs, so subshell_end
can restore it (matches C fork-copy semantics at
Src/exec.c::entersubsh).
This clones the TABLE, not a HashMap of its entries: the scan
order is part of the state (Src/Modules/parameter.c:480-481
walks shfunctab->nodes[i] directly), and rebuilding a bucket
array from an unordered map would reshuffle ${(k)functions}
after every ( … ) / $( … ).
Sourcepub fn restore(&mut self, snap: Arc<shfunc_table>)
pub fn restore(&mut self, snap: Arc<shfunc_table>)
restore — replace the internal table with a saved snapshot.
Called by subshell_end after the subshell body completes.
Takes the Arc-shared snapshot stored in SubshellSnapshot;
unwraps in place when uniquely owned (the common case), else
clones out of the shared handle.
Sourcepub fn reserve(&mut self, _additional: usize)
pub fn reserve(&mut self, _additional: usize)
Formerly pre-sized the backing HashMap. C has no such call and
CANNOT have one: hsize only ever moves through
expandhashtable’s x4 steps (Src/hashtable.c:466), and the
bucket count is what hasher(nam) % hsize — hence the whole scan
order — is computed against. Pre-sizing to the batch size would
put every name in a different bucket than zsh does. Kept as a
no-op so the compinit call site (which is a Rust-only
optimisation) still compiles.
Sourcepub fn add(&mut self, func: shfunc) -> Option<shfunc>
pub fn add(&mut self, func: shfunc) -> Option<shfunc>
add — addhashnode2 (Src/hashtable.c:168) with the displaced
node handed back to the caller instead of freenoded.
Sourcepub fn get(&self, name: &str) -> Option<&shfunc>
pub fn get(&self, name: &str) -> Option<&shfunc>
get — gethashnode (Src/hashtable.c:231): DISABLED nodes read
as absent.
Sourcepub fn get_including_disabled(&self, name: &str) -> Option<&shfunc>
pub fn get_including_disabled(&self, name: &str) -> Option<&shfunc>
get_including_disabled — gethashnode2 (Src/hashtable.c:255).
Sourcepub fn remove(&mut self, name: &str) -> Option<shfunc>
pub fn remove(&mut self, name: &str) -> Option<shfunc>
remove — removehashnode (Src/hashtable.c:275).
Sourcepub fn contains_key(&self, name: &str) -> bool
pub fn contains_key(&self, name: &str) -> bool
contains_key — see implementation.
Sourcepub fn addnode(&mut self, shf: *mut shfunc)
pub fn addnode(&mut self, shf: *mut shfunc)
Port of C’s HashTable.addnode GSU function pointer
(Src/zsh.h:281+). Takes a *mut shfunc (typedef Shfunc)
previously obtained via Box::into_raw — reclaims ownership
into the table by name. After this call, the caller’s shf
pointer is INVALIDATED in the Rust ownership sense; subsequent
reads must go through getnode(name) to get a fresh pointer.
In practice, C code re-uses the same shf pointer because the
Box stays at the same heap address — we keep that semantic by
boxing-on-heap. Replaces any prior entry with the same name
(matching C addnode’s overwrite-and-free-old behavior).
Sourcepub fn getnode(&self, name: &str) -> *mut shfunc
pub fn getnode(&self, name: &str) -> *mut shfunc
Port of C’s HashTable.getnode GSU. Returns the raw Shfunc
pointer (typedef *mut shfunc) or null if missing or disabled.
Pointer stays valid as long as the underlying Box<shfunc>
lives in the table (i.e. until remove/addnode-overwrite).
Sourcepub fn getnode2(&self, name: &str) -> *mut shfunc
pub fn getnode2(&self, name: &str) -> *mut shfunc
Port of C’s HashTable.getnode2 GSU — same as getnode but
returns disabled nodes too. Used by unhash/enable -f paths.
Sourcepub fn iter_sorted(&self) -> Vec<(&String, &shfunc)>
pub fn iter_sorted(&self) -> Vec<(&String, &shfunc)>
iter_sorted — see implementation.
Trait Implementations§
Source§impl Clone for shfunc_table
impl Clone for shfunc_table
Source§fn clone(&self) -> shfunc_table
fn clone(&self) -> shfunc_table
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for shfunc_table
impl Debug for shfunc_table
Auto Trait Implementations§
impl Freeze for shfunc_table
impl RefUnwindSafe for shfunc_table
impl Send for shfunc_table
impl Sync for shfunc_table
impl Unpin for shfunc_table
impl UnsafeUnpin for shfunc_table
impl UnwindSafe for shfunc_table
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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