- Timestamp:
- Jan 27, 2016, 11:18:36 AM (10 years ago)
- Location:
- trunk/Ohana/src
- Files:
-
- 6 edited
-
libfits/header/F_scan.c (modified) (10 diffs)
-
libfits/table/F_set_column.c (modified) (13 diffs)
-
libfits/table/F_uncompress_T.c (modified) (2 diffs)
-
libohana/Makefile (modified) (1 diff)
-
libohana/include/ohana_allocate.h (modified) (2 diffs)
-
libohana/src/ohana_allocate.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/libfits/header/F_scan.c
r34405 r39324 44 44 if (p[8] != '=') return (FALSE); 45 45 46 s = gfits_keyword_start (p); /* points at first char (not ') */ 47 q = gfits_keyword_end (p); /* points at following space or ' */ 48 49 // these are invalid conditions: 50 if (s - p > 80) return FALSE; 51 if (q - p > 80) return FALSE; 52 46 53 /* extract data into char array (exclude containing ' chars) */ 54 Nchar = MIN (80, MAX (0, (q - s))); 55 bzero (tmp, 81); 56 memcpy (tmp, s, Nchar); 57 58 // for string types, copy the data to the target pointer 47 59 if (!strcmp (mode, "%s")) { 48 s = gfits_keyword_start (p); /* points at first char (not ') */49 q = gfits_keyword_end (p); /* points at following space or ' */50 51 Nchar = MAX (0, (q - s));52 bzero (tmp, 81);53 memcpy (tmp, s, Nchar);54 60 stripwhite (tmp); 55 61 strcpy (va_arg (argp, char *), tmp); … … 59 65 /* remaining options are numerical data */ 60 66 /* need to interpret 1.0d5 as 1.0e5 */ 61 s = gfits_keyword_start (p); /* points at first char (not ') */62 q = gfits_keyword_end (p); /* points at following space or ' */63 67 64 68 if (!strcmp (mode, "%f") || !strcmp (mode, "%lf")) { 65 fvalue = strtod (s, &q); 66 if ((*q == 'd') || (*q == 'D')) 67 fvalue *= pow (10.0, atof (q + 1)); 69 fvalue = strtod (tmp, &q); 70 if ((*q == 'd') || (*q == 'D')) fvalue *= pow (10.0, atof (q + 1)); 68 71 69 72 if (!strcmp (mode, "%f")) { *va_arg (argp, float *) = fvalue; return (TRUE); } … … 71 74 } 72 75 73 value = strtoll ( s, &q, 0);76 value = strtoll (tmp, &q, 0); 74 77 if ((*q == 'd') || (*q == 'D')) value *= pow (10.0, atof (q + 1)); 75 78 … … 96 99 int gfits_vscan_alt (Header *header, char *field, char *mode, int N, va_list argp) { 97 100 98 char *p, *q, *s, tmp[ 81];101 char *p, *q, *s, tmp[128]; 99 102 int Nchar, status; 100 103 … … 117 120 /* comment from data line */ 118 121 if (!strcmp (mode, "%C")) { 119 q = gfits_keyword_end (p) + 3; 122 q = gfits_keyword_end (p); 123 if (!q) return (FALSE); 124 q += 3; 120 125 q = MIN (p + 80, q); 121 126 bzero (tmp, 81); 122 Nchar = M IN (80, p + 80 - q);127 Nchar = MAX (0, MIN (80, p + 80 - q)); 123 128 memcpy (tmp, q, Nchar); 124 129 stripwhite (tmp); … … 147 152 int gfits_vscan_hierarch (Header *header, char *field, char *mode, int N, va_list argp) { 148 153 149 char *p, *q, *s, tmp[ 81];154 char *p, *q, *s, tmp[128]; 150 155 int Nchar, Nfield; 151 156 long long value; … … 172 177 q = MIN (p + HIERARCH_LENGTH, q); 173 178 bzero (tmp, 81); 174 Nchar = M IN (HIERARCH_LENGTH, p + HIERARCH_LENGTH - q);179 Nchar = MAX (0, MIN (HIERARCH_LENGTH, p + HIERARCH_LENGTH - q)); 175 180 memcpy (tmp, q, Nchar); 176 181 stripwhite (tmp); … … 179 184 } 180 185 181 /* extract data into char array (exclude containing ' chars) */ 182 if (!strcmp (mode, "%s")) { 183 s = gfits_hierarch_keyword_start (p, field); /* points at first char (not ') */ 184 q = gfits_hierarch_keyword_end (p, field); /* points at following space or ' */ 185 186 Nchar = MIN (HIERARCH_LENGTH, MAX (0, (q - s))); 187 bzero (tmp, 81); 188 memcpy (tmp, s, Nchar); 189 stripwhite (tmp); 190 strcpy (va_arg (argp, char *), tmp); 191 return (TRUE); 192 } 193 186 s = gfits_hierarch_keyword_start (p, field); /* points at first char (not ') */ 187 q = gfits_hierarch_keyword_end (p, field); /* points at following space or ' */ 188 189 // these are invalid conditions: 190 if (s - p > 80) return FALSE; 191 if (q - p > 80) return FALSE; 192 194 193 /* boolean data, requires int target */ 195 194 if (!strcmp (mode, "%t")) { 196 s = gfits_hierarch_keyword_start (p, field);197 195 if (*s == 'T') { 198 196 *va_arg (argp, int *) = TRUE; … … 205 203 } 206 204 205 /* extract data into char array (exclude containing ' chars) */ 206 Nchar = MIN (HIERARCH_LENGTH, MAX (0, (q - s))); 207 bzero (tmp, 81); 208 memcpy (tmp, s, Nchar); 209 210 // for string types, copy the data to the target pointer 211 if (!strcmp (mode, "%s")) { 212 stripwhite (tmp); 213 strcpy (va_arg (argp, char *), tmp); 214 return (TRUE); 215 } 216 207 217 /* remaining options are numerical data */ 208 218 /* need to interpret 1.0d5 as 1.0e5 */ 209 s = gfits_hierarch_keyword_start (p, field); /* points at first char (not ') */210 q = gfits_hierarch_keyword_end (p, field); /* points at following space or ' */211 219 212 220 if (!strcmp (mode, "%f") || !strcmp (mode, "%lf")) { 213 fvalue = strtod (s, &q); 214 if ((*q == 'd') || (*q == 'D')) 215 fvalue *= pow (10.0, atof (q + 1)); 221 fvalue = strtod (tmp, &q); 222 if ((*q == 'd') || (*q == 'D')) fvalue *= pow (10.0, atof (q + 1)); 216 223 217 224 if (!strcmp (mode, "%f")) { *va_arg (argp, float *) = fvalue; return (TRUE); } … … 219 226 } 220 227 221 value = strtoll ( s, &q, 0);228 value = strtoll (tmp, &q, 0); 222 229 if ((*q == 'd') || (*q == 'D')) value *= pow (10.0, atof (q + 1)); 223 230 -
trunk/Ohana/src/libfits/table/F_set_column.c
r38553 r39324 1 1 # include <ohana.h> 2 2 # include <gfitsio.h> 3 # define OHANA_MEMCHECK 0 3 4 4 5 # define SWAP_NONE … … 34 35 double Bscale, Bzero; 35 36 37 # if (OHANA_MEMCHECK) 38 memset (tlabel, 0x7f, 256); 39 memset (field, 0x7f, 256); 40 memset (format, 0x7f, 256); 41 memset (type, 0x7f, 64); 42 memset (tmpline, 0x7f, 64); 43 44 ohana_memcheck_block (data); 45 # endif 46 36 47 if (label == (char *) NULL) return (FALSE); 37 48 if (label[0] == 0) return (FALSE); … … 42 53 for (i = 1; strcasecmp (label, tlabel) && (i < Nfields + 1); i++) { 43 54 snprintf (field, 256, "TTYPE%d", i); 44 gfits_scan (header, field, "%s", 1, tlabel);55 if (!gfits_scan (header, field, "%s", 1, tlabel)) return FALSE; 45 56 } 46 57 if (strcasecmp (label, tlabel)) return (FALSE); … … 57 68 } 58 69 snprintf (field, 256, "TFORM%d", N); 59 gfits_scan (header, field, "%s", 1, format);70 if (!gfits_scan (header, field, "%s", 1, format)) return FALSE; 60 71 61 72 if (!gfits_bintable_format (format, type, &Nval, &Nbytes)) return (FALSE); … … 72 83 if (Ny != Nrow) return (FALSE); 73 84 85 // if we call this function with a null pointer, we are only validating the header and allocating the data array 86 if (!data) return TRUE; 87 74 88 /* scan columns to find insert point */ 75 89 Nstart = 0; 76 90 for (i = 1; i < N; i++) { 77 91 snprintf (field, 256, "TFORM%d", i); 78 gfits_scan (header, field, "%s", 1, format);92 if (!gfits_scan (header, field, "%s", 1, format)) return FALSE; 79 93 gfits_bintable_format (format, tmpline, &Nv, &Nb); 80 94 Nstart += Nv*Nb; … … 86 100 Pin = data; 87 101 Pout = array; 102 88 103 // does it makes sense to scale 'char' data? 89 104 if (!strcmp (type, "char")) { … … 92 107 } 93 108 } 109 94 110 if (!strcmp (type, "byte")) { 95 111 for (i = 0; i < Nval*Nrow; i++, Pin+=Nbytes, Pout+=Nbytes) { … … 97 113 } 98 114 } 115 99 116 if (!strcmp (type, "short")) { 100 117 for (i = 0; i < Nval*Nrow; i++, Pin+=Nbytes, Pout+=Nbytes) { … … 105 122 } 106 123 } 124 107 125 if (!strcmp (type, "int")) { 108 126 for (i = 0; i < Nval*Nrow; i++, Pin+=Nbytes, Pout+=Nbytes) { … … 113 131 } 114 132 } 133 115 134 if (!strcmp (type, "int64_t")) { 116 135 // XXX 64 bit int operations with Bzero & Bscale are inaccurate even with doubles … … 131 150 } 132 151 } 152 133 153 if (!strcmp (type, "float")) { 134 154 for (i = 0; i < Nval*Nrow; i++, Pin+=Nbytes, Pout+=Nbytes) { … … 139 159 } 140 160 } 161 141 162 if (!strcmp (type, "double")) { 142 163 for (i = 0; i < Nval*Nrow; i++, Pin+=Nbytes, Pout+=Nbytes) { … … 179 200 } 180 201 202 # if (OHANA_MEMCHECK) 203 myAssert ( tlabel[255] == 0x7f, "oops"); 204 myAssert ( field[255] == 0x7f, "oops"); 205 myAssert ( format[255] == 0x7f, "oops"); 206 myAssert ( type[63] == 0x7f, "oops"); 207 myAssert (tmpline[63] == 0x7f, "oops"); 208 209 ohana_memcheck (TRUE); 210 # endif 211 181 212 free (array); 213 182 214 return (TRUE); 183 215 } -
trunk/Ohana/src/libfits/table/F_uncompress_T.c
r38553 r39324 8 8 int gfits_distribute_table_gzp2 (FTable *table, TableField *field, char *raw, int row_start, int Nrows); 9 9 10 # define OHANA_MEMCHECK 0 10 11 # define VERBOSE_DUMP 0 11 12 … … 164 165 gettimeofday (&startTimer, (void *) NULL); 165 166 166 // this allocates the pointer data array for the full set of tiles (NOT the heap) 167 char *tmpbuffer = NULL; 168 ALLOCATE_ZERO (tmpbuffer, char, max_width*Ny); 167 if (OHANA_MEMCHECK) ohana_memcheck (TRUE); 168 169 // this allocates the pointer data array for the full set of tiles (NOT the heap) by 170 // calling with an empty data array, data values are not actually copied (this is done 171 // below after decompression) 169 172 for (i = 0; i < Nfields; i++) { 170 if (!gfits_set_bintable_column (tgtheader, tgttable, fields[i].ttype, tmpbuffer, Ny)) ESCAPE; 171 } 172 free (tmpbuffer); 173 if (!gfits_set_bintable_column (tgtheader, tgttable, fields[i].ttype, NULL, Ny)) ESCAPE; 174 } 173 175 176 if (OHANA_MEMCHECK) ohana_memcheck (TRUE); 177 174 178 int Ntile = srcheader->Naxis[1]; 175 179 int ztilelast; -
trunk/Ohana/src/libohana/Makefile
r39242 r39324 66 66 $(DESTLIB)/libohana.$(DLLTYPE): $(LIB)/libohana.$(ARCH).$(DLLTYPE) 67 67 68 TESTPROG = sprintf_floats69 #TESTPROG = memtest typetest string68 # TESTPROG = sprintf_floats 69 TESTPROG = memtest typetest string 70 70 71 71 $(TESTPROG) : % : $(TESTBIN)/% $(OBJS) -
trunk/Ohana/src/libohana/include/ohana_allocate.h
r38986 r39324 41 41 void ohana_free (const char *file, int line, const char *func, void *in); 42 42 void ohana_memdump_func (int mode); 43 int ohana_memcheck_func (int mode); 43 int ohana_memcheck_func (const char *myFile, int myLine, const char *myFunc, int mode); 44 void ohana_memcheck_block_func (const char *myFile, int myLine, const char *myFunc, void *in); 44 45 void real_free (void *in); 45 46 46 # define ohana_memcheck(X) ohana_memcheck_func (X) 47 # define ohana_memcheck(X) ohana_memcheck_func (__FILE__, __LINE__, __func__, X) 48 # define ohana_memcheck_block(X) ohana_memcheck_block_func (__FILE__, __LINE__, __func__, X) 47 49 # define ohana_memdump(X) ohana_memdump_func (X); 48 50 … … 77 79 78 80 # define ohana_memcheck(X) ohana_memcheck_noop (X) 81 # define ohana_memcheck_block(X) ohana_memcheck_noop (X) 79 82 # define ohana_memdump(X) /* NOP */ 80 83 void real_free (void *in); -
trunk/Ohana/src/libohana/src/ohana_allocate.c
r38986 r39324 18 18 19 19 static OhanaMemblock *lastBlock = NULL; 20 static int Nblock = 0; 20 21 21 22 # if (TEST_SAVE_FREE_BLOCKS) … … 95 96 lastBlock = new; 96 97 98 Nblock ++; 97 99 pthread_mutex_unlock(&memBlockListMutex); 98 100 … … 212 214 if (!in) return; 213 215 216 if (!lastBlock) ohana_memabort ("no memory allocated yet (%s@%d : %s)\n", file, line, func); 217 214 218 // fprintf (stderr, "free %zx\n", (size_t) in); 215 219 … … 221 225 // fprintf (stderr, " file: %s, line: %d, func: %s, size: %zd, addr: %zx\n", 222 226 // ref->file, ref->line, ref->func, ref->size, (size_t) ref); 227 228 if (!lastBlock) ohana_memabort ("corruption? (%s@%d : %s)\n", file, line, func); 223 229 224 230 pthread_mutex_lock(&memBlockListMutex); … … 227 233 OhanaMemblock *prevBlock = ref->prevBlock; 228 234 235 if (!nextBlock && !prevBlock && (Nblock > 1)) ohana_memabort ("orphan block?? (%s@%d : %s)\n", file, line, func); 236 229 237 // remove this memBlock from the list 230 238 if (nextBlock) { … … 238 246 } 239 247 248 if (!lastBlock && (Nblock > 1)) ohana_memabort ("corruption? (%s@%d : %s)\n", file, line, func); 249 240 250 // XXX FOR TESTING, save the freed blocks 241 251 # if (TEST_SAVE_FREE_BLOCKS) … … 252 262 memset (ptr, 0x77, ref->size); 253 263 264 Nblock --; 265 if (Nblock < 0) ohana_memabort ("excess frees? (%s@%d : %s)\n", file, line, func); 266 254 267 pthread_mutex_unlock(&memBlockListMutex); 255 268 … … 265 278 } 266 279 267 int ohana_memcheck_func ( int VERBOSE) {280 int ohana_memcheck_func (const char *myFile, int myLine, const char *myFunc, int VERBOSE) { 268 281 269 282 if (!lastBlock) { … … 310 323 311 324 if (Ntotal || VERBOSE) { 312 fprintf (stderr, "%zd memory blocks allocated (%zd bytes total), %zd good, %zd bad\n", Ntotal, Nbytes, Ngood, Nbad); 325 fprintf (stderr, "%zd memory blocks allocated (%zd bytes total), %zd good, %zd bad ", Ntotal, Nbytes, Ngood, Nbad); 326 fprintf (stderr, "@ %s:%d (%s)\n", myFile, myLine, myFunc); 313 327 } 314 328 … … 415 429 416 430 if (Ntotal_drop || VERBOSE) { 417 fprintf (stderr, "%zd memory blocks dropped (%zd bytes total), %zd good, %zd bad\n", Ntotal_drop, Nbytes_drop, Ngood_drop, Nbad_drop); 431 fprintf (stderr, "%zd memory blocks dropped (%zd bytes total), %zd good, %zd bad", Ntotal_drop, Nbytes_drop, Ngood_drop, Nbad_drop); 432 fprintf (stderr, "@ %s:%d (%d)\n", myFile, myLine, myFunc); 418 433 } 419 434 … … 422 437 423 438 return status; 439 } 440 441 void ohana_memcheck_block_func (const char *myFile, int myLine, const char *myFunc, void *in) { 442 443 OhanaMemblock *ref; 444 445 if (!in) return; 446 447 if (!lastBlock) ohana_memabort ("no memory allocated yet (%s@%d : %s)\n", myFile, myLine, myFunc); 448 449 ref = (OhanaMemblock *) in - 1; 450 451 if (ref->freed) ohana_memabort ("memory already freed (%s, %d, %s [%d bytes])\n", ref->file, ref->line, ref->func, ref->size); 452 453 OhanaMemblock *nextBlock = ref->nextBlock; 454 OhanaMemblock *prevBlock = ref->prevBlock; 455 456 if (!nextBlock && !prevBlock) ohana_memabort ("orphan block?? (%s@%d : %s)\n", myFile, myLine, myFunc); 424 457 } 425 458
Note:
See TracChangeset
for help on using the changeset viewer.
