(NSCreateZone): Call initialize(), so that we won't crash if someone

tries to create an object before main() and before initialize() gets
called as a constructor.
(NSDefaultMallocZone): Likewise.
(initialize): Use a static variable to return immediately if we've
been run already.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@2042 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Andrew McCallum 1997-01-11 21:39:38 +00:00
parent 61ba3d1097
commit eaadce5a82

View file

@ -19,6 +19,7 @@
You should have received a copy of the GNU Library General Public You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* This uses some GCC specific extensions. But since the library is /* This uses some GCC specific extensions. But since the library is
supposed to compile on GCC 2.7.2 (patched) or higher, and the only supposed to compile on GCC 2.7.2 (patched) or higher, and the only
@ -355,7 +356,8 @@ NSCreateZone(unsigned startSize, unsigned granularity, BOOL canFree)
{ {
NSZone *zone; NSZone *zone;
BlockHeader *block; BlockHeader *block;
initialize ();
if ((startSize == 0) || (startSize > maxsblock())) if ((startSize == 0) || (startSize > maxsblock()))
startSize = bsize; startSize = bsize;
else else
@ -403,6 +405,7 @@ NSCreateZone(unsigned startSize, unsigned granularity, BOOL canFree)
NSZone* NSZone*
NSDefaultMallocZone(void) NSDefaultMallocZone(void)
{ {
initialize ();
return &defaultZone; return &defaultZone;
} }
@ -514,8 +517,13 @@ NSMallocCheck(void)
static void static void
initialize(void) initialize(void)
{ {
static int initialize_done = 0;
BlockHeader *block; BlockHeader *block;
if (initialize_done)
return;
initialize_done = 1;
bsize = NSPageSize(); bsize = NSPageSize();
zunit = (bsize-sizeof(ZoneTable))/sizeof(NSZone); zunit = (bsize-sizeof(ZoneTable))/sizeof(NSZone);
zonelock = makelock(); zonelock = makelock();