Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

ZSH_HASH_DEBUG is too visible



-----BEGIN PGP SIGNED MESSAGE-----

This patch moves all the hashtable debugging code into hashtable.c,
where it belongs.  Instead of having to use preprocessor conditionals,
the various create*table() functions just pass the name of the hash table
to newhashtable(), which ignores it if hashtables are not being debugged.

The reason for doing this, apart from it looking neater, is that it
avoids certain problems with module interfaces.  At the moment there
are two wildly incompatible versions of the hash table interface --
one with ZSH_HASH_DEBUG defined and one without -- and mismatches could
occur with separately compiled modules.

This patch makes the hashtable debugging code invisible everywhere
outside hashtable.c.  The hashtable structure is changed so that the
debugging members are at the end, and are in fact completely invisible
to code that doesn't specifically want to know about them.  This means
that there is only one hash table interface, and whether the debugging
occurs or not is dependent only on the base zsh executable.

 -zefram

      Index: Src/hashtable.c
      ===================================================================
      RCS file: /home/zefram/usr/cvsroot/zsh/Src/hashtable.c,v
      retrieving revision 1.16
      diff -c -r1.16 hashtable.c
      *** Src/hashtable.c	1996/12/22 22:26:26	1.16
      --- Src/hashtable.c	1996/12/22 23:39:07
      ***************
      *** 29,34 ****
      --- 29,35 ----
         *
         */
        
      + #define IN_HASHTABLE
        #include "zsh.h"
        
        /********************************/
      ***************
      *** 37,43 ****
        
        #ifdef ZSH_HASH_DEBUG
        static HashTable firstht, lastht;
      ! #endif
        
        /* Generic hash function */
        
      --- 38,46 ----
        
        #ifdef ZSH_HASH_DEBUG
        static HashTable firstht, lastht;
      ! 
      ! static void printhashtabinfo _((HashTable ht));
      ! #endif /* ZSH_HASH_DEBUG */
        
        /* Generic hash function */
        
      ***************
      *** 57,63 ****
        
        /**/
        HashTable
      ! newhashtable(int size)
        {
            HashTable ht;
        
      --- 60,66 ----
        
        /**/
        HashTable
      ! newhashtable(int size, char const *name, PrintTableStats printinfo)
        {
            HashTable ht;
        
      ***************
      *** 70,75 ****
      --- 73,80 ----
            if(lastht)
        	lastht->next = ht;
            lastht = ht;
      +     ht->printinfo = printinfo ? printinfo : printhashtabinfo;
      +     ht->tablename = ztrdup(name);
        #endif /* ZSH_HASH_DEBUG */
            ht->nodes = (HashNode *) zcalloc(size * sizeof(HashNode));
            ht->hsize = size;
      ***************
      *** 469,476 ****
        
        #define MAXDEPTH 7
        
      ! /**/
      ! void
        printhashtabinfo(HashTable ht)
        {
            HashNode hn;
      --- 474,480 ----
        
        #define MAXDEPTH 7
        
      ! static void
        printhashtabinfo(HashTable ht)
        {
            HashNode hn;
      ***************
      *** 530,536 ****
        void
        createcmdnamtable(void)
        {
      !     cmdnamtab = newhashtable(INITIAL_CMDNAMTAB);
        
            cmdnamtab->hash        = hasher;
            cmdnamtab->emptytable  = emptycmdnamtable;
      --- 534,540 ----
        void
        createcmdnamtable(void)
        {
      !     cmdnamtab = newhashtable(INITIAL_CMDNAMTAB, "cmdnamtab", NULL);
        
            cmdnamtab->hash        = hasher;
            cmdnamtab->emptytable  = emptycmdnamtable;
      ***************
      *** 543,552 ****
            cmdnamtab->enablenode  = NULL;
            cmdnamtab->freenode    = freecmdnamnode;
            cmdnamtab->printnode   = printcmdnamnode;
      - #ifdef ZSH_HASH_DEBUG
      -     cmdnamtab->printinfo   = printhashtabinfo;
      -     cmdnamtab->tablename   = ztrdup("cmdnamtab");
      - #endif
        
            pathchecked = path;
        }
      --- 547,552 ----
      ***************
      *** 673,679 ****
        void
        createshfunctable(void)
        {
      !     shfunctab = newhashtable(7);
        
            shfunctab->hash        = hasher;
            shfunctab->emptytable  = NULL;
      --- 673,679 ----
        void
        createshfunctable(void)
        {
      !     shfunctab = newhashtable(7, "shfunctab", NULL);
        
            shfunctab->hash        = hasher;
            shfunctab->emptytable  = NULL;
      ***************
      *** 686,695 ****
            shfunctab->enablenode  = enableshfuncnode;
            shfunctab->freenode    = freeshfuncnode;
            shfunctab->printnode   = printshfuncnode;
      - #ifdef ZSH_HASH_DEBUG
      -     shfunctab->printinfo   = printhashtabinfo;
      -     shfunctab->tablename   = ztrdup("shfunctab");
      - #endif
        }
        
        /* Remove an entry from the shell function hash table.   *
      --- 686,691 ----
      ***************
      *** 812,818 ****
        {
            Builtin bn;
        
      !     builtintab = newhashtable(85);
        
            builtintab->hash        = hasher;
            builtintab->emptytable  = NULL;
      --- 808,814 ----
        {
            Builtin bn;
        
      !     builtintab = newhashtable(85, "builtintab", NULL);
        
            builtintab->hash        = hasher;
            builtintab->emptytable  = NULL;
      ***************
      *** 825,834 ****
            builtintab->enablenode  = enablehashnode;
            builtintab->freenode    = freebuiltinnode;
            builtintab->printnode   = printbuiltinnode;
      - #ifdef ZSH_HASH_DEBUG
      -     builtintab->printinfo   = printhashtabinfo;
      -     builtintab->tablename   = ztrdup("builtintab");
      - #endif
        
            for (bn = builtins; bn->nam; bn++)
        	builtintab->addnode(builtintab, bn->nam, bn);
      --- 821,826 ----
      ***************
      *** 882,888 ****
        {
            Reswd rw;
        
      !     reswdtab = newhashtable(23);
        
            reswdtab->hash        = hasher;
            reswdtab->emptytable  = NULL;
      --- 874,880 ----
        {
            Reswd rw;
        
      !     reswdtab = newhashtable(23, "reswdtab", NULL);
        
            reswdtab->hash        = hasher;
            reswdtab->emptytable  = NULL;
      ***************
      *** 895,904 ****
            reswdtab->enablenode  = enablehashnode;
            reswdtab->freenode    = NULL;
            reswdtab->printnode   = printreswdnode;
      - #ifdef ZSH_HASH_DEBUG
      -     reswdtab->printinfo   = printhashtabinfo;
      -     reswdtab->tablename   = ztrdup("reswdtab");
      - #endif
        
            for (rw = reswds; rw->nam; rw++)
        	reswdtab->addnode(reswdtab, rw->nam, rw);
      --- 887,892 ----
      ***************
      *** 936,942 ****
        void
        createaliastable(void)
        {
      !     aliastab = newhashtable(23);
        
            aliastab->hash        = hasher;
            aliastab->emptytable  = NULL;
      --- 924,930 ----
        void
        createaliastable(void)
        {
      !     aliastab = newhashtable(23, "aliastab", NULL);
        
            aliastab->hash        = hasher;
            aliastab->emptytable  = NULL;
      ***************
      *** 949,958 ****
            aliastab->enablenode  = enablehashnode;
            aliastab->freenode    = freealiasnode;
            aliastab->printnode   = printaliasnode;
      - #ifdef ZSH_HASH_DEBUG
      -     aliastab->printinfo   = printhashtabinfo;
      -     aliastab->tablename   = ztrdup("aliastab");
      - #endif
        
            /* add the default aliases */
            aliastab->addnode(aliastab, ztrdup("run-help"), createaliasnode(ztrdup("man"), 0));
      --- 937,942 ----
      ***************
      *** 1148,1154 ****
        void
        createnameddirtable(void)
        {
      !     nameddirtab = newhashtable(INITIAL_NAMEDDIR);
        
            nameddirtab->hash        = hasher;
            nameddirtab->emptytable  = emptynameddirtable;
      --- 1132,1138 ----
        void
        createnameddirtable(void)
        {
      !     nameddirtab = newhashtable(INITIAL_NAMEDDIR, "nameddirtab", NULL);
        
            nameddirtab->hash        = hasher;
            nameddirtab->emptytable  = emptynameddirtable;
      ***************
      *** 1161,1170 ****
            nameddirtab->enablenode  = NULL;
            nameddirtab->freenode    = freenameddirnode;
            nameddirtab->printnode   = printnameddirnode;
      - #ifdef ZSH_HASH_DEBUG
      -     nameddirtab->printinfo   = printhashtabinfo;
      -     nameddirtab->tablename   = ztrdup("nameddirtab");
      - #endif
        
            allusersadded = 0;
            finddir(NULL);		/* clear the finddir cache */
      --- 1145,1150 ----
      Index: Src/options.c
      ===================================================================
      RCS file: /home/zefram/usr/cvsroot/zsh/Src/options.c,v
      retrieving revision 1.1
      diff -c -r1.1 options.c
      *** Src/options.c	1996/12/22 09:11:46	1.1
      --- Src/options.c	1996/12/22 23:23:25
      ***************
      *** 375,381 ****
        static void
        createoptiontable(void)
        {
      !     optiontab = newhashtable(199);
        
            optiontab->hash        = hasher;
            optiontab->emptytable  = NULL;
      --- 375,381 ----
        static void
        createoptiontable(void)
        {
      !     optiontab = newhashtable(199, "optiontab", NULL);
        
            optiontab->hash        = hasher;
            optiontab->emptytable  = NULL;
      ***************
      *** 388,397 ****
            optiontab->enablenode  = NULL;
            optiontab->freenode    = NULL;
            optiontab->printnode   = NULL;
      - #ifdef ZSH_HASH_DEBUG
      -     optiontab->printinfo   = printhashtabinfo;
      -     optiontab->tablename   = ztrdup("optiontab");
      - #endif
        }
        
        static Optname
      --- 388,393 ----
      Index: Src/params.c
      ===================================================================
      RCS file: /home/zefram/usr/cvsroot/zsh/Src/params.c,v
      retrieving revision 1.23
      diff -c -r1.23 params.c
      *** Src/params.c	1996/12/22 09:11:47	1.23
      --- Src/params.c	1996/12/22 23:23:37
      ***************
      *** 47,53 ****
            char buf[50], *str, *iname;
            int num_env;
        
      !     paramtab = newhashtable(151);
        
            paramtab->hash        = hasher;
            paramtab->emptytable  = NULL;
      --- 47,53 ----
            char buf[50], *str, *iname;
            int num_env;
        
      !     paramtab = newhashtable(151, "paramtab", NULL);
        
            paramtab->hash        = hasher;
            paramtab->emptytable  = NULL;
      ***************
      *** 60,69 ****
            paramtab->enablenode  = NULL;
            paramtab->freenode    = freeparamnode;
            paramtab->printnode   = printparamnode;
      - #ifdef ZSH_HASH_DEBUG
      -     paramtab->printinfo   = printhashtabinfo;
      -     paramtab->tablename   = ztrdup("paramtab");
      - #endif
        
            /* Add the special parameters to the hash table */
            for (ip = special_params; ip->nam; ip++)
      --- 60,65 ----
      Index: Src/zsh.h
      ===================================================================
      RCS file: /home/zefram/usr/cvsroot/zsh/Src/zsh.h,v
      retrieving revision 1.34
      diff -c -r1.34 zsh.h
      *** Src/zsh.h	1996/12/22 09:11:49	1.34
      --- Src/zsh.h	1996/12/22 23:25:35
      ***************
      *** 646,662 ****
         * scanhashtable or scanmatchtable    */
        typedef void     (*ScanFunc)       _((HashNode, int));
        
      - #ifdef ZSH_HASH_DEBUG
        typedef void (*PrintTableStats) _((HashTable));
      - #endif
        
        /* hash table for standard open hashing */
        
        struct hashtable {
      - #ifdef ZSH_HASH_DEBUG
      -     HashTable next, last;	/* linked list of all hash tables */
      -     char *tablename;		/* string containing name of the hash table */
      - #endif
            /* HASHTABLE DATA */
            int hsize;			/* size of nodes[]  (number of hash values)   */
            int ct;			/* number of elements                         */
      --- 646,656 ----
      ***************
      *** 676,684 ****
            FreeNodeFunc freenode;	/* pointer to function to free a node         */
            ScanFunc printnode;		/* pointer to function to print a node        */
        
      ! #ifdef ZSH_HASH_DEBUG
      !     PrintTableStats printinfo;	/* pointer to function to print table stats */
      ! #endif
        };
        
        /* generic hash table node */
      --- 670,680 ----
            FreeNodeFunc freenode;	/* pointer to function to free a node         */
            ScanFunc printnode;		/* pointer to function to print a node        */
        
      ! #if defined(IN_HASHTABLE) && defined(ZSH_HASH_DEBUG)
      !     HashTable next, last;	/* linked list of all hash tables             */
      !     char *tablename;		/* string containing name of the hash table   */
      !     PrintTableStats printinfo;	/* pointer to function to print table stats   */
      ! #endif /* IN_HASHTABLE || ZSH_HASH_DEBUG */
        };
        
        /* generic hash table node */
      Index: Src/Zle/zle_main.c
      ===================================================================
      RCS file: /home/zefram/usr/cvsroot/zsh/Src/Zle/zle_main.c,v
      retrieving revision 1.3
      diff -c -r1.3 zle_main.c
      *** Src/Zle/zle_main.c	1996/12/22 05:16:30	1.3
      --- Src/Zle/zle_main.c	1996/12/22 23:22:53
      ***************
      *** 1367,1373 ****
        void
        createcompctltable(void)
        {
      !     compctltab = newhashtable(23);
        
            compctltab->hash        = hasher;
            compctltab->emptytable  = NULL;
      --- 1367,1373 ----
        void
        createcompctltable(void)
        {
      !     compctltab = newhashtable(23, "compctltab", NULL);
        
            compctltab->hash        = hasher;
            compctltab->emptytable  = NULL;
      ***************
      *** 1384,1393 ****
        #else
            compctltab->printnode   = printcompctlp;
        #endif
      - #ifdef ZSH_HASH_DEBUG
      -     compctltab->printinfo   = printhashtabinfo;
      -     compctltab->tablename   = ztrdup("compctltab");
      - #endif
        }
        
        /**/
      --- 1384,1389 ----
      ***************
      *** 1450,1456 ****
        void
        createemkeybindtable(void)
        {
      !     emkeybindtab = newhashtable(INITIAL_EMKEYBINDTAB);
        
            emkeybindtab->hash        = hasher;
            emkeybindtab->emptytable  = emptyemkeybindtable;
      --- 1446,1452 ----
        void
        createemkeybindtable(void)
        {
      !     emkeybindtab = newhashtable(INITIAL_EMKEYBINDTAB, "emkeybindtab", NULL);
        
            emkeybindtab->hash        = hasher;
            emkeybindtab->emptytable  = emptyemkeybindtable;
      ***************
      *** 1465,1474 ****
        
            /* need to combine printbinding and printfuncbinding for this */
            emkeybindtab->printnode   = NULL;
      - #ifdef ZSH_HASH_DEBUG
      -     emkeybindtab->printinfo   = printhashtabinfo;
      -     emkeybindtab->tablename   = ztrdup("emkeybindtab");
      - #endif
        }
        
        /**/
      --- 1461,1466 ----
      ***************
      *** 1490,1496 ****
        void
        createvikeybindtable(void)
        {
      !     vikeybindtab = newhashtable(INITIAL_VIKEYBINDTAB);
        
            vikeybindtab->hash        = hasher;
            vikeybindtab->emptytable  = emptyvikeybindtable;
      --- 1482,1488 ----
        void
        createvikeybindtable(void)
        {
      !     vikeybindtab = newhashtable(INITIAL_VIKEYBINDTAB, "vikeybindtab", NULL);
        
            vikeybindtab->hash        = hasher;
            vikeybindtab->emptytable  = emptyvikeybindtable;
      ***************
      *** 1505,1514 ****
        
            /* need to combine printbinding and printfuncbinding for this */
            vikeybindtab->printnode   = NULL;
      - #ifdef ZSH_HASH_DEBUG
      -     vikeybindtab->printinfo   = printhashtabinfo;
      -     vikeybindtab->tablename   = ztrdup("vikeybindtab");
      - #endif
        }
        
        /**/
      --- 1497,1502 ----
      ***************
      *** 1530,1536 ****
        void
        createaltkeybindtable(void)
        {
      !     altkeybindtab = newhashtable(INITIAL_ALTKEYBINDTAB);
        
            altkeybindtab->hash        = hasher;
            altkeybindtab->emptytable  = emptyaltkeybindtable;
      --- 1518,1524 ----
        void
        createaltkeybindtable(void)
        {
      !     altkeybindtab = newhashtable(INITIAL_ALTKEYBINDTAB, "altkeybindtab", NULL);
        
            altkeybindtab->hash        = hasher;
            altkeybindtab->emptytable  = emptyaltkeybindtable;
      ***************
      *** 1545,1554 ****
        
            /* need to combine printbinding and printfuncbinding for this */
            altkeybindtab->printnode   = NULL;
      - #ifdef ZSH_HASH_DEBUG
      -     altkeybindtab->printinfo   = printhashtabinfo;
      -     altkeybindtab->tablename   = ztrdup("altkeybindtab");
      - #endif
        }
        
        /**/
      --- 1533,1538 ----

-----BEGIN PGP SIGNATURE-----
Version: 2.6.2

iQCVAwUBMr3M8HD/+HJTpU/hAQGKGQP+IVGaq6CTyONgOTqv6XrltIm8lVYBb78v
C59rI5upAed02lojtepmKP7P8spIz1Xr2wCBdHtobfFBqDops39eqz21Xz6BHmhb
NT/8Fk/+px6FfzVMCbvgMzlbH0mEB40MPgpor+OUcjXzMNqWwvN+PKZ/5wqFJlKk
2w4LHEeL/QA=
=e/Ky
-----END PGP SIGNATURE-----



Messages sorted by: Reverse Date, Date, Thread, Author