summaryrefslogtreecommitdiff
path: root/libobjc
diff options
context:
space:
mode:
authornicola <nicola@138bc75d-0d04-0410-961f-82ee72b054a4>2010-09-12 00:43:15 +0000
committernicola <nicola@138bc75d-0d04-0410-961f-82ee72b054a4>2010-09-12 00:43:15 +0000
commitc3a945cde92094f4713cefdafe5c1bd3f07fbbcc (patch)
treee22bed6f4601015a5042c0e66fd318e63707468e /libobjc
parentf02cc357b43d02bd0cc19a701401ec8bd82985f0 (diff)
downloadgcc-c3a945cde92094f4713cefdafe5c1bd3f07fbbcc.tar.gz
In libobjc/:
* objc/deprecated/objc_error.h: New file. * objc/objc-api.h: Include deprecated/objc_error.h instead of defining objc_error and related. * error.c: New file. Added _objc_abort function which replaces objc_error. No change in functionality as they both print an error and abort. * misc.c: File removed. Code moved into memory.c and error.c. * memory.c: New file. * objc-private/error.h: New file. * archive.c: Include objc-private/error.h and use _objc_abort instead of objc_error everywhere. * class.c: Same change. * encoding.c: Same change. * init.c: Same change, and simplified init_check_module_version. * memory.c: Same change. * sendmsg.c: Same change. * thr.c: Same change. * Makefile.in (OBJ_DEPRECATED_H): Added objc_error.h. (OBJ_H): Reordered list. (OBJS): Removed misc.lo, added memory.lo and error.lo. (OBJS_GC): Removed misc_gc.lo, added memory_gc.lo and error_gc.lo. (misc_gc.lo): Rule removed. (error_gc.lo): Rule added. (memory_gc.lo): Rule added. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@164223 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libobjc')
-rw-r--r--libobjc/ChangeLog27
-rw-r--r--libobjc/Makefile.in72
-rw-r--r--libobjc/archive.c83
-rw-r--r--libobjc/class.c6
-rw-r--r--libobjc/encoding.c28
-rw-r--r--libobjc/error.c99
-rw-r--r--libobjc/init.c23
-rw-r--r--libobjc/libobjc.def2
-rw-r--r--libobjc/memory.c (renamed from libobjc/misc.c)91
-rw-r--r--libobjc/objc-private/error.h37
-rw-r--r--libobjc/objc/deprecated/objc_error.h56
-rw-r--r--libobjc/objc/objc-api.h50
-rw-r--r--libobjc/sendmsg.c4
-rw-r--r--libobjc/thr.c13
14 files changed, 374 insertions, 217 deletions
diff --git a/libobjc/ChangeLog b/libobjc/ChangeLog
index 0fdcb6e4621..0d46882a8ea 100644
--- a/libobjc/ChangeLog
+++ b/libobjc/ChangeLog
@@ -1,5 +1,32 @@
2010-09-12 Nicola Pero <nicola.pero@meta-innovation.com>
+ * objc/deprecated/objc_error.h: New file.
+ * objc/objc-api.h: Include deprecated/objc_error.h instead of
+ defining objc_error and related.
+ * error.c: New file. Added _objc_abort function which replaces
+ objc_error. No change in functionality as they both print an
+ error and abort.
+ * misc.c: File removed. Code moved into memory.c and error.c.
+ * memory.c: New file.
+ * objc-private/error.h: New file.
+ * archive.c: Include objc-private/error.h and use _objc_abort
+ instead of objc_error everywhere.
+ * class.c: Same change.
+ * encoding.c: Same change.
+ * init.c: Same change, and simplified init_check_module_version.
+ * memory.c: Same change.
+ * sendmsg.c: Same change.
+ * thr.c: Same change.
+ * Makefile.in (OBJ_DEPRECATED_H): Added objc_error.h.
+ (OBJ_H): Reordered list.
+ (OBJS): Removed misc.lo, added memory.lo and error.lo.
+ (OBJS_GC): Removed misc_gc.lo, added memory_gc.lo and error_gc.lo.
+ (misc_gc.lo): Rule removed.
+ (error_gc.lo): Rule added.
+ (memory_gc.lo): Rule added.
+
+2010-09-12 Nicola Pero <nicola.pero@meta-innovation.com>
+
* objc/objc.h (__GNU_LIBOBJC__): New #define providing an easy way
to check the API version. Added some comments.
diff --git a/libobjc/Makefile.in b/libobjc/Makefile.in
index 1dfced3dfb4..ac042accf96 100644
--- a/libobjc/Makefile.in
+++ b/libobjc/Makefile.in
@@ -147,18 +147,18 @@ OBJC_H = \
objc.h \
objc-exception.h \
\
- message.h \
- hash.h \
- objc-list.h \
- sarray.h \
- objc-api.h \
NXConstStr.h \
Object.h \
Protocol.h \
encoding.h \
- typedstream.h \
+ hash.h \
+ message.h \
+ objc-api.h \
+ objc-decls.h \
+ objc-list.h \
+ sarray.h \
thr.h \
- objc-decls.h
+ typedstream.h
# User-visible header files containing deprecated APIs, from the
# objc/deprecated directory
@@ -167,6 +167,7 @@ OBJC_DEPRECATED_H = \
MetaClass.h \
Object.h \
STR.h \
+ objc_error.h \
objc_unexpected_exception.h \
struct_objc_class.h \
struct_objc_protocol.h \
@@ -175,16 +176,47 @@ OBJC_DEPRECATED_H = \
# Modules that comprise the runtime library.
-OBJS = archive.lo class.lo encoding.lo gc.lo hash.lo init.lo linking.lo \
- misc.lo nil_method.lo NXConstStr.lo Object.lo objects.lo \
- Protocol.lo sarray.lo selector.lo sendmsg.lo thr.lo \
- exception.lo
-
-OBJS_GC = archive_gc.lo class_gc.lo encoding_gc.lo gc_gc.lo hash_gc.lo \
- init_gc.lo linking_gc.lo misc_gc.lo nil_method_gc.lo \
- NXConstStr_gc.lo Object_gc.lo objects_gc.lo Protocol_gc.lo \
- sarray_gc.lo selector_gc.lo sendmsg_gc.lo thr_gc.lo \
- exception_gc.lo
+OBJS = \
+ NXConstStr.lo \
+ Object.lo \
+ Protocol.lo \
+ archive.lo \
+ class.lo \
+ encoding.lo \
+ error.lo \
+ gc.lo \
+ hash.lo \
+ init.lo \
+ linking.lo \
+ memory.lo \
+ nil_method.lo \
+ objects.lo \
+ sarray.lo \
+ selector.lo \
+ sendmsg.lo \
+ thr.lo \
+ exception.lo
+
+OBJS_GC = \
+ NXConstStr_gc.lo \
+ Object_gc.lo \
+ Protocol_gc.lo \
+ archive_gc.lo \
+ class_gc.lo \
+ encoding_gc.lo \
+ error_gc.lo \
+ gc_gc.lo \
+ hash_gc.lo \
+ init_gc.lo \
+ linking_gc.lo \
+ memory_gc.lo \
+ nil_method_gc.lo \
+ objects_gc.lo \
+ sarray_gc.lo \
+ selector_gc.lo \
+ sendmsg_gc.lo \
+ thr_gc.lo \
+ exception_gc.lo
runtime-info.h:
echo "" > tmp-runtime.m
@@ -208,6 +240,10 @@ encoding_gc.lo: encoding.c
$(LIBTOOL_COMPILE) $(CC) -c -o $@ $(ALL_CFLAGS) $(OBJC_GCFLAGS) \
$(INCLUDES) $<
+error_gc.lo: error.c
+ $(LIBTOOL_COMPILE) $(CC) -c $(ALL_CFLAGS) -o $@ $(OBJC_GCFLAGS) \
+ $(INCLUDES) $<
+
gc.lo: gc.c
$(LIBTOOL_COMPILE) $(CC) -c -o $@ $(ALL_CFLAGS) $(INCLUDES) $<
@@ -231,7 +267,7 @@ linking_gc.lo: linking.m
$(LIBTOOL_COMPILE) $(CC) -fgnu-runtime -c -o $@ $(ALL_CFLAGS) \
$(OBJC_GCFLAGS) $(INCLUDES) $<
-misc_gc.lo: misc.c
+memory_gc.lo: memory.c
$(LIBTOOL_COMPILE) $(CC) -c $(ALL_CFLAGS) -o $@ $(OBJC_GCFLAGS) \
$(INCLUDES) $<
diff --git a/libobjc/archive.c b/libobjc/archive.c
index 6603ab12d51..9b46976fbf4 100644
--- a/libobjc/archive.c
+++ b/libobjc/archive.c
@@ -22,7 +22,10 @@ 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 is entirely deprecated and will be removed. */
+
#include "objc-private/common.h"
+#include "objc-private/error.h"
#include "tconfig.h"
#include "objc/objc.h"
#include "objc/objc-api.h"
@@ -364,8 +367,7 @@ __objc_write_extension (struct objc_typed_stream *stream, unsigned char code)
}
else
{
- objc_error (nil, OBJC_ERR_BAD_OPCODE,
- "__objc_write_extension: bad opcode %c\n", code);
+ _objc_abort ("__objc_write_extension: bad opcode %c\n", code);
return -1;
}
}
@@ -402,8 +404,7 @@ objc_write_root_object (struct objc_typed_stream *stream, id object)
{
int len = 0;
if (stream->writing_root_p)
- objc_error (nil, OBJC_ERR_RECURSE_ROOT,
- "objc_write_root_object called recursively");
+ _objc_abort ("objc_write_root_object called recursively");
else
{
stream->writing_root_p = 1;
@@ -527,9 +528,8 @@ objc_read_char (struct objc_typed_stream *stream, char *val)
}
else
- objc_error (nil, OBJC_ERR_BAD_DATA,
- "expected 8bit signed int, got %dbit int",
- (int) (buf&_B_NUMBER)*8);
+ _objc_abort ("expected 8bit signed int, got %dbit int",
+ (int) (buf&_B_NUMBER)*8);
}
return len;
}
@@ -549,9 +549,8 @@ objc_read_unsigned_char (struct objc_typed_stream *stream, unsigned char *val)
len = (*stream->read) (stream->physical, (char*)val, 1);
else
- objc_error (nil, OBJC_ERR_BAD_DATA,
- "expected 8bit unsigned int, got %dbit int",
- (int) (buf&_B_NUMBER)*8);
+ _objc_abort ("expected 8bit unsigned int, got %dbit int",
+ (int) (buf&_B_NUMBER)*8);
}
return len;
}
@@ -571,8 +570,7 @@ objc_read_short (struct objc_typed_stream *stream, short *value)
int pos = 1;
int nbytes = buf[0] & _B_NUMBER;
if (nbytes > (int) sizeof (short))
- objc_error (nil, OBJC_ERR_BAD_DATA,
- "expected short, got bigger (%dbits)", nbytes*8);
+ _objc_abort ("expected short, got bigger (%dbits)", nbytes*8);
len = (*stream->read) (stream->physical, (char*)buf + 1, nbytes);
(*value) = 0;
while (pos <= nbytes)
@@ -600,8 +598,7 @@ objc_read_unsigned_short (struct objc_typed_stream *stream,
int pos = 1;
int nbytes = buf[0] & _B_NUMBER;
if (nbytes > (int) sizeof (short))
- objc_error (nil, OBJC_ERR_BAD_DATA,
- "expected short, got int or bigger");
+ _objc_abort ("expected short, got int or bigger");
len = (*stream->read) (stream->physical, (char*)buf + 1, nbytes);
(*value) = 0;
while (pos <= nbytes)
@@ -627,7 +624,7 @@ objc_read_int (struct objc_typed_stream *stream, int *value)
int pos = 1;
int nbytes = buf[0] & _B_NUMBER;
if (nbytes > (int) sizeof (int))
- objc_error (nil, OBJC_ERR_BAD_DATA, "expected int, got bigger");
+ _objc_abort ("expected int, got bigger");
len = (*stream->read) (stream->physical, (char*)buf + 1, nbytes);
(*value) = 0;
while (pos <= nbytes)
@@ -654,7 +651,7 @@ objc_read_long (struct objc_typed_stream *stream, long *value)
int pos = 1;
int nbytes = buf[0] & _B_NUMBER;
if (nbytes > (int) sizeof (long))
- objc_error (nil, OBJC_ERR_BAD_DATA, "expected long, got bigger");
+ _objc_abort ("expected long, got bigger");
len = (*stream->read) (stream->physical, (char*)buf + 1, nbytes);
(*value) = 0;
while (pos <= nbytes)
@@ -675,7 +672,7 @@ __objc_read_nbyte_uint (struct objc_typed_stream *stream,
unsigned char buf[sizeof (unsigned int) + 1];
if (nbytes > sizeof (int))
- objc_error (nil, OBJC_ERR_BAD_DATA, "expected int, got bigger");
+ _objc_abort ("expected int, got bigger");
len = (*stream->read) (stream->physical, (char*)buf, nbytes);
(*val) = 0;
@@ -712,7 +709,7 @@ __objc_read_nbyte_ulong (struct objc_typed_stream *stream,
unsigned char buf[sizeof (unsigned long) + 1];
if (nbytes > sizeof (long))
- objc_error (nil, OBJC_ERR_BAD_DATA, "expected long, got bigger");
+ _objc_abort ("expected long, got bigger");
len = (*stream->read) (stream->physical, (char*)buf, nbytes);
(*val) = 0;
@@ -793,8 +790,7 @@ objc_read_string (struct objc_typed_stream *stream,
break;
default:
- objc_error (nil, OBJC_ERR_BAD_DATA,
- "expected string, got opcode %c\n", (buf[0]&_B_CODE));
+ _objc_abort ("expected string, got opcode %c\n", (buf[0]&_B_CODE));
}
}
@@ -839,14 +835,13 @@ objc_read_object (struct objc_typed_stream *stream, id *object)
/* check null-byte */
len = (*stream->read) (stream->physical, (char*)buf, 1);
if (buf[0] != '\0')
- objc_error (nil, OBJC_ERR_BAD_DATA,
- "expected null-byte, got opcode %c", buf[0]);
+ _objc_abort ("expected null-byte, got opcode %c", buf[0]);
}
else if ((buf[0]&_B_CODE) == _B_UCOMM)
{
if (key)
- objc_error (nil, OBJC_ERR_BAD_KEY, "cannot register use upcode...");
+ _objc_abort ("cannot register use upcode...");
len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key);
(*object) = objc_hash_value_for_key (stream->object_table,
LONG2PTR(key));
@@ -866,15 +861,13 @@ objc_read_object (struct objc_typed_stream *stream, id *object)
else if (buf[0] == (_B_EXT | _BX_OBJROOT)) /* a root object */
{
if (key)
- objc_error (nil, OBJC_ERR_BAD_KEY,
- "cannot register root object...");
+ _objc_abort ("cannot register root object...");
len = objc_read_object (stream, object);
__objc_finish_read_root_object (stream);
}
else
- objc_error (nil, OBJC_ERR_BAD_DATA,
- "expected object, got opcode %c", buf[0]);
+ _objc_abort ("expected object, got opcode %c", buf[0]);
}
return len;
}
@@ -917,18 +910,16 @@ objc_read_class (struct objc_typed_stream *stream, Class *class)
else if ((buf[0]&_B_CODE) == _B_UCOMM)
{
if (key)
- objc_error (nil, OBJC_ERR_BAD_KEY, "cannot register use upcode...");
+ _objc_abort ("cannot register use upcode...");
len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key);
*class = objc_hash_value_for_key (stream->stream_table,
LONG2PTR(key));
if (! *class)
- objc_error (nil, OBJC_ERR_BAD_CLASS,
- "cannot find class for key %lu", key);
+ _objc_abort ("cannot find class for key %lu", key);
}
else
- objc_error (nil, OBJC_ERR_BAD_DATA,
- "expected class, got opcode %c", buf[0]);
+ _objc_abort ("expected class, got opcode %c", buf[0]);
}
return len;
}
@@ -974,15 +965,14 @@ objc_read_selector (struct objc_typed_stream *stream, SEL* selector)
else if ((buf[0]&_B_CODE) == _B_UCOMM)
{
if (key)
- objc_error (nil, OBJC_ERR_BAD_KEY, "cannot register use upcode...");
+ _objc_abort ("cannot register use upcode...");
len = __objc_read_nbyte_ulong (stream, (buf[0] & _B_VALUE), &key);
(*selector) = objc_hash_value_for_key (stream->stream_table,
LONG2PTR(key));
}
else
- objc_error (nil, OBJC_ERR_BAD_DATA,
- "expected selector, got opcode %c", buf[0]);
+ _objc_abort ("expected selector, got opcode %c", buf[0]);
}
return len;
}
@@ -1082,8 +1072,7 @@ objc_write_type (TypedStream *stream, const char *type, const void *data)
default:
{
- objc_error (nil, OBJC_ERR_BAD_TYPE,
- "objc_write_type: cannot parse typespec: %s\n", type);
+ _objc_abort ("objc_write_type: cannot parse typespec: %s\n", type);
return 0;
}
}
@@ -1178,8 +1167,7 @@ objc_read_type(TypedStream *stream, const char *type, void *data)
default:
{
- objc_error (nil, OBJC_ERR_BAD_TYPE,
- "objc_read_type: cannot parse typespec: %s\n", type);
+ _objc_abort ("objc_read_type: cannot parse typespec: %s\n", type);
return 0;
}
}
@@ -1276,13 +1264,12 @@ objc_write_types (TypedStream *stream, const char *type, ...)
res = objc_write_array (stream, t, len, va_arg (args, void *));
t = objc_skip_typespec (t);
if (*t != _C_ARY_E)
- objc_error (nil, OBJC_ERR_BAD_TYPE, "expected `]', got: %s", t);
+ _objc_abort ("expected `]', got: %s", t);
}
break;
default:
- objc_error (nil, OBJC_ERR_BAD_TYPE,
- "objc_write_types: cannot parse typespec: %s\n", type);
+ _objc_abort ("objc_write_types: cannot parse typespec: %s\n", type);
}
}
va_end(args);
@@ -1368,13 +1355,12 @@ objc_read_types(TypedStream *stream, const char *type, ...)
res = objc_read_array (stream, t, len, va_arg (args, void *));
t = objc_skip_typespec (t);
if (*t != _C_ARY_E)
- objc_error (nil, OBJC_ERR_BAD_TYPE, "expected `]', got: %s", t);
+ _objc_abort ("expected `]', got: %s", t);
}
break;
default:
- objc_error (nil, OBJC_ERR_BAD_TYPE,
- "objc_read_types: cannot parse typespec: %s\n", type);
+ _objc_abort ("objc_read_types: cannot parse typespec: %s\n", type);
}
}
va_end (args);
@@ -1446,7 +1432,7 @@ __objc_no_write (FILE *file __attribute__ ((__unused__)),
const char *data __attribute__ ((__unused__)),
int len __attribute__ ((__unused__)))
{
- objc_error (nil, OBJC_ERR_NO_WRITE, "TypedStream not open for writing");
+ _objc_abort ("TypedStream not open for writing");
return 0;
}
@@ -1455,7 +1441,7 @@ __objc_no_read (FILE *file __attribute__ ((__unused__)),
const char *data __attribute__ ((__unused__)),
int len __attribute__ ((__unused__)))
{
- objc_error (nil, OBJC_ERR_NO_READ, "TypedStream not open for reading");
+ _objc_abort ("TypedStream not open for reading");
return 0;
}
@@ -1470,8 +1456,7 @@ __objc_read_typed_stream_signature (TypedStream *stream)
;
sscanf (buffer, "GNU TypedStream %d", &stream->version);
if (stream->version != OBJC_TYPED_STREAM_VERSION)
- objc_error (nil, OBJC_ERR_STREAM_VERSION,
- "cannot handle TypedStream version %d", stream->version);
+ _objc_abort ("cannot handle TypedStream version %d", stream->version);
return 1;
}
diff --git a/libobjc/class.c b/libobjc/class.c
index 37b2b4eebf9..76f9e8feecd 100644
--- a/libobjc/class.c
+++ b/libobjc/class.c
@@ -88,6 +88,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
structures is freeing data when is removed from the structures. */
#include "objc-private/common.h"
+#include "objc-private/error.h"
#include "objc/objc.h"
#include "objc/objc-api.h"
#include "objc/thr.h"
@@ -500,8 +501,9 @@ objc_get_class (const char *name)
if (class)
return class;
- objc_error (nil, OBJC_ERR_BAD_CLASS,
- "objc runtime: cannot find class %s\n", name);
+ /* FIXME: Should we abort the program here ? */
+ _objc_abort ("objc runtime: cannot find class %s\n", name);
+
return 0;
}
diff --git a/libobjc/encoding.c b/libobjc/encoding.c
index 5694530a220..c0d79d9f349 100644
--- a/libobjc/encoding.c
+++ b/libobjc/encoding.c
@@ -27,7 +27,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
/* FIXME: This file has no business including tm.h. */
+/* FIXME: This file contains functions that will abort the entire
+ program if they fail. Is that really needed ?
+*/
+
#include "objc-private/common.h"
+#include "objc-private/error.h"
#include "tconfig.h"
#include "coretypes.h"
#include "tm.h"
@@ -316,8 +321,11 @@ objc_sizeof_type (const char *type)
default:
{
- objc_error (nil, OBJC_ERR_BAD_TYPE, "unknown complex type %s\n",
- type);
+ /* FIXME: Is this so bad that we have to abort the
+ entire program ? (it applies to all the other
+ _objc_abort calls in this file).
+ */
+ _objc_abort ("unknown complex type %s\n", type);
return 0;
}
}
@@ -325,7 +333,7 @@ objc_sizeof_type (const char *type)
default:
{
- objc_error (nil, OBJC_ERR_BAD_TYPE, "unknown type %s\n", type);
+ _objc_abort ("unknown type %s\n", type);
return 0;
}
}
@@ -491,8 +499,7 @@ objc_alignof_type (const char *type)
default:
{
- objc_error (nil, OBJC_ERR_BAD_TYPE, "unknown complex type %s\n",
- type);
+ _objc_abort ("unknown complex type %s\n", type);
return 0;
}
}
@@ -500,7 +507,7 @@ objc_alignof_type (const char *type)
default:
{
- objc_error (nil, OBJC_ERR_BAD_TYPE, "unknown type %s\n", type);
+ _objc_abort ("unknown type %s\n", type);
return 0;
}
}
@@ -643,7 +650,7 @@ objc_skip_typespec (const char *type)
return ++type;
else
{
- objc_error (nil, OBJC_ERR_BAD_TYPE, "bad array type %s\n", type);
+ _objc_abort ("bad array type %s\n", type);
return 0;
}
@@ -684,7 +691,7 @@ objc_skip_typespec (const char *type)
default:
{
- objc_error (nil, OBJC_ERR_BAD_TYPE, "unknown type %s\n", type);
+ _objc_abort ("unknown type %s\n", type);
return 0;
}
}
@@ -882,9 +889,8 @@ objc_layout_structure (const char *type,
if (*type != _C_UNION_B && *type != _C_STRUCT_B)
{
- objc_error (nil, OBJC_ERR_BAD_TYPE,
- "record (or union) type expected in objc_layout_structure, got %s\n",
- type);
+ _objc_abort ("record (or union) type expected in objc_layout_structure, got %s\n",
+ type);
}
type ++;
diff --git a/libobjc/error.c b/libobjc/error.c
new file mode 100644
index 00000000000..0dc8fd8dae0
--- /dev/null
+++ b/libobjc/error.c
@@ -0,0 +1,99 @@
+/* GNU Objective C Runtime Error Functions
+ Copyright (C) 1993, 1994, 1995, 1996, 1997, 2002, 2009, 2010
+ Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC 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 3, or (at your option) any
+later version.
+
+GCC 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.
+
+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/>. */
+
+#include "objc-private/common.h"
+#include "objc-private/error.h"
+
+/* __USE_FIXED_PROTOTYPES__ used to be required to get prototypes for
+ malloc, free, etc. on some platforms. It is unclear if we still
+ need it, but it can't hurt.
+*/
+#define __USE_FIXED_PROTOTYPES__
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+
+/* Prints an error message and aborts the program. */
+void
+_objc_abort (const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start (ap, fmt);
+ vfprintf (stderr, fmt, ap);
+ abort ();
+ va_end (ap);
+}
+
+/* The rest of the file is deprecated. */
+#include "objc/objc.h"
+#include "objc/objc-api.h"
+
+/*
+** Error handler function
+** NULL so that default is to just print to stderr
+*/
+static objc_error_handler _objc_error_handler = NULL;
+
+/* Trigger an objc error */
+void
+objc_error (id object, int code, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start (ap, fmt);
+ objc_verror (object, code, fmt, ap);
+ va_end (ap);
+}
+
+/* Trigger an objc error */
+void
+objc_verror (id object, int code, const char *fmt, va_list ap)
+{
+ BOOL result = NO;
+
+ /* Call the error handler if its there
+ Otherwise print to stderr */
+ if (_objc_error_handler)
+ result = (*_objc_error_handler) (object, code, fmt, ap);
+ else
+ vfprintf (stderr, fmt, ap);
+
+ /* Continue if the error handler says its ok
+ Otherwise abort the program */
+ if (result)
+ return;
+ else
+ abort ();
+}
+
+/* Set the error handler */
+objc_error_handler
+objc_set_error_handler (objc_error_handler func)
+{
+ objc_error_handler temp = _objc_error_handler;
+ _objc_error_handler = func;
+ return temp;
+}
diff --git a/libobjc/init.c b/libobjc/init.c
index 75e0b1036ea..de624cf79c1 100644
--- a/libobjc/init.c
+++ b/libobjc/init.c
@@ -25,6 +25,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */
#include "objc-private/common.h"
+#include "objc-private/error.h"
#include "objc/objc.h"
#include "objc/objc-api.h"
#include "objc/thr.h"
@@ -824,17 +825,8 @@ init_check_module_version (Module_t module)
{
if ((module->version != OBJC_VERSION) || (module->size != sizeof (Module)))
{
- int code;
-
- if (module->version > OBJC_VERSION)
- code = OBJC_ERR_OBJC_VERSION;
- else if (module->version < OBJC_VERSION)
- code = OBJC_ERR_GCC_VERSION;
- else
- code = OBJC_ERR_MODULE_SIZE;
-
- objc_error (nil, code, "Module %s version %d doesn't match runtime %d\n",
- module->name, (int)module->version, OBJC_VERSION);
+ _objc_abort ("Module %s version %d doesn't match runtime %d\n",
+ module->name, (int)module->version, OBJC_VERSION);
}
}
@@ -876,11 +868,10 @@ __objc_init_protocols (struct objc_protocol_list *protos)
}
else if (protos->list[i]->class_pointer != proto_class)
{
- objc_error (nil, OBJC_ERR_PROTOCOL_VERSION,
- "Version %d doesn't match runtime protocol version %d\n",
- (int) ((char *) protos->list[i]->class_pointer
- - (char *) 0),
- PROTOCOL_VERSION);
+ _objc_abort ("Version %d doesn't match runtime protocol version %d\n",
+ (int) ((char *) protos->list[i]->class_pointer
+ - (char *) 0),
+ PROTOCOL_VERSION);
}
}
diff --git a/libobjc/libobjc.def b/libobjc/libobjc.def
index 27be47e0c0e..2d27fa5dce3 100644
--- a/libobjc/libobjc.def
+++ b/libobjc/libobjc.def
@@ -16,6 +16,8 @@
; You should have received a copy of the GNU General Public License along with
; GCC; see the file COPYING3. If not, see <http://www.gnu.org/licenses/>.
+; FIXME: This file needs to be updated or removed
+
LIBRARY libobjc
EXPORTS
search_for_method_in_list
diff --git a/libobjc/misc.c b/libobjc/memory.c
index fde1f308671..2cb4dd360d0 100644
--- a/libobjc/misc.c
+++ b/libobjc/memory.c
@@ -1,5 +1,5 @@
-/* GNU Objective C Runtime Miscellaneous
- Copyright (C) 1993, 1994, 1995, 1996, 1997, 2002, 2009
+/* GNU Objective C Runtime Memory allocation functions
+ Copyright (C) 1993, 1994, 1995, 1996, 1997, 2002, 2009, 2010
Free Software Foundation, Inc.
Contributed by Kresten Krab Thorup
@@ -25,6 +25,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */
#include "objc-private/common.h"
+#include "objc-private/error.h"
/* __USE_FIXED_PROTOTYPES__ used to be required to get prototypes for
malloc, free, etc. on some platforms. It is unclear if we still
@@ -38,57 +39,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#include "objc-private/runtime.h"
/*
-** Error handler function
-** NULL so that default is to just print to stderr
-*/
-static objc_error_handler _objc_error_handler = NULL;
-
-/* Trigger an objc error */
-void
-objc_error (id object, int code, const char *fmt, ...)
-{
- va_list ap;
-
- va_start (ap, fmt);
- objc_verror (object, code, fmt, ap);
- va_end (ap);
-}
-
-/* Trigger an objc error */
-void
-objc_verror (id object, int code, const char *fmt, va_list ap)
-{
- BOOL result = NO;
-
- /* Call the error handler if its there
- Otherwise print to stderr */
- if (_objc_error_handler)
- result = (*_objc_error_handler) (object, code, fmt, ap);
- else
- vfprintf (stderr, fmt, ap);
-
- /* Continue if the error handler says its ok
- Otherwise abort the program */
- if (result)
- return;
- else
- abort ();
-}
-
-/* Set the error handler */
-objc_error_handler
-objc_set_error_handler (objc_error_handler func)
-{
- objc_error_handler temp = _objc_error_handler;
- _objc_error_handler = func;
- return temp;
-}
-
-/*
-** 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
+ properly with garbage collectors as well as can take advantage of
+ the exception/error handling available.
*/
void *
@@ -96,7 +50,7 @@ objc_malloc (size_t size)
{
void *res = (void *) (*_objc_malloc) (size);
if (! res)
- objc_error (nil, OBJC_ERR_MEMORY, "Virtual memory exhausted\n");
+ _objc_abort ("Virtual memory exhausted\n");
return res;
}
@@ -105,7 +59,7 @@ objc_atomic_malloc (size_t size)
{
void *res = (void *) (*_objc_atomic_malloc) (size);
if (! res)
- objc_error (nil, OBJC_ERR_MEMORY, "Virtual memory exhausted\n");
+ _objc_abort ("Virtual memory exhausted\n");
return res;
}
@@ -114,7 +68,7 @@ objc_valloc (size_t size)
{
void *res = (void *) (*_objc_valloc) (size);
if (! res)
- objc_error (nil, OBJC_ERR_MEMORY, "Virtual memory exhausted\n");
+ _objc_abort ("Virtual memory exhausted\n");
return res;
}
@@ -123,7 +77,7 @@ objc_realloc (void *mem, size_t size)
{
void *res = (void *) (*_objc_realloc) (mem, size);
if (! res)
- objc_error (nil, OBJC_ERR_MEMORY, "Virtual memory exhausted\n");
+ _objc_abort ("Virtual memory exhausted\n");
return res;
}
@@ -132,7 +86,7 @@ objc_calloc (size_t nelem, size_t size)
{
void *res = (void *) (*_objc_calloc) (nelem, size);
if (! res)
- objc_error (nil, OBJC_ERR_MEMORY, "Virtual memory exhausted\n");
+ _objc_abort ("Virtual memory exhausted\n");
return res;
}
@@ -143,25 +97,28 @@ 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.
+ 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.
*/
#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!
+*/
static void *
GC_calloc (size_t nelem, size_t size)
{
void *p = GC_malloc (nelem * size);
if (! p)
- objc_error (nil, OBJC_ERR_MEMORY, "Virtual memory exhausted!\n");
+ _objc_abort ("Virtual memory exhausted!\n");
memset (p, 0, nelem * size);
return p;
diff --git a/libobjc/objc-private/error.h b/libobjc/objc-private/error.h
new file mode 100644
index 00000000000..2df9cb733ec
--- /dev/null
+++ b/libobjc/objc-private/error.h
@@ -0,0 +1,37 @@
+/* GNU Objective C Runtime Common Private Definitions
+ Copyright (C) 2010 Free Software Foundation, Inc.
+ Contributed by Nicola Pero
+
+This file is part of GCC.
+
+GCC 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 3, or (at your option) any later version.
+
+GCC 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.
+
+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/>. */
+
+#ifndef __objc_private_error_INCLUDE_GNU
+#define __objc_private_error_INCLUDE_GNU
+
+/* Prints an unrecoverable error to stderr, then aborts the program.
+ This should only be used for errors that really are unrecorevable:
+ failure to allocate memory, and failure to load an Objective-C
+ module. All other usages of this function should be converted into
+ some milder type of error.
+*/
+void
+_objc_abort (const char *fmt, ...);
+
+#endif /* __objc_private_error_INCLUDE_GNU */
diff --git a/libobjc/objc/deprecated/objc_error.h b/libobjc/objc/deprecated/objc_error.h
new file mode 100644
index 00000000000..7a7ebe941b2
--- /dev/null
+++ b/libobjc/objc/deprecated/objc_error.h
@@ -0,0 +1,56 @@
+/* This API is incredibly limited and unsophisticated. objc_error()
+ generally causes the program to abort, so it should only be used
+ when something so dramatic happens that it could be pointless to
+ continue. Only two cases I can think of: failure to allocate new
+ memory or failure to load an Objective-C module.
+*/
+/* Error handling
+
+ Call objc_error() or objc_verror() to record an error; this error
+ routine will generally exit the program but not necessarily if the
+ user has installed his own error handler.
+
+ Call objc_set_error_handler to assign your own function for
+ handling errors. The function should return YES if it is ok
+ to continue execution, or return NO or just abort if the
+ program should be stopped. The default error handler is just to
+ print a message on stderr.
+
+ The error handler function should be of type objc_error_handler
+ The first parameter is an object instance of relevance.
+ The second parameter is an error code.
+ The third parameter is a format string in the printf style.
+ The fourth parameter is a variable list of arguments. */
+void objc_error(id object, int code, const char* fmt, ...);
+void objc_verror(id object, int code, const char* fmt, va_list ap);
+typedef BOOL (*objc_error_handler)(id, int code, const char *fmt, va_list ap);
+objc_error_handler objc_set_error_handler(objc_error_handler func);
+
+/* Error codes
+ These are used by the runtime library, and your
+ error handling may use them to determine if the error is
+ hard or soft thus whether execution can continue or abort. */
+#define OBJC_ERR_UNKNOWN 0 /* Generic error */
+
+#define OBJC_ERR_OBJC_VERSION 1 /* Incorrect runtime version */
+#define OBJC_ERR_GCC_VERSION 2 /* Incorrect compiler version */
+#define OBJC_ERR_MODULE_SIZE 3 /* Bad module size */
+#define OBJC_ERR_PROTOCOL_VERSION 4 /* Incorrect protocol version */
+
+#define OBJC_ERR_MEMORY 10 /* Out of memory */
+
+#define OBJC_ERR_RECURSE_ROOT 20 /* Attempt to archive the root
+ object more than once. */
+#define OBJC_ERR_BAD_DATA 21 /* Didn't read expected data */
+#define OBJC_ERR_BAD_KEY 22 /* Bad key for object */
+#define OBJC_ERR_BAD_CLASS 23 /* Unknown class */
+#define OBJC_ERR_BAD_TYPE 24 /* Bad type specification */
+#define OBJC_ERR_NO_READ 25 /* Cannot read stream */
+#define OBJC_ERR_NO_WRITE 26 /* Cannot write stream */
+#define OBJC_ERR_STREAM_VERSION 27 /* Incorrect stream version */
+#define OBJC_ERR_BAD_OPCODE 28 /* Bad opcode */
+
+#define OBJC_ERR_UNIMPLEMENTED 30 /* Method is not implemented */
+
+#define OBJC_ERR_BAD_STATE 40 /* Bad thread state */
+
diff --git a/libobjc/objc/objc-api.h b/libobjc/objc/objc-api.h
index 0ae4322005b..89c5fcd9f3b 100644
--- a/libobjc/objc/objc-api.h
+++ b/libobjc/objc/objc-api.h
@@ -83,55 +83,7 @@ struct objc_method_description
#define _C_COMPLEX 'j'
-/* Error handling
-
- Call objc_error() or objc_verror() to record an error; this error
- routine will generally exit the program but not necessarily if the
- user has installed his own error handler.
-
- Call objc_set_error_handler to assign your own function for
- handling errors. The function should return YES if it is ok
- to continue execution, or return NO or just abort if the
- program should be stopped. The default error handler is just to
- print a message on stderr.
-
- The error handler function should be of type objc_error_handler
- The first parameter is an object instance of relevance.
- The second parameter is an error code.
- The third parameter is a format string in the printf style.
- The fourth parameter is a variable list of arguments. */
-extern void objc_error(id object, int code, const char* fmt, ...);
-extern void objc_verror(id object, int code, const char* fmt, va_list ap);
-typedef BOOL (*objc_error_handler)(id, int code, const char *fmt, va_list ap);
-extern objc_error_handler objc_set_error_handler(objc_error_handler func);
-
-/* Error codes
- These are used by the runtime library, and your
- error handling may use them to determine if the error is
- hard or soft thus whether execution can continue or abort. */
-#define OBJC_ERR_UNKNOWN 0 /* Generic error */
-
-#define OBJC_ERR_OBJC_VERSION 1 /* Incorrect runtime version */
-#define OBJC_ERR_GCC_VERSION 2 /* Incorrect compiler version */
-#define OBJC_ERR_MODULE_SIZE 3 /* Bad module size */
-#define OBJC_ERR_PROTOCOL_VERSION 4 /* Incorrect protocol version */
-
-#define OBJC_ERR_MEMORY 10 /* Out of memory */
-
-#define OBJC_ERR_RECURSE_ROOT 20 /* Attempt to archive the root
- object more than once. */
-#define OBJC_ERR_BAD_DATA 21 /* Didn't read expected data */
-#define OBJC_ERR_BAD_KEY 22 /* Bad key for object */
-#define OBJC_ERR_BAD_CLASS 23 /* Unknown class */
-#define OBJC_ERR_BAD_TYPE 24 /* Bad type specification */
-#define OBJC_ERR_NO_READ 25 /* Cannot read stream */
-#define OBJC_ERR_NO_WRITE 26 /* Cannot write stream */
-#define OBJC_ERR_STREAM_VERSION 27 /* Incorrect stream version */
-#define OBJC_ERR_BAD_OPCODE 28 /* Bad opcode */
-
-#define OBJC_ERR_UNIMPLEMENTED 30 /* Method is not implemented */
-
-#define OBJC_ERR_BAD_STATE 40 /* Bad thread state */
+#include "deprecated/objc_error.h"
/* For every class which happens to have statically allocated instances in
diff --git a/libobjc/sendmsg.c b/libobjc/sendmsg.c
index 3bf28b97588..32d9dc7bea6 100644
--- a/libobjc/sendmsg.c
+++ b/libobjc/sendmsg.c
@@ -29,6 +29,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
and friends. */
#include "objc-private/common.h"
+#include "objc-private/error.h"
#include "tconfig.h"
#include "coretypes.h"
#include "tm.h"
@@ -661,6 +662,7 @@ __objc_forward (id object, SEL sel, arglist_t args)
: "instance" ),
object->class_pointer->name, sel_get_name (sel));
+ /* TODO: support for error: is surely deprecated ? */
err_sel = sel_get_any_uid ("error:");
if (__objc_responds_to (object, err_sel))
{
@@ -670,7 +672,7 @@ __objc_forward (id object, SEL sel, arglist_t args)
/* The object doesn't respond to doesNotRecognize: or error:; Therefore,
a default action is taken. */
- objc_error (object, OBJC_ERR_UNIMPLEMENTED, "%s\n", msg);
+ _objc_abort ("%s\n", msg);
return 0;
}
diff --git a/libobjc/thr.c b/libobjc/thr.c
index 0a5853608d6..50196e81c58 100644
--- a/libobjc/thr.c
+++ b/libobjc/thr.c
@@ -23,6 +23,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */
#include "objc-private/common.h"
+#include "objc-private/error.h"
#define _LIBOBJC
/* The line below is needed for declarations of functions such as
pthread_mutexattr_settype, without which gthr-posix.h may fail to
@@ -129,12 +130,16 @@ __objc_thread_detach_function (struct __objc_thread_start_state *istate)
if ((imp = (id (*) (id, SEL, id))objc_msg_lookup (object, selector)))
(*imp) (object, selector, argument);
else
- objc_error (object, OBJC_ERR_UNIMPLEMENTED,
- "objc_thread_detach called with bad selector.\n");
+ {
+ /* FIXME: Should we abort here ? */
+ _objc_abort ("objc_thread_detach called with bad selector.\n");
+ }
}
else
- objc_error (nil, OBJC_ERR_BAD_STATE,
- "objc_thread_detach called with NULL state.\n");
+ {
+ /* FIXME: Should we abort here ? */
+ _objc_abort ("objc_thread_detach called with NULL state.\n");
+ }
/* Exit the thread */
objc_thread_exit ();