diff --git a/ChangeLog b/ChangeLog index 923ddaa94..9c3c4b7b7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2008-10-13 Richard Frith-Macdonald + + * Source/NSPage.m: Update to use NSUInteger and to cope with large + address space in windows. + * Headers/Foundation/NSObjCRuntime.h: typedef NSUInteger earlier + * Headers/Foundation/NSZone.h: Update to use NSUInteger. + * Source/NSProcessInfo.m; implement new MacOS-x 5 methods based on + Fred's suggestion and Scotts code as fallback and wiht a version + for mswindows too. + 2008-10-11 Richard Frith-Macdonald * Source/NSUserDefaults.m: implement KVC methods to get and set values diff --git a/Headers/Foundation/NSObjCRuntime.h b/Headers/Foundation/NSObjCRuntime.h index 48de0c3b4..53b466010 100644 --- a/Headers/Foundation/NSObjCRuntime.h +++ b/Headers/Foundation/NSObjCRuntime.h @@ -31,15 +31,18 @@ #import #import #import + +/* These typedefs must be in place before GSObjCRuntime.h is imported. + */ +typedef gsaddr NSInteger; +typedef gsuaddr NSUInteger; + #import #if defined(__cplusplus) extern "C" { #endif -typedef gsaddr NSInteger; -typedef gsuaddr NSUInteger; - #if OS_API_VERSION(100500,GS_API_LATEST) GS_EXPORT NSString *NSStringFromProtocol(Protocol *aProtocol); GS_EXPORT Protocol *NSProtocolFromString(NSString *aProtocolName); diff --git a/Headers/Foundation/NSZone.h b/Headers/Foundation/NSZone.h index 2ecbc0628..6910928a3 100644 --- a/Headers/Foundation/NSZone.h +++ b/Headers/Foundation/NSZone.h @@ -434,23 +434,23 @@ GS_ZONE_SCOPE struct NSZoneStats NSZoneStats (NSZone *zone) #endif /* GS_WITH_GC */ -GS_EXPORT unsigned NSPageSize (void) __attribute__ ((const)); +GS_EXPORT NSUInteger NSPageSize (void) __attribute__ ((const)); -GS_EXPORT unsigned NSLogPageSize (void) __attribute__ ((const)); +GS_EXPORT NSUInteger NSLogPageSize (void) __attribute__ ((const)); -GS_EXPORT unsigned NSRoundDownToMultipleOfPageSize (unsigned bytes) +GS_EXPORT NSUInteger NSRoundDownToMultipleOfPageSize (NSUInteger bytes) __attribute__ ((const)); -GS_EXPORT unsigned NSRoundUpToMultipleOfPageSize (unsigned bytes) +GS_EXPORT NSUInteger NSRoundUpToMultipleOfPageSize (NSUInteger bytes) __attribute__ ((const)); -GS_EXPORT unsigned NSRealMemoryAvailable (void); +GS_EXPORT NSUInteger NSRealMemoryAvailable (void); -GS_EXPORT void* NSAllocateMemoryPages (unsigned bytes); +GS_EXPORT void* NSAllocateMemoryPages (NSUInteger bytes); -GS_EXPORT void NSDeallocateMemoryPages (void *ptr, unsigned bytes); +GS_EXPORT void NSDeallocateMemoryPages (void *ptr, NSUInteger bytes); -GS_EXPORT void NSCopyMemoryPages (const void *src, void *dest, unsigned bytes); +GS_EXPORT void NSCopyMemoryPages (const void *src, void *dest, NSUInteger bytes); #if defined(__cplusplus) } diff --git a/Source/NSPage.m b/Source/NSPage.m index be6465b01..c141cd8ac 100644 --- a/Source/NSPage.m +++ b/Source/NSPage.m @@ -72,27 +72,27 @@ getpagesize(void) /* Cache the size of a memory page here, so we don't have to make the getpagesize() system call repeatedly. */ -static unsigned ns_page_size = 0; +static NSUInteger ns_page_size = 0; /** * Return the number of bytes in a memory page. */ -unsigned +NSUInteger NSPageSize (void) { if (!ns_page_size) - ns_page_size = (unsigned) getpagesize (); + ns_page_size = getpagesize (); return ns_page_size; } /** * Return log base 2 of the number of bytes in a memory page. */ -unsigned +NSUInteger NSLogPageSize (void) { - unsigned tmp_page_size = NSPageSize(); - unsigned log = 0; + NSUInteger tmp_page_size = NSPageSize(); + NSUInteger log = 0; while (tmp_page_size >>= 1) log++; @@ -103,10 +103,10 @@ NSLogPageSize (void) * Round bytes down to the nearest multiple of the memory page size, * and return it. */ -unsigned -NSRoundDownToMultipleOfPageSize (unsigned bytes) +NSUInteger +NSRoundDownToMultipleOfPageSize (NSUInteger bytes) { - unsigned a = NSPageSize(); + NSUInteger a = NSPageSize(); return (bytes / a) * a; } @@ -115,10 +115,10 @@ NSRoundDownToMultipleOfPageSize (unsigned bytes) * Round bytes up to the nearest multiple of the memory page size, * and return it. */ -unsigned -NSRoundUpToMultipleOfPageSize (unsigned bytes) +NSUInteger +NSRoundUpToMultipleOfPageSize (NSUInteger bytes) { - unsigned a = NSPageSize(); + NSUInteger a = NSPageSize(); return ((bytes % a) ? ((bytes / a + 1) * a) : bytes); } @@ -130,7 +130,7 @@ NSRoundUpToMultipleOfPageSize (unsigned bytes) /** * Return the number of bytes of real (physical) memory available. */ -unsigned +NSUInteger NSRealMemoryAvailable () { #if __linux__ @@ -138,18 +138,19 @@ NSRealMemoryAvailable () if ((sysinfo(&info)) != 0) return 0; - return (unsigned) info.freeram; + return info.freeram; #elif defined(__MINGW32__) - MEMORYSTATUS memory; + MEMORYSTATUSEX memory; - GlobalMemoryStatus(&memory); - return (unsigned)memory.dwAvailPhys; + memory.dwLength = sizeof(memory); + GlobalMemoryStatusEx(&memory); + return memory.ullAvailPhys; #elif defined(__BEOS__) system_info info; if (get_system_info(&info) != B_OK) return 0; - return (unsigned)(info.max_pages - info.used_pages) * B_PAGE_SIZE; + return (info.max_pages - info.used_pages) * B_PAGE_SIZE; #else fprintf (stderr, "NSRealMemoryAvailable() not implemented.\n"); return 0; @@ -161,7 +162,7 @@ NSRealMemoryAvailable () * pointer on failure). */ void * -NSAllocateMemoryPages (unsigned bytes) +NSAllocateMemoryPages (NSUInteger bytes) { void *where; #if __mach__ @@ -184,7 +185,7 @@ NSAllocateMemoryPages (unsigned bytes) * NSAllocateMemoryPages() function. */ void -NSDeallocateMemoryPages (void *ptr, unsigned bytes) +NSDeallocateMemoryPages (void *ptr, NSUInteger bytes) { #if __mach__ vm_deallocate (mach_task_self (), ptr, bytes); @@ -198,7 +199,7 @@ NSDeallocateMemoryPages (void *ptr, unsigned bytes) * The value bytes specifies the length of the data copied. */ void -NSCopyMemoryPages (const void *src, void *dest, unsigned bytes) +NSCopyMemoryPages (const void *src, void *dest, NSUInteger bytes) { #if __mach__ kern_return_t r; diff --git a/Source/NSProcessInfo.m b/Source/NSProcessInfo.m index 680ed58ab..747e5bc62 100644 --- a/Source/NSProcessInfo.m +++ b/Source/NSProcessInfo.m @@ -1185,27 +1185,144 @@ static void determineOperatingSystem() - (void) setProcessName: (NSString *)newName { - if (newName && [newName length]) { - [_gnu_processName autorelease]; - _gnu_processName = [newName copyWithZone: [self zone]]; - } + if (newName && [newName length]) + { + [_gnu_processName autorelease]; + _gnu_processName = [newName copyWithZone: [self zone]]; + } return; } - (NSUInteger) processorCount { - return 0; // FIXME + static NSUInteger procCount = 0; + static BOOL beenHere = NO; + + if (beenHere == NO) + { +#if defined(__MINGW32__) + SYSTEM_INFO info; + + GetSystemInfo(&info); + return info.dwNumberOfProcessors; +#elif defined(_SC_NPROCESSORS_CONF) + procCount = sysconf(_SC_NPROCESSORS_CONF); +#elif defined(HAVE_PROCFS) + NSFileManager *fileManager = [NSFileManager defaultManager]; + + if ([fileManager fileExistsAtPath: @"/proc/cpuinfo"]) + { + NSString *cpuInfo; + NSArray *a; + unsigned i; + + cpuInfo = [NSString stringWithContentsOfFile: @"/proc/cpuinfo"]; + a = [cpuInfo componentsSeparatedByCharactersInSet: + [NSCharacterSet whitespaceAndNewlineCharacterSet]]; + // syntax is processor : # + // count up each one + for (i = 0; i < [a count]; ++i) + { + if ([[a objectAtIndex: i] isEqualToString: @"processor"]) + { + if (((i+1) < [a count]) + && [[a objectAtIndex: i+1] isEqualToString: @":"]) + { + procCount++; + } + } + } + } +#else +#warning "no known way to determine number of processors on this system" +#endif + + beenHere = YES; + if (procCount == 0) + { + NSLog(@"Cannot determine processor count."); + } + } + return procCount; } - (NSUInteger) activeProcessorCount { - return 0; // FIXME +#if defined(__MINGW32__) + SYSTEM_INFO info; + int index; + int count = 0; + + GetSystemInfo(&info); + for (index = 0; index < 32; index++) + { + if (info.dwActiveProcessorMask & (1<