Skip to main content

Module module

Module module 

Source
Expand description

module submodule. Module system for zshrs

Port from zsh/Src/module.c (3,646 lines)

Hash of modules // c:46 The list of hook functions defined. // c:840 List of math functions. // c:1255

In C, module.c provides dynamic loading of .so modules at runtime via dlopen/dlsym. In Rust, all modules are statically compiled into the binary — there’s no dynamic loading. This module provides the registration, lookup, and management API that the rest of the shell uses to interact with module features (builtins, conditions, parameters, hooks, and math functions).

Re-exports§

pub use crate::ported::zsh_h::BINF_ADDED;
pub use crate::ported::zsh_h::CONDF_ADDED;
pub use crate::ported::zsh_h::CONDF_INFIX;
pub use crate::ported::zsh_h::MFF_ADDED;

Structs§

modulestab
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.

Constants§

FEATURE_TYPE_BUILTIN
Feature-type index passed to features_() (Src/module.c:313+). C ships bare ints; Rust adds names for readability.
FEATURE_TYPE_CONDITION
FEATURE_TYPE_CONDITION constant.
FEATURE_TYPE_HOOK
FEATURE_TYPE_HOOK constant.
FEATURE_TYPE_MATHFUNC
FEATURE_TYPE_MATHFUNC constant.
FEATURE_TYPE_PARAMETER
FEATURE_TYPE_PARAMETER constant.
FEAT_AUTOALL
FEAT_AUTOALL — zmodload -a enable-all-features. Port of enum { FEAT_AUTOALL = 0x0004 } from Src/module.c:69.
FEAT_CHECKAUTO
FEAT_CHECKAUTO — verify autoloads are actually provided. Port of enum { FEAT_CHECKAUTO = 0x0010 } from Src/module.c:81.
FEAT_IGNORE
FEAT_IGNORE — bit in the flags arg to add_/del_-automathfunc and friends. Port of enum { FEAT_IGNORE = 0x0001 } from Src/module.c:62. /* -i option: ignore redefinition errors. */
FEAT_INFIX
FEAT_INFIX — bit indicating a condition is infix-style. Port of enum { FEAT_INFIX = 0x0002 } from Src/module.c:64.
FEAT_PATTERN_ARGS
!!! WARNING: RUST-ONLY FLAG BIT !!! C has no such bit. It carries the zmodload -m decision on the Patprog pat field of each struct feature_enables entry (Src/module.c:3253-3262 fills fep->pat = patprogs ? *patprogs++ : NULL, and do_module_features at c:2093 branches fep->pat ? pattry(fep->pat, *fp) : !strcmp(*fp, esp)). zshrs’s feature list is a plain &[String] with no per-entry payload, so there is nowhere to hang the compiled pattern. -m sets the pat for EVERY entry of one invocation uniformly, so the decision is carried as this one flag bit alongside FEAT_IGNORE/FEAT_CHECKAUTO and the pattern is compiled at the match site. Deliberately outside C’s 0x0001-0x0010 range so it cannot collide with a future upstream bit.
FEAT_REMOVE
FEAT_REMOVE — bit indicating feature removal pass. Port of enum { FEAT_REMOVE = 0x0008 } from Src/module.c:76.
FINDMOD_ALIASP
FINDMOD_ALIASP — bit in find_module()’s flags arg. Port of enum { FINDMOD_ALIASP = 0x0001 } from Src/module.c:110. /* Resolve any aliases to the underlying module. */
FINDMOD_CREATE
FINDMOD_CREATE — bit in find_module()’s flags arg. Port of enum { FINDMOD_CREATE = 0x0002 } from Src/module.c:115. /* Create an element for the module in the list if not found. */
PRINTMOD_ALIAS
PRINTMOD_ALIAS from Src/module.c:140. Resolve aliases when emitting under PRINTMOD_EXIST.
PRINTMOD_AUTO
PRINTMOD_AUTO from Src/module.c:148. Emit autoloads (zmodload -a).
PRINTMOD_DEPS
PRINTMOD_DEPS from Src/module.c:142. Emit the dependency list (zmodload -d).
PRINTMOD_EXIST
PRINTMOD_EXIST from Src/module.c:138. Print only when the module exists.
PRINTMOD_FEATURES
PRINTMOD_FEATURES from Src/module.c:144. Emit feature flags (zmodload -F).
PRINTMOD_LIST
PRINTMOD_LIST from Src/module.c:136. Long-form (zmodload -L) output.
PRINTMOD_LISTALL
PRINTMOD_LISTALL from Src/module.c:146. Include disabled features (zmodload -lL).
WRAPPER_BIT_KSH93
WRAPPERS_ADDED bit for zsh/ksh93’s WRAPDEF(ksh93_wrapper) (Src/Modules/ksh93.c:230-232).
WRAPPER_BIT_ZPROF
WRAPPERS_ADDED bit for zsh/zprof’s WRAPDEF(zprof_wrapper) (Src/Modules/zprof.c:318-320).

Statics§

CONDTAB
Port of file-static Conddef condtab; from Src/cond.c:21 — the global condition-definition linked-list head consulted by [[ ... ]] dispatch. Modules register custom conditions via addconddef; the runtime walks condtab looking for the matching name+infix flag at each [[ evaluation. Rust port stores entries in a Vec (linear add/remove + walk; same observable behaviour as C linked list).
DISABLED_MODULE_BUILTINS
!!! RUST-ONLY REGISTRY — NO C COUNTERPART !!!
MATHFUNCS
Port of MathFunc mathfuncs; from Src/module.c:1258 — the global head of the linked list of math functions. Both autoloadable math ported (added by modules) and user math ported (added by functions -M) live here.
MODULESTAB
Port of mod_export ModuleTable modulestab from Src/Modules/zmodload.c:32. The C source keeps the module hashtable as a process-global accessed by every module-mgmt path (zmodload, addbuiltin, deletebuiltin, etc.). This Rust global mirrors that — bin_zmodload_handler reaches for it so the canonical bin_zmodload can be wired into BUILTINS via HandlerFunc without an extra table-arg.
WRAPPERS
Port of file-static FuncWrap wrappers; from Src/module.c:567 — the global wrapper-function linked-list head. Modules register wrapper callbacks via addwrapper(FuncWrap) and the runtime fires them around runshfunc(). The Rust port stores entries in a Vec (linear add/remove + iterate; same observable behaviour).
WRAPPERS_ADDED
Relaxed-atomic membership mirror of WRAPPERS, one bit per wrapper-installing module (see WRAPPER_BIT_ZPROF). Written by addwrapper / deletewrapper, read by exec::runshfunc. See the WARNING block above.
hooktab
Port of Hookdef hooktab; from Src/module.c:843 — the file-static linked-list head pointer to the chain of registered hookdef nodes. Walked by gethookdef; mutated by addhookdef / deletehookdef. Each node is a Box::leak’d hookdef (so the raw pointer has program-lifetime, matching C’s static-storage zshhooks[] and module-side hookdef arrays).

Traits§

ModuleLifecycle
Module lifecycle callbacks (from module.c setup_/getrandom_buffer/cleanup_/finish_) Lifecycle hooks every module must implement. Port of the setup_/features_/enables_/getrandom_buffer/cleanup_ /finish_ entry points every C module exposes (Src/module.c lines 306-345 illustrate the canonical no-op set). Rust modules implement this trait directly.

Functions§

add_automathfunc
Port of add_automathfunc() from Src/module.c:1410. — C decl add_automathfunc(const char *module, const char *fnam, int flags).
add_autoparam
Port of add_autoparam() from Src/module.c:1198. — C decl add_autoparam(const char *module, const char *pnam, int flags).
add_dep
Port of add_dep() from Src/module.c:2369. — C decl add_dep(const char *name, char *from).
addbuiltin
Port of addbuiltin() from Src/module.c:409. — C decl addbuiltin(Builtin b). C body: look up b->node.nam in builtintab; if BINF_ADDED clash → return 1; otherwise replace any pre-existing entry and add b. Returns 0 on add, 1 on clash.
addbuiltins
Port of addbuiltins() from Src/module.c:544. — C decl addbuiltins(char const *nam, Builtin binl, int size). Walks the slice; for each entry not already flagged BINF_ADDED, calls addbuiltin. Returns 0 if all succeeded, 1 if any clashed. zwarnnam emitted on each clash matches C.
addconddef
Port of addconddef() from Src/module.c:703. — C decl addconddef(Conddef c). Walks CONDTAB for a clash on (name, infix-flag); replaces autoloadable entries via deleteconddef; otherwise prepends. Returns 0 on add, 1 on clash (existing entry already added).
addhookdef
Port of addhookdef() from Src/module.c:864. — C decl addhookdef(Hookdef h).
addhookdeffunc
Port of addhookdeffunc() from Src/module.c:939. — C decl addhookdeffunc(Hookdef h, Hookfn f).
addhookdefs
Port of addhookdefs() from Src/module.c:883. — C decl addhookdefs(Module m, Hookdef h, int size).
addhookfunc
Port of addhookfunc() from Src/module.c:948. — C decl addhookfunc(char *n, Hookfn f).
addmathfunc
Port of addmathfunc() from Src/module.c:1313. — C decl addmathfunc(MathFunc f). Returns 0 on add, 1 on clash (existing entry not autoloadable). Replaces autoloadable entries via removemathfunc.
addparamdef
Port of addparamdef() from Src/module.c:1061. — C decl addparamdef(Paramdef d). Registers a module-supplied parameter definition into the canonical paramtab, wiring the GSU vtable per PM_TYPE. Returns 0 on success, 1 on error.
addwrapper
Port of addwrapper() from Src/module.c:577. — C decl addwrapper(Module m, FuncWrap w). Tail-appends a module’s function wrapper onto the global WRAPPERS list. Returns 1 on error, 0 on success.
autofeatures
Port of autofeatures() from Src/module.c:3437. — C decl autofeatures(const char *cmdnam, const char *module, char **features, int prefchar, int defflags).
autoloadscan
Port of autoloadscan() from Src/module.c:2403. — C decl autoloadscan(HashNode hn, int printflags).
bin_zmodload
Port of bin_zmodload() from Src/module.c:2440. — C decl bin_zmodload(char *nam, char **args, Options ops, UNUSED(int func)). Top-level dispatcher for the zmodload builtin. Validates flag combinations then routes to one of the per-mode helpers: -F → bin_zmodload_features (c:3003) -e → bin_zmodload_exist (c:2623) -d → bin_zmodload_dep (c:2649) -a/-b/-c/-p/-f → bin_zmodload_auto (c:2726) default → bin_zmodload_load (c:2971) -A/-R → bin_zmodload_alias (c:2515) WARNING: param names don’t match C — Rust=(nam, args, _func) vs C=(nam, args, ops, func)
bin_zmodload_alias
Port of bin_zmodload_alias() from Src/module.c:2515. — C decl bin_zmodload_alias(char *nam, char **args, Options ops).
bin_zmodload_auto
Port of bin_zmodload_auto() from Src/module.c:2726. — C decl bin_zmodload_auto(char *nam, char **args, Options ops).
bin_zmodload_dep
Port of bin_zmodload_dep() from Src/module.c:2649. — C decl bin_zmodload_dep(UNUSED(char *nam), char **args, Options ops).
bin_zmodload_exist
Port of bin_zmodload_exist() from Src/module.c:2623. — C decl bin_zmodload_exist(UNUSED(char *nam), char **args, Options ops).
bin_zmodload_features
Port of bin_zmodload_features() from Src/module.c:3003. — C decl bin_zmodload_features(const char *nam, char **args, Options ops).
bin_zmodload_load
Port of bin_zmodload_load() from Src/module.c:2971. — C decl bin_zmodload_load(char *nam, char **args, Options ops).
boot_
Port of boot_() from Src/module.c:331. — C decl boot_(UNUSED(Module m)).
boot_module
Port of boot_module() from Src/module.c:1910. — C decl boot_module(Module m).
checkaddparam
Port of checkaddparam() from Src/module.c:1026. — C decl checkaddparam(const char *nam, int opt_i).
cleanup_
Port of cleanup_() from Src/module.c:338. — C decl cleanup_(UNUSED(Module m)).
cleanup_module
Port of cleanup_module() from Src/module.c:1918. — C decl cleanup_module(Module m).
del_automathfunc
Port of del_automathfunc() from Src/module.c:1436. — C decl del_automathfunc(UNUSED(const char *modnam), const char *fnam, int flags).
del_autoparam
Port of del_autoparam() from Src/module.c:1235. — C decl del_autoparam(UNUSED(const char *modnam), const char *pnam, int flags).
delete_module
Port of delete_module() from Src/module.c:1687. — C decl delete_module(Module m).
deletebuiltin
Port of deletebuiltin() from Src/module.c:449. — C decl deletebuiltin(const char *nam).
deleteconddef
Port of deleteconddef() from Src/module.c:724. — C decl deleteconddef(Conddef c). Removes condition definition c from condtab. Returns 0 on success, -1 on miss. C also frees the autoloaded entry’s name + module; Rust drop subsumes that.
deletehookdef
Port of deletehookdef() from Src/module.c:902. — C decl deletehookdef(Hookdef h).
deletehookdeffunc
Port of deletehookdeffunc() from Src/module.c:961. — C decl deletehookdeffunc(Hookdef h, Hookfn f).
deletehookdefs
Port of deletehookdefs() from Src/module.c:923. — C decl deletehookdefs(UNUSED(Module m), Hookdef h, int size). m is unused per UNUSED(Module m) in C.
deletehookfunc
Port of deletehookfunc() from Src/module.c:977. — C decl deletehookfunc(const char *n, Hookfn f).
deletemathfunc
Port of deletemathfunc() from Src/module.c:1342. — C decl deletemathfunc(MathFunc f). Removes f from MATHFUNCS; for unloaded/user-defined entries clears the MFF_ADDED flag instead of dropping the node (C: f->flags &= ~MFF_ADDED when f->module is null).
deleteparamdef
Port of deleteparamdef() from Src/module.c:1124. — C decl deleteparamdef(Paramdef d). Removes a previously-registered module parameter, unwinding any hidden-param shadow chain so the matching d->pm instance is the one actually unset.
deletewrapper
Port of deletewrapper() from Src/module.c:609. — C decl deletewrapper(Module m, FuncWrap w). Unlinks a module’s wrapper from WRAPPERS. Returns 0 when the node was found and removed, 1 otherwise.
do_boot_module
Port of do_boot_module() from Src/module.c:2139. — C decl do_boot_module(Module m, Feature_enables enablesarr, int silent).
do_cleanup_module
Port of do_cleanup_module() from Src/module.c:2159. — C decl do_cleanup_module(Module m).
do_load_module
Port of do_load_module() from Src/module.c:1610. — C decl do_load_module(char const *name, int silent).
do_module_features
Port of do_module_features() from Src/module.c:1998. — C decl do_module_features(Module m, Feature_enables enablesarr, int flags).
dyn_boot_module
Port of dyn_boot_module() from Src/module.c:1747. — C decl dyn_boot_module(Module m).
dyn_cleanup_module
Port of dyn_cleanup_module() from Src/module.c:1754. — C decl dyn_cleanup_module(Module m).
dyn_enables_module
Port of dyn_enables_module() from Src/module.c:1740. — C decl dyn_enables_module(Module m, int **enables).
dyn_features_module
Port of dyn_features_module() from Src/module.c:1733. — C decl dyn_features_module(Module m, char ***features).
dyn_finish_module
Port of dyn_finish_module() from Src/module.c:1761. — C decl dyn_finish_module(Module m). C body: return ((int (*)(int,Module,void*)) m->u.handle)(3, m, NULL); — invokes the DSO entry point with opcode 3 (finish). no-op in Rust: zshrs has no dlopen path, all modules are statically linked, m->u.handle is always null, and finish-time resource release happens at process exit. Static-link path defers all DSO entry calls; the no-op return preserves caller semantics (0 = success).
dyn_setup_module
Port of dyn_setup_module() from Src/module.c:1726. — C decl dyn_setup_module(Module m).
enables_
Port of enables_() from Src/module.c:324. — C decl enables_(UNUSED(Module m), UNUSED(int **enables)).
enables_module
Port of enables_module() from Src/module.c:1901. — C decl enables_module(Module m, int **enables).
ensurefeature
Port of ensurefeature() from Src/module.c:3415. — C decl ensurefeature(const char *modname, const char *prefix, const char *feature).
features_
Port of features_() from Src/module.c:313. — C decl features_(UNUSED(Module m), UNUSED(char ***features)).
features_module
Port of features_module() from Src/module.c:1892. — C decl features_module(Module m, char ***features).
featuresarray
Port of featuresarray() from Src/module.c:3279. — C decl featuresarray(UNUSED(Module m), Features f). Construct the feature-name array for a module: builtins get b:NAME, conditions c:NAME or C:NAME if CONDF_INFIX, math funcs f:NAME, params p:NAME. Trailing abstract slots (n_abstract) are pre-allocated but left empty so the module’s own setup can fill them in. C uses zhalloc heap allocation — Box goes out of scope here as Rust’s Vec<String> owns the entries (Drop happens automatically). Per-module Rust files in src/ported/modules/*.rs and src/ported/builtins/*.rs each carry a featuresarray shim that delegates to this canonical free fn once the modules table is wired through. WARNING: param names don’t match C — Rust=(_m, bn, cd, mf, pd, n_abstract) vs C=(m, f)
find_module
Port of find_module() from Src/module.c:1659. — C decl find_module(const char *name, int flags, const char **namep).
finish_
Port of finish_() from Src/module.c:345. — C decl finish_(UNUSED(Module m)).
finish_module
Port of finish_module() from Src/module.c:1926. — C decl finish_module(Module m).
freemodulenode
Free module node (from module.c freemodulenode) Free a module table entry. Port of freemodulenode() from Src/module.c:119. — C decl freemodulenode(HashNode hn). Rust’s Drop handles the per-field free; this exists for API parity with C callers.
getconddef
Port of getconddef() from Src/module.c:648. — C decl getconddef(int inf, const char *name, int autol).
getfeatureenables
Port of getfeatureenables() from Src/module.c:3314. — C decl getfeatureenables(UNUSED(Module m), Features f). Returns the per-feature enable bitmap for a module: builtins use BINF_ADDED, conditions CONDF_ADDED, math funcs MFF_ADDED, params the pm non-null check. Trailing abstract slots are left at 0 (filled by the module’s own enables_). C uses zhalloc heap allocation; Rust’s Vec<i32> owns the entries (Drop happens automatically). Per- module shims in src/ported/modules/*.rs delegate to this canonical free fn once the modules table is wired through. WARNING: param names don’t match C — Rust=(_m, bn, cd, mf, pd, n_abstract) vs C=(m, f)
gethookdef
Port of gethookdef() from Src/module.c:849. — C decl gethookdef(const char *n).
getmathfunc
Port of getmathfunc() from Src/module.c:1283. — C decl getmathfunc(const char *name, int autol).
handlefeatures
Port of handlefeatures() from Src/module.c:3392. — C decl handlefeatures(Module m, Features f, int **enables).
hpux_dlsym
Port of hpux_dlsym() from Src/module.c:1530. — C decl hpux_dlsym(void *handle, char *name).
load_and_bind
Port of load_and_bind() from Src/module.c:1468. — C decl load_and_bind(const char *fn).
modname_ok
Port of modname_ok() from Src/module.c:2173. — C decl modname_ok(char const *p).
module_func
Port of module_func() from Src/module.c:1770. — C decl module_func(Module m, const char *name).
module_loaded
Port of module_loaded() from Src/module.c:1703. — C decl module_loaded(const char *name).
newmoduletable
Create new module table (from module.c newmoduletable) Create an empty module table. Port of newmoduletable() from Src/module.c:274. — C decl newmoduletable(int size, char const *name). the C source allocates the modulestab hash with createhashtable. WARNING: param names don’t match C — Rust=() vs C=(size, name)
printautoparams
Port of printautoparams() from Src/module.c:2710. — C decl printautoparams(HashNode hn, int lon).
printmodulenode
Port of printmodulenode() from Src/module.c:154. — C decl printmodulenode(HashNode hn, int flags).
register_module
Register module (from module.c register_module) Register a module by name. Port of register_module() from Src/module.c:359. — C decl register_module(const char *n, Module_void_func setup, Module_features_func features, Module_enables_func enables, Module_void_func boot, Module_void_func cleanup, Module_void_func finish). wraps a slot in the global modulestab and seeds its lifecycle callbacks. WARNING: param names don’t match C — Rust=(table, name) vs C=(n, setup, features, enables, boot, cleanup, finish)
removemathfunc
Port of removemathfunc() from Src/module.c:1267. — C decl removemathfunc(MathFunc previous, MathFunc current). Removes the named entry from MATHFUNCS and drops it (Rust drop subsumes C’s zsfree/zfree ladder). WARNING: param names don’t match C — Rust=(name) vs C=(previous, current)
require_module
Port of require_module() from Src/module.c:2344. — C decl require_module(const char *module, Feature_enables features, int silent).
runhookdef
Port of runhookdef() from Src/module.c:990. — C decl runhookdef(Hookdef h, void *d).
setconddefs
Port of setconddefs() from Src/module.c:754. — C decl setconddefs(char const *nam, Conddef c, int size, int *e). Bulk add/delete of condition definitions: the parallel e[] array selects per-entry add (e[i] != 0) vs delete (e[i] == 0). Returns 1 if any individual op clashed, 0 if all clean.
setfeatureenables
Port of setfeatureenables() from Src/module.c:3354. — C decl setfeatureenables(Module m, Features f, int *e).
setmathfuncs
Port of setmathfuncs() from Src/module.c:1374. — C decl setmathfuncs(char const *nam, MathFunc f, int size, int *e). Bulk add/delete of math-function definitions via the parallel e[] selector array (same shape as setconddefs).
setup_
Port of setup_() from Src/module.c:306. — C decl setup_(UNUSED(Module m)).
setup_module
Port of setup_module() from Src/module.c:1884. — C decl setup_module(Module m).
try_load_module
Port of try_load_module() from Src/module.c:1583. — C decl try_load_module(char const *name).
unload_named_module
Port of unload_named_module() from Src/module.c:2924. — C decl unload_named_module(char *modname, char *nam, int silent).