delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/25/23:00:54

From: Robert Hoehne <Robert DOT Hoehne AT Mathematik DOT TU-Chemnitz DOT DE>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: [Q] wrapping functions with linker
Date: Thu, 21 Aug 1997 11:56:28 +0200
Organization: TU Chemnitz-Zwickau
Lines: 52
Message-ID: <33FC10CC.7248A404@Mathematik.TU-Chemnitz.DE>
References: <5stvfi$ffm$1 AT newton DOT pacific DOT net DOT sg> <33F43A43 DOT 6E6EF6B2 AT Mathematik DOT TU-Chemnitz DOT DE> <33f54e90 DOT 1752245 AT news DOT pacific DOT net DOT sg> <33F81374 DOT 7D6987A7 AT Mathematik DOT TU-Chemnitz DOT DE> <5tg75j$sj3$1 AT newton DOT pacific DOT net DOT sg>
NNTP-Posting-Host: deneb.hrz.tu-chemnitz.de
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Victor wrote:

> void* malloc(size_t size)
> {      void *p=(void*)(__imd+___im__ptr);
>     if(WRITE_TO_LOGFILE)
>       mprintf(" Program requested %8li bytes. Ptr =
> %li\n",size,___im__ptr);

UUhhh!!! Never NEVER use such things without exactly
knowlage about the internals!!

You cannot use at least fopen() in malloc()!! This function
itself calls again malloc() and so you will go in an endless
recursion!!

Either you use write() or something else. And also NEVER
use stream io functions in malloc() without deeply thinking
about it, because malloc() is called already in the startup code!!

When remember I did something like this is the past similar
to the following (not tested, only an idea):

static int write_to_log = 0;
static FILE *logfile;

void *maolloc(size_t size)
{
  if (write_to_log)
    fprintf(logfile,...)
  ....
}

...

int main()
{
  logfile = fopen("logfile",...);
  write_to_log = 1;
  ....
  write_to_log = 0;
  fclose(logfile);
  return 0;
}

Robert
---
*****************************************************************
* Robert Hoehne, Fakultaet fuer Mathematik, TU-Chemnitz-Zwickau *
* Post:    Am Berg 3, D-09573 Dittmannsdorf                     *
* e-Mail:  Robert DOT Hoehne AT Mathematik DOT TU-Chemnitz DOT DE              *
* WWW:     http://www.tu-chemnitz.de/~rho                       *
*****************************************************************

- Raw text -


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