2001-12-17 14:31:42 +00:00
|
|
|
/** NSAssertionHandler - Object encapsulation of assertions
|
1997-01-06 22:40:16 +00:00
|
|
|
Copyright (C) 1995, 1997 Free Software Foundation, Inc.
|
1995-04-10 00:34:30 +00:00
|
|
|
|
1995-04-10 00:10:51 +00:00
|
|
|
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
|
|
|
Date: Apr 1995
|
1995-04-10 00:34:30 +00:00
|
|
|
|
1996-05-12 00:56:10 +00:00
|
|
|
This file is part of the GNUstep Base Library.
|
1995-04-10 00:34:30 +00:00
|
|
|
|
1995-04-10 00:10:51 +00:00
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library 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
|
|
|
|
Library General Public License for more details.
|
1995-04-10 00:34:30 +00:00
|
|
|
|
1995-04-10 00:10:51 +00:00
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
License along with this library; if not, write to the Free
|
1999-09-09 02:56:20 +00:00
|
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
2001-12-18 16:54:15 +00:00
|
|
|
|
|
|
|
<title>NSAssertionHandler class reference</title>
|
|
|
|
$Date$ $Revision$
|
1995-04-10 00:34:30 +00:00
|
|
|
*/
|
1997-09-01 21:59:51 +00:00
|
|
|
|
1997-11-06 00:51:23 +00:00
|
|
|
#include <config.h>
|
2000-06-14 04:03:56 +00:00
|
|
|
#include <base/preface.h>
|
1995-04-17 21:13:20 +00:00
|
|
|
#include <Foundation/NSException.h>
|
1997-03-03 19:51:04 +00:00
|
|
|
#include <Foundation/NSDictionary.h>
|
1997-09-01 21:59:51 +00:00
|
|
|
#include <Foundation/NSObjCRuntime.h>
|
1995-04-17 21:13:20 +00:00
|
|
|
#include <Foundation/NSString.h>
|
1997-03-03 19:51:04 +00:00
|
|
|
#include <Foundation/NSThread.h>
|
1995-04-10 00:10:51 +00:00
|
|
|
|
|
|
|
@implementation NSAssertionHandler
|
|
|
|
|
1997-03-03 19:51:04 +00:00
|
|
|
/* Key for thread dictionary. */
|
|
|
|
static NSString *dict_key = @"_NSAssertionHandler";
|
|
|
|
|
2002-05-03 07:51:28 +00:00
|
|
|
/**
|
|
|
|
* Returns the assertion handler object for the current thread.<br />
|
|
|
|
* If none exists, creates one and returns it.
|
|
|
|
*/
|
2001-04-11 12:30:32 +00:00
|
|
|
+ (NSAssertionHandler*) currentHandler
|
1995-04-10 00:10:51 +00:00
|
|
|
{
|
2001-04-11 12:30:32 +00:00
|
|
|
NSMutableDictionary *dict;
|
|
|
|
NSAssertionHandler *handler;
|
1997-03-03 19:51:04 +00:00
|
|
|
|
1999-04-19 14:29:52 +00:00
|
|
|
dict = GSCurrentThreadDictionary();
|
1997-03-03 19:51:04 +00:00
|
|
|
handler = [dict objectForKey: dict_key];
|
|
|
|
if (handler == nil)
|
|
|
|
{
|
|
|
|
handler = [[NSAssertionHandler alloc] init];
|
|
|
|
[dict setObject: handler forKey: dict_key];
|
2002-05-03 08:17:04 +00:00
|
|
|
RELEASE(handler);
|
1997-03-03 19:51:04 +00:00
|
|
|
}
|
|
|
|
return handler;
|
1995-04-10 00:10:51 +00:00
|
|
|
}
|
|
|
|
|
2002-05-03 07:51:28 +00:00
|
|
|
/**
|
|
|
|
* Handles an assertion failure by using NSLogv() to print an error
|
|
|
|
* message built from the supplied arguments, and then raising an
|
|
|
|
* NSInternalInconsistencyException
|
|
|
|
*/
|
2000-02-19 00:40:47 +00:00
|
|
|
- (void) handleFailureInFunction: (NSString*)functionName
|
|
|
|
file: (NSString*)fileName
|
|
|
|
lineNumber: (int)line
|
|
|
|
description: (NSString*)format,...
|
1995-04-10 00:10:51 +00:00
|
|
|
{
|
2001-04-11 12:30:32 +00:00
|
|
|
id message;
|
|
|
|
va_list ap;
|
1995-04-10 00:10:51 +00:00
|
|
|
|
1995-04-10 00:34:30 +00:00
|
|
|
va_start(ap, format);
|
1997-09-01 21:59:51 +00:00
|
|
|
message =
|
|
|
|
[NSString
|
2000-02-19 00:40:47 +00:00
|
|
|
stringWithFormat: @"%@:%d Assertion failed in %@. %@",
|
|
|
|
fileName, line, functionName, format];
|
1997-09-01 21:59:51 +00:00
|
|
|
NSLogv(message, ap);
|
|
|
|
|
2001-04-11 12:30:32 +00:00
|
|
|
[NSException raise: NSInternalInconsistencyException
|
|
|
|
format: message arguments: ap];
|
2002-05-03 07:51:28 +00:00
|
|
|
va_end(ap);
|
1995-04-10 00:34:30 +00:00
|
|
|
/* NOT REACHED */
|
1995-04-10 00:10:51 +00:00
|
|
|
}
|
|
|
|
|
2002-05-03 07:51:28 +00:00
|
|
|
/**
|
|
|
|
* Handles an assertion failure by using NSLogv() to print an error
|
|
|
|
* message built from the supplied arguments, and then raising an
|
|
|
|
* NSInternalInconsistencyException
|
|
|
|
*/
|
1997-01-06 22:40:16 +00:00
|
|
|
- (void) handleFailureInMethod: (SEL) aSelector
|
|
|
|
object: object
|
|
|
|
file: (NSString *) fileName
|
|
|
|
lineNumber: (int) line
|
|
|
|
description: (NSString *) format,...
|
1995-04-10 00:10:51 +00:00
|
|
|
{
|
2001-04-11 12:30:32 +00:00
|
|
|
id message;
|
|
|
|
va_list ap;
|
1995-04-10 00:10:51 +00:00
|
|
|
|
1995-04-10 00:34:30 +00:00
|
|
|
va_start(ap, format);
|
1997-09-01 21:59:51 +00:00
|
|
|
message =
|
|
|
|
[NSString
|
2002-03-12 12:48:11 +00:00
|
|
|
stringWithFormat: @"%@:%d Assertion failed in %@(%@), method %@. %@",
|
2001-05-29 02:38:22 +00:00
|
|
|
fileName, line, NSStringFromClass([object class]),
|
2002-03-12 12:48:11 +00:00
|
|
|
[object isInstance] ? @"instance" : @"class",
|
2001-05-29 02:38:22 +00:00
|
|
|
NSStringFromSelector(aSelector), format];
|
1997-09-01 21:59:51 +00:00
|
|
|
NSLogv(message, ap);
|
1997-01-06 22:40:16 +00:00
|
|
|
|
|
|
|
[NSException raise: NSInternalInconsistencyException
|
2001-04-11 12:30:32 +00:00
|
|
|
format: message arguments: ap];
|
1995-04-10 00:34:30 +00:00
|
|
|
va_end(ap);
|
|
|
|
/* NOT REACHED */
|
1995-04-10 00:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|