Update NSError to 10.4 compatibility

Fix format string errors


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/branches/mswin-ng@23927 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Sheldon Gill 2006-10-21 03:09:52 +00:00
parent 8b1ef1ab48
commit c818fe501d
12 changed files with 256 additions and 144 deletions

View file

@ -1,3 +1,24 @@
2006-10-20 Sheldon Gill <sheldon@westnet.net.au>
* Source/NSException.m:
* Source/NSProcessInfo.m:
No longer need target_os. Hidden concrete class should be GS
Clean out need for GSArgZero
2006-10-19 Sheldon Gill <sheldon@westnet.net.au>
* Headers/Foundation/NSError.h:
* Source/NSError.m:
Update to Tiger compatible level
2006-10-18 Sheldon Gill <sheldon@westnet.net.au>
* SSL/GSSSLHandle.m:
Compilation fix
* Source/NSDistributedLock.m
* Source/win32/NSMessagePortNameServerWin32.m
Fix format string error
2006-10-18 Sheldon Gill <sheldon@westnet.net.au>
* Headers/Foundation/NSException.h:
@ -41,31 +62,31 @@
2006-10-03 Sheldon Gill <sheldon@westnet.net.au>
* Source\GSFileHandle.m:
* Source\GSFormat.m:
* Source\GSFTPURLHandle.m:
* Source\GSHTTPURLHandle.m:
* Source\GSStream.m:
* Source\NSData.m:
* Source\NSDistributedLock.m:
* Source\NSFileManager.m:
* Source\NSMessagePort.m:
* Source\NSPipe.m:
* Source\NSSocketPort.m:
* Source\NSTask.m:
* Source\NSThread.m:
* Source/GSFileHandle.m:
* Source/GSFormat.m:
* Source/GSFTPURLHandle.m:
* Source/GSHTTPURLHandle.m:
* Source/GSStream.m:
* Source/NSData.m:
* Source/NSDistributedLock.m:
* Source/NSFileManager.m:
* Source/NSMessagePort.m:
* Source/NSPipe.m:
* Source/NSSocketPort.m:
* Source/NSTask.m:
* Source/NSThread.m:
* Source\win32\GSFileHandleWin32.m:
* Source\win32\GSRunLoopCtxt.m:
* Source\win32\NSMessagePortNameServerWin32.m:
* Source\win32\NSMessagePortWin32.m:
* Source\win32\NSStreamWin32.m:
* Source/win32/GSFileHandleWin32.m:
* Source/win32/GSRunLoopCtxt.m:
* Source/win32/NSMessagePortNameServerWin32.m:
* Source/win32/NSMessagePortWin32.m:
* Source/win32/NSStreamWin32.m:
* Headers/Additions/GNUstepBase/GSObjCRuntime.h:
* Headers/Additions/GNUstepBase/GSFunctions.h:
* Additions\GSCompatibility.m:
* Additions\GSObjCRuntime.m:
* Additions\GSFunctions.m:
* Additions/GSCompatibility.m:
* Additions/GSObjCRuntime.m:
* Additions/GSFunctions.m:
Moved GSPrintf() and GSLastErrorStr() to GSFunctions
Altered GSLastErrorStr(long) to GSLastError(void)

View file

@ -3,31 +3,33 @@
Written by: Richard Frith-Macdonald <rfm@gnu.org>
Date: May 2004
Additions: Sheldon Gill <sheldon@westnet.net.au>
Date: Oct 2006
This file is part of the GNUstep Base Library.
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.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02111 USA.
AutogsdocSource: NSError.m
*/
*/
#ifndef __NSError_h_GNUSTEP_BASE_INCLUDE
#define __NSError_h_GNUSTEP_BASE_INCLUDE
#ifndef STRICT_OPENSTEP
#if OS_API_VERSION(100207,GS_API_LATEST)
#include <Foundation/NSObject.h>
@ -41,37 +43,64 @@ extern "C" {
* Key for user info dictionary component which describes the error in
* a human readable format.
*/
GS_EXPORT NSString* const NSLocalizedDescriptionKey;
GS_EXPORT const NSString *NSLocalizedDescriptionKey;
/**
* Where one error has caused another, the underlying error can be stored
* in the user info dictionary using this key.
*/
GS_EXPORT NSString* const NSUnderlyingErrorKey;
GS_EXPORT const NSString *NSUnderlyingErrorKey;
/**
* Domain for system errors (on MACH).
* Where the error relates to a particular file or directory, this
* key stores the particular path in question.
*/
GS_EXPORT NSString* const NSMACHErrorDomain;
/**
* Domain for system errors.
*/
GS_EXPORT NSString* const NSOSStatusErrorDomain;
/**
* Domain for system and system library errors.
*/
GS_EXPORT NSString* const NSPOSIXErrorDomain;
GS_EXPORT const NSString *NSFilePathErrorKey;
GS_EXPORT const NSString *NSStringEncodingErrorKey;
#if OS_API_VERSION(100400,GS_API_LATEST) && GS_API_VERSION(011400,GS_API_LATEST)
GS_EXPORT const NSString *NSLocalizedFailureReasonErrorKey;
GS_EXPORT const NSString *NSLocalizedRecoverySuggestionErrorKey;
GS_EXPORT const NSString *NSLocalizedRecoveryOptionsErrorKey;
GS_EXPORT const NSString *NSRecoveryAttempterErrorKey;
/**
* Error information class.
* Domain for errors generated in MS-Windows libraries.
*/
GS_EXPORT const NSString *GSMSWindowsErrorDomain;
#endif
/**
* Domain for kernel errors (on MACH).
*/
GS_EXPORT const NSString *NSMACHErrorDomain;
/**
* Domain for Carbon errors.
*/
GS_EXPORT const NSString *NSOSStatusErrorDomain;
/**
* Domain for errors from libc and such.
*/
GS_EXPORT const NSString *NSPOSIXErrorDomain;
/**
* <p>
* NSError objects encapsulate information about an error. This includes the
* domain where the error was generated, an integer error code for the
* specific error and a dictionary containing application defined information
* </p>
* <p>
* GNUstep provides localized descriptive strings for the NSPOSIXErrorDomain
* & GSMSWindowsErrorDomain.
* </p>
*/
// TODO: document what this is for, especially since it's not in OS X
@interface NSError : NSObject <NSCopying, NSCoding>
{
@private
int _code;
NSString *_domain;
NSDictionary *_userInfo;
int _code;
NSString *_domain;
NSDictionary *_userInfo;
}
/**
@ -101,18 +130,37 @@ GS_EXPORT NSString* const NSPOSIXErrorDomain;
code: (int)aCode
userInfo: (NSDictionary*)aDictionary;
/** <override-subclass />
/**
* Return a human readable description for the error.<br />
* The default implementation uses the value from the user info dictionary
* if it is available, otherwise it generates a generic one from domain
* and code.
* if it is available, otherwise it generates one from domain and code.
*/
- (NSString *)localizedDescription;
#if OS_API_VERSION(100400,GS_API_LATEST) && GS_API_VERSION(011400,GS_API_LATEST)
/**
* Returns a localised string explaining the reason why the error was
* generated and should be more descriptive and helpful than given by
* localizedDescription. If no localised failure reasons are available
* this will return nil;
*/
- (NSString *)localizedFailureReason;
/**
* Returns an array containing the localized titles of buttons appropriate for displaying in an alert panel.
*/
- (NSArray *)localizedRecoveryOptions;
- (NSString *)localizedRecoverySuggestion;
- (id)recoveryAttempter;
#endif
/**
* Return the user info for this instance (or nil if none is set)<br />
* The <code>NSLocalizedDescriptionKey</code> should locate a human readable
* description in the dictionary.<br />
* description in the dictionary.<br />
* The <code>NSUnderlyingErrorKey</code> key should locate an
* <code>NSError</code> instance if an error is available describing any
* underlying problem.<br />

View file

@ -18,7 +18,8 @@
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/
@ -106,7 +107,7 @@ sslError(int err, int e)
break;
case SSL_ERROR_SYSCALL:
str = [NSString stringWithFormat: @"Syscall error %d - %s",
e, GSLastErrorStr(e)];
e, GSErrorString(e)];
break;
case SSL_ERROR_SSL:
str = @"SSL Error: really helpful";

View file

@ -63,6 +63,7 @@ GSErrorString(long error_id)
#endif
}
// FIXME: This should be GSFPrintf
BOOL
GSPrintf (FILE *fptr, NSString* format, ...)
{

View file

@ -361,18 +361,16 @@ static RunLoopEventType typeForStream(NSStream *aStream)
NSError *theError;
#if defined(__MINGW32__)
errno = GetLastError(); // FIXME: Make this NSWin32ErrorDomain -SG
/*
theError = [NSError errorWithDomain: NSMSWindowsErrorDomain
theError = [NSError errorWithDomain: (NSString *)GSMSWindowsErrorDomain
code: GetLastError()
userInfo: nil];
#else
*/
#endif
theError = [NSError errorWithDomain: NSPOSIXErrorDomain
theError = [NSError errorWithDomain: (NSString *)NSPOSIXErrorDomain
code: errno
userInfo: nil];
NSLog(@"%@ error(%d): - %@", self, errno, GSLastError());
#endif
NSDebugLog(@"%@ error(%d): - %@", self, errno, GSLastError());
ASSIGN(_lastError, theError);
_currentStatus = NSStreamStatusError;
}

View file

@ -18,7 +18,8 @@
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
<title>NSDistributedLock class reference</title>
$Date$ $Revision$

View file

@ -3,6 +3,8 @@
Written by: Richard Frith-Macdonald <rfm@gnu.org>
Date: May 2004
Additions: Sheldon Gill <sheldon@westnet.net.au>
Date: Oct 2006
This file is part of the GNUstep Base Library.
@ -18,19 +20,38 @@
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/
#include <Foundation/NSDictionary.h>
#include <Foundation/NSString.h>
#include <Foundation/NSError.h>
#include <Foundation/NSCoder.h>
#include <Foundation/NSArray.h>
#include <Foundation/NSDictionary.h>
#include <Foundation/NSString.h>
#include <Foundation/NSError.h>
#include <Foundation/NSCoder.h>
#include <GNUstepBase/GSFunctions.h>
#include <GNUstepBase/Win32_Utilities.h>
/* ---- Error Keys ---- */
const NSString *NSLocalizedDescriptionKey = @"NSLocalizedDescriptionKey";
const NSString *NSUnderlyingErrorKey = @"NSUnderlyingErrorKey";
const NSString *NSFilePathErrorKey = @"NSFilePathErrorKey";
const NSString *NSStringEncodingErrorKey = @"NSStringEncodingErrorKey";
const NSString *NSLocalizedFailureReasonErrorKey = @"NSLocalizedFailureReasonErrorKey";
const NSString *NSLocalizedRecoverySuggestionErrorKey = @"NSLocalizedRecoverySuggestionErrorKey";
const NSString *NSLocalizedRecoveryOptionsErrorKey = @"NSLocalizedRecoveryOptionsErrorKey";
const NSString *NSRecoveryAttempterErrorKey = @"NSRecoveryAttempterErrorKey";
/* ---- Error Domains ---- */
const NSString *NSMACHErrorDomain = @"NSMACHErrorDomain";
const NSString *NSOSStatusErrorDomain = @"NSOSStatusErrorDomain";
const NSString *NSPOSIXErrorDomain = @"NSPOSIXErrorDomain";
const NSString *GSMSWindowsErrorDomain = @"GSMSWindowsErrorDomain";
NSString* const NSLocalizedDescriptionKey = @"NSLocalizedDescriptionKey";
NSString* const NSUnderlyingErrorKey = @"NSUnderlyingErrorKey";
NSString* const NSMACHErrorDomain = @"NSMACHErrorDomain";
NSString* const NSOSStatusErrorDomain = @"NSOSStatusErrorDomain";
NSString* const NSPOSIXErrorDomain = @"NSPOSIXErrorDomain";
@implementation NSError
@ -44,11 +65,6 @@ NSString* const NSPOSIXErrorDomain = @"NSPOSIXErrorDomain";
return AUTORELEASE(e);
}
- (int) code
{
return _code;
}
- (id) copyWithZone: (NSZone*)z
{
NSError *e = [[self class] allocWithZone: z];
@ -64,11 +80,6 @@ NSString* const NSPOSIXErrorDomain = @"NSPOSIXErrorDomain";
[super dealloc];
}
- (NSString*) domain
{
return _domain;
}
- (void) encodeWithCoder: (NSCoder*)aCoder
{
if ([aCoder allowsKeyedCoding])
@ -116,6 +127,7 @@ NSString* const NSPOSIXErrorDomain = @"NSPOSIXErrorDomain";
code: (int)aCode
userInfo: (NSDictionary*)aDictionary
{
// FIXME: This should be NSParameterAssert(), so it throws -SG
if (aDomain == nil)
{
NSLog(@"[%@-%@] with nil domain",
@ -131,20 +143,81 @@ NSString* const NSPOSIXErrorDomain = @"NSPOSIXErrorDomain";
return self;
}
- (NSString *)localizedDescription
- (int) code
{
NSString *desc = [_userInfo objectForKey: NSLocalizedDescriptionKey];
return _code;
}
- (NSString*) domain
{
return _domain;
}
- (NSString *) localizedDescription
{
NSString *desc = [_userInfo objectForKey: (NSString *)NSLocalizedDescriptionKey];
/*
* Autofill the description if it hasn't been specified
*/
if (desc == nil)
{
desc = [NSString stringWithFormat: @"%@ %d", _domain, _code];
if ([_domain isEqualToString: (NSString *)NSPOSIXErrorDomain])
{
/* It's the system/libc error code. */
return [NSString stringWithCString: strerror(_code)
encoding: [NSString defaultCStringEncoding]];
}
#if defined(__MACOSX__)
/* These only have meaning on MacOSX... */
else if ([_domain isEqualToString: NSOSStatusErrorDomain])
{
/* This only has meaning on Carbon... */
return [NSString stringWithFormat: @"%@",
GetMacOSStatusErrorString()];
}
else if ([_domain isEqualToString: NSMACHErrorDomain])
{
; // FIXME: How do we get error strings from MACH? -SG
}
#endif
#if defined(__MINGW32__)
/* This only has meaning on MS-Windows... */
else if ([_domain isEqualToString: (NSString *)GSMSWindowsErrorDomain])
{
return Win32ErrorString(_code);
}
#endif
else
{
desc = [NSString stringWithFormat: @"%@ Error#%d", _domain, _code];
}
}
return desc;
}
- (NSString *) localizedFailureReason
{
return [_userInfo objectForKey: (NSString *)NSLocalizedFailureReasonErrorKey];
}
- (NSArray *) localizedRecoveryOptions
{
return [_userInfo objectForKey: (NSString *)NSLocalizedRecoveryOptionsErrorKey];
}
- (NSString *) localizedRecoverySuggestion
{
return [_userInfo objectForKey: (NSString *)NSLocalizedRecoverySuggestionErrorKey];
}
- (id) recoveryAttempter
{
return [_userInfo objectForKey: (NSString *)NSRecoveryAttempterErrorKey];
}
- (NSDictionary*) userInfo
{
return _userInfo;
}
@end

View file

@ -599,10 +599,11 @@ static void _terminate()
static void
_NSFoundationUncaughtExceptionHandler (NSException *exception)
{
extern const char* GSArgZero(void);
NSString *process_name = [[NSProcessInfo processInfo] processName];
fprintf(stderr, "%s: Uncaught exception %s, reason: %s\n", GSArgZero(),
[[exception name] lossyCString], [[exception reason] lossyCString]);
fprintf(stderr, "%s: Uncaught exception %s\n Reason: %s\n",
[process_name lossyCString], [[exception name] lossyCString],
[[exception reason] lossyCString]);
fflush(stderr); /* NEEDED UNDER MINGW */
_terminate();

View file

@ -36,7 +36,7 @@
* behavior. The same is true for the meaning of argv[0] (process name).
* 2) The global variable _gnu_sharedProcessInfoObject should NEVER be
* deallocated during the process runtime. Therefore I implemented a
* concrete NSProcessInfo subclass (_NSConcreteProcessInfo) with the only
* concrete NSProcessInfo subclass (_GSConcreteProcessInfo) with the only
* purpose to override the autorelease, retain, and release methods.
* -----------------------------------------------------------------------
* TODO : Clean up the initialisation. Its too messy and confusing.
@ -100,16 +100,12 @@
#include "GSPrivate.h"
@interface NSBundle (Private)
+ (NSString*) _gnustep_target_os;
@end
/* This error message should be called only if the private main function
* was not executed successfully. This may happen ONLY if another library
* or kit defines its own main function (as gnustep-base does).
*/
#if GS_FAKE_MAIN
#define _GNU_MISSING_MAIN_FUNCTION_CALL @"\nGNUSTEP Internal Error:\n\
#define _GNU_MISSING_MAIN_FUNCTION_CALL @"GNUSTEP Internal Error\n\
The private GNUstep function to establish the argv and environment\n\
variables was not called.\n\
Perhaps your program failed to #include <Foundation/NSObject.h> or\n\
@ -117,18 +113,18 @@ Perhaps your program failed to #include <Foundation/NSObject.h> or\n\
If that is not the problem, Please report the error to bug-gnustep@gnu.org.\n\n"
#else
#ifdef GS_PASS_ARGUMENTS
#define _GNU_MISSING_MAIN_FUNCTION_CALL @"\nGNUSTEP Error:\n\
#define _GNU_MISSING_MAIN_FUNCTION_CALL @"GNUSTEP Error\n\
A call to NSProcessInfo +initializeWithArguments:... must be made\n\
as the first ObjC statment in main. This function is used to \n\
establish the argv and environment variables.\n"
#else
#define _GNU_MISSING_MAIN_FUNCTION_CALL @"\nGNUSTEP Internal Error:\n\
The private GNUstep function to establish the argv and environment\n\
variables was not called.\n\
#define _GNU_MISSING_MAIN_FUNCTION_CALL @"GNUSTEP Internal Error\n\
GNUstep failed to establish the argv and environment variables so it's\n\
unable to initialise properly.\n\
\n\
Mismatched library versions between GNUstep Foundation (base) and AppKit\n\
(gui) is most often the cause of this message. Please be sure you\n\
are using known compatible versions and not a mismatched set. Generally,\n\
Mismatched library versions between gnustep-base and gnustep-gui is most\n\
often the cause of this message. Please be sure you are using known\n\
compatible versions and not a mismatched set. Generally,\n\
we recommend you use versions of base and gui which were released together.\n\
\n\
For more detailed assistance, please report the error to bug-gnustep@gnu.org.\n\n"
@ -136,15 +132,15 @@ For more detailed assistance, please report the error to bug-gnustep@gnu.org.\n\
#endif
/*************************************************************************
*** _NSConcreteProcessInfo
*** _GSConcreteProcessInfo
*************************************************************************/
@interface _NSConcreteProcessInfo: NSProcessInfo
@interface _GSConcreteProcessInfo: NSProcessInfo
- (id) autorelease;
- (void) release;
- (id) retain;
@end
@implementation _NSConcreteProcessInfo
@implementation _GSConcreteProcessInfo
- (id) autorelease
{
return self;
@ -815,7 +811,7 @@ _gnu_noobjc_free_vars(void)
}
#else /*! HAVE_PROCFS !HAVE_LOAD_METHOD !HAVE_KVM_ENV */
#ifdef __MINGW32__
#if defined(__MINGW32__)
/* For WindowsAPI Library, we know the global variables (argc, etc) */
+ (void) initialize
{
@ -852,21 +848,6 @@ int main(int argc, char *argv[], char *env[])
sizeof(_NSConstantStringClassReference));
#endif
#if defined(__MINGW32__)
WSADATA lpWSAData;
// Initialize Windows Sockets
if (WSAStartup(MAKEWORD(1,1), &lpWSAData))
{
printf("Could not startup Windows Sockets\n");
exit(1);
}
#endif /* __MINGW32__ */
#ifdef __MS_WIN__
_MB_init_runtime();
#endif /* __MS_WIN__ */
_gnu_process_args(argc, argv, env);
/* Call the user defined main function */
@ -882,18 +863,19 @@ int main(int argc, char *argv[], char *env[])
*/
+ (NSProcessInfo *) processInfo
{
// Check if the main() function was successfully called
// Check if we're properly set up.
// We can't use NSAssert, which calls NSLog, which calls NSProcessInfo...
if (!(_gnu_processName && _gnu_arguments && _gnu_environment))
{
_NSLog_printf_handler(_GNU_MISSING_MAIN_FUNCTION_CALL);
_gnu_processName = @"";
_gnu_arguments = [NSArray arrayWithObjects: nil];
_gnu_environment = [NSDictionary dictionaryWithObjectsAndKeys: nil];
[NSException raise: NSInternalInconsistencyException
format: _GNU_MISSING_MAIN_FUNCTION_CALL];
format: _GNU_MISSING_MAIN_FUNCTION_CALL];
}
if (!_gnu_sharedProcessInfoObject)
{
_gnu_sharedProcessInfoObject = [[_NSConcreteProcessInfo alloc] init];
_gnu_sharedProcessInfoObject = [[_GSConcreteProcessInfo alloc] init];
}
return _gnu_sharedProcessInfoObject;
}
@ -1224,7 +1206,7 @@ BOOL GSDebugSet(NSString *level)
}
debugImp = [_debug_set methodForSelector: debugSel];
}
if ((*debugImp)(_debug_set, debugSel, level) == nil)
if (debugImp && ((*debugImp)(_debug_set, debugSel, level) == nil))
{
return NO;
}
@ -1259,18 +1241,3 @@ GSEnvironmentFlag(const char *name, BOOL def)
}
return a;
}
/**
* Used by NSException uncaught exception handler - must not call any
* methods/functions which might cause a recursive exception.
*/
const char*
GSArgZero(void)
{
if (_gnu_arg_zero == 0)
return "";
else
return _gnu_arg_zero;
}

View file

@ -1487,7 +1487,8 @@ static NSMapTable *absolutes = 0;
bufsize--;
}
localZoneString
= [NSString stringWithUTF8String: buf length: bufsize];
= [NSString stringWithCString: buf
length: bufsize];
}
RegCloseKey(regkey);
}

View file

@ -21,10 +21,10 @@
extern BOOL GSCheckTasks();
#if GS_WITH_GC == 0
static SEL wRelSel;
static SEL wRetSel;
static IMP wRelImp;
static IMP wRetImp;
SEL wRelSel;
SEL wRetSel;
IMP wRelImp;
IMP wRetImp;
static void
wRelease(NSMapTable* t, void* w)

View file

@ -312,7 +312,7 @@ OutputDebugStringW(L"");
}
else
{
NSLog(@"Failed to insert HKEY_CURRENT_USER\\%@\\%@ (%x) %s",
NSLog(@"Failed to insert HKEY_CURRENT_USER\\%@\\%@ (%x) %@",
registry, n, rc, GSLastError());
return NO;
}