Changeset 31591 for branches/eam_branches/ipp-20110505/Ohana
- Timestamp:
- May 31, 2011, 3:50:46 PM (15 years ago)
- Location:
- branches/eam_branches/ipp-20110505/Ohana/src
- Files:
-
- 1 added
- 5 edited
-
libohana/Makefile (modified) (1 diff)
-
libohana/include/ohana.h (modified) (1 diff)
-
libohana/include/ohana_allocate.h (modified) (2 diffs)
-
libohana/src/ohana_allocate.c (modified) (6 diffs)
-
libohana/test/memtest.c (added)
-
opihi/lib.shell/CommandOps.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20110505/Ohana/src/libohana/Makefile
r28241 r31591 50 50 51 51 TEST = \ 52 $(TESTDIR)/string.$(ARCH) 52 $(TESTDIR)/memtest.$(ARCH) 53 # $(TESTDIR)/string.$(ARCH) 53 54 54 55 testcode: install $(TEST) 55 56 test: 56 57 make testcode 58 for i in $(TEST); do $$i; done 59 60 quicktest: 57 61 for i in $(TEST); do $$i; done 58 62 -
branches/eam_branches/ipp-20110505/Ohana/src/libohana/include/ohana.h
r31589 r31591 19 19 # include <readline/readline.h> 20 20 21 // comment this out to avoid the internal Ohana memory management code 21 22 # define OHANA_MEMORY 22 23 -
branches/eam_branches/ipp-20110505/Ohana/src/libohana/include/ohana_allocate.h
r31589 r31591 1 1 # ifndef OHANA_ALLOCATE 2 2 # define OHANA_ALLOCATE 3 4 typedef 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 12 OhanaMemstats ohana_memstats (int mode); 3 13 4 14 /* default is to use basic system memory functions */ 5 15 # ifdef OHANA_MEMORY 6 16 7 void *ohana_malloc (c har *file, int line,char *func, int Nelem, size_t esize);8 void *ohana_realloc (c har *file, int line,char *func, void *in, int Nelem, size_t esize);9 void ohana_free (c har *file, int line,char *func, void *in);17 void *ohana_malloc (const char *file, int line, const char *func, int Nelem, size_t esize); 18 void *ohana_realloc (const char *file, int line, const char *func, void *in, int Nelem, size_t esize); 19 void ohana_free (const char *file, int line, const char *func, void *in); 10 20 void ohana_memdump_func (int mode); 11 21 void ohana_memcheck_func (int mode); 22 void real_free (void *in); 12 23 13 24 # define ohana_memcheck(X) ohana_memcheck_func (X); 14 25 # define ohana_memdump(X) ohana_memdump_func (X); 15 26 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 25 46 # 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); } 28 48 29 # else /* OHANA_MEMORY */49 # else /* below: not OHANA_MEMORY */ 30 50 31 51 # define ohana_memcheck(X) /* NOP */ 32 52 # define ohana_memdump(X) /* NOP */ 33 # define real_free(PTR) { if (PTR) { free(PTR); }} 53 void real_free (void *in); 34 54 35 # ifndef ALLOCATE36 55 # define ALLOCATE(PTR,TYPE,SIZE) { \ 37 56 PTR = (TYPE *) malloc ((size_t)(MAX(((SIZE)*((int)sizeof(TYPE))),1))); \ … … 62 81 63 82 # define FREE(PTR) { if (PTR != NULL) { free (PTR); } } 64 # endif /* ALLOCATE */65 83 # endif /* OHANA_MEMORY */ 66 84 -
branches/eam_branches/ipp-20110505/Ohana/src/libohana/src/ohana_allocate.c
r31589 r31591 4 4 # include <stdint.h> 5 5 # include <pthread.h> 6 # include "ohana_allocate.h" 6 7 7 8 /* need an internal version that does not use ohana_memory functions */ … … 17 18 struct Memblock *nextBlock; // next allocated memory 18 19 size_t size; // size of memory 19 c har *file;// file (re)allocated20 c har *func;// func (re)allocated20 const char *file; // file (re)allocated 21 const char *func; // func (re)allocated 21 22 int line; // line (re)allocated 22 23 uint32_t endblock; // endpost marker … … 40 41 } 41 42 42 void *ohana_malloc (c har *file, int line,char *func, size_t Nelem, size_t esize) {43 void *ohana_malloc (const char *file, int line, const char *func, size_t Nelem, size_t esize) { 43 44 44 45 void *ptr; // actual user memory allocated … … 94 95 } 95 96 96 void *ohana_realloc (c har *file, int line,char *func, void *in, size_t Nelem, size_t esize) {97 void *ohana_realloc (const char *file, int line, const char *func, void *in, size_t Nelem, size_t esize) { 97 98 98 99 void *ptr; // actual user memory allocated … … 158 159 } 159 160 161 void real_free (void *in) { 162 163 if (!in) return; 164 free (in); 165 return; 166 } 167 160 168 // this is very slow. should we speed this up by indexing on the ptr? 161 void ohana_free (c har *file, int line,char *func, void *in) {169 void ohana_free (const char *file, int line, const char *func, void *in) { 162 170 163 171 Memblock *ref; … … 278 286 return; 279 287 } 288 289 OhanaMemstats 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 106 106 } 107 107 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 */ 111 char *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 108 123 /* generate a command completion list for readline */ 109 124 /**** these probably do not interact well with OHANA memory!!! ****/ … … 122 137 for (i++; i < Ncommands; i++) { 123 138 if (!len) 124 return (strcreate(commands[i].name)); 139 140 141 return (strcreate_sans_ohana(commands[i].name)); 125 142 if (!strncmp (commands[i].name, text, len)) { 126 return (strcreate (commands[i].name));143 return (strcreate_sans_ohana(commands[i].name)); 127 144 } 128 145 }
Note:
See TracChangeset
for help on using the changeset viewer.
