Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

mcw_malloc.c File Reference

#include "mcw_malloc.h"
#include "Amalloc.h"
#include "debugtrace.h"

Go to the source code of this file.


Data Structures

struct  mallitem

Defines

#define MAGIC   ((char) 0xd7)
#define NEXTRA   (2*sizeof(int))
#define UINT   unsigned int
#define NTB   5
#define SLOTS   8191
#define INLINE
#define ADD_TRACEBACK(ip)
#define shift_tracker(fff)   ptr_tracker( ((char *)(fff)) - NEXTRA )
#define JBASE   32768

Functions

INLINE UINT mallkey (char *fred)
mallitemptr_tracker (void *fred)
mallitemfind_empty_slot (int jj)
void add_tracker (void *fred, size_t n, char *fn, int ln)
void * malloc_track (size_t n, char *fn, int ln)
void probe_track (mallitem *ip)
void * realloc_track (mallitem *ip, size_t n, char *fn, int ln)
void * calloc_track (size_t n, size_t m, char *fn, int ln)
void free_track (mallitem *ip)
char * mcw_malloc_status (const char *fn, int ln)
int THD_is_file (char *)
void qsort_intint (int, int *, int *)
void mcw_malloc_dump (void)
void enable_mcw_malloc ()
void pause_mcw_malloc ()
void resume_mcw_malloc ()
int mcw_malloc_paused ()
int mcw_malloc_enabled ()
void * mcw_malloc (size_t n, char *fnam, int lnum)
void * mcw_realloc (void *fred, size_t n, char *fnam, int lnum)
void * mcw_calloc (size_t n, size_t m, char *fnam, int lnum)
void mcw_free (void *fred)
char * mcw_XtMalloc (Cardinal n, char *fnam, int lnum)
char * mcw_XtRealloc (char *p, Cardinal n, char *fnam, int lnum)
void mcw_XtFree (char *p)
char * mcw_XtCalloc (Cardinal n, Cardinal m, char *fnam, int lnum)

Variables

mallitem ** htab = NULL
int * nhtab = NULL
UINT serial = 0
const char * pr_nam = NULL
int pr_lin = 0
int use_tracking = 0
int pz = 0

Define Documentation

#define ADD_TRACEBACK ip   
 

Value:

do{ int tt ;                                                              \
       for( tt=1 ; tt <= NTB ; tt++ )                                        \
         ip->ptb[tt-1] = (tt < DBG_num) ? DBG_rout[DBG_num-tt] : NULL; } while(0)

Definition at line 76 of file mcw_malloc.c.

Referenced by add_tracker(), and realloc_track().

#define INLINE
 

Definition at line 72 of file mcw_malloc.c.

Referenced by mallkey().

#define JBASE   32768
 

#define MAGIC   ((char) 0xd7)
 

Definition at line 17 of file mcw_malloc.c.

Referenced by malloc_track(), probe_track(), and realloc_track().

#define NEXTRA   (2*sizeof(int))
 

Definition at line 18 of file mcw_malloc.c.

Referenced by malloc_track(), probe_track(), and realloc_track().

#define NTB   5
 

Definition at line 39 of file mcw_malloc.c.

Referenced by mcw_malloc_dump(), and probe_track().

#define shift_tracker fff       ptr_tracker( ((char *)(fff)) - NEXTRA )
 

Definition at line 122 of file mcw_malloc.c.

Referenced by hidden_NI_free(), hidden_NI_realloc(), mcw_free(), mcw_realloc(), mcw_XtFree(), and mcw_XtRealloc().

#define SLOTS   8191
 

define SLOTS 503 *

Definition at line 59 of file mcw_malloc.c.

Referenced by add_tracker(), enable_mcw_malloc(), mcw_malloc_dump(), mcw_malloc_status(), ptr_tracker(), and realloc_track().

#define UINT   unsigned int
 

Definition at line 34 of file mcw_malloc.c.

Referenced by mallkey(), and mcw_malloc_status().


Function Documentation

void add_tracker void *    fred,
size_t    n,
char *    fn,
int    ln
[static]
 

Add an entry to the hash table, given the address, the user's size, and the filename and line number. ------------------------------------------------------------------

Definition at line 157 of file mcw_malloc.c.

References ADD_TRACEBACK, find_empty_slot(), mallkey(), mallitem::pfn, mallitem::pln, mallitem::pmt, mallitem::pss, mallitem::psz, serial, and SLOTS.

00158 {
00159    int jj ;
00160    mallitem * ip ;
00161 
00162    if( fred == NULL ) return ;   /* bad news */
00163 
00164    jj = mallkey((char *)fred) % SLOTS ;  /* which hash list to use */
00165    ip = find_empty_slot(jj) ;    /* get an empty slot in this list */
00166 
00167    /* now put the data into the hash table */
00168 
00169    ip->pmt = fred ;
00170    ip->psz = n ;
00171    ip->pfn = fn ;
00172    ip->pln = ln ;
00173    ip->pss = ++serial ;
00174 
00175    ADD_TRACEBACK(ip) ;  /* 16 Feb 2001 */
00176 
00177    return ;
00178 }

void* calloc_track size_t    n,
size_t    m,
char *    fn,
int    ln
[static]
 

Tracking replacement for calloc(). -------------------------------------------------------------------

Definition at line 318 of file mcw_malloc.c.

References malloc_track().

00319 {
00320    void * fred ;
00321    size_t nn = n*m ;
00322 
00323    fred = malloc_track(nn,fn,ln) ; if( fred == NULL ) return NULL ;
00324    memset( fred , 0 , nn ) ;
00325    return fred ;
00326 }

void enable_mcw_malloc  
 

Definition at line 494 of file mcw_malloc.c.

References getenv(), malloc, nhtab, SLOTS, and use_tracking.

Referenced by machdep(), and main().

00495 {
00496    char * str = getenv("AFNI_NO_MCW_MALLOC") ;  /* NOT my_getenv */
00497 
00498    if( use_tracking ) return ;   /* 05 Nov 2001 */
00499 
00500    use_tracking = 1 ;
00501    if( str!=NULL && ( str[0]=='y' || str[0]=='Y') ) use_tracking = 0 ;
00502 
00503    if( use_tracking && htab == NULL ){  /* initialize hash table */
00504       int jj ;
00505       htab  = (mallitem **) malloc( SLOTS * sizeof(mallitem *) ) ;
00506       nhtab = (int *)       malloc( SLOTS * sizeof(int) ) ;
00507       for( jj=0 ; jj < SLOTS ; jj++ ){
00508          htab[jj] = NULL ; nhtab[jj] = 0 ;
00509       }
00510    }
00511 
00512    return ;
00513 }

mallitem* find_empty_slot int    jj [static]
 

Find an empty entry in the hash table list [jj] and return a pointer to it. Will create the entry, if need be. -------------------------------------------------------------------

Definition at line 129 of file mcw_malloc.c.

References malloc, nhtab, mallitem::pmt, and realloc.

00130 {
00131    int kk ;
00132 
00133    if( htab[jj] == NULL ){                               /* must make new list  */
00134       htab[jj] = (mallitem *) malloc(sizeof(mallitem)) ; /* of length 1 at [jj] */
00135      nhtab[jj] = 1 ;
00136       kk       = 0 ;
00137       htab[jj][0].pmt = NULL ;  /* mark as empty */
00138    } else {
00139       for( kk=nhtab[jj]-1 ; kk >= 0 ; kk-- )    /* scan (backwards) for NULL entry */
00140          if( htab[jj][kk].pmt == NULL ) break ; /* found it? */
00141 
00142       if( kk < 0 ){                             /* must make list longer */
00143          kk = nhtab[jj] ; nhtab[jj]++ ;
00144          htab[jj] = (mallitem *) realloc( htab[jj], sizeof(mallitem)*nhtab[jj] ) ;
00145          htab[jj][kk].pmt = NULL ;  /* mark as empty */
00146       }
00147    }
00148 
00149    return (htab[jj]+kk) ;
00150 }

void free_track mallitem   ip [static]
 

Definition at line 332 of file mcw_malloc.c.

References free, mallitem::pmt, pr_nam, and probe_track().

00333 {
00334    char * cfred ;
00335 
00336    if( ip == NULL ) return ;
00337    cfred = (char *) ip->pmt ;
00338    if( cfred == NULL ) return ;
00339 
00340    pr_nam = NULL ;
00341    probe_track(ip) ;  /* check for integrity before freeing */
00342 
00343    free(cfred) ; ip->pmt = NULL ; return ;
00344 }

INLINE UINT mallkey char *    fred [static]
 

Compute a unique non-negative integer key from an address -----------------------------------------------------------------

Definition at line 88 of file mcw_malloc.c.

References INLINE, q, and UINT.

00089 {
00090    UINT q = ((UINT) fred) ;
00091 
00092    q =   ((q & 0xf0f0f0f0) >> 4)   /* swap nibbles */
00093        | ((q & 0x0f0f0f0f) << 4) ;
00094 
00095    return q ;
00096 }

void* malloc_track size_t    n,
char *    fn,
int    ln
[static]
 

The tracking replacement for malloc(). -------------------------------------------------------------------

Definition at line 184 of file mcw_malloc.c.

References add_tracker(), MAGIC, malloc, and NEXTRA.

00185 {
00186    char * fred ;
00187    size_t nn = n + 2*NEXTRA ;
00188    int ii ;
00189 
00190    fred = (char *) malloc(nn) ;
00191    if( fred == NULL ){                                     /* real bad news */
00192       fprintf(stderr,
00193               "\n*** MCW_malloc(%d) from %s#%d FAILS!\a\n",  /* 02 Jan 2002 */
00194               (int)n , fn , ln ) ;
00195       return NULL ;
00196    }
00197 
00198    /* mark overrun buffers */
00199 
00200    for( ii=0 ; ii < NEXTRA ; ii++ )
00201       fred[ii] = fred[n+NEXTRA+ii] = MAGIC ;
00202 
00203    add_tracker(fred,n,fn,ln) ;      /* put in hash table */
00204    return (void *)(fred+NEXTRA) ;
00205 }

void* mcw_calloc size_t    n,
size_t    m,
char *    fnam,
int    lnum
 

Definition at line 580 of file mcw_malloc.c.

References calloc, and calloc_track().

00581 {
00582    if( use_tracking ) return calloc_track( n , m , fnam,lnum ) ;
00583    else               return calloc( n , m ) ;
00584 }

void mcw_free void *    fred
 

Definition at line 590 of file mcw_malloc.c.

References free, free_track(), shift_tracker, and use_tracking.

00591 {
00592    mallitem * ip ;
00593 
00594    if( fred == NULL ) return ;
00595 
00596    if( use_tracking && (ip=shift_tracker(fred)) != NULL ) free_track( ip ) ;
00597    else                                                   free( fred ) ;
00598 }

void* mcw_malloc size_t    n,
char *    fnam,
int    lnum
 

Definition at line 553 of file mcw_malloc.c.

References malloc, and malloc_track().

Referenced by mcw_realloc().

00554 {
00555    if( use_tracking ) return malloc_track(n,fnam,lnum) ;
00556    else               return malloc(n) ;
00557 }

void mcw_malloc_dump void   
 

Definition at line 380 of file mcw_malloc.c.

References free, malloc, mcw_malloc_status(), nhtab, NTB, mallitem::pmt, mallitem::pss, mallitem::ptb, qsort_intint(), SLOTS, THD_is_file(), tt, and use_tracking.

Referenced by AFNI_misc_CB(), and SUMA_input().

00381 {
00382    int ii,jj,kk ;
00383    char fname[32] , * str ;
00384    FILE * fp = NULL ;
00385    int nptr=0 ;
00386    int * ss , * jk ;
00387 
00388    if( ! use_tracking ) return ;
00389 
00390    /* find and open an output file */
00391 
00392    for( ii=1 ; ii < 1000 ; ii++ ){
00393       sprintf(fname,"malldump.%03d",ii) ;
00394       if( THD_is_file(fname) ) continue ;
00395       fp = fopen( fname , "w" ) ;
00396       if( fp == NULL ){
00397          fprintf(stderr,"** Unable to open file %s for malloc table dump!\n",
00398                  fname ) ;
00399          return ;
00400       }
00401       break ;
00402    }
00403 
00404    if( fp == NULL ){
00405       fprintf(stderr,"** Attempt to exceed 999 malloc table dump files!\n") ;
00406       return ;
00407    }
00408 
00409    /* count number of entries in the hash table */
00410 
00411    for( jj=0 ; jj < SLOTS ; jj++ ){
00412       for( kk=0 ; kk < nhtab[jj] ; kk++ ){
00413          if( htab[jj][kk].pmt != NULL ) nptr++ ;
00414       }
00415    }
00416 
00417    if( nptr < 1 ){
00418       fprintf(fp    ,"--- Nothing is malloc()-ed !? ---\n") ;
00419       fprintf(stderr,"--- Nothing is malloc()-ed !? ---\n") ;
00420       fclose(fp) ;
00421    }
00422 
00423    /* setup to sort by serial number */
00424 
00425    ss = (int *) malloc(sizeof(int)*nptr) ;  /* serial number */
00426    jk = (int *) malloc(sizeof(int)*nptr) ;  /* holds combination of jj and kk */
00427 
00428 #define JBASE 32768  /* JBASE * SLOTS must be less than max int */
00429 
00430    /* scan table for non-NULL entries */
00431 
00432    for( ii=jj=0 ; jj < SLOTS ; jj++ ){
00433       for( kk=0 ; kk < nhtab[jj] ; kk++ ){
00434          if( htab[jj][kk].pmt != NULL ){
00435             ss[ii] = htab[jj][kk].pss ;   /* save serial number */
00436             jk[ii] = JBASE*jj + kk ;      /* save jj and kk */
00437             ii++ ;
00438          }
00439       }
00440    }
00441 
00442    qsort_intint( nptr , ss , jk ) ;  /* sort by ss, carrying jk along */
00443 
00444    /* now print table in serial number order */
00445 
00446 #ifdef USE_TRACING
00447    fprintf(fp, "MCW Malloc Table Dump:\n"
00448                "serial# size       source file          line# address    hash(j,k) <- Called by\n"
00449                "------- ---------- -------------------- ----- ---------- ----- ---    ---------\n");
00450 #else
00451    fprintf(fp, "MCW Malloc Table Dump:\n"
00452                "serial# size       source file          line# address    hash(j,k)\n"
00453                "------- ---------- -------------------- ----- ---------- ----- ---\n") ;
00454 #endif
00455 
00456    for( ii=0 ; ii < nptr ; ii++ ){
00457       jj = jk[ii] / JBASE ;           /* retrieve jj and kk */
00458       kk = jk[ii] % JBASE ;
00459       if( htab[jj][kk].pmt != NULL ){
00460          fprintf(fp,"%7u %10d %-20.30s %5d %10p %5d %3d",
00461                  htab[jj][kk].pss , (int)htab[jj][kk].psz ,
00462                  htab[jj][kk].pfn , htab[jj][kk].pln , htab[jj][kk].pmt ,
00463                  jj,kk ) ;
00464 #ifdef USE_TRACING
00465          { int tt ;
00466            for( tt=0 ; tt < NTB && htab[jj][kk].ptb[tt] != NULL ; tt++ )
00467               fprintf(fp," <- %s",htab[jj][kk].ptb[tt]) ;
00468          }
00469 #endif
00470          fprintf(fp,"\n") ;
00471       }
00472       else
00473          fprintf(fp,"*** Error at ii=%d jj=%d kk=%d\n",ii,jj,kk) ;
00474    }
00475 
00476    free(ss) ; free(jk) ;
00477 
00478    /* and print out the summary line (to the file and screen) */
00479 
00480    str = mcw_malloc_status(NULL,0) ;
00481    fprintf(fp,"----- Summary: %s\n",str) ;
00482    fclose(fp) ;
00483 
00484    fprintf(stderr,"** Malloc table dumped to file %s\n",fname) ;
00485    fprintf(stderr,"** Summary: %s\n",str) ;
00486 
00487    return ;
00488 }

int mcw_malloc_enabled void   
 

Definition at line 547 of file mcw_malloc.c.

References use_tracking.

00547 { return (use_tracking != 0) ; }

int mcw_malloc_paused void   
 

Definition at line 539 of file mcw_malloc.c.

00540 {
00541    return(pz);
00542 }

char* mcw_malloc_status const char *    fn,
int    ln
 

Definition at line 352 of file mcw_malloc.c.

References nhtab, mallitem::pmt, pr_lin, pr_nam, probe_track(), mallitem::psz, SLOTS, UINT, and use_tracking.

Referenced by mcw_malloc_dump().

00353 {
00354    static char buf[128] = "\0" ;
00355    int jj,kk , nptr=0 ; size_t nbyt=0 ;
00356 
00357    if( ! use_tracking ) return NULL ;
00358 
00359    for( jj=0 ; jj < SLOTS ; jj++ ){
00360       for( kk=0 ; kk < nhtab[jj] ; kk++ ){
00361          if( htab[jj][kk].pmt != NULL ){
00362             pr_nam = (const char *)fn ; pr_lin = ln ;
00363             probe_track( htab[jj]+kk ) ; /* check for integrity */
00364             nptr++ ; nbyt += htab[jj][kk].psz ;
00365          }
00366       }
00367    }
00368 
00369    sprintf(buf,"chunks=%d bytes=%u",nptr,(UINT)nbyt) ;
00370    return buf ;
00371 }

void* mcw_realloc void *    fred,
size_t    n,
char *    fnam,
int    lnum
 

Definition at line 563 of file mcw_malloc.c.

References mcw_malloc(), realloc, realloc_track(), shift_tracker, and use_tracking.

00564 {
00565    mallitem * ip ;
00566 
00567    if( fred == NULL )
00568       return mcw_malloc( n , fnam , lnum ) ;
00569 
00570    if( use_tracking && (ip=shift_tracker(fred)) != NULL )
00571       return realloc_track( ip , n , fnam,lnum ) ;
00572    else
00573       return realloc( fred , n ) ;
00574 }

char* mcw_XtCalloc Cardinal    n,
Cardinal    m,
char *    fnam,
int    lnum
 

Definition at line 645 of file mcw_malloc.c.

References calloc_track(), and XtCalloc.

00646 {
00647    if( use_tracking ) return (char *) calloc_track( n , m , fnam,lnum ) ;
00648    else               return XtCalloc( n , m ) ;
00649 }

void mcw_XtFree char *    p
 

Definition at line 631 of file mcw_malloc.c.

References free_track(), p, shift_tracker, use_tracking, and XtFree.

00632 {
00633    mallitem * ip ;
00634 
00635    if( p == NULL ) return ;
00636 
00637    if( use_tracking && (ip=shift_tracker(p)) != NULL ) free_track(ip) ;
00638    else                                                XtFree(p) ;
00639 }

char* mcw_XtMalloc Cardinal    n,
char *    fnam,
int    lnum
 

Definition at line 604 of file mcw_malloc.c.

References malloc_track(), and XtMalloc.

Referenced by mcw_XtRealloc().

00605 {
00606    if( use_tracking ) return (char *) malloc_track(n,fnam,lnum) ;
00607    else               return (char *)XtMalloc(n) ;
00608 }

char* mcw_XtRealloc char *    p,
Cardinal    n,
char *    fnam,
int    lnum
 

Definition at line 614 of file mcw_malloc.c.

References mcw_XtMalloc(), p, realloc_track(), shift_tracker, use_tracking, and XtRealloc.

00615 {
00616    mallitem * ip ;
00617 
00618    if( p == NULL )
00619       return mcw_XtMalloc( n , fnam , lnum ) ;
00620 
00621    if( use_tracking && (ip=shift_tracker(p)) != NULL )
00622       return (char*)realloc_track( ip , n , fnam,lnum ) ;
00623    else
00624       return (char*)XtRealloc( p , n ) ;
00625 }

void pause_mcw_malloc void   
 

Definition at line 523 of file mcw_malloc.c.

References pz, and use_tracking.

Referenced by SUMA_allocate2D(), and SUMA_free2D().

00524 {
00525    if (pz) return;   /* nothing to do */
00526    if (use_tracking) {
00527       pz = 1;
00528       use_tracking = 0;
00529    }
00530    return;
00531 }    

void probe_track mallitem   ip [static]
 

Definition at line 214 of file mcw_malloc.c.

References MAGIC, NEXTRA, NTB, mallitem::pfn, mallitem::pln, mallitem::pmt, pr_lin, pr_nam, mallitem::pss, mallitem::psz, mallitem::ptb, and tt.

00215 {
00216    int ii ;
00217    size_t n ;
00218    char * fred ;
00219 
00220    if( ip == NULL ){ pr_nam=NULL; return; } /* error */
00221    fred = (char *) ip->pmt ; if( fred == NULL ){ pr_nam=NULL; return; }
00222    n = ip->psz ;
00223 
00224    for( ii=0 ; ii < NEXTRA ; ii++ )
00225       if( fred[ii] != MAGIC ){
00226          fprintf(stderr,"*** MCW_malloc pre-corruption!  "
00227                         "serial=%u size=%d source=%s line#%d",
00228                         ip->pss,(int)ip->psz,ip->pfn,ip->pln ) ;
00229 #ifdef USE_TRACING
00230          { int tt ;
00231            for( tt=0 ; tt < NTB && ip->ptb[tt] != NULL ; tt++ )
00232              fprintf(stderr," <- %s",ip->ptb[tt]) ;
00233          }
00234 #endif
00235          fprintf(stderr,"\n") ;
00236 
00237          if( pr_nam != NULL )
00238           fprintf(stderr," [[ Called from source=%.50s line#%d ]]\n",pr_nam,pr_lin);
00239          break ;
00240       }
00241 
00242    for( ii=0 ; ii < NEXTRA ; ii++ )
00243       if( fred[n+NEXTRA+ii] != MAGIC ){
00244          fprintf(stderr,"*** MCW_malloc post-corruption!  "
00245                         "serial=%u size=%d source=%s line#%d\n",
00246                         ip->pss,(int)ip->psz,ip->pfn,ip->pln ) ;
00247 #ifdef USE_TRACING
00248          { int tt ;
00249            for( tt=0 ; tt < NTB && ip->ptb[tt] != NULL ; tt++ )
00250              fprintf(stderr," <- %s",ip->ptb[tt]) ;
00251          }
00252 #endif
00253          fprintf(stderr,"\n") ;
00254 
00255          if( pr_nam != NULL )
00256           fprintf(stderr," [[ Called from source=%.50s line#%d ]]\n",pr_nam,pr_lin);
00257          break ;
00258       }
00259 
00260    pr_nam = NULL ;  /* reset */
00261    return ;
00262 }

mallitem* ptr_tracker void *    fred [static]
 

Find an address in the hash table; returns a pointer to the NI_mallitem that owns it (or NULL) ------------------------------------------------------------------

Definition at line 103 of file mcw_malloc.c.

References mallkey(), nhtab, mallitem::pmt, and SLOTS.

00104 {
00105    int jj,kk ;
00106 
00107    if( fred == NULL ) return NULL ;
00108 
00109    jj = mallkey((char *)fred) % SLOTS ;      /* hash table location */
00110 
00111    if( htab[jj] == NULL ) return NULL ;  /* nothing there */
00112 
00113    for( kk=0 ; kk < nhtab[jj] ; kk++ )   /* scan for match */
00114       if( htab[jj][kk].pmt == fred ) return (htab[jj]+kk) ;
00115 
00116    return NULL ; /* no match found */
00117 }

void qsort_intint int   ,
int *   ,
int *   
 

Definition at line 763 of file niml_malloc.c.

00764 {
00765    qsrec_intint( n , a , ia , QS_CUTOFF ) ;
00766    isort_intint( n , a , ia ) ;
00767    return ;
00768 }

void* realloc_track mallitem   ip,
size_t    n,
char *    fn,
int    ln
[static]
 

Definition at line 268 of file mcw_malloc.c.

References ADD_TRACEBACK, add_tracker(), MAGIC, mallkey(), NEXTRA, mallitem::pfn, mallitem::pln, mallitem::pmt, pr_lin, pr_nam, probe_track(), mallitem::pss, mallitem::psz, realloc, serial, and SLOTS.

00269 {
00270    char * nfred , * cfred ;
00271    size_t nn = n + 2*NEXTRA ;
00272    int ii , cjj,njj , kk ;
00273 
00274    if( ip == NULL ) return NULL ;  /* should not happen */
00275 
00276    pr_nam = (const char *)fn ; pr_lin = ln ;
00277    probe_track(ip) ;  /* check for integrity before reallocation */
00278    cfred = ip->pmt ;  /* old address */
00279 
00280    nfred = (char*)realloc( cfred , nn ) ;
00281    if( nfred == NULL ){                                       /* real bad */
00282       fprintf(stderr,
00283               "\n*** MCW_realloc(%d) from %s#%d FAILS!\a\n",  /* 02 Jan 2002 */
00284               (int)n , fn , ln ) ;
00285       return NULL ;
00286    }
00287 
00288    for( ii=0 ; ii < NEXTRA ; ii++ )
00289       nfred[ii] = nfred[n+NEXTRA+ii] = MAGIC ;
00290 
00291    cjj = mallkey(cfred) % SLOTS ;  /* hash table list for old */
00292    njj = mallkey(nfred) % SLOTS ;  /* and for new address */
00293 
00294    if( cjj == njj ){  /* can just update old hashtable entry */
00295 
00296       ip->pmt = nfred ;
00297       ip->psz = n ;
00298       ip->pfn = fn ;
00299       ip->pln = ln ;
00300       ip->pss = ++serial ;
00301 
00302       ADD_TRACEBACK(ip) ;  /* 16 Feb 2001 */
00303 
00304    } else {           /* must move into a different list */
00305 
00306       add_tracker( nfred , n , fn , ln ) ;
00307 
00308       ip->pmt = NULL ; /* mark old entry as free */
00309    }
00310 
00311    return (void *)(nfred+NEXTRA) ;
00312 }

void resume_mcw_malloc void   
 

Definition at line 532 of file mcw_malloc.c.

References pz, and use_tracking.

Referenced by SUMA_allocate2D(), and SUMA_free2D().

00533 {
00534    if (!pz) return; 
00535    pz = 0;
00536    use_tracking = 1;
00537    return;
00538 }

int THD_is_file char *    pathname
 

Determine if this is really a regular file or not.

Definition at line 94 of file thd_filestuff.c.

Referenced by AFNI_finalize_read_palette_CB(), AFNI_finalize_read_sess_CB(), AFNI_parse_args(), afni_vol2surf(), basis_write_iresp(), basis_write_sresp(), check_one_output_file(), check_outfile(), check_output_file(), DRAW_saveas_finalize_CB(), EDIT_main(), form_clusters(), get_options(), HISTO_main(), main(), mcw_malloc_dump(), NLFIT_read_MODEL(), output_ts_array(), PBAR_enviro_bigmaps(), PLUG_read_plugin(), RCREND_save_many_CB(), RCREND_save_this_CB(), RENAME_main(), REND_save_many_CB(), REND_save_this_CB(), SUMA_FormAfnidset(), T3D_check_data(), THD_extract_regular_files(), THD_is_dataset(), THD_open_one_dataset(), THD_rename_dataset_files(), TTRR_load_CB(), validate_options(), VOLREG_main(), write_3dtime(), write_afni_data(), write_afni_fict(), write_afni_fizt(), write_bucket(), write_bucket_data(), write_output(), write_results(), and write_ts_array().

00095 {
00096    static struct stat buf ; int ii ;
00097 
00098    if( pathname == NULL || *pathname == '\0' ) return 0 ;
00099    ii = stat( pathname , &buf ) ; if( ii != 0 ) return 0 ;
00100    ii = (buf.st_mode & S_IFREG) != 0 ; return ii ;
00101 }

Variable Documentation

mallitem** htab = NULL [static]
 

define SLOTS 32003 *

Definition at line 64 of file mcw_malloc.c.

int* nhtab = NULL [static]
 

Definition at line 65 of file mcw_malloc.c.

Referenced by enable_mcw_malloc(), find_empty_slot(), mcw_malloc_dump(), mcw_malloc_status(), and ptr_tracker().

int pr_lin = 0 [static]
 

Definition at line 212 of file mcw_malloc.c.

Referenced by mcw_malloc_status(), probe_track(), and realloc_track().

const char* pr_nam = NULL [static]
 

Definition at line 211 of file mcw_malloc.c.

Referenced by free_track(), mcw_malloc_status(), probe_track(), and realloc_track().

int pz = 0 [static]
 

Definition at line 522 of file mcw_malloc.c.

Referenced by pause_mcw_malloc(), and resume_mcw_malloc().

UINT serial = 0 [static]
 

Definition at line 66 of file mcw_malloc.c.

Referenced by add_tracker(), and realloc_track().

int use_tracking = 0 [static]
 

Definition at line 350 of file mcw_malloc.c.

Referenced by enable_mcw_malloc(), mcw_free(), mcw_malloc_dump(), mcw_malloc_enabled(), mcw_malloc_status(), mcw_realloc(), mcw_XtFree(), mcw_XtRealloc(), pause_mcw_malloc(), and resume_mcw_malloc().

 

Powered by Plone

This site conforms to the following standards: