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_AUTOALLzmodload -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_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).

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).
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).
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(const char *module, const char *fnam, int flags) from Src/module.c:1410.
add_autoparam
Port of static int add_autoparam(const char *module, const char *pnam, int flags) from Src/module.c:1197.
add_dep
Port of add_dep(const char *name, char *from) from Src/module.c:2369.
addbuiltin
Port of addbuiltins(char const *nam, Builtin binl, int size) from Src/module.c:544.
addbuiltins
Port of addbuiltins(char const *nam, Builtin binl, int size) from Src/module.c:544. 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 int addconddef(Conddef c) from Src/module.c:703. 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 int addhookdef(Hookdef h) from Src/module.c:864.
addhookdeffunc
Port of int addhookdeffunc(Hookdef h, Hookfn f) from Src/module.c:939.
addhookdefs
Port of int addhookdefs(Module m, Hookdef h, int size) from Src/module.c:883.
addhookfunc
Port of int addhookfunc(char *n, Hookfn f) from Src/module.c:948.
addmathfunc
Port of addmathfunc(MathFunc f) from Src/module.c:1313. Returns 0 on add, 1 on clash (existing entry not autoloadable). Replaces autoloadable entries via removemathfunc.
addparamdef
Port of int addparamdef(Paramdef d) from Src/module.c:1061. 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(Module m, FuncWrap w) from Src/module.c:577. Returns 0 on add, 1 on clash. Walks WRAPPERS for an existing entry with the same handler; appends if absent and sets WRAPF_ADDED on the input record.
autofeatures
Port of addmathfunc(MathFunc f) from Src/module.c:1313.
autoloadscan
Port of autoloadscan(HashNode hn, int printflags) from Src/module.c:2403.
bin_zmodload
Direct port of bin_zmodload(char *nam, char **args, Options ops, UNUSED(int func)) from Src/module.c:2440. 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(char *nam, char **args, Options ops) from Src/module.c:2515.
bin_zmodload_auto
Port of bin_zmodload_auto(char *nam, char **args, Options ops) from Src/module.c:2726.
bin_zmodload_dep
Port of bin_zmodload_dep(UNUSED(char *nam), char **args, Options ops) from Src/module.c:2649.
bin_zmodload_exist
Port of bin_zmodload_exist(UNUSED(char *nam), char **args, Options ops) from Src/module.c:2623.
bin_zmodload_features
Port of bin_zmodload_features(const char *nam, char **args, Options ops) from Src/module.c:3003.
bin_zmodload_load
Port of bin_zmodload_load(char *nam, char **args, Options ops) from Src/module.c:2971.
boot_
Port of boot_(UNUSED(Module m)) from Src/module.c:331.
boot_module
Port of boot_module(Module m) from Src/module.c:1910.
checkaddparam
Port of checkaddparam(const char *nam, int opt_i) from Src/module.c:1026.
cleanup_
Port of cleanup_(UNUSED(Module m)) from Src/module.c:338.
cleanup_module
Port of cleanup_module(Module m) from Src/module.c:1918.
del_automathfunc
Port of del_automathfunc(UNUSED(const char *modnam), const char *fnam, int flags) from Src/module.c:1436.
del_autoparam
Port of static int del_autoparam(const char *modnam, const char *pnam, int flags) from Src/module.c:1234.
delete_module
Port of delete_module(Module m) from Src/module.c:1687.
deletebuiltin
Port of int deletebuiltin(const char *nam) from Src/module.c:449.
deleteconddef
Port of int deleteconddef(Conddef c) from Src/module.c:724. 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 int deletehookdef(Hookdef h) from Src/module.c:902.
deletehookdeffunc
Port of int deletehookdeffunc(Hookdef h, Hookfn f) from Src/module.c:961.
deletehookdefs
Port of int deletehookdefs(Module m, Hookdef h, int size) from Src/module.c:923. m is unused per UNUSED(Module m) in C.
deletehookfunc
Port of int deletehookfunc(const char *n, Hookfn f) from Src/module.c:977.
deletemathfunc
Port of deletemathfunc(MathFunc f) from Src/module.c:1342. 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 int deleteparamdef(Paramdef d) from Src/module.c:1128. 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(Module m, FuncWrap w) from Src/module.c:609. Removes entry with the same handler from WRAPPERS. Returns 0 on success, 1 on miss / alias / never-added.
do_boot_module
Port of deletemathfunc(MathFunc f) from Src/module.c:1342.
do_cleanup_module
Port of do_cleanup_module(Module m) from Src/module.c:2159.
do_load_module
Port of do_load_module(char const *name, int silent) from Src/module.c:1610.
do_module_features
Port of do_module_features(Module m, Feature_enables enablesarr, int flags) from Src/module.c:1998.
dyn_boot_module
Port of dyn_boot_module(Module m) from Src/module.c:1747.
dyn_cleanup_module
Port of dyn_cleanup_module(Module m) from Src/module.c:1754.
dyn_enables_module
Port of dyn_enables_module(Module m, int **enables) from Src/module.c:1740.
dyn_features_module
Port of dyn_features_module(Module m, char ***features) from Src/module.c:1733.
dyn_finish_module
Port of static int dyn_finish_module(Module m) from Src/module.c:1766. 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(Module m) from Src/module.c:1726.
enables_
Port of enables_(UNUSED(Module m), UNUSED(int **enables)) from Src/module.c:324.
enables_module
Port of enables_module(Module m, int **enables) from Src/module.c:1901.
ensurefeature
Port of ensurefeature(const char *modname, const char *prefix, const char *feature) from Src/module.c:3415.
features_
Port of features_(UNUSED(Module m), UNUSED(char ***features)) from Src/module.c:313.
features_module
Port of features_module(Module m, char ***features) from Src/module.c:1892.
featuresarray
Port of mod_export char **featuresarray(UNUSED(Module m), Features f) from Src/module.c:3284. 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(const char *name, int flags, const char **namep) from Src/module.c:1659.
finish_
Port of finish_(UNUSED(Module m)) from Src/module.c:345.
finish_module
Port of finish_module(Module m) from Src/module.c:1926.
freemodulenode
Free module node (from module.c freemodulenode) Free a module table entry. Port of freemodulenode(HashNode hn) from Src/module.c:119 — Rust’s Drop handles the per-field free; this exists for API parity with C callers.
getconddef
Port of Conddef getconddef(int inf, const char *name, int autol) from Src/module.c:648.
getfeatureenables
Port of mod_export int *getfeatureenables(UNUSED(Module m), Features f) from Src/module.c:3319. 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 Hookdef gethookdef(const char *n) from Src/module.c:849.
getmathfunc
Port of getmathfunc(const char *name, int autol) from Src/module.c:1283.
hpux_dlsym
Port of hpux_dlsym(void *handle, char *name) from Src/module.c:1530.
load_and_bind
Port of load_and_bind(const char *fn) from Src/module.c:1468.
modname_ok
Port of modname_ok(char const *p) from Src/module.c:2173.
module_func
Port of module_func(Module m, const char *name) from Src/module.c:1770.
module_loaded
Port of module_loaded(const char *name) from Src/module.c:1703.
newmoduletable
Create new module table (from module.c newmoduletable) Create an empty module table. Port of newmoduletable(int size, char const *name) from Src/module.c:274 — 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(HashNode hn, int lon) from Src/module.c:2710.
printmodulenode
Direct port of void printmodulenode(HashNode hn, int flags) from Src/module.c:154.
register_module
Register module (from module.c register_module) Register a module by name. Port of 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) from Src/module.c:359 — 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(MathFunc previous, MathFunc current) from Src/module.c:1267. 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 removemathfunc(MathFunc previous, MathFunc current) from Src/module.c:1267.
resolvebuiltin
Port of static HashNode resolvebuiltin(const char *cmdarg, HashNode hn) from Src/exec.c:2700-2724 — the autoloaded-builtin stub firing.
runhookdef
Port of int runhookdef(Hookdef h, void *d) from Src/module.c:990.
setconddefs
Port of int setconddefs(char const *nam, Conddef c, int size, int *e) from Src/module.c:754. 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.
setmathfuncs
Port of int setmathfuncs(char const *nam, MathFunc f, int size, int *e) from Src/module.c:1374. Bulk add/delete of math-function definitions via the parallel e[] selector array (same shape as setconddefs).
setup_
Port of setup_(UNUSED(Module m)) from Src/module.c:306.
setup_module
Port of setup_module(Module m) from Src/module.c:1884.
try_load_module
Port of try_load_module(char const *name) from Src/module.c:1583.
unload_named_module
Port of unload_named_module(char *modname, char *nam, int silent) from Src/module.c:2923-2965.