mirror of
https://gcc.gnu.org/git/gcc.git
synced 2024-11-23 19:03:59 +08:00
In libobjc/:
* objc/deprecated/objc_malloc.h: New file. * objc/deprecated/objc_valloc.h: New file. * objc/objc-api.h: Include the files instead of defining objc_valloc, _objc_malloc() and similar. * Makefile.in (OBJC_DEPRECATED_H): Added objc_valloc.h and objc_malloc.h. * memory.c: Removed the extra layer of indirection of _objc_malloc and similar. (objc_calloc): Use GC_malloc in the garbage-collected implementation as GC_malloc returns memory that is already freed. (objc_valloc): Deprecated. From-SVN: r164224
This commit is contained in:
parent
7b86998664
commit
d1be5d82e0
@ -1,3 +1,17 @@
|
||||
2010-09-12 Nicola Pero <nicola.pero@meta-innovation.com>
|
||||
|
||||
* objc/deprecated/objc_malloc.h: New file.
|
||||
* objc/deprecated/objc_valloc.h: New file.
|
||||
* objc/objc-api.h: Include the files instead of defining
|
||||
objc_valloc, _objc_malloc() and similar.
|
||||
* Makefile.in (OBJC_DEPRECATED_H): Added objc_valloc.h and
|
||||
objc_malloc.h.
|
||||
* memory.c: Removed the extra layer of indirection of _objc_malloc
|
||||
and similar.
|
||||
(objc_calloc): Use GC_malloc in the garbage-collected
|
||||
implementation as GC_malloc returns memory that is already freed.
|
||||
(objc_valloc): Deprecated.
|
||||
|
||||
2010-09-12 Nicola Pero <nicola.pero@meta-innovation.com>
|
||||
|
||||
* objc/deprecated/objc_error.h: New file.
|
||||
|
@ -168,7 +168,9 @@ OBJC_DEPRECATED_H = \
|
||||
Object.h \
|
||||
STR.h \
|
||||
objc_error.h \
|
||||
objc_malloc.h \
|
||||
objc_unexpected_exception.h \
|
||||
objc_valloc.h \
|
||||
struct_objc_class.h \
|
||||
struct_objc_protocol.h \
|
||||
struct_objc_selector.h \
|
||||
|
145
libobjc/memory.c
145
libobjc/memory.c
@ -24,6 +24,12 @@ 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/>. */
|
||||
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#include "objc-private/common.h"
|
||||
#include "objc-private/error.h"
|
||||
|
||||
@ -38,17 +44,13 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
||||
#include "objc/objc-api.h"
|
||||
#include "objc-private/runtime.h"
|
||||
|
||||
/*
|
||||
Standard functions for memory allocation and disposal. Users should
|
||||
use these functions in their ObjC programs so that they work
|
||||
properly with garbage collectors as well as can take advantage of
|
||||
the exception/error handling available.
|
||||
*/
|
||||
#if OBJC_WITH_GC
|
||||
#include <gc.h>
|
||||
|
||||
void *
|
||||
objc_malloc (size_t size)
|
||||
{
|
||||
void *res = (void *) (*_objc_malloc) (size);
|
||||
void *res = (void *)(GC_malloc (size));
|
||||
if (! res)
|
||||
_objc_abort ("Virtual memory exhausted\n");
|
||||
return res;
|
||||
@ -57,16 +59,7 @@ objc_malloc (size_t size)
|
||||
void *
|
||||
objc_atomic_malloc (size_t size)
|
||||
{
|
||||
void *res = (void *) (*_objc_atomic_malloc) (size);
|
||||
if (! res)
|
||||
_objc_abort ("Virtual memory exhausted\n");
|
||||
return res;
|
||||
}
|
||||
|
||||
void *
|
||||
objc_valloc (size_t size)
|
||||
{
|
||||
void *res = (void *) (*_objc_valloc) (size);
|
||||
void *res = (void *)(GC_malloc_atomic (size));
|
||||
if (! res)
|
||||
_objc_abort ("Virtual memory exhausted\n");
|
||||
return res;
|
||||
@ -75,7 +68,7 @@ objc_valloc (size_t size)
|
||||
void *
|
||||
objc_realloc (void *mem, size_t size)
|
||||
{
|
||||
void *res = (void *) (*_objc_realloc) (mem, size);
|
||||
void *res = (void *)(GC_realloc (mem, size));
|
||||
if (! res)
|
||||
_objc_abort ("Virtual memory exhausted\n");
|
||||
return res;
|
||||
@ -84,7 +77,9 @@ objc_realloc (void *mem, size_t size)
|
||||
void *
|
||||
objc_calloc (size_t nelem, size_t size)
|
||||
{
|
||||
void *res = (void *) (*_objc_calloc) (nelem, size);
|
||||
/* Note that GC_malloc returns cleared memory (see documentation) so
|
||||
there is no need to clear it. */
|
||||
void *res = (void *)(GC_malloc (nelem, size));
|
||||
if (! res)
|
||||
_objc_abort ("Virtual memory exhausted\n");
|
||||
return res;
|
||||
@ -93,50 +88,85 @@ objc_calloc (size_t nelem, size_t size)
|
||||
void
|
||||
objc_free (void *mem)
|
||||
{
|
||||
(*_objc_free) (mem);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
Hook functions for memory allocation and disposal. This makes it
|
||||
easy to substitute garbage collection systems such as Boehm's GC by
|
||||
assigning these function pointers to the GC's allocation routines.
|
||||
By default these point to the ANSI standard malloc, realloc, free,
|
||||
etc.
|
||||
#else
|
||||
|
||||
Users should call the normal objc routines above for memory
|
||||
allocation and disposal within their programs.
|
||||
*/
|
||||
void *
|
||||
objc_malloc (size_t size)
|
||||
{
|
||||
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));
|
||||
if (! res)
|
||||
_objc_abort ("Virtual memory exhausted\n");
|
||||
return res;
|
||||
}
|
||||
|
||||
void *
|
||||
objc_realloc (void *mem, size_t size)
|
||||
{
|
||||
void *res = (void *)(realloc (mem, size));
|
||||
if (! res)
|
||||
_objc_abort ("Virtual memory exhausted\n");
|
||||
return res;
|
||||
}
|
||||
|
||||
void *
|
||||
objc_calloc (size_t nelem, size_t size)
|
||||
{
|
||||
void *res = (void *)(calloc (nelem, size));
|
||||
if (! res)
|
||||
_objc_abort ("Virtual memory exhausted\n");
|
||||
return res;
|
||||
}
|
||||
|
||||
void
|
||||
objc_free (void *mem)
|
||||
{
|
||||
free (mem);
|
||||
}
|
||||
|
||||
#endif /* !OBJC_WITH_GC */
|
||||
|
||||
/* The rest of the file contains deprecated code. */
|
||||
|
||||
#if OBJC_WITH_GC
|
||||
#include <gc.h>
|
||||
|
||||
/* FIXME: The following sounds pointless because the GC_malloc
|
||||
documentation says that it returns memory that is already zeroed!
|
||||
void *
|
||||
objc_valloc (size_t size)
|
||||
{
|
||||
void *res = (void *)(GC_malloc (size));
|
||||
if (! res)
|
||||
_objc_abort ("Virtual memory exhausted\n");
|
||||
return res;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void *
|
||||
objc_valloc (size_t size)
|
||||
{
|
||||
void *res = (void *)(malloc (size));
|
||||
if (! res)
|
||||
_objc_abort ("Virtual memory exhausted\n");
|
||||
return res;
|
||||
}
|
||||
|
||||
#endif /* !OBJC_WITH_GC */
|
||||
|
||||
/*
|
||||
Hook functions for memory allocation and disposal. Deprecated
|
||||
and currently unused.
|
||||
*/
|
||||
static void *
|
||||
GC_calloc (size_t nelem, size_t size)
|
||||
{
|
||||
void *p = GC_malloc (nelem * size);
|
||||
if (! p)
|
||||
_objc_abort ("Virtual memory exhausted!\n");
|
||||
|
||||
memset (p, 0, nelem * size);
|
||||
return p;
|
||||
}
|
||||
|
||||
static void
|
||||
noFree (void *p)
|
||||
{
|
||||
}
|
||||
|
||||
void *(*_objc_malloc) (size_t) = GC_malloc;
|
||||
void *(*_objc_atomic_malloc) (size_t) = GC_malloc_atomic;
|
||||
void *(*_objc_valloc) (size_t) = GC_malloc;
|
||||
void *(*_objc_realloc) (void *, size_t) = GC_realloc;
|
||||
void *(*_objc_calloc) (size_t, size_t) = GC_calloc;
|
||||
void (*_objc_free) (void *) = noFree;
|
||||
|
||||
#else /* !OBJC_WITH_GC */
|
||||
|
||||
void *(*_objc_malloc) (size_t) = malloc;
|
||||
void *(*_objc_atomic_malloc) (size_t) = malloc;
|
||||
@ -144,6 +174,3 @@ void *(*_objc_valloc) (size_t) = malloc;
|
||||
void *(*_objc_realloc) (void *, size_t) = realloc;
|
||||
void *(*_objc_calloc) (size_t, size_t) = calloc;
|
||||
void (*_objc_free) (void *) = free;
|
||||
|
||||
|
||||
#endif /* !OBJC_WITH_GC */
|
||||
|
17
libobjc/objc/deprecated/objc_malloc.h
Normal file
17
libobjc/objc/deprecated/objc_malloc.h
Normal file
@ -0,0 +1,17 @@
|
||||
/*
|
||||
** Hook functions for memory allocation and disposal.
|
||||
** This makes it easy to substitute garbage collection systems
|
||||
** such as Boehm's GC by assigning these function pointers
|
||||
** to the GC's allocation routines. By default these point
|
||||
** to the ANSI standard malloc, realloc, free, etc.
|
||||
**
|
||||
** Users should call the normal objc routines above for
|
||||
** memory allocation and disposal within their programs.
|
||||
*/
|
||||
objc_EXPORT void *(*_objc_malloc)(size_t);
|
||||
objc_EXPORT void *(*_objc_atomic_malloc)(size_t);
|
||||
objc_EXPORT void *(*_objc_valloc)(size_t);
|
||||
objc_EXPORT void *(*_objc_realloc)(void *, size_t);
|
||||
objc_EXPORT void *(*_objc_calloc)(size_t, size_t);
|
||||
objc_EXPORT void (*_objc_free)(void *);
|
||||
|
2
libobjc/objc/deprecated/objc_valloc.h
Normal file
2
libobjc/objc/deprecated/objc_valloc.h
Normal file
@ -0,0 +1,2 @@
|
||||
void *
|
||||
objc_valloc(size_t size);
|
@ -82,10 +82,8 @@ struct objc_method_description
|
||||
#define _C_VECTOR '!'
|
||||
#define _C_COMPLEX 'j'
|
||||
|
||||
|
||||
#include "deprecated/objc_error.h"
|
||||
|
||||
|
||||
/* For every class which happens to have statically allocated instances in
|
||||
this module, one OBJC_STATIC_INSTANCES is allocated by the compiler.
|
||||
INSTANCES is NULL terminated and points to all statically allocated
|
||||
@ -328,20 +326,19 @@ objc_EXPORT id (*_objc_object_copy)(id object);
|
||||
objc_EXPORT id (*_objc_object_dispose)(id object);
|
||||
|
||||
/*
|
||||
** Standard functions for memory allocation and disposal.
|
||||
** Users should use these functions in their ObjC programs so
|
||||
** that they work properly with garbage collectors as well as
|
||||
** can take advantage of the exception/error handling available.
|
||||
Standard functions for memory allocation and disposal. Users should
|
||||
use these functions in their ObjC programs so that they work so that
|
||||
they work properly with garbage collectors.
|
||||
*/
|
||||
void *
|
||||
objc_malloc(size_t size);
|
||||
|
||||
/* FIXME: Shouldn't the following be called objc_malloc_atomic ? The
|
||||
GC function is GC_malloc_atomic() which makes sense.
|
||||
*/
|
||||
void *
|
||||
objc_atomic_malloc(size_t size);
|
||||
|
||||
void *
|
||||
objc_valloc(size_t size);
|
||||
|
||||
void *
|
||||
objc_realloc(void *mem, size_t size);
|
||||
|
||||
@ -351,22 +348,8 @@ objc_calloc(size_t nelem, size_t size);
|
||||
void
|
||||
objc_free(void *mem);
|
||||
|
||||
/*
|
||||
** Hook functions for memory allocation and disposal.
|
||||
** This makes it easy to substitute garbage collection systems
|
||||
** such as Boehm's GC by assigning these function pointers
|
||||
** to the GC's allocation routines. By default these point
|
||||
** to the ANSI standard malloc, realloc, free, etc.
|
||||
**
|
||||
** Users should call the normal objc routines above for
|
||||
** memory allocation and disposal within their programs.
|
||||
*/
|
||||
objc_EXPORT void *(*_objc_malloc)(size_t);
|
||||
objc_EXPORT void *(*_objc_atomic_malloc)(size_t);
|
||||
objc_EXPORT void *(*_objc_valloc)(size_t);
|
||||
objc_EXPORT void *(*_objc_realloc)(void *, size_t);
|
||||
objc_EXPORT void *(*_objc_calloc)(size_t, size_t);
|
||||
objc_EXPORT void (*_objc_free)(void *);
|
||||
#include "deprecated/objc_valloc.h"
|
||||
#include "deprecated/objc_malloc.h"
|
||||
|
||||
/*
|
||||
** Hooks for method forwarding. This makes it easy to substitute a
|
||||
|
Loading…
Reference in New Issue
Block a user