mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Add error functions for NeXT runtime.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@9946 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
93117bdbbd
commit
1f7efc480e
3 changed files with 92 additions and 1 deletions
|
@ -1,3 +1,8 @@
|
|||
2001-05-14 Adam Fedor <fedor@gnu.org>
|
||||
|
||||
* Headers/gnustep/base/objc-gnu2next.h: Add error prototypes.
|
||||
* Source/objc-gnu2next.m: Include preface.h, define error funcs.
|
||||
|
||||
2001-05-12 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSObject.m: Removed some unused obsolete code.
|
||||
|
|
|
@ -134,7 +134,41 @@ extern const char *objc_skip_argspec (const char* type);
|
|||
extern unsigned objc_get_type_qualifiers (const char* type);
|
||||
extern BOOL sel_types_match (const char* t1, const char* t2);
|
||||
|
||||
/* Error handling */
|
||||
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);
|
||||
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 */
|
||||
#endif /* NeXT_RUNTIME */
|
||||
|
||||
#endif /* __objc_gnu2next_h_GNUSTEP_BASE_INCLUDE */
|
||||
|
|
|
@ -23,7 +23,13 @@
|
|||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <base/objc-gnu2next.h>
|
||||
#include <base/preface.h>
|
||||
|
||||
#ifndef ROUND
|
||||
#define ROUND(V, A) \
|
||||
({ typeof(V) __v=(V); typeof(A) __a=(A); \
|
||||
__a*((__v+__a-1)/__a); })
|
||||
#endif
|
||||
|
||||
/*
|
||||
return the size of an object specified by type
|
||||
|
@ -516,4 +522,50 @@ objc_free(void *mem)
|
|||
(*_objc_free)(mem);
|
||||
}
|
||||
|
||||
/*
|
||||
** 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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue