implement realloc() for MONITOR_HEAP or vice versa

Add new routine 're_alloc()' that functions as MONITOR_HEAP-aware
libc realloc().  'nhrealloc()' is the version that passes source
file and line info if built with MONITOR_HEAP enabled.  The heaplog
data might now contain '<' (freed by realloc), '>' (replacement
allocation by realloc), and '*' (resized by realloc) entries in
addition to the previous '+' (allocated) and '-' (freed) entries.
heaputil has already been updated in the NHinternal repository.

Move FITSint_() and FITSuint_() from hacklib.c to alloc.c so that
they can be accessed by miscellaneous utility programs.

Remove three or four copies of FITSint_() that were duplicated in
utility programs like dlb and tile2bmp due to those not having
access to src/hacklib.o.  They do have access to src/alloc.o (and
util/panic.o).
This commit is contained in:
PatR
2022-05-30 23:19:35 -07:00
parent 4a8deefaa3
commit 687e7c12f7
8 changed files with 95 additions and 70 deletions

View File

@@ -301,6 +301,7 @@ extern char *dupstr_n(const char *string, unsigned int *lenout);
#ifdef MONITOR_HEAP
/* plain alloc() is not declared except in alloc.c */
extern long *nhalloc(unsigned int, const char *, int);
extern long *nhrealloc(long *, unsigned int, const char *, int);
extern void nhfree(genericptr_t, const char *, int);
extern char *nhdupstr(const char *, const char *, int);
/* this predates C99's __func__; that is trickier to use conditionally
@@ -314,11 +315,13 @@ extern char *nhdupstr(const char *, const char *, int);
#define __LINE__ 0
#endif
#define alloc(a) nhalloc(a, __FILE__, (int) __LINE__)
#define re_alloc(a,n) nhrealloc(a, n, __FILE__, (int) __LINE__)
#define free(a) nhfree(a, __FILE__, (int) __LINE__)
#define dupstr(s) nhdupstr(s, __FILE__, (int) __LINE__)
#else /* !MONITOR_HEAP */
/* declare alloc.c's alloc(); allocations made with it use ordinary free() */
extern long *alloc(unsigned int); /* alloc.c */
extern long *re_alloc(long *, unsigned int);
#endif /* ?MONITOR_HEAP */
/* Used for consistency checks of various data files; declare it here so