www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/21/03:29:18

Sender: crough45 AT amc DOT de
Message-Id: <97Aug21.092223gmt+0100.17025@internet01.amc.de>
Date: Thu, 21 Aug 1997 08:26:55 +0100
From: Chris Croughton <crough45 AT amc DOT de>
Mime-Version: 1.0
To: billc AT blackmagic DOT tait DOT co DOT nz
Cc: fesenko AT pacific DOT net DOT sg, djgpp AT delorie DOT com
Subject: Re: [Q] wrapping functions with linker

Bill Currie writes:

> That's your problem: fopen calls malloc which (for you) calls fopen 
> which calls malloc... I got tipped off by esp in your stack dump 
> being so low.

Been there, done that - my solution was to explicitly test
for recursion, and only do the print if it's not recursing.
So in malloc do something like:

void*
malloc(size_t size)
{
  static bool recurse = false;
  if (!recurse)
  {
    recurse = true;
    mprintf(...);
    recurse = false;
  }
  /* do alloc stuff... */
}

This stops it trying to print while printing.  You might also want to
provide a sparate function to allocate memory while 'recurse' is set,
this can be very simple and reset itself after returning from the
print (on the assumption that the C library functions are well-behaved).

Chris C

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019