🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.sys.next.programmer
4 messages
4 total messages Started by Sugou Shinichirou Sat, 29 Aug 1992 10:04
malloc_error
#878
Author: Sugou Shinichirou
Date: Sat, 29 Aug 1992 10:04
51 lines
1616 bytes
Hello.

I don't know the way how to use 'malloc_error' function. Please refer to
the UNIX manual 'malloc_error' about the detailed information.

Suppose I want to execute myMallocErr() instead of the default routine
whenever memory allocation error happens.

void myMallocErr(int code)
{
        printf("error");
        abort();
}

How do I write the code? Following two trials failed:

(1)  malloc_error = myMallocErr      // compiler rejects

(2)  malloc_error(myMallocErr)      // not myMallocErr but default routine is called


PS: If you are going to 'start' malloc-check-routine, following procedure
    is one example:
(1) Execute malloc_debug(level) in somewhere. For example:

        main()
        {
            malloc_debug(32);
            ...
            exit(0);
        }
(2) Link program with  '-lMallocDebug'. For example: If you are using IB,
    define the following line within Makefile.preamble, and 'make debug'
    will generate the malloc-check-routine active code.

	OTHER_DEBUG_LIBS = -lMallocDebug


That all.

Thank you.

---
Shin'ichirou Sugou    (NeXTmail acceptable)
--
Shin'ichirou Sugou

shin@apple.juice.or.jp (NeXTmail acceptable)


				   
Re: malloc_error
#1007
Author: moose
Date: Mon, 31 Aug 1992 17:25
30 lines
1515 bytes
In article <SHIN.92Aug29190422@sgtp.sgtp.apple.juice.or.jp>  
shin@sgtp.apple.juice.or.jp (Sugou Shinichirou) writes:
> Hello.
> 
> I don't know the way how to use 'malloc_error' function. Please refer to
> the UNIX manual 'malloc_error' about the detailed information.
> 
> Suppose I want to execute myMallocErr() instead of the default routine
> whenever memory allocation error happens.
> 
> void myMallocErr(int code)
> {
>         printf("error");
>         abort();
> }
> 
> (2) Link program with  '-lMallocDebug'. For example: If you are using IB,
>     define the following line within Makefile.preamble, and 'make debug'
>     will generate the malloc-check-routine active code.
> 
> 	OTHER_DEBUG_LIBS = -lMallocDebug
> 

I believe that linking MallocDebug will override your call you malloc_error.   
Try this without linking in MallocDebug
--
Michael Rutman			|	moose@svcdudes.com
Cubist				|	makes me a NeXT programmer
Software Ventures		|	maker of MicroPhone Pro
#include <std.disclaimer>	|	really offesive political statement
Re: malloc_error
#759
Author: Sugou Shinichirou
Date: Sat, 05 Sep 1992 08:10
78 lines
2702 bytes
In article <1992Aug31.172521.847@svcdudes.com> moose@svcdudes.com writes:
   > I don't know the way how to use 'malloc_error' function. Please refer to
   > the UNIX manual 'malloc_error' about the detailed information.
   > 
   > Suppose I want to execute myMallocErr() instead of the default routine
   > whenever memory allocation error happens.
   > 
   > void myMallocErr(int code)
   > {
   >         printf("error");
   >         abort();
   > }
   > 
   > (2) Link program with  '-lMallocDebug'. For example: If you are using IB,
   >     define the following line within Makefile.preamble, and 'make debug'
   >     will generate the malloc-check-routine active code.
   > 
   > 	OTHER_DEBUG_LIBS = -lMallocDebug
   > 

   I believe that linking MallocDebug will override your call you malloc_error.   
   Try this without linking in MallocDebug

I thank you for your suggestion.

I tried, but it seems not to be invoked still yet. The following is a very
simple test program.

------tmp1.c----------------------------------------
#import <stdlib.h>
#import <stdio.h>

void myMallocErr(int code)
{
   fprintf(stderr, "malloc error");
}

main()
{
   char *p;

   malloc_debug(32);
   malloc_error(myMallocErr);

   p = malloc(10);
   free(p);
   free(p);    // should be error!!
   exit(0);
}
---------------------------------------------------
When I compile it without '-lMallocDebug':

        %shell cc -g tmp1.c -o tmp1

No malloc error is detected. Even if I comment out 'malloc_error()'
sentence, again, no malloc error is detected.(--> malloc check routine deactiveted?)

When I compile with '-lMallocDebug':

        %shell cc -g tmp1.c -o tmp1 -lMallocDebug

the default error-message-routine is called. Even if I comment out
'malloc_error()' sentence, the result is the same.

Therefore, I think '-lMallocDebug' library is necessary when I make malloc
routine active.

But still I don't know the way how to change error-message-routine.

Any suggestion is appreciated.

--
Shin'ichirou Sugou

shin@apple.juice.or.jp (NeXTmail acceptable)


				   
Re: malloc_error
#829
Author: Sugou Shinichirou
Date: Tue, 08 Sep 1992 01:31
20 lines
1112 bytes
Dear sirs:

I've got e-mail from Mr.Jim McKelvey about 'malloc_error', and he says

(1) the integer value in malloc_debug() should be not 32 but 62.
(2) no MallocDebug library is needed.

I tested the program again, and confirmed that everythig goes well now.

Mr.Michael Rutman suggested the same thing as (2) in his posted article.

I thank you very much, Mr.Jim McKelvey and Mr.Michael Rutman.

--
Shin'ichirou Sugou

shin@apple.juice.or.jp (NeXTmail acceptable)


				   
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads