Keith Kyzivat wrote:
> See inline comments.
> 
> On 4/27/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>>
>> I don't want to write this kind of code:
> 
> 
> 
>> And if we had 10 more members, then .. oh god
> 
> 
> Understandable, I wouldn't want to write that code for each new either.
> Each additional member would add a rediculous amount of complexity to write
> and execute.
> 
> It becomes even more complicated in long functions that have lots of
>> nested ifs and new's in them.
> 
> 
> *nod* and that is why they created exceptions, but our code is not
> structured well enough to use exceptions, and we use libraries that don't
> like exceptions either, unfortunately...  *sigh*
> 
> We could have a macro "AllocationCheck(P)" that would check whether the
>> pointer is NULL, and if it is, then print the line of code to cerr with
>> an error message and do exit(-somecode).
> 
> 
> This sounds like a pretty good approach, though, given this is in the
> sipXxxx libraries, we probably want to use osPrintf instead of cerr, and
> maybe an assert?
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> sipxtapi-dev mailing list
> [email protected]
> List Archive: http://list.sipfoundry.org/archive/sipxtapi-dev/

We could have a new .h file with:


#define ALLOCATION_ERROR_EXIT_CODE -10

#ifdef WIN32
#define ALLOCATION_CHECK(PTR) if(!(PTR)) {fputs("Out of memory error in
file: "__FILE__ " function: "__FUNCTION__"\n", stderr);
exit(ALLOCATION_ERROR_EXIT_CODE);}
#else
#define ALLOCATION_CHECK(PTR) if(!(PTR)) {fputs("Out of memory error\n",
stderr); exit(ALLOCATION_ERROR_EXIT_CODE);}
#endif


fputs should be more resilient to out of memory errors than any other
functions

Jaroslav Libak
_______________________________________________
sipxtapi-dev mailing list
[email protected]
List Archive: http://list.sipfoundry.org/archive/sipxtapi-dev/

Reply via email to