RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  ____________________________________________________________________________

  Server: rpm5.org                         Name:   Jeff Johnson
  Root:   /v/rpm/cvs                       Email:  j...@rpm5.org
  Module: rpm                              Date:   10-May-2017 23:39:09
  Branch: rpm-5_4                          Handle: 2017051021390900

  Modified files:           (Branch: rpm-5_4)
    rpm                     CHANGES configure.ac
    rpm/lib                 poptALL.c
    rpm/rpmio               librpmio.vers poptIO.c rpmmalloc.c

  Log:
    - mcheck: link -lmcheck to enable, wrap mtrace et al in rpmio.

  Summary:
    Revision    Changes     Path
    1.3501.2.548+1  -0      rpm/CHANGES
    2.472.2.169 +5  -4      rpm/configure.ac
    2.144.2.16  +15 -112    rpm/lib/poptALL.c
    2.199.2.73  +13 -0      rpm/rpmio/librpmio.vers
    1.94.2.25   +6  -10     rpm/rpmio/poptIO.c
    1.29.2.5    +178 -54    rpm/rpmio/rpmmalloc.c
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/CHANGES
  ============================================================================
  $ cvs diff -u -r1.3501.2.547 -r1.3501.2.548 CHANGES
  --- rpm/CHANGES       10 May 2017 16:59:43 -0000      1.3501.2.547
  +++ rpm/CHANGES       10 May 2017 21:39:09 -0000      1.3501.2.548
  @@ -1,4 +1,5 @@
   5.4.17 -> 5.4.18:
  +    - jbj: mcheck: link -lmcheck to enable, wrap mtrace et al in rpmio.
       - jbj: bsd: use getmode/setmode/strmode from glibc -lbsd (if possible).
       - jbj: capng: stub in process capabilities support.
       - jbj: bsd: use setproctitle from glibc -lbsd (if possible).
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/configure.ac
  ============================================================================
  $ cvs diff -u -r2.472.2.168 -r2.472.2.169 configure.ac
  --- rpm/configure.ac  10 May 2017 16:57:56 -0000      2.472.2.168
  +++ rpm/configure.ac  10 May 2017 21:39:09 -0000      2.472.2.169
  @@ -1734,7 +1734,7 @@
   dnl # glibc malloc info/check/tracing.
   AC_CHECK_HEADERS(malloc.h)
   AC_CHECK_FUNCS(malloc calloc realloc free cfree memalign valloc pvalloc)
  -AC_CHECK_FUNCS(mallopt malloc_trim malloc_usable_size malloc_stats)
  +AC_CHECK_FUNCS(mallopt)
   AC_CHECK_MEMBERS([
           struct mallinfo.arena,
           struct mallinfo.ordblks,
  @@ -1749,7 +1749,8 @@
       [   AC_DEFINE(HAVE_STRUCT_MALLINFO, 1, [Define as 1 if you have "struct 
mallinfo" (only glibc?)])
       ], [],
       [#include <malloc.h>])
  -AC_CHECK_FUNCS(mallinfo)
  +AC_CHECK_FUNCS(malloc_trim malloc_usable_size malloc_stats)
  +AC_CHECK_FUNCS(malloc_info)
   AC_CHECK_FUNCS(malloc_get_state malloc_set_state)
   AC_CHECK_FUNCS(__default_morecore __malloc_check_init)
   AC_CHECK_FUNCS(posix_memalign)
  @@ -4067,8 +4068,8 @@
       [Glibc MEMCHECK], [mcheck],
       [c], [mcheck], [mcheck.h],
       [yes,external:none], [],
  -    [   LIBS="$OLIBS"
  -        AC_CHECK_FUNCS(mcheck)               dnl used in rpmqv.c
  +    [   LIBS="$OLIBS -lmcheck"
  +        AC_CHECK_FUNCS(mcheck)
           AC_CHECK_FUNCS(mcheck_pedantic)
           AC_CHECK_FUNCS(mcheck_check_all)
           AC_CHECK_FUNCS(mprobe)
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/lib/poptALL.c
  ============================================================================
  $ cvs diff -u -r2.144.2.15 -r2.144.2.16 poptALL.c
  --- rpm/lib/poptALL.c 21 Apr 2017 06:19:16 -0000      2.144.2.15
  +++ rpm/lib/poptALL.c 10 May 2017 21:39:09 -0000      2.144.2.16
  @@ -59,7 +59,6 @@
   
   #endif       /* __cplusplus */
   
  -/*@unchecked@*/ /*@only@*/ /*@null@*/
   extern unsigned int * keyids;
   
   #define POPT_SHOWVERSION     -999
  @@ -68,116 +67,77 @@
   #define POPT_PREDEFINE               -996
   #define POPT_UNDEFINE                -994
   
  -/*@access headerTagIndices @*/               /* XXX rpmcliFini */
  -/*@access headerTagTableEntry @*/    /* XXX rpmcliFini */
  -
  -/*@unchecked@*/
   static int _debug = 0;
   
  -/*@-exportheadervar@*/
  -/*@unchecked@*/
   extern int _rpmds_nopromote;
   
  -/*@unchecked@*/
   extern int _fps_debug;
   
  -/*@unchecked@*/
   extern int _fsm_debug;
   
  -/*@unchecked@*/
   extern int _fsm_threads;
   
  -/*@unchecked@*/
   extern int _hdr_debug;
  -/*@unchecked@*/
   extern int _hdrqf_debug;
   
  -/*@unchecked@*/
   extern int _pkgio_debug;
   
  -/*@unchecked@*/
   extern int _rpmrepo_debug;
   
  -/*@unchecked@*/
   extern int _print_pkts;
   
  -/*@unchecked@*/
   extern int _rpmpsm_debug;
   
  -/*@unchecked@*/
   extern int _psm_threads;
   
  -/*@unchecked@*/
   extern int _rpmal_debug;
   
  -/*@unchecked@*/
   extern int _rpmds_debug;
   
  -/*@unchecked@*/
          int _rpmfc_debug;
   
  -/*@unchecked@*/
   extern int _rpmfi_debug;
   
  -/*@unchecked@*/
   extern int _rpmgi_debug;
   
  -/*@unchecked@*/
   extern int _rpmmi_debug;
   
  -/*@unchecked@*/
   extern int _rpmps_debug;
   
  -/*@unchecked@*/
   extern int _rpmsq_debug;
   
  -/*@unchecked@*/
   extern int _rpmte_debug;
   
  -/*@unchecked@*/
   extern int _rpmts_debug;
   
  -/*@unchecked@*/
   extern int _rpmwf_debug;
   
  -/*@unchecked@*/
   extern int _rpmts_macros;
   
  -/*@unchecked@*/
   extern int _rpmts_stats;
   
  -/*@unchecked@*/
   extern int _hdr_stats;
   
   static int _noplugins;
   static int _initdb;
   
  -/*@unchecked@*/
   rpmQueryFlags rpmcliQueryFlags;
   
  -/*@unchecked@*/ /*@null@*/
   const char * rpmcliTargets = NULL;
   
  -/*@unchecked@*/
   static int rpmcliInitialized = -1;
   
   #ifdef WITH_LUA
  -/*@unchecked@*/
   extern const char *rpmluaFiles;
   #endif
   
  -/*@-readonlytrans@*/ /* argv loading prevents observer, xstrdup needed. */
  -/*@unchecked@*/
   static const char *rpmpoptfiles = RPMPOPTFILES;
   static const char *rpmMacrofilesSave;
  -/*@=readonlytrans@*/
   
   /**
    * Display rpm version.
    */
   static void printVersion(FILE * fp)
  -     /*@globals rpmEVR, fileSystem, internalState @*/
  -     /*@modifies *fp, fileSystem, internalState @*/
   {
       fprintf(fp, _("%s (" RPM_NAME ") %s\n"), __progname, rpmEVR);
       if (rpmIsVerbose())
  @@ -186,10 +146,6 @@
   }
   
   void rpmcliConfigured(void)
  -     /*@globals rpmcliInitialized, rpmCLIMacroContext, rpmGlobalMacroContext,
  -             h_errno, fileSystem, internalState @*/
  -     /*@modifies rpmcliInitialized, rpmCLIMacroContext, 
rpmGlobalMacroContext,
  -             fileSystem, internalState @*/
   {
       if (rpmcliInitialized < 0) {
        char * t = NULL;
  @@ -209,8 +165,6 @@
   /* ========== all-rpm-modes popt args */
   
   static const char * rpmcliEvalSlurp(const char * arg)
  -     /*@globals rpmGlobalMacroContext @*/
  -     /*@modifies rpmGlobalMacroContext @*/
   {
       const char * pre = "";
       const char * post = "";
  @@ -238,13 +192,9 @@
   /**
    */
   static void rpmcliAllArgCallback(poptContext con,
  -                /*@unused@*/ enum poptCallbackReason reason,
  +                enum poptCallbackReason reason,
                   const struct poptOption * opt, const char * arg,
  -                /*@unused@*/ const void * data)
  -     /*@globals pgpDigVSFlags, rpmcliTargets, rpmcliQueryFlags, 
rpmCLIMacroContext,
  -             rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
  -     /*@modifies con, pgpDigVSFlags, rpmcliTargets, rpmcliQueryFlags, 
rpmCLIMacroContext,
  -             rpmGlobalMacroContext, fileSystem, internalState @*/
  +                const void * data)
   {
   
       /* XXX avoid accidental collisions with POPT_BIT_SET for flags */
  @@ -264,11 +214,9 @@
        t = s;
        if (*t == '%') t++;
        rpmcliConfigured();
  -/*@-type@*/
        /* XXX adding macro to global context isn't Right Thing Todo. */
        (void) rpmDefineMacro(NULL, t, RMIL_CMDLINE);
        (void) rpmDefineMacro(rpmCLIMacroContext, t, RMIL_CMDLINE);
  -/*@=type@*/
        s = _free(s);
       }        break;
       case POPT_UNDEFINE:
  @@ -281,11 +229,9 @@
        }
        t = s;
        if (*t == '%') t++;
  -/*@-type@*/
        rpmcliConfigured();
        (void) rpmUndefineMacro(NULL, t);
        (void) rpmUndefineMacro(rpmCLIMacroContext, t);
  -/*@=type@*/
        s = _free(s);
       }        break;
       case 'E':
  @@ -299,20 +245,20 @@
       }        break;
       case POPT_SHOWVERSION:
        printVersion(stdout);
  -/*@i@*/      con = rpmcliFini(con);
  +     con = rpmcliFini(con);
        exit(EXIT_SUCCESS);
  -     /*@notreached@*/ break;
  +     break;
       case POPT_SHOWRC:
        rpmcliConfigured();
        (void) rpmShowRC(stdout);
  -/*@i@*/      con = rpmcliFini(con);
  +     con = rpmcliFini(con);
        exit(EXIT_SUCCESS);
  -     /*@notreached@*/ break;
  +     break;
       case POPT_QUERYTAGS:
        rpmDisplayQueryTags(NULL, NULL, NULL);
  -/*@i@*/      con = rpmcliFini(con);
  +     con = rpmcliFini(con);
        exit(EXIT_SUCCESS);
  -     /*@notreached@*/ break;
  +     break;
       case RPMCLI_POPT_NODIGEST:
        rpmcliQueryFlags = (rpmQueryFlags)(rpmcliQueryFlags | VERIFY_DIGEST);
   #if defined(SUPPORT_NOSIGNATURES)
  @@ -347,22 +293,18 @@
        if (rpmcliTargets == NULL)
            rpmcliTargets = xstrdup(arg);
        else {
  -/*@-modobserver @*/
            char * t = (char *) rpmcliTargets;
            size_t nb = strlen(t) + (sizeof(",")-1) + strlen(arg) + 1;
  -/*@i@*/          t = (char *) xrealloc(t, nb);
  +         t = (char *) xrealloc(t, nb);
            (void) stpcpy( stpcpy(t, ","), arg);
            rpmcliTargets = t;
  -/*@=modobserver @*/
        }
        break;
       }
   }
   
  -/*@unchecked@*/
   int global_depFlags = RPMDEPS_FLAG_ADDINDEPS;
   
  -/*@unchecked@*/
   struct poptOption rpmcliDepFlagsPoptTable[] = {
    { "noaid", '\0', POPT_BIT_CLR|POPT_ARGFLAG_TOGGLE, &global_depFlags, 
RPMDEPS_FLAG_ADDINDEPS,
        N_("Add packages to resolve dependencies"), NULL },
  @@ -396,13 +338,9 @@
      POPT_TABLEEND
   };
   
  -/*@-bitwisesigned -compmempass @*/
  -/*@unchecked@*/
   struct poptOption rpmcliAllPoptTable[] = {
  -/*@-type@*/ /* FIX: cast? */
    { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | 
POPT_CBFLAG_CONTINUE,
           (void *) rpmcliAllArgCallback, 0, NULL, NULL },
  -/*@=type@*/
   
    { "debug", 'd', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_debug, -1,
        N_("Debug generic operations"), NULL},
  @@ -504,32 +442,25 @@
   
      POPT_TABLEEND
   };
  -/*@=bitwisesigned =compmempass @*/
   
   poptContext
   rpmcliFini(poptContext optCon)
  -     /*@globals keyids @*/
  -     /*@modifies keyids @*/
   {
  -/*@-nestedextern@*/
       extern rpmioPool _rpmjniPool;
       extern rpmioPool _rpmjsPool;
       extern rpmioPool _headerPool;
       extern const char * evr_tuple_order;
       extern const char * evr_tuple_match;
       extern miRE evr_tuple_mire;
  -/*@=nestedextern@*/
   
       /* If the value has changed, free the macro paths. */
       if (rpmMacrofiles != rpmMacrofilesSave)
        rpmMacrofiles = _free(rpmMacrofiles);
   
  -/*@-mods@*/
       evr_tuple_order = _free(evr_tuple_order);
       evr_tuple_match = _free(evr_tuple_match);
       evr_tuple_mire = mireFree(evr_tuple_mire);
   
  -/*@-onlyunqglobaltrans@*/
       /* Realease (and dereference) embedded interpreter global objects first. 
*/
       _rpmjniI = rpmjniFree(_rpmjniI);
       _rpmjniPool = rpmioFreePool(_rpmjniPool);
  @@ -565,18 +496,16 @@
   #endif
       RPMIOPOOL_FREE(dbi)
       _headerPool = rpmioFreePool(_headerPool);
  -/*@=onlyunqglobaltrans@*/
  -/*@=mods@*/
   
       /* XXX this should be done in the rpmioClean() wrapper. */
       /* keeps memory leak checkers quiet */
       rpmFreeMacros(NULL);
  -/*@i@*/      rpmFreeMacros(rpmCLIMacroContext);
  +    rpmFreeMacros(rpmCLIMacroContext);
   
       rpmFreeRpmrc();  /* XXX mireFreeAll(platpat) before rpmioFreePool. */
   
       rpmFreeFilesystems();
  -/*@i@*/      rpmcliTargets = _free(rpmcliTargets);
  +    rpmcliTargets = _free(rpmcliTargets);
   
       keyids = _free(keyids);
   
  @@ -586,19 +515,13 @@
   
       optCon = poptFreeContext(optCon);
   
  -#if defined(HAVE_MCHECK_H) && defined(HAVE_MTRACE)
  -    /*@-noeffect@*/
  -    muntrace();   /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
  -    /*@=noeffect@*/
  -#endif
  +    rpmioMuntrace();
  +    rpmioMallocInfo(NULL);
   
  -/*@-globstate@*/
       return NULL;
  -/*@=globstate@*/
   }
   
   static inline int checkfd(const char * devnull, int fdno, int flags)
  -     /*@*/
   {
       struct stat sb;
       int ret = 0;
  @@ -643,11 +566,8 @@
   }
   #endif
   
  -/*@-globstate@*/
   poptContext
   rpmcliInit(int argc, char *const argv[], struct poptOption * optionsTable)
  -     /*@globals rpmpoptfiles @*/
  -     /*@modifies rpmpoptfiles @*/
   {
       poptContext optCon;
       char * arg0 = argv[0];
  @@ -655,20 +575,14 @@
       int xx;
       int i;
   
  -#if defined(HAVE_MCHECK_H) && defined(HAVE_MTRACE)
  -    /*@-noeffect@*/
  -    mtrace();   /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
  -    /*@=noeffect@*/
  -#endif
  +    rpmioMtrace();
   
  -/*@-globs -mods@*/
       setprogname(arg0);       /* Retrofit glibc __progname */
       /* XXX glibc churn sanity */
       if (__progname == NULL) {
        if ((__progname = strrchr(arg0, '/')) != NULL) __progname++;
        else __progname = arg0;
       }
  -/*@=globs =mods@*/
   
       /* Insure that stdin/stdout/stderr are open, lest stderr end up in 
rpmdb. */
      { static const char _devnull[] = "/dev/null";
  @@ -728,9 +642,7 @@
        s = "rpm";
       if (!strcmp(s, "wdjbuild"))
        s = "rpmbuild";
  -/*@-nullpass -temptrans@*/
       optCon = poptGetContext(s, argc, (const char **)argv, optionsTable, 0);
  -/*@=nullpass =temptrans@*/
   }
   
   #if defined(RPM_VENDOR_OPENPKG) /* stick-with-rpm-file-sanity-checking */ || 
\
  @@ -763,7 +675,7 @@
                fn++;
                if (!rpmSecuritySaneFile(fn)) {
                    rpmlog(RPMLOG_WARNING, "existing POPT configuration file 
\"%s\" considered INSECURE -- not loaded\n", fn);
  -                 /*@innercontinue@*/ continue;
  +                 continue;
                }
            }
            (void) poptReadConfigFile(optCon, fn);
  @@ -802,15 +714,11 @@
       /* Process all options, whine if unknown. */
       while ((rc = poptGetNextOpt(optCon)) > 0) {
        const char * optArg = poptGetOptArg(optCon);
  -/*@-dependenttrans -observertrans@*/ /* Avoid popt memory leaks. */
        optArg = _free(optArg);
  -/*@=dependenttrans =observertrans @*/
        switch (rc) {
        default:
  -/*@-nullpass@*/
            fprintf(stderr, _("%s: option table misconfigured (%d)\n"),
                __progname, rc);
  -/*@=nullpass@*/
            exit(EXIT_FAILURE);
   
            /*@notreached@*/ /*@switchbreak@*/ break;
  @@ -818,11 +726,9 @@
       }
   
       if (rc < -1) {
  -/*@-nullpass@*/
        fprintf(stderr, "%s: %s: %s\n", __progname,
                poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
                poptStrerror(rc));
  -/*@=nullpass@*/
        exit(EXIT_FAILURE);
       }
   
  @@ -835,10 +741,7 @@
       }
   
       /* Initialize header stat collection. */
  -/*@-mods@*/
       _hdr_stats = _rpmts_stats;
  -/*@=mods@*/
   
       return optCon;
   }
  -/*@=globstate@*/
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/librpmio.vers
  ============================================================================
  $ cvs diff -u -r2.199.2.72 -r2.199.2.73 librpmio.vers
  --- rpm/rpmio/librpmio.vers   10 May 2017 16:57:56 -0000      2.199.2.72
  +++ rpm/rpmio/librpmio.vers   10 May 2017 21:39:09 -0000      2.199.2.73
  @@ -578,6 +578,19 @@
       rpmioInit;
       rpmioLinkPoolItem;
       rpmioMkpath;
  +    rpmioMallopt;
  +    rpmioMallocInfo;
  +    rpmioMallocStats;
  +    rpmioMallocTrim;
  +    rpmioMallocUsableSize;
  +    rpmioMallocGetState;
  +    rpmioMallocSetState;
  +    rpmioMtrace;
  +    rpmioMuntrace;
  +    rpmioMcheck;
  +    rpmioMcheckPedantic;
  +    rpmioMcheckCheckAll;
  +    rpmioMprobe;
       rpmioNewPool;
       rpmioParse;
       rpmioPFree;
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/poptIO.c
  ============================================================================
  $ cvs diff -u -r1.94.2.24 -r1.94.2.25 poptIO.c
  --- rpm/rpmio/poptIO.c        16 Jul 2016 14:40:26 -0000      1.94.2.24
  +++ rpm/rpmio/poptIO.c        10 May 2017 21:39:09 -0000      1.94.2.25
  @@ -5,6 +5,8 @@
   
   #include "system.h"
   
  +#include <malloc.h>
  +
   #include <poptIO.h>
   
   #if defined(WITH_BEECRYPT)
  @@ -705,9 +707,8 @@
   
       optCon = poptFreeContext(optCon);
   
  -#if defined(HAVE_MCHECK_H) && defined(HAVE_MTRACE)
  -    muntrace();   /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
  -#endif
  +    rpmioMuntrace();
  +    rpmioMallocInfo(NULL);
   
       return NULL;
   }
  @@ -728,13 +729,8 @@
       poptContext optCon;
       char * arg0 = argv[0];
       int rc;
  -#ifdef       NOTYET
  -    int i;
  -#endif
   
  -#if defined(HAVE_MCHECK_H) && defined(HAVE_MTRACE)
  -    mtrace();   /* Trace malloc only if MALLOC_TRACE=mtrace-output-file. */
  -#endif
  +    rpmioMtrace();
   
       setprogname(arg0);       /* Retrofit glibc __progname */
   
  @@ -773,7 +769,7 @@
   
   #ifdef       NOTYET
       /* read all RPM POPT configuration files */
  -    for (i = 1; i < argc; i++) {
  +    for (int i = 1; i < argc; i++) {
           if (strcmp(argv[i], "--rpmpopt") == 0 && i+1 < argc) {
               rpmpoptfiles = argv[i+1];
               break;
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmmalloc.c
  ============================================================================
  $ cvs diff -u -r1.29.2.4 -r1.29.2.5 rpmmalloc.c
  --- rpm/rpmio/rpmmalloc.c     24 Sep 2014 13:03:04 -0000      1.29.2.4
  +++ rpm/rpmio/rpmmalloc.c     10 May 2017 21:39:09 -0000      1.29.2.5
  @@ -3,10 +3,16 @@
    */
   
   #include "system.h"
  +
  +#if defined(HAVE_MALLOC_H)
  +#include <malloc.h>
  +#endif
  +
   #include <rpmiotypes.h>
   #include <rpmio.h>
   #include <rpmlog.h>
   #include <yarn.h>
  +
   #include "debug.h"
   
   #ifdef __cplusplus
  @@ -24,56 +30,38 @@
   #define      EXIT_FAILURE    1
   #endif
   
  -/*@-modfilesys@*/
  -/*@only@*/ void *vmefail(size_t size)
  +void *vmefail(size_t size)
   {
       fprintf(stderr, _("memory alloc (%u bytes) returned NULL.\n"), 
(unsigned)size);
       exit(EXIT_FAILURE);
  -    /*@notreached@*/
   #if     !(__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4))
  -/*@-nullret@*/
       return NULL;
  -/*@=nullret@*/
   #endif
   }
  -/*@=modfilesys@*/
   
   /**
    */
   struct rpmioPool_s {
       yarnLock have;           /*!< unused items available, lock for list */
  -/*@relnull@*/
       void *pool;
  -/*@relnull@*/
       rpmioItem head;          /*!< linked list of available items */
  -/*@dependent@*/
       rpmioItem * tail;
       size_t size;             /*!< size of items in this pool */
       int limit;                       /*!< number of new items allowed, or -1 
*/
       int flags;
  -/*@null@*/
  -    const char * (*dbg) (void *item)
  -     /*@*/;                  /*!< generate string w Unlink/Link debugging */
  -/*@null@*/
  -    void (*init) (void *item)
  -     /*@modifies *item @*/;  /*!< create item contents. */
  -/*@null@*/
  -    void (*fini) (void *item)
  -     /*@modifies *item @*/;  /*!< destroy item contents. */
  +    const char * (*dbg) (void *item);
  +                             /*!< generate string w Unlink/Link debugging */
  +    void (*init) (void *item);       /*!< create item contents. */
  +    void (*fini) (void *item);       /*!< destroy item contents. */
       int reused;                      /*!< number of items reused */
       int made;                        /*!< number of items made */
  -/*@observer@*/
       const char *name;
  -/*@null@*/
       void * zlog;
   };
   
  -/*@unchecked@*/ /*@only@*/ /*@null@*/
   static rpmioPool _rpmioPool;
   
   rpmioPool rpmioFreePool(rpmioPool pool)
  -     /*@globals _rpmioPool @*/
  -     /*@modifies _rpmioPool @*/
   {
       if (pool == NULL) {
        pool = _rpmioPool;
  @@ -107,12 +95,10 @@
       return NULL;
   }
   
  -/*@-internalglobs@*/
   rpmioPool rpmioNewPool(const char * name, size_t size, int limit, int flags,
                char * (*dbg) (void *item),
                void (*init) (void *item),
                void (*fini) (void *item))
  -     /*@*/
   {
       rpmioPool pool = (rpmioPool) xcalloc(1, sizeof(*pool));
   #if defined(WITH_VALGRIND)
  @@ -139,9 +125,7 @@
       rpmlog(RPMLOG_DEBUG, D_("pool %s:\tcreated size %u limit %d flags 
%d\n"), pool->name, (unsigned)pool->size, pool->limit, pool->flags);
       return pool;
   }
  -/*@=internalglobs@*/
   
  -/*@-internalglobs@*/
   rpmioItem rpmioUnlinkPoolItem(rpmioItem item, const char * msg,
                const char * fn, unsigned ln)
   {
  @@ -151,19 +135,13 @@
   ANNOTATE_HAPPENS_AFTER(item);
       if ((pool = (rpmioPool) item->pool) != NULL && pool->flags && msg != 
NULL) {
        const char * imsg = (pool->dbg ? (*pool->dbg)((void *)item) : "");
  -/*@-modfilesys@*/
        fprintf(stderr, "--> %s %p -- %ld %s at %s:%u%s\n", pool->name,
                        item, yarnPeekLock(item->use), msg, fn, ln, imsg);
  -/*@=modfilesys@*/
       }
       yarnTwist(item->use, BY, -1);
  -/*@-retalias@*/      /* XXX returning the deref'd item is used to detect 
nrefs = 0 */
       return item;
  -/*@=retalias@*/
   }
  -/*@=internalglobs@*/
   
  -/*@-internalglobs@*/
   rpmioItem rpmioLinkPoolItem(rpmioItem item, const char * msg,
                const char * fn, unsigned ln)
   {
  @@ -172,22 +150,16 @@
       yarnPossess(item->use);
       if ((pool = (rpmioPool) item->pool) != NULL && pool->flags && msg != 
NULL) {
        const char * imsg = (pool->dbg ? (*pool->dbg)((void *)item) : "");
  -/*@-modfilesys@*/
        fprintf(stderr, "--> %s %p ++ %ld %s at %s:%u%s\n", pool->name,
                        item, yarnPeekLock(item->use)+1, msg, fn, ln, imsg);
  -/*@=modfilesys@*/
       }
   ANNOTATE_HAPPENS_BEFORE(item);
       yarnTwist(item->use, BY, 1);
       return item;
   }
  -/*@=internalglobs@*/
   
  -/*@-internalglobs@*/
  -/*@null@*/
  -void * rpmioFreePoolItem(/*@killref@*/ /*@null@*/ rpmioItem item,
  +void * rpmioFreePoolItem(rpmioItem item,
                   const char * msg, const char * fn, unsigned ln)
  -        /*@modifies item @*/
   {
       rpmioPool pool;
       if (item == NULL) return NULL;
  @@ -199,10 +171,8 @@
   ANNOTATE_HAPPENS_AFTER(item);
       if ((pool = (rpmioPool) item->pool) != NULL && pool->flags && msg != 
NULL) {
        const char * imsg = (pool->dbg ? (*pool->dbg)((void *)item) : "");
  -/*@-modfilesys@*/
        fprintf(stderr, "--> %s %p -- %ld %s at %s:%u%s\n", pool->name,
                        item, yarnPeekLock(item->use), msg, fn, ln, imsg);
  -/*@=modfilesys@*/
       }
       if (yarnPeekLock(item->use) <= 1L) {
   VALGRIND_HG_CLEAN_MEMORY(item, pool->size);
  @@ -212,13 +182,9 @@
        item = rpmioPutPool(item);
       } else
        yarnTwist(item->use, BY, -1);
  -/*@-retalias@*/      /* XXX returning the deref'd item is used to detect 
nrefs = 0 */
       return (void *) item;
  -/*@=retalias@*/
   }
  -/*@=internalglobs@*/
   
  -/*@-internalglobs@*/
   rpmioItem rpmioGetPool(rpmioPool pool, size_t size)
   {
       rpmioItem item;
  @@ -260,9 +226,7 @@
        size - sizeof(struct rpmioItem_s));
       return item;
   }
  -/*@=internalglobs@*/
   
  -/*@-internalglobs@*/
   rpmioItem rpmioPutPool(rpmioItem item)
   {
       rpmioPool pool;
  @@ -285,11 +249,171 @@
       (void) _free(item);
       return NULL;
   }
  -/*@=internalglobs@*/
   
  -#if !(HAVE_MCHECK_H && defined(__GNUC__)) && !defined(__LCLINT__)
  +int rpmioMcheck(void (*abortfunc)())
  +{
  +    int rc = -2;
  +#if defined(HAVE_MCHECK)
  +    rc = mcheck(abortfunc);
  +#endif       /* HAVE_MCHECK */
  +    return rc;
  +}
  +
  +int rpmioMcheckPedantic(void (*abortfunc)())
  +{
  +    int rc = -2;
  +#if defined(HAVE_MCHECK_PEDANTIC)
  +    rc = mcheck_pedantic(abortfunc);
  +#endif       /* HAVE_MCHECK_PEDANTIC */
  +    return rc;
  +}
  +
  +void rpmioMcheckCheckAll(void)
  +{
  +#if defined(HAVE_MCHECK_CHECK_ALL)
  +    mcheck_check_all();
  +#endif       /* HAVE_MCHECK_CHECK_ALL */
  +}
  +
  +int rpmioMprobe(void *ptr)
  +{
  +    int rc = -2;
  +#if defined(HAVE_MPROBE)
  +    rc = mprobe(ptr);
  +#endif       /* HAVE_MPROBE */
  +    return rc;
  +}
  +
  +int rpmioMallopt(int param, int val)
  +{
  +    int rc = -2;
  +
  +    (void)val;
  +    switch (param) {
  +    default:
  +     break;
  +#if defined(HAVE_MALLOC_INFO)
  +    case 0:
  +     rc = malloc_info(param, stderr);
  +     break;
  +#endif       /* HAVE_MALLOC_INFO */
  +#if defined(HAVE_MALLOPT)
  +    case M_MXFAST:
  +    case M_NLBLKS:
  +    case M_GRAIN:
  +    case M_KEEP:
  +    case M_TRIM_THRESHOLD:
  +    case M_TOP_PAD:
  +    case M_MMAP_THRESHOLD:
  +    case M_MMAP_MAX:
  +    case M_CHECK_ACTION:
  +    case M_PERTURB:
  +    case M_ARENA_TEST:
  +    case M_ARENA_MAX:
  +     rc = mallopt(param, val);
  +     break;
  +#endif       /* HAVE_MALLOPT */
  +    }
  +
  +fprintf(stderr, "<-- %s(%d,%d) rc %d\n", __FUNCTION__, param, val, rc);
  +    return rc;
  +}
  +
  +void rpmioMallocInfo(const char *msg)
  +{
  +#if defined(HAVE_MALLINFO)
  +#define      _MLOG(_item, _desc) \
  +    rpmlog(RPMLOG_DEBUG, "%10s: %10d | %s\n", #_item, minfo._item, _desc)
  +    struct mallinfo minfo = mallinfo();      /* structure assignment */
  +    if (msg == NULL)
  +     msg = "malloc info:";
  +    rpmlog(RPMLOG_DEBUG, "======================== %s\n", msg);
  +    _MLOG(arena,     "non-mmap'ed space allocated from system sbrk()");
  +    _MLOG(ordblks,   "no. free chunks not in use");
  +    _MLOG(smblks,    "no. fastbin blocks (unused)");
  +    _MLOG(hblks,     "no. mmap'ed regions");
  +    _MLOG(hblkhd,    "space in mmap'ed regions");
  +    _MLOG(usmblks,   "always 0, backward compatibility (unused)");
  +    _MLOG(fsmblks,   "space available in free'd fastbin blocks");
  +    _MLOG(uordblks,  "total allocated space");
  +    _MLOG(fordblks,  "total free space");
  +    _MLOG(keepcost,  "top-most, releasable (via malloc_trim) space");
  +#undef       _MLOG
  +#endif       /* HAVE_MALLINFO */
  +fprintf(stderr, "<-- %s(%s)\n", __FUNCTION__, msg);
  +}
  +
  +void rpmioMallocStats(void)
  +{
  +#if defined(HAVE_MALLOC_STATS)
  +    malloc_stats();
  +#endif
  +fprintf(stderr, "<-- %s()\n", __FUNCTION__);
  +}
  +
  +int rpmioMallocTrim(size_t pad)
  +{
  +    int rc = -2;
  +    (void)pad;
  +#if defined(HAVE_MALLOC_TRIM)
  +    rc = malloc_trim(pad);
  +#endif
  +fprintf(stderr, "<-- %s(%lu) rc %d\n", __FUNCTION__, (unsigned long)pad, rc);
  +    return rc;
  +}
  +
  +size_t rpmioMallocUsableSize(void *ptr)
  +{
  +    size_t rc = 0;
  +    (void)ptr;
  +#if defined(HAVE_MALLOC_USABLE_SIZE)
  +    rc = malloc_usable_size(ptr);
  +#endif
  +fprintf(stderr, "<-- %s(%p) rc %lu\n", __FUNCTION__, ptr, (unsigned long)rc);
  +    return rc;
  +}
  +
  +void * rpmioMallocGetState(void)
  +{
  +    void *ptr = NULL;
  +#if defined(HAVE_MALLOC_GET_STATE)
  +    ptr = malloc_get_state();
  +#endif
  +fprintf(stderr, "<-- %s() rc %p\n", __FUNCTION__, ptr);
  +    return ptr;
  +}
  +
  +int rpmioMallocSetState(void *ptr)
  +{
  +    int rc = -2;
  +    (void)ptr;
  +#if defined(HAVE_MALLOC_SET_STATE)
  +    if (ptr)
  +     rc = malloc_set_state(ptr);
  +#endif
  +fprintf(stderr, "<-- %s(%p) rc %d\n", __FUNCTION__, ptr, rc);
  +    return rc;
  +}
  +
  +void rpmioMtrace(void)
  +{
  +#if defined(HAVE_MTRACE)
  +    mtrace();        /* Trace malloc only if 
MALLOC_TRACE=mtrace-output-file. */
  +#endif
  +fprintf(stderr, "<-- %s()\n", __FUNCTION__);
  +}
  +
  +void rpmioMuntrace(void)
  +{
  +#if defined(HAVE_MUNTRACE)
  +    muntrace();      /* Trace malloc only if 
MALLOC_TRACE=mtrace-output-file. */
  +#endif
  +fprintf(stderr, "<-- %s()\n", __FUNCTION__);
  +}
  +
  +#if !(HAVE_MCHECK_H && defined(__GNUC__))
   
  -/*@out@*/ /*@only@*/ void * xmalloc (size_t size)
  +void * xmalloc (size_t size)
   {
       register void *value;
       if (size == 0) size++;
  @@ -299,7 +423,7 @@
       return value;
   }
   
  -/*@only@*/ void * xcalloc (size_t nmemb, size_t size)
  +void * xcalloc (size_t nmemb, size_t size)
   {
       register void *value;
       if (size == 0) size++;
  @@ -310,7 +434,7 @@
       return value;
   }
   
  -/*@only@*/ void * xrealloc (/*@only@*/ void *ptr, size_t size)
  +void * xrealloc (void *ptr, size_t size)
   {
       register void *value;
       if (size == 0) size++;
  @@ -320,7 +444,7 @@
       return value;
   }
   
  -/*@only@*/ char * xstrdup (const char *str)
  +char * xstrdup (const char *str)
   {
       size_t size = strlen(str) + 1;
       char *newstr = (char *) malloc (size);
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                rpm-cvs@rpm5.org

Reply via email to