/**
***  MemPools:	malloc() replacement using standard Amiga pool functions.
***  Copyright	(C)  1994    Jochen Wiedmann
***
***  This program is free software; you can redistribute it and/or modify
***  it under the terms of the GNU General Public License as published by
***  the Free Software Foundation; either version 2 of the License, or
***  (at your option) any later version.
***
***  This program is distributed in the hope that it will be useful,
***  but WITHOUT ANY WARRANTY; without even the implied warranty of
***  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
***  GNU General Public License for more details.
***
***  You should have received a copy of the GNU General Public License
***  along with this program; if not, write to the Free Software
***  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
***
***
***  This file contains the initialization stuff.
***
***
***  Computer:	Amiga 1200
***
***  Compilers: Dice 3.01
***		SAS/C 6.3
***		gcc 2.6.1
***
***
***  Author:	Jochen Wiedmann
***		Am Eisteich 9
***	  72555 Metzingen
***		Germany
***
***		Phone: (0049) 7123 14881
***		Internet: jochen.wiedmann@uni-tuebingen.de
**/


/***************************************************************************
***
***  This file uses the auto initialization possibilities of Dice, gcc and
***  SAS/C, respectively.
***
***  Dice does this by using the keywords __autoinit and __autoexit, SAS
***  uses names beginning with _STI or _STD, respectively. gcc uses the
***  asm() instruction, to emulate C++ constructors and destructors.
***
***************************************************************************/


/*
    Include files and compiler specific stuff
*/
#include <stdlib.h>
#include <exec/types.h>
#include <clib/alib_protos.h>

#if defined(__SASC)  ||  defined(__GNUC__)
#define __autoinit
#define __autoexit
#elif !defined(_DCC)
#error "Don't know how to handle your compiler."
#endif




APTR __MemPool;
extern ULONG __MemPoolPuddleSize;
extern ULONG __MemPoolThreshSize;
extern ULONG __MemPoolFlags;


STATIC __autoinit VOID _STIInitMemFunctions(VOID)

{ if (!(__MemPool = LibCreatePool(__MemPoolFlags, __MemPoolPuddleSize, __MemPoolThreshSize)))
  {
#if defined(__SASC)
    { extern VOID _XCEXIT(LONG);
      _XCEXIT(20);
    }
#elif defined(_DCC)
    { extern VOID _AutoFail0(VOID);
      _AutoFail0();
    }
#elif defined(__GNUC__)
    { abort();
    }
#endif
  }
}



STATIC __autoexit VOID _STDTerminateMemFunctions(VOID)

{ if (__MemPool)
  { LibDeletePool(__MemPool);
  }
}


#if defined(__GNUC__)
asm ("  .text;  .stabs \"___CTOR_LIST__\",22,0,0,__STIInitMemFunctions");
asm ("  .text;  .stabs \"___DTOR_LIST__\",22,0,0,__STDTerminateMemFunctions");
#endif
