diff options
Diffstat (limited to 'Src/zsh.h')
-rw-r--r-- | Src/zsh.h | 89 |
1 files changed, 86 insertions, 3 deletions
@@ -1731,6 +1731,23 @@ struct nameddir { #define ND_USERNAME (1<<1) /* nam is actually a username */ #define ND_NOABBREV (1<<2) /* never print as abbrev (PWD or OLDPWD) */ +/* Storage for single group/name mapping */ +typedef struct { + /* Name of group */ + char *name; + /* Group identifier */ + gid_t gid; +} groupmap; +typedef groupmap *Groupmap; + +/* Storage for a set of group/name mappings */ +typedef struct { + /* The set of name to gid mappings */ + Groupmap array; + /* A count of the valid entries in groupmap. */ + int num; +} groupset; +typedef groupset *Groupset; /* flags for controlling printing of hash table nodes */ #define PRINT_NAMEONLY (1<<0) @@ -2310,11 +2327,68 @@ enum { * Memory management * *********************/ +/* + * A Heapid is a type for identifying, uniquely up to the point where + * the count of new identifiers wraps. all heaps that are or + * (importantly) have been valid. Each valid heap is given an + * identifier, and every time we push a heap we save the old identifier + * and give the heap a new identifier so that when the heap is popped + * or freed we can spot anything using invalid memory from the popped + * heap. + * + * We could make this unsigned long long if we wanted a big range. + */ +typedef unsigned int Heapid; + +#ifdef ZSH_HEAP_DEBUG + +/* printf format specifier corresponding to Heapid */ +#define HEAPID_FMT "%x" + +/* Marker that memory is permanently allocated */ +#define HEAPID_PERMANENT (UINT_MAX) + +/* + * Heap debug verbosity. + * Bits to be 'or'ed into the variable also called heap_debug_verbosity. + */ +enum heap_debug_verbosity { + /* Report when we push a heap */ + HDV_PUSH = 0x01, + /* Report when we pop a heap */ + HDV_POP = 0x02, + /* Report when we create a new heap from which to allocate */ + HDV_CREATE = 0x04, + /* Report every time we free a complete heap */ + HDV_FREE = 0x08, + /* Report when we temporarily install a new set of heaps */ + HDV_NEW = 0x10, + /* Report when we restore an old set of heaps */ + HDV_OLD = 0x20, + /* Report when we temporarily switch heaps */ + HDV_SWITCH = 0x40, + /* + * Report every time we allocate memory from the heap. + * This is very verbose, and arguably not very useful: we + * would expect to allocate memory from a heap we create. + * For much debugging heap_debug_verbosity = 0x7f should be sufficient. + */ + HDV_ALLOC = 0x80 +}; + +#define HEAP_ERROR(heap_id) \ + fprintf(stderr, "%s:%d: HEAP DEBUG: invalid heap: " HEAPID_FMT ".\n", \ + __FILE__, __LINE__, heap_id) +#endif + /* heappush saves the current heap state using this structure */ struct heapstack { struct heapstack *next; /* next one in list for this heap */ size_t used; +#ifdef ZSH_HEAP_DEBUG + Heapid heap_id; +#endif }; /* A zsh heap. */ @@ -2325,6 +2399,10 @@ struct heap { size_t used; /* bytes used from the heap */ struct heapstack *sp; /* used by pushheap() to save the value used */ +#ifdef ZSH_HEAP_DEBUG + unsigned int heap_id; +#endif + /* Uncomment the following if the struct needs padding to 64-bit size. */ /* Make sure sizeof(heap) is a multiple of 8 #if defined(PAD_64_BIT) && !defined(__GNUC__) @@ -2492,7 +2570,11 @@ enum { * Yes, I know that doesn't seem to make much sense. * It's for use in completion, comprenez? */ - GETKEY_UPDATE_OFFSET = (1 << 7) + GETKEY_UPDATE_OFFSET = (1 << 7), + /* + * When replacing numeric escapes for printf format strings, % -> %% + */ + GETKEY_PRINTF_PERCENT = (1 << 8) }; /* @@ -2501,8 +2583,9 @@ enum { */ /* echo builtin */ #define GETKEYS_ECHO (GETKEY_BACKSLASH_C) -/* printf format string: \123 -> S, \0123 -> NL 3 */ -#define GETKEYS_PRINTF_FMT (GETKEY_OCTAL_ESC|GETKEY_BACKSLASH_C) +/* printf format string: \123 -> S, \0123 -> NL 3, \045 -> %% */ +#define GETKEYS_PRINTF_FMT \ + (GETKEY_OCTAL_ESC|GETKEY_BACKSLASH_C|GETKEY_PRINTF_PERCENT) /* printf argument: \123 -> \123, \0123 -> S */ #define GETKEYS_PRINTF_ARG (GETKEY_BACKSLASH_C) /* Full print without -e */ |