Skip to main content

modulestab

Struct modulestab 

Source
pub struct modulestab {
    pub modules: HashMap<String, module>,
    pub autoload_builtins: HashMap<String, String>,
    pub autoload_conditions: HashMap<String, String>,
    pub autoload_params: HashMap<String, String>,
    pub autoload_mathfuncs: HashMap<String, String>,
    pub added_builtins: HashMap<String, u32>,
}
Expand description

Module table (from module.c module hash table) Table of registered modules. Port of the modulestab HashTable Src/module.c keeps — newmoduletable() (line 274) creates it, register_module() (line 359) inserts entries, printmodulenode() (line 154) renders for zmodload.

Fields§

§modules: HashMap<String, module>

modules field.

§autoload_builtins: HashMap<String, String>

Builtin name → module name mapping for autoload

§autoload_conditions: HashMap<String, String>

Condition name → module name mapping for autoload

§autoload_params: HashMap<String, String>

Parameter name → module name mapping for autoload

§autoload_mathfuncs: HashMap<String, String>

Math function name → module name mapping for autoload

§added_builtins: HashMap<String, u32>

BINF_ADDED ledger — tracks which builtins have been added via setbuiltins (C: b->node.flags & BINF_ADDED, c:508).

Implementations§

Source§

impl modulestab

Source

pub fn new() -> Self

new — see implementation.

Source

pub fn load_module(&mut self, name: &str) -> bool

Port of int load_module(char const *name, Feature_enables enablesarr, int silent) from Src/module.c:2206. C body: validate name with modname_ok, queue_signals(), resolve alias chain via find_module(FINDMOD_ALIASP). If not found, attempt module_linked then do_load_module (dlopen). Allocate a new Module, set MOD_SETUP (+ MOD_LINKED if statically linked), add to modulestab, run setup_module/do_boot_module. If either fails, cleanup+finish+delete and return 1. Else clear MOD_SETUP, set MOD_INIT_S | MOD_INIT_B, return bootret. If found and already MOD_SETUP, return 0. Detect circular deps via MOD_BUSY, load dependency list recursively. zshrs: all modules are statically linked, so dlopen path is skipped and we operate on the static registry. WARNING: param names don’t match C — Rust=(name) vs C=(name, enablesarr, silent)

Source

pub fn unload_module(&mut self, name: &str) -> bool

Port of int unload_module(Module m) from Src/module.c:2817. C body: resolve MOD_ALIAS via find_module(FINDMOD_ALIASP); if MOD_INIT_S set and !MOD_UNLOAD, call do_cleanup_module. Clear MOD_INIT_B|MOD_INIT_S. If a wrapper is present, set MOD_UNLOAD and bail (deferred). Else clear MOD_UNLOAD and call m->u.linked->finish(m) or finish_module(m) depending on MOD_LINKED. Finally walk m->deps and unload modules that were tagged MOD_UNLOAD when the last dependent dies. WARNING: param names don’t match C — Rust=(name) vs C=(m)

Source

pub fn is_loaded(&self, name: &str) -> bool

Check if module is loaded

Source

pub fn is_bound(&self, name: &str) -> bool

Whether a module is BOUND — its setup_/boot_ has actually run. Mirrors the zmodload -e existence test (bin_zmodload_exist, c:Src/module.c:2637): the union slot m->u.handle is non-NULL (handle for dlopen, linked for a static module) and the module is not mid-unload. Distinct from is_loaded() / module_loaded(), which key off MOD_LINKED — a flag register_builtin_modules pre-seeds for every statically-compiled module at startup, so it is true before zmodload ever runs. Use this for “was the module actually loaded by the user” gates.

Source

pub fn list_loaded(&self) -> Vec<&str>

List all loaded modules

Source

pub fn list_all(&self) -> Vec<(&str, i32)>

List all modules (including unloaded). Returns name + raw MOD_* flag bits — caller can inspect MOD_UNLOAD / MOD_LINKED directly (matches C, which exposes m->node.flags).

Source

pub fn addbuiltin(&mut self, name: &str, module: &str) -> i32

Register a builtin (from module.c addbuiltin) Port of addbuiltin(Builtin b) from Src/module.c:409. WARNING: param names don’t match C — Rust=(name, module) vs C=(b)

In C, this inserts the builtin into the canonical builtintab hashtable (Src/builtin.c). The real builtin registration lives in cmd.rs::BUILTINTAB and the routing fn here delegates to the free addbuiltin (c:303 port) so the canonical BINF_ADDED clash gate fires.

Returns 0 on success, 1 on clash (per C’s signature).

Source

pub fn deletebuiltin(&mut self, name: &str, _module: &str) -> i32

Unregister a builtin (from module.c deletebuiltin) Port of deletebuiltin(const char *nam) from Src/module.c:449. Returns 0 on success (entry found + removed from ledger), -1 on miss — matching the canonical free fn (00e6a9ce7e) and C’s deletebuiltin return contract. WARNING: param names don’t match C — Rust=(name, module) vs C=(nam)

Source

pub fn add_autobin(&mut self, name: &str, module: &str, flags: i32) -> i32

Register autoloading builtin. Port of static int add_autobin(const char *module, const char *bnam, int flags) from Src/module.c:426. C allocates a Builtin node with optstr=module, sets BINF_AUTOALL if FEAT_AUTOALL is in flags, then calls addbuiltin(bn). On failure, the freshly allocated node is freed; success returns 0, conflict returns 1 unless FEAT_IGNORE masks it. WARNING: param names don’t match C — Rust=(name, module, flags) vs C=(module, bnam, flags)

Source

pub fn del_autobin(&mut self, name: &str, flags: i32) -> i32

Port of static int del_autobin(const char *module, const char *bnam, int flags) from Src/module.c:464.

C body (c:464-478):

Builtin bn = (Builtin) builtintab->getnode2(builtintab, bnam);
if (!bn) { if(!(flags & FEAT_IGNORE)) return 2; }
else if (bn->node.flags & BINF_ADDED) {
    if (!(flags & FEAT_IGNORE)) return 3;
} else deletebuiltin(bnam);
return 0;

2 = “no such builtin”, 3 = “real registered builtin (BINF_ADDED) — can’t unload”, 0 = success (removed autoload entry). FEAT_IGNORE masks both error returns.

zshrs architecture: builtintab is static-linked at startup (createbuiltintable() builds an immutable HashMap), so every entry there is effectively BINF_ADDED. The autoload-only entries live in self.autoload_builtins. The faithful mapping:

  • if name is in builtintab → BINF_ADDED → return 3 (or 0 with FEAT_IGNORE).
  • else if name is in autoload_builtins → remove it, return 0.
  • else → not present → return 2 (or 0 with FEAT_IGNORE). WARNING: param names don’t match C — Rust=(name, flags) vs C=(module, bnam, flags)
Source

pub fn setbuiltins( &mut self, module: &str, names: &[&str], e: Option<&[i32]>, ) -> i32

Set/clear a slice of builtins per e[] mask. Port of static int setbuiltins(char const *nam, Builtin binl, int size, int *e) from Src/module.c:501. For each Builtin in binl[0..size]: if e[n] is set, add the builtin (skip if already BINF_ADDED); else delete the builtin (skip if not BINF_ADDED). Warnings on clash/already-deleted; returns 1 if any op failed. WARNING: param names don’t match C — Rust=(module, names, e) vs C=(nam, binl, size, e)

Source

pub fn addconddef(&mut self, name: &str, module: &str) -> i32

Register a condition (from module.c addconddef) Port of addconddef(Conddef c) from Src/module.c:703. WARNING: param names don’t match C — Rust=(name, module) vs C=(c)

Like addbuiltin, the real registration lives in cond.rs::CONDTAB; the routing fn here delegates to the free addconddef (4304-port) so the canonical name+infix-flag clash gate fires.

Returns 0 on success, 1 on clash (matches C’s signature).

Source

pub fn deleteconddef(&mut self, name: &str, _module: &str) -> i32

Unregister a condition (from module.c deleteconddef) Port of deleteconddef(Conddef c) from Src/module.c:724. Returns 0 on success (entry was found + removed), -1 on miss. Mirrors C’s deleteconddef return contract. WARNING: param names don’t match C — Rust=(name, module) vs C=(c)

Source

pub fn getconddef(&self, name: &str) -> Option<&str>

Get condition definition (from module.c getconddef) Port of getconddef(int inf, const char *name, int autol) from Src/module.c:648. WARNING: param names don’t match C — Rust=(name) vs C=(inf, name, autol)

Returns the autoload mapping if any. C consults the canonical condtab first; the autoload table is the fallback.

Source

pub fn add_autocond(&mut self, name: &str, module: &str, flags: i32) -> i32

Register autoloading condition. Port of static int add_autocond(const char *module, const char *cnam, int flags) from Src/module.c:792. C body allocates a Conddef, copies name/module, sets CONDF_INFIX if FEAT_INFIX and CONDF_AUTOALL if FEAT_AUTOALL, then calls addconddef(c). On addconddef failure (already exists) the node is freed; returns 1 unless FEAT_IGNORE. WARNING: param names don’t match C — Rust=(name, module, flags) vs C=(module, cnam, flags)

Source

pub fn del_autocond(&mut self, name: &str, flags: i32) -> i32

Port of static int del_autocond(const char *modnam, const char *cnam, int flags) from Src/module.c:819.

C body (c:819-835):

Conddef cd = getconddef((flags & FEAT_INFIX) ? 1 : 0, cnam, 0);
if (!cd) { if (!(flags & FEAT_IGNORE)) return 2; }
else if (cd->flags & CONDF_ADDED) {
    if (!(flags & FEAT_IGNORE)) return 3;
} else deleteconddef(cd);
return 0;

2 = “no such condition”, 3 = “registered condition (CONDF_ADDED) — can’t unload”, 0 = success. FEAT_IGNORE masks both error returns. WARNING: param names don’t match C — Rust=(name, flags) vs C=(modnam, cnam, flags)

Source

pub fn setparamdefs( &mut self, module: &str, names: &[&str], e: Option<&[i32]>, ) -> i32

Add or remove sets of parameters; same shape as setbuiltins. Port of static int setparamdefs(char const *nam, Paramdef d, int size, int *e) from Src/module.c:1170. For each Paramdef in d[0..size]: if e[n] is set and d->pm is null, add the param via addparamdef(d); if e[n] is clear and d->pm is non-null, remove via deleteparamdef(d). Warnings on error/already-deleted; returns 1 if any op failed. WARNING: param names don’t match C — Rust=(module, names, e) vs C=(nam, d, size, e)

Source

pub fn add_autoparam(&mut self, name: &str, module: &str, flags: i32) -> i32

Register autoloading parameter. Port of static int add_autoparam(const char *module, const char *pnam, int flags) from Src/module.c:1198. C body: checkaddparam() clash check (returns 2 if -i’d), then setsparam(pnam, module) creating the param with PM_AUTOLOAD (+ PM_AUTOALL if FEAT_AUTOALL). queue_signals/noerrs=2 bracket so the setsparam doesn’t echo errors out. WARNING: param names don’t match C — Rust=(name, module, flags) vs C=(module, pnam, flags)

Source

pub fn del_autoparam(&mut self, name: &str, flags: i32) -> i32

Port of static int del_autoparam(const char *modnam, const char *pnam, int flags) from Src/module.c:1240.

C body (c:1240-1255):

Param pm = (Param) gethashnode2(paramtab, pnam);
if (!pm) { if (!(flags & FEAT_IGNORE)) return 2; }
else if (!(pm->node.flags & PM_AUTOLOAD)) {
    if (!(flags & FEAT_IGNORE)) return 3;
} else unsetparam_pm(pm, 0, 1);
return 0;

2 = “no such param”, 3 = “real param (not autoload) — can’t unload”, 0 = success. FEAT_IGNORE masks both error returns. WARNING: param names don’t match C — Rust=(name, flags) vs C=(modnam, pnam, flags)

Source

pub fn enable_feature(&mut self, module: &str, _name: &str) -> bool

Enable a feature (from module.c enables_)

Without a per-module feature ledger, enable/disable maps onto the canonical builtin/conddef/paramdef tables. Returns true if the module itself is registered. The actual per-feature enabled-bit lives on the canonical record (e.g. Builtin.flags BINF_DISABLED).

Source

pub fn disable_feature(&mut self, module: &str, _name: &str) -> bool

Disable a feature

Source

pub fn list_features(&self, _module: &str) -> Vec<String>

List feature names of a module (from module.c features_). Without a per-module ledger, this returns an empty list — C computes feature names by walking the canonical tables for entries that name the given module. Callers that care use features_module/features_ directly.

Source

pub fn module_linked(&self, name: &str) -> bool

Check if a module is linked (statically compiled) (from module.c module_linked) Port of module_linked(char const *name) from Src/module.c:385.

Source

pub fn resolve_autoload_builtin(&self, name: &str) -> Option<&str>

Resolve autoload — find which module provides a builtin

Source

pub fn resolve_autoload_param(&self, name: &str) -> Option<&str>

Resolve autoload — find which module provides a parameter

Source

pub fn ensurefeature(&mut self, module: &str, feature: &str) -> bool

Ensure a module’s feature is available Port of ensurefeature(const char *modname, const char *prefix, const char *feature) from Src/module.c:3415. WARNING: param names don’t match C — Rust=(module, feature) vs C=(modname, prefix, feature)

Trait Implementations§

Source§

impl Debug for modulestab

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for modulestab

Source§

fn default() -> modulestab

Returns the “default value” for a type. Read more

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