2010-09-12 02:43:15 +02:00
|
|
|
/* GNU Objective C Runtime Memory allocation functions
|
2015-01-05 13:33:28 +01:00
|
|
|
Copyright (C) 1993-2015 Free Software Foundation, Inc.
|
1998-09-21 03:22:07 +02:00
|
|
|
Contributed by Kresten Krab Thorup
|
|
|
|
|
hash.c, [...]: Replace "GNU CC" with "GCC".
* hash.c, init.c, libobjc.def, libobjc_entry.c, linking.m,
makefile.dos, misc.c, nil_method.c, objects.c, sarray.c,
selector.c, sendmsg.c, thr-dce.c, thr-decosf1.c, thr-irix.c,
thr-mach.c, thr-objc.c, thr-os2.c, thr-posix.c, thr-pthreads.c,
thr-rtems.c, thr-single.c, thr-solaris.c, thr-vxworks.c,
thr-win32.c, thr.c: Replace "GNU CC" with "GCC".
From-SVN: r67134
2003-05-23 22:25:39 +02:00
|
|
|
This file is part of GCC.
|
1998-09-21 03:22:07 +02:00
|
|
|
|
hash.c, [...]: Replace "GNU CC" with "GCC".
* hash.c, init.c, libobjc.def, libobjc_entry.c, linking.m,
makefile.dos, misc.c, nil_method.c, objects.c, sarray.c,
selector.c, sendmsg.c, thr-dce.c, thr-decosf1.c, thr-irix.c,
thr-mach.c, thr-objc.c, thr-os2.c, thr-posix.c, thr-pthreads.c,
thr-rtems.c, thr-single.c, thr-solaris.c, thr-vxworks.c,
thr-win32.c, thr.c: Replace "GNU CC" with "GCC".
From-SVN: r67134
2003-05-23 22:25:39 +02:00
|
|
|
GCC is free software; you can redistribute it and/or modify it
|
1998-09-21 03:22:07 +02:00
|
|
|
under the terms of the GNU General Public License as published by the
|
2009-04-09 17:00:19 +02:00
|
|
|
Free Software Foundation; either version 3, or (at your option) any
|
1998-09-21 03:22:07 +02:00
|
|
|
later version.
|
|
|
|
|
hash.c, [...]: Replace "GNU CC" with "GCC".
* hash.c, init.c, libobjc.def, libobjc_entry.c, linking.m,
makefile.dos, misc.c, nil_method.c, objects.c, sarray.c,
selector.c, sendmsg.c, thr-dce.c, thr-decosf1.c, thr-irix.c,
thr-mach.c, thr-objc.c, thr-os2.c, thr-posix.c, thr-pthreads.c,
thr-rtems.c, thr-single.c, thr-solaris.c, thr-vxworks.c,
thr-win32.c, thr.c: Replace "GNU CC" with "GCC".
From-SVN: r67134
2003-05-23 22:25:39 +02:00
|
|
|
GCC is distributed in the hope that it will be useful, but WITHOUT
|
1998-09-21 03:22:07 +02:00
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
for more details.
|
|
|
|
|
2009-04-09 17:00:19 +02:00
|
|
|
Under Section 7 of GPL version 3, you are granted additional
|
|
|
|
permissions described in the GCC Runtime Library Exception, version
|
|
|
|
3.1, as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License and
|
|
|
|
a copy of the GCC Runtime Library Exception along with this program;
|
|
|
|
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2010-12-18 13:22:59 +01:00
|
|
|
/* This file includes the standard functions for memory allocation and
|
|
|
|
disposal. Users should use these functions in their ObjC programs
|
|
|
|
so that they work properly with garbage collectors. */
|
2010-09-12 03:44:58 +02:00
|
|
|
|
2010-10-11 01:28:12 +02:00
|
|
|
/* TODO: Turn these into macros or inline functions. */
|
|
|
|
|
2010-09-12 00:47:14 +02:00
|
|
|
#include "objc-private/common.h"
|
2010-09-12 02:43:15 +02:00
|
|
|
#include "objc-private/error.h"
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2010-09-12 00:47:14 +02:00
|
|
|
/* __USE_FIXED_PROTOTYPES__ used to be required to get prototypes for
|
|
|
|
malloc, free, etc. on some platforms. It is unclear if we still
|
2010-12-18 13:22:59 +01:00
|
|
|
need it, but it can't hurt. */
|
1998-09-21 03:22:07 +02:00
|
|
|
#define __USE_FIXED_PROTOTYPES__
|
|
|
|
#include <stdlib.h>
|
2010-09-12 00:47:14 +02:00
|
|
|
|
2010-10-12 18:17:18 +02:00
|
|
|
#include "objc/runtime.h"
|
1998-09-21 03:22:07 +02:00
|
|
|
|
2010-09-12 03:44:58 +02:00
|
|
|
#if OBJC_WITH_GC
|
|
|
|
#include <gc.h>
|
1998-09-21 03:22:07 +02:00
|
|
|
|
|
|
|
void *
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_malloc (size_t size)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2010-09-12 03:44:58 +02:00
|
|
|
void *res = (void *)(GC_malloc (size));
|
2002-07-02 21:43:03 +02:00
|
|
|
if (! res)
|
2010-09-12 02:43:15 +02:00
|
|
|
_objc_abort ("Virtual memory exhausted\n");
|
1998-09-21 03:22:07 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_atomic_malloc (size_t size)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2010-09-12 03:44:58 +02:00
|
|
|
void *res = (void *)(GC_malloc_atomic (size));
|
2002-07-02 21:43:03 +02:00
|
|
|
if (! res)
|
2010-09-12 02:43:15 +02:00
|
|
|
_objc_abort ("Virtual memory exhausted\n");
|
1998-09-21 03:22:07 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2010-09-12 03:44:58 +02:00
|
|
|
objc_realloc (void *mem, size_t size)
|
|
|
|
{
|
|
|
|
void *res = (void *)(GC_realloc (mem, size));
|
|
|
|
if (! res)
|
|
|
|
_objc_abort ("Virtual memory exhausted\n");
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
objc_calloc (size_t nelem, size_t size)
|
|
|
|
{
|
|
|
|
/* Note that GC_malloc returns cleared memory (see documentation) so
|
|
|
|
there is no need to clear it. */
|
2010-09-12 16:55:21 +02:00
|
|
|
void *res = (void *)(GC_malloc (nelem * size));
|
2010-09-12 03:44:58 +02:00
|
|
|
if (! res)
|
|
|
|
_objc_abort ("Virtual memory exhausted\n");
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-10-11 01:28:12 +02:00
|
|
|
objc_free (void *mem __attribute__ ((__unused__)))
|
2010-09-12 03:44:58 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
void *
|
|
|
|
objc_malloc (size_t size)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2010-09-12 03:44:58 +02:00
|
|
|
void *res = (void *)(malloc (size));
|
|
|
|
if (! res)
|
|
|
|
_objc_abort ("Virtual memory exhausted\n");
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
objc_atomic_malloc (size_t size)
|
|
|
|
{
|
|
|
|
void *res = (void *)(malloc (size));
|
2002-07-02 21:43:03 +02:00
|
|
|
if (! res)
|
2010-09-12 02:43:15 +02:00
|
|
|
_objc_abort ("Virtual memory exhausted\n");
|
1998-09-21 03:22:07 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_realloc (void *mem, size_t size)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2010-09-12 03:44:58 +02:00
|
|
|
void *res = (void *)(realloc (mem, size));
|
2002-07-02 21:43:03 +02:00
|
|
|
if (! res)
|
2010-09-12 02:43:15 +02:00
|
|
|
_objc_abort ("Virtual memory exhausted\n");
|
1998-09-21 03:22:07 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_calloc (size_t nelem, size_t size)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2010-09-12 03:44:58 +02:00
|
|
|
void *res = (void *)(calloc (nelem, size));
|
2002-07-02 21:43:03 +02:00
|
|
|
if (! res)
|
2010-09-12 02:43:15 +02:00
|
|
|
_objc_abort ("Virtual memory exhausted\n");
|
1998-09-21 03:22:07 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-07-02 21:43:03 +02:00
|
|
|
objc_free (void *mem)
|
1998-09-21 03:22:07 +02:00
|
|
|
{
|
2010-09-12 03:44:58 +02:00
|
|
|
free (mem);
|
1998-09-21 03:22:07 +02:00
|
|
|
}
|
|
|
|
|
2010-09-12 03:44:58 +02:00
|
|
|
#endif /* !OBJC_WITH_GC */
|