NSBundle.m: objc_executable_location(): A cast was obsuring a misuse of fileSystemRepresentation

NSFileManager.m: isExecutableFileAtPath: Added a comment
NSPropertyList.m: propertyListFromData:mutabilityOption:format:errorDescription: Don't call memcmp if the data is smaller than 8 bytes.
objc-load.m: mingw unicode
win32-load.h: mingw unicode
NSUserDefaultsWin32.m: Write defaults to registry as unicode strings, read in either unicode(REG_SZ) or ascii(REG_BINARY).


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@22782 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
jbettis 2006-04-12 19:52:10 +00:00
parent 2ee54ee5a6
commit 55c7cd74a5
6 changed files with 71 additions and 14 deletions

View file

@ -255,10 +255,14 @@ static NSString *ExecutablePath()
/* This function is provided for objc-load.c, although I'm not sure it /* This function is provided for objc-load.c, although I'm not sure it
really needs it (So far only needed if using GNU dld library) */ really needs it (So far only needed if using GNU dld library) */
#ifdef __MINGW32__
const unichar *
#else
const char * const char *
#endif
objc_executable_location (void) objc_executable_location (void)
{ {
return (const char*)[[ExecutablePath() stringByDeletingLastPathComponent] return [[ExecutablePath() stringByDeletingLastPathComponent]
fileSystemRepresentation]; fileSystemRepresentation];
} }

View file

@ -1491,6 +1491,7 @@ static NSStringEncoding defaultEncoding;
{ {
return NO; return NO;
} }
// TODO: Actually should check all extensions in env var PATHEXT
if ([[[path pathExtension] lowercaseString] isEqualToString: @"exe"]) if ([[[path pathExtension] lowercaseString] isEqualToString: @"exe"])
{ {
return YES; return YES;

View file

@ -2255,7 +2255,7 @@ GSPropertyListMake(id obj, NSDictionary *loc, BOOL xml,
{ {
bytes = [data bytes]; bytes = [data bytes];
length = [data length]; length = [data length];
if (length > 0 && memcmp(bytes, "bplist00", 8) == 0) if (length >= 8 && memcmp(bytes, "bplist00", 8) == 0)
{ {
format = NSPropertyListBinaryFormat_v1_0; format = NSPropertyListBinaryFormat_v1_0;
} }

View file

@ -55,7 +55,11 @@
#include "dynamic-load.h" #include "dynamic-load.h"
/* Declaration from NSBundle.m */ /* Declaration from NSBundle.m */
#ifdef __MINGW32__
const unichar *objc_executable_location (void);
#else
const char *objc_executable_location (void); const char *objc_executable_location (void);
#endif
/* dynamic_loaded is YES if the dynamic loader was sucessfully initialized. */ /* dynamic_loaded is YES if the dynamic loader was sucessfully initialized. */
static BOOL dynamic_loaded; static BOOL dynamic_loaded;
@ -101,7 +105,11 @@ objc_check_undefineds(FILE *errorStream)
static int static int
objc_initialize_loading(FILE *errorStream) objc_initialize_loading(FILE *errorStream)
{ {
#ifdef __MINGW32__
const unichar *path;
#else
const char *path; const char *path;
#endif
dynamic_loaded = NO; dynamic_loaded = NO;
path = objc_executable_location(); path = objc_executable_location();

View file

@ -34,7 +34,7 @@ typedef void* dl_symbol_t;
if no initialization needed. if no initialization needed.
*/ */
static int static int
__objc_dynamic_init(const char* exec_path) __objc_dynamic_init(const unichar* exec_path)
{ {
return 0; return 0;
} }

View file

@ -205,7 +205,7 @@ struct NSUserDefaultsWin32_DomainInfo
{ {
DWORD i = 0; DWORD i = 0;
unichar *name = malloc(200); unichar *name = malloc(200);
unsigned char *data = malloc(1000); unichar *data = malloc(1000);
DWORD namelenbuf = 100, datalenbuf = 1000; DWORD namelenbuf = 100, datalenbuf = 1000;
DWORD type; DWORD type;
@ -219,7 +219,7 @@ struct NSUserDefaultsWin32_DomainInfo
&namelen, &namelen,
NULL, NULL,
&type, &type,
data, (void*)data,
&datalen); &datalen);
if (rc == ERROR_SUCCESS) if (rc == ERROR_SUCCESS)
{ {
@ -228,12 +228,31 @@ struct NSUserDefaultsWin32_DomainInfo
id v; id v;
NSString *k; NSString *k;
v = [NSString stringWithCString: data switch (type) {
case REG_SZ: {
int datacharlen = datalen / 2;
if (datacharlen > 0 && data[datacharlen-1] == 0)
datacharlen--;
v = [NSString stringWithCharacters:data length:datacharlen];
}
break;
case REG_BINARY: {
v = [NSString stringWithCString: (char*)data
encoding: NSASCIIStringEncoding]; encoding: NSASCIIStringEncoding];
}
break;
default:
NSLog(@"Bad registry type %d for '%S'", type, name);
v = 0;
}
v = [v propertyList]; v = [v propertyList];
if (v)
{
k = [NSString stringWithCharacters: name length: namelen]; k = [NSString stringWithCharacters: name length: namelen];
[domainDict setObject: v forKey: k]; [domainDict setObject: v forKey: k];
} }
}
NS_HANDLER NS_HANDLER
NSLog(@"Bad registry value for '%S'", name); NSLog(@"Bad registry value for '%S'", name);
NS_ENDHANDLER NS_ENDHANDLER
@ -271,7 +290,7 @@ struct NSUserDefaultsWin32_DomainInfo
{ {
DWORD i = 0; DWORD i = 0;
unichar *name = malloc(200); unichar *name = malloc(200);
unsigned char *data = malloc(1000); unichar *data = malloc(1000);
DWORD namelenbuf = 100, datalenbuf = 1000; DWORD namelenbuf = 100, datalenbuf = 1000;
DWORD type; DWORD type;
@ -279,13 +298,19 @@ struct NSUserDefaultsWin32_DomainInfo
{ {
DWORD namelen = namelenbuf, datalen = datalenbuf; DWORD namelen = namelenbuf, datalen = datalenbuf;
// RegEnumValueW returns the data as a wide string
// but returns the length in bytes.
// To add insult to injury, datalen includes the terminating
// NULL character, unless there isn't enough room, in which
// case it doesn't.
rc = RegEnumValueW(dinfo->userKey, rc = RegEnumValueW(dinfo->userKey,
i, i,
name, name,
&namelen, &namelen,
NULL, NULL,
&type, &type,
data, (void*)data,
&datalen); &datalen);
if (rc == ERROR_SUCCESS) if (rc == ERROR_SUCCESS)
{ {
@ -294,12 +319,31 @@ struct NSUserDefaultsWin32_DomainInfo
id v; id v;
NSString *k; NSString *k;
v = [NSString stringWithCString: data switch (type) {
case REG_SZ: {
int datacharlen = datalen / 2;
if (datacharlen > 0 && data[datacharlen-1] == 0)
datacharlen--;
v = [NSString stringWithCharacters:data length:datacharlen];
}
break;
case REG_BINARY: {
v = [NSString stringWithCString: (char*)data
encoding: NSASCIIStringEncoding]; encoding: NSASCIIStringEncoding];
}
break;
default:
NSLog(@"Bad registry type %d for '%S'", type, name);
v = 0;
}
v = [v propertyList]; v = [v propertyList];
if (v)
{
k = [NSString stringWithCharacters: name length: namelen]; k = [NSString stringWithCharacters: name length: namelen];
[domainDict setObject: v forKey: k]; [domainDict setObject: v forKey: k];
} }
}
NS_HANDLER NS_HANDLER
NSLog(@"Bad registry value for '%S'", name); NSLog(@"Bad registry value for '%S'", name);
NS_ENDHANDLER NS_ENDHANDLER
@ -523,16 +567,16 @@ struct NSUserDefaultsWin32_DomainInfo
if (oldvalue == nil || [value isEqual: oldvalue] == NO) if (oldvalue == nil || [value isEqual: oldvalue] == NO)
{ {
NSString *result = nil; NSString *result = nil;
const unsigned char *ptr; const unichar *ptr;
GSPropertyListMake(value, nil, NO, NO, 0, &result); GSPropertyListMake(value, nil, NO, NO, 0, &result);
ptr = [result cStringUsingEncoding: NSASCIIStringEncoding]; ptr = UNISTR(result);
rc = RegSetValueExW(dinfo->userKey, rc = RegSetValueExW(dinfo->userKey,
UNISTR(valName), UNISTR(valName),
0, 0,
REG_BINARY, REG_SZ,
ptr, (void*)ptr,
strlen(ptr) + 1); 2*(wcslen(ptr) + 1));
if (rc != ERROR_SUCCESS) if (rc != ERROR_SUCCESS)
{ {
NSLog(@"Failed to insert HKEY_CURRENT_USER\\%@\\%@ (%x)", NSLog(@"Failed to insert HKEY_CURRENT_USER\\%@\\%@ (%x)",