Skip to content

Commit

Permalink
malloc debugging for flex
Browse files Browse the repository at this point in the history
  • Loading branch information
markokr committed Oct 29, 2007
1 parent 45d145b commit 63efaf9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Makefile
Expand Up @@ -21,7 +21,8 @@ SHLIB_LINK = -L$(PQLIB) -lpq

DIST_FILES = Makefile src/plproxy.h src/rowstamp.h src/scanner.l src/parser.y \
sql/*.sql expected/*.out config/*.sql doc/*.txt doc/Makefile \
AUTHORS COPYRIGHT README plproxy.sql.in NEWS debian/packages
AUTHORS COPYRIGHT README plproxy.sql.in NEWS debian/packages \
src/dbgmalloc.h
DIST_DIRS = src sql expected config doc debian
TARNAME = plproxy-$(PLPROXY_VERSION)

Expand All @@ -45,7 +46,7 @@ src/scanner.c: src/scanner.l
cd src; $(FLEX) -oscanner.c scanner.l

# dependencies
$(OBJS): src/plproxy.h src/rowstamp.h
$(OBJS): src/plproxy.h src/rowstamp.h src/dbgmalloc.h

# utility rules

Expand Down
28 changes: 28 additions & 0 deletions src/dbgmalloc.h
@@ -0,0 +1,28 @@

#define MALLOCLOGx

static inline void *my_malloc(const char *pfx, int len) {
void *p = palloc(len);
#ifdef MALLOCLOG
elog(NOTICE, "%s:%s(%d) = %p", pfx, __FUNCTION__, len, p);
#endif
return p;
}
static inline void *my_realloc(const char *pfx, void *old, int len) {
void *p = repalloc(old, len);
#ifdef MALLOCLOG
elog(NOTICE, "%s:%s(%p, %d) = %p", pfx, __FUNCTION__, old, len, p);
#endif
return p;
}
static inline void my_free(const char *pfx, void *p) {
pfree(p);
#ifdef MALLOCLOG
elog(NOTICE, "%s:%s(%p)", pfx, __FUNCTION__, p);
#endif
}

#define malloc(x) my_malloc(__FILE__, x)
#define realloc(x, y) my_realloc(__FILE__, x, y)
#define free(x) my_free(__FILE__, x)

0 comments on commit 63efaf9

Please sign in to comment.