zpmod
b19981f
High-performance Zsh module for script optimization and filesystem helpers
|
Overrides for '. More...
#include "zpmod.mdh"
#include "zpmod.pro"
#include "zpmod_vendor_shims.h"
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "zpmod_compat.h"
#include "zpmod_emoji.h"
#include "zpmod_source.h"
#include "zpmod_utils.h"
Go to the source code of this file.
Data Structures | |
struct | fdhead |
Macros | |
#define | FD_EXT ".zwc" |
#define | FD_PRELEN 12 |
#define | FD_MAGIC 0x04050607 |
#define | FD_OMAGIC 0x07060504 |
#define | FDF_MAP 1 |
#define | FDF_OTHER 2 |
#define | FDHEADERLEN(f) (((Wordcode)(f))[FD_PRELEN]) |
#define | FDMAGIC(f) (((Wordcode)(f))[0]) |
#define | FDSETBYTE(f, i, v) ((((unsigned char *)(((Wordcode)(f)) + 1))[i]) = ((unsigned char)(v))) |
#define | fdbyte(f, i) ((wordcode)(((unsigned char *)(((Wordcode)(f)) + 1))[i])) |
#define | FDFLAGS(f) fdbyte(f, 0) |
#define | FDOTHER(f) (fdbyte(f, 1) + (fdbyte(f, 2) << 8) + (fdbyte(f, 3) << 16)) |
#define | FDVERSION(f) ((char *)((f) + 2)) |
#define | FIRSTFDHEAD(f) ((FDHead)(((Wordcode)(f)) + FD_PRELEN)) |
#define | NEXTFDHEAD(f) ((FDHead)(((Wordcode)(f)) + (f)->hlen)) |
#define | FDHFLAGS(f) (((FDHead)(f))->flags) |
#define | FDHTAIL(f) (((FDHead)(f))->flags >> 2) |
#define | FDHF_KSHLOAD 1 |
#define | FDHF_ZSHLOAD 2 |
#define | FDNAME(f) ((char *)(((FDHead)(f)) + 1)) |
#define | custom_zwcstat(f, b) (!!stat(f, b)) |
Typedefs | |
typedef struct fdhead * | FDHead |
Functions | |
int | bin_custom_dot (char *name, char **argv, UNUSED(Options ops), UNUSED(int func)) |
Replacement handler for '. More... | |
static FDHead | custom_dump_find_func (Wordcode h, char *name) |
static Wordcode | custom_load_dump_header (char *nam, char *name, int err) |
static Eprog | custom_check_dump_file (char *file, struct stat *sbuf, char *name, int *ksh, int test_only) |
Eprog | custom_try_source_file (char *file) |
Try to locate or build a ZWC dump for the script and return Eprog. More... | |
mod_export enum source_return | custom_source (char *s) |
Execute a sourced script and record a timing event for reporting. More... | |
char * | zp_build_source_report (int no_paths, int *rep_size) |
void | zp_free_sevent_node (HashNode hn) |
Hash lifecycle. More... | |
void | zp_source_setup_overrides (void) |
void | zp_source_restore_overrides (void) |
Variables | |
static HandlerFunc | original_dot = NULL |
static HandlerFunc | original_source = NULL |
static HashTable | zp_source_events = NULL |
static int | zp_sevent_count = 0 |
Overrides for '.
'/source and source-study event recording/reporting.
This module hooks into zsh’s sourcing mechanism to optionally compile ZWC caches, measure durations, and produce a report via the zpmod source-study
subcommand. It also respects user options like FUNCTION_ARGZERO, PATH_DIRS, POSIX_BUILTINS, SHIN_STDIN, and SOURCE_TRACE through the stable option mapping helpers.
Definition in file source.c.
#define fdbyte | ( | f, | |
i | |||
) | ((wordcode)(((unsigned char *)(((Wordcode)(f)) + 1))[i])) |
#define FDSETBYTE | ( | f, | |
i, | |||
v | |||
) | ((((unsigned char *)(((Wordcode)(f)) + 1))[i]) = ((unsigned char)(v))) |
#define NEXTFDHEAD | ( | f | ) | ((FDHead)(((Wordcode)(f)) + (f)->hlen)) |
Replacement handler for '.
' and 'source' builtins.
Mirrors zsh’s semantics while integrating custom search behavior and error reporting, and delegates to custom_source() to execute the script.
Definition at line 48 of file source.c.
References argzero, custom_source(), dupstring(), freearray(), FUNCTIONARGZERO__, lastval, path, PATHDIRS__, popheap(), POSIXBUILTINS__, pparams, pushheap(), unmeta(), zarrdup(), zerrnam(), zhtricat(), zp_conv_opt(), zsfree(), ztrdup(), and zwarnnam().
Referenced by zp_source_setup_overrides().
|
static |
Definition at line 387 of file source.c.
References custom_dump_find_func(), custom_load_dump_header(), custom_zwcstat, dummy_eprog, FDF_MAP, FDF_OTHER, FDFLAGS, FDHF_KSHLOAD, FDHF_ZSHLOAD, FDHFLAGS, FDOTHER, incrdumpcount(), fdhead::len, fdhead::npats, fdhead::start, fdhead::strs, zalloc(), and zfree().
Referenced by custom_try_source_file().
|
static |
Definition at line 191 of file source.c.
References FDHEADERLEN, FDHTAIL, FDNAME, FIRSTFDHEAD, and NEXTFDHEAD.
Referenced by custom_check_dump_file().
|
static |
Definition at line 202 of file source.c.
References FD_MAGIC, FD_OMAGIC, FD_PRELEN, FDHEADERLEN, FDMAGIC, FDOTHER, FDVERSION, getsparam(), zhalloc(), and zwarnnam().
Referenced by custom_check_dump_file().
mod_export enum source_return custom_source | ( | char * | s | ) |
Execute a sourced script and record a timing event for reporting.
Overridden dot/source and helpers exported from core.
Integrates with zsh state (opts, cmdstack, funcstack) and restores on exit. Records duration and paths for later consumption by the report generator.
Definition at line 506 of file source.c.
References addhashnode(), cmdsp, cmdstack, custom_try_source_file(), source_event::dir_path, dosetopt(), dupstring(), source_event::duration, errflag, zp_sevent_node::event, execode(), exit_pending, fdtable, source_event::file_name, freeeprog(), source_event::full_path, funcstack, source_event::id, lastval, lineno, source_event::load_error, loop(), loops, movefd(), opts, popheap(), printprompt4(), pushheap(), pwd, retflag, scriptfilename, scriptname, SHIN, shinbufrestore(), shinbufsave(), SHINSTDIN__, sourcelevel, SOURCETRACE__, subsh, thisjob, trap_return, trap_state, source_event::ts, unmeta(), xtrerr, zalloc(), zfree(), zp_conv_opt(), zp_sevent_count, zp_source_events, zshcalloc(), and ztrdup().
Referenced by bin_custom_dot().
Eprog custom_try_source_file | ( | char * | file | ) |
Try to locate or build a ZWC dump for the script and return Eprog.
When possible, compiles to .zwc and loads that for performance. Returns NULL if no dump is available and the caller should use a file fd.
Definition at line 322 of file source.c.
References bin_zcompile(), custom_check_dump_file(), dyncat(), FD_EXT, getsparam(), queue_signals(), strsfx(), unqueue_signals(), zfree(), ztrdup(), and zwarnnam().
Referenced by custom_source().
char* zp_build_source_report | ( | int | no_paths, |
int * | rep_size | ||
) |
Definition at line 670 of file source.c.
References source_event::duration, zp_sevent_node::event, source_event::file_name, source_event::full_path, gethashnode2(), zalloc(), zfree(), zp_icon(), zp_sevent_count, zp_source_events, zrealloc(), and ztrdup().
void zp_free_sevent_node | ( | HashNode | hn | ) |
Hash lifecycle.
Definition at line 727 of file source.c.
References source_event::dir_path, zp_sevent_node::event, source_event::file_name, source_event::full_path, zfree(), and zsfree().
Referenced by zp_source_setup_overrides().
void zp_source_restore_overrides | ( | void | ) |
Definition at line 762 of file source.c.
References builtintab, deletehashtable(), original_dot, original_source, and zp_source_events.
Referenced by finish_().
void zp_source_setup_overrides | ( | void | ) |
Definition at line 737 of file source.c.
References addhashnode(), bin_custom_dot(), builtintab, emptyhashtable(), gethashnode2(), hasher(), newhashtable(), original_dot, original_source, removehashnode(), zp_free_sevent_node(), zp_source_events, and zwarn().
Referenced by setup_().
|
static |
Definition at line 37 of file source.c.
Referenced by zp_source_restore_overrides(), and zp_source_setup_overrides().
|
static |
Definition at line 37 of file source.c.
Referenced by zp_source_restore_overrides(), and zp_source_setup_overrides().
|
static |
Definition at line 39 of file source.c.
Referenced by custom_source(), and zp_build_source_report().
|
static |
Definition at line 38 of file source.c.
Referenced by custom_source(), zp_build_source_report(), zp_source_restore_overrides(), and zp_source_setup_overrides().