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.
|
2005-02-22 11:22:44 +00:00
|
|
|
|
1995-04-10 00:10:51 +00:00
|
|
|
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
|
|
|
Date: Apr 1995
|
2005-02-22 11:22:44 +00:00
|
|
|
|
1996-05-12 00:56:10 +00:00
|
|
|
This file is part of the GNUstep Base Library.
|
2005-02-22 11:22:44 +00:00
|
|
|
|
1995-04-10 00:10:51 +00:00
|
|
|
This library is free software; you can redistribute it and/or
|
2007-09-14 11:36:11 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
1995-04-10 00:10:51 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2008-06-08 10:38:33 +00:00
|
|
|
version 2 of the License, or (at your option) any later version.
|
2005-02-22 11:22:44 +00:00
|
|
|
|
1995-04-10 00:10:51 +00:00
|
|
|
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
|
2019-12-09 23:36:00 +00:00
|
|
|
Lesser General Public License for more details.
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2007-09-14 11:36:11 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
1995-04-10 00:10:51 +00:00
|
|
|
License along with this library; if not, write to the Free
|
2024-11-07 13:37:59 +00:00
|
|
|
Software Foundation, Inc., 31 Milk Street #960789 Boston, MA 02196 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
|
|
|
|
2010-02-19 08:12:46 +00:00
|
|
|
#import "common.h"
|
2010-02-17 11:47:06 +00:00
|
|
|
#import "Foundation/NSException.h"
|
|
|
|
#import "Foundation/NSDictionary.h"
|
|
|
|
#import "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. */
|
2010-11-07 15:37:19 +00:00
|
|
|
NSString *const NSAssertionHandlerKey = @"NSAssertionHandler";
|
|
|
|
|
1997-03-03 19:51:04 +00:00
|
|
|
|
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();
|
2010-11-07 15:37:19 +00:00
|
|
|
handler = [dict objectForKey: NSAssertionHandlerKey];
|
1997-03-03 19:51:04 +00:00
|
|
|
if (handler == nil)
|
|
|
|
{
|
|
|
|
handler = [[NSAssertionHandler alloc] init];
|
2010-11-07 15:37:19 +00:00
|
|
|
[dict setObject: handler forKey: NSAssertionHandlerKey];
|
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
|
|
|
|
*/
|
2005-02-22 11:22:44 +00:00
|
|
|
- (void) handleFailureInFunction: (NSString*)functionName
|
|
|
|
file: (NSString*)fileName
|
2009-02-23 20:42:32 +00:00
|
|
|
lineNumber: (NSInteger)line
|
2000-02-19 00:40:47 +00:00
|
|
|
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
|
2013-07-03 06:46:41 +00:00
|
|
|
stringWithFormat: @"%@:%"PRIdPTR" Assertion failed in %@. %@",
|
2000-02-19 00:40:47 +00:00
|
|
|
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);
|
2011-07-24 13:09:22 +00:00
|
|
|
GS_UNREACHABLE();
|
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
|
2009-02-23 20:42:32 +00:00
|
|
|
lineNumber: (NSInteger) line
|
1997-01-06 22:40:16 +00:00
|
|
|
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 =
|
2013-07-03 06:46:41 +00:00
|
|
|
[NSString stringWithFormat:
|
|
|
|
@"%@:%"PRIdPTR" Assertion failed in %@(%@), method %@. %@",
|
2005-02-22 11:22:44 +00:00
|
|
|
fileName, line, NSStringFromClass([object class]),
|
2010-02-25 08:19:52 +00:00
|
|
|
class_isMetaClass([object class]) ? @"class" : @"instance",
|
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
|
|
|
|
2005-02-22 11:22:44 +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 */
|
2011-07-24 13:09:22 +00:00
|
|
|
GS_UNREACHABLE();
|
1995-04-10 00:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|