IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 31, 2011, 3:50:46 PM (15 years ago)
Author:
eugene
Message:

added test for ohana_memory functions; updated CommandOps to fix interaction between ohana and readline; ohana memory seems to work

Location:
branches/eam_branches/ipp-20110505/Ohana/src
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20110505/Ohana/src/libohana/Makefile

    r28241 r31591  
    5050
    5151TEST = \
    52 $(TESTDIR)/string.$(ARCH)
     52$(TESTDIR)/memtest.$(ARCH)
     53# $(TESTDIR)/string.$(ARCH)
    5354
    5455testcode: install $(TEST)
    5556test:
    5657        make testcode
     58        for i in $(TEST); do $$i; done
     59
     60quicktest:
    5761        for i in $(TEST); do $$i; done
    5862
  • branches/eam_branches/ipp-20110505/Ohana/src/libohana/include/ohana.h

    r31589 r31591  
    1919# include <readline/readline.h>
    2020
     21// comment this out to avoid the internal Ohana memory management code
    2122# define OHANA_MEMORY
    2223
  • branches/eam_branches/ipp-20110505/Ohana/src/libohana/include/ohana_allocate.h

    r31589 r31591  
    11# ifndef OHANA_ALLOCATE
    22# define OHANA_ALLOCATE
     3
     4typedef struct {
     5  int    exists; // has the memory management system been created?
     6  size_t Ntotal; // number of blocks currently allocated
     7  size_t Nbytes; // number of bytes currently allocated
     8  size_t Ngood;  // number of good blocks
     9  size_t Nbad;   // number of bad blocks
     10} OhanaMemstats;
     11
     12OhanaMemstats ohana_memstats (int mode);
    313
    414/* default is to use basic system memory functions */
    515# ifdef OHANA_MEMORY
    616
    7 void *ohana_malloc (char *file, int line, char *func, int Nelem, size_t esize);
    8 void *ohana_realloc (char *file, int line, char *func, void *in, int Nelem, size_t esize);
    9 void  ohana_free (char *file, int line, char *func, void *in);
     17void *ohana_malloc (const char *file, int line, const char *func, int Nelem, size_t esize);
     18void *ohana_realloc (const char *file, int line, const char *func, void *in, int Nelem, size_t esize);
     19void  ohana_free (const char *file, int line, const char *func, void *in);
    1020void  ohana_memdump_func (int mode);
    1121void  ohana_memcheck_func (int mode);
     22void  real_free (void *in);
    1223
    1324# define ohana_memcheck(X) ohana_memcheck_func (X);
    1425# define ohana_memdump(X) ohana_memdump_func (X);
    1526
    16 # define ALLOCATE(PTR,TYPE,SIZE) \
    17   { PTR = (TYPE *) ohana_malloc (__FILE__, __LINE__, __func__, (SIZE), sizeof(TYPE)) }
    18 # define ALLOCATE_ZERO(PTR,TYPE,SIZE)                                   \
    19   { PTR = (TYPE *) ohana_malloc (__FILE__, __LINE__, __func__, (SIZE), sizeof(TYPE)); memset (PTR, 0, (SIZE)*sizeof(TYPE)); }
    20 # define REALLOCATE(PTR,TYPE,SIZE) \
    21   { PTR = (TYPE *) ohana_realloc(__FILE__, __LINE__, __func__, PTR, (SIZE), sizeof(TYPE)); }
    22 # define CHECK_REALLOCATE(PTR,TYPE,SIZE,NCURR,DELTA) {                  \
    23   if ((NCURR) >= (SIZE)) { SIZE += DELTA;                               \
    24     PTR = (TYPE *) ohana_realloc(__FILE__, __LINE__, __func__, PTR, (SIZE), sizeof(TYPE)); } }
     27# define ALLOCATE(PTR,TYPE,SIZE) { \
     28    PTR = (TYPE *) ohana_malloc (__FILE__, __LINE__, __func__, (SIZE), sizeof(TYPE)); \
     29  }
     30
     31# define ALLOCATE_ZERO(PTR,TYPE,SIZE) { \
     32    PTR = (TYPE *) ohana_malloc (__FILE__, __LINE__, __func__, (SIZE), sizeof(TYPE)); \
     33    memset (PTR, 0, (SIZE)*sizeof(TYPE)); \
     34  }
     35
     36# define REALLOCATE(PTR,TYPE,SIZE) { \
     37    PTR = (TYPE *) ohana_realloc(__FILE__, __LINE__, __func__, PTR, (SIZE), sizeof(TYPE)); \
     38  }
     39
     40# define CHECK_REALLOCATE(PTR,TYPE,SIZE,NCURR,DELTA) { \
     41  if ((NCURR) >= (SIZE)) { \
     42    SIZE += DELTA; \
     43    PTR = (TYPE *) ohana_realloc(__FILE__, __LINE__, __func__, PTR, (SIZE), sizeof(TYPE)); \
     44  } }
     45
    2546# define FREE(PTR) { if (PTR != NULL) { ohana_free (__FILE__, __LINE__, __func__, PTR); } }
    26 # define free(PTR) { ohana_free(__FILE__, __LINE__, PTR); }
    27 # define real_free(PTR) { if (PTR) { free(PTR); }}
     47# define free(PTR) { ohana_free(__FILE__, __LINE__, __func__, PTR); }
    2848
    29 # else  /* OHANA_MEMORY */
     49# else  /* below: not OHANA_MEMORY */
    3050
    3151# define ohana_memcheck(X) /* NOP */
    3252# define ohana_memdump(X) /* NOP */
    33 # define real_free(PTR) { if (PTR) { free(PTR); }}
     53void  real_free (void *in);
    3454
    35 # ifndef ALLOCATE
    3655# define ALLOCATE(PTR,TYPE,SIZE) {                                      \
    3756  PTR = (TYPE *) malloc ((size_t)(MAX(((SIZE)*((int)sizeof(TYPE))),1))); \
     
    6281
    6382# define FREE(PTR) { if (PTR != NULL) { free (PTR); } }
    64 # endif /* ALLOCATE */
    6583# endif /* OHANA_MEMORY */
    6684
  • branches/eam_branches/ipp-20110505/Ohana/src/libohana/src/ohana_allocate.c

    r31589 r31591  
    44# include <stdint.h>
    55# include <pthread.h>
     6# include "ohana_allocate.h"
    67
    78/* need an internal version that does not use ohana_memory functions */
     
    1718  struct Memblock *nextBlock; // next allocated memory
    1819  size_t size;                // size of memory
    19   char *file;                 // file (re)allocated
    20   char *func;                 // func (re)allocated
     20  const char *file;           // file (re)allocated
     21  const char *func;           // func (re)allocated
    2122  int line;                   // line (re)allocated
    2223  uint32_t endblock;          // endpost marker
     
    4041}
    4142
    42 void *ohana_malloc (char *file, int line, char *func, size_t Nelem, size_t esize) {
     43void *ohana_malloc (const char *file, int line, const char *func, size_t Nelem, size_t esize) {
    4344
    4445  void *ptr;                  // actual user memory allocated
     
    9495}
    9596
    96 void *ohana_realloc (char *file, int line, char *func, void *in, size_t Nelem, size_t esize) {
     97void *ohana_realloc (const char *file, int line, const char *func, void *in, size_t Nelem, size_t esize) {
    9798
    9899  void *ptr;                  // actual user memory allocated
     
    158159}
    159160
     161void real_free (void *in) {
     162
     163  if (!in) return;
     164  free (in);
     165  return;
     166}
     167
    160168// this is very slow.  should we speed this up by indexing on the ptr?
    161 void ohana_free (char *file, int line, char *func, void *in) {
     169void ohana_free (const char *file, int line, const char *func, void *in) {
    162170
    163171  Memblock *ref;
     
    278286  return;
    279287}
     288
     289OhanaMemstats ohana_memstats (int allmemory) {
     290
     291  OhanaMemstats memstats;
     292
     293  memstats.exists = 0;
     294  memstats.Ntotal = 0;
     295  memstats.Nbytes = 0;
     296  memstats.Ngood = 0;
     297  memstats.Nbad = 0;
     298 
     299  Memblock *thisBlock = lastBlock;
     300
     301  while (thisBlock) {
     302
     303    memstats.exists = TRUE;
     304
     305    int good = TRUE;
     306   
     307    if (thisBlock->startblock != OHANA_MEMMAGIC) good = FALSE;
     308    if (thisBlock->endblock != OHANA_MEMMAGIC) good = FALSE;
     309
     310    // pointer to the start of the user memory
     311    char *ptr = (char *)(thisBlock + 1) + thisBlock->size;
     312    uint32_t endpost = *(uint32_t *)ptr;
     313    if (endpost != OHANA_MEMMAGIC) good = FALSE;
     314
     315    memstats.Ntotal ++;
     316    memstats.Nbytes += thisBlock->size;
     317
     318    if (good) {
     319      memstats.Ngood ++;
     320    } else {
     321      memstats.Nbad ++;
     322    }
     323
     324    thisBlock = thisBlock->prevBlock;
     325  }
     326
     327  return memstats;
     328}
  • branches/eam_branches/ipp-20110505/Ohana/src/opihi/lib.shell/CommandOps.c

    r16888 r31591  
    106106
    107107
     108/* we need a strcreate function that does NOT use the ohana memory management
     109 * system to interact with some external libraries (which themselves free the memory)
     110 */
     111char *strcreate_sans_ohana (char *string) {
     112
     113  char *line;
     114
     115  if (string == (char *) NULL) return ((char *) NULL);
     116 
     117  line = malloc (MAX (1, strlen(string)) + 1);
     118  line = strcpy (line, string);
     119
     120  return (line);
     121}
     122
    108123/* generate a command completion list for readline */
    109124/**** these probably do not interact well with OHANA memory!!! ****/
     
    122137  for (i++; i < Ncommands; i++) {
    123138    if (!len)
    124       return (strcreate(commands[i].name));
     139
     140
     141      return (strcreate_sans_ohana(commands[i].name));
    125142    if (!strncmp (commands[i].name, text, len)) {
    126       return (strcreate(commands[i].name));
     143      return (strcreate_sans_ohana(commands[i].name));
    127144    }
    128145  }
Note: See TracChangeset for help on using the changeset viewer.