mirror of
https://github.com/darlinghq/darling-cocotron.git
synced 2025-02-26 14:56:51 +00:00
manual cherry pick of fixes from glennganz-cocotron1
This commit is contained in:
parent
8025219054
commit
2253a18a32
@ -94,11 +94,11 @@ second, 0);
|
||||
|
||||
+dateWithString:(NSString *)string calendarFormat:(NSString *)format
|
||||
locale:(NSDictionary *)locale {
|
||||
return [[[self allocWithZone:NULL] initWithString:string calendarFormat:format locale:locale] autorelease];;
|
||||
return [[[self allocWithZone:NULL] initWithString:string calendarFormat:format locale:locale] autorelease];
|
||||
}
|
||||
|
||||
+dateWithString:(NSString *)string calendarFormat:(NSString *)format {
|
||||
return [[[self allocWithZone:NULL] initWithString:string calendarFormat:format] autorelease];;
|
||||
return [[[self allocWithZone:NULL] initWithString:string calendarFormat:format] autorelease];
|
||||
}
|
||||
|
||||
-(Class)classForCoder {
|
||||
@ -144,10 +144,16 @@ second, 0);
|
||||
|
||||
|
||||
-(void)setCalendarFormat:(NSString *)format {
|
||||
[format retain];
|
||||
if (format != nil) {
|
||||
format=[format copy];
|
||||
[_format release];
|
||||
_format=format;
|
||||
}
|
||||
else {
|
||||
[_format release];
|
||||
_format=[defaultCalendarDate copy];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)setTimeZone:(NSTimeZone *)timeZone {
|
||||
[timeZone retain];
|
||||
|
@ -47,6 +47,7 @@ FOUNDATION_EXPORT const NSTimeInterval NSTimeIntervalSince1970;
|
||||
-(NSDate *)laterDate:(NSDate *)date;
|
||||
|
||||
-addTimeInterval:(NSTimeInterval)seconds;
|
||||
-dateByAddingTimeInterval:(NSTimeInterval)seconds;
|
||||
|
||||
-(NSCalendarDate *)dateWithCalendarFormat:(NSString *)format
|
||||
timeZone:(NSTimeZone *)timeZone;
|
||||
|
@ -194,6 +194,11 @@ const NSTimeInterval NSTimeIntervalSince1970 = (NSTimeInterval)978307200.0;
|
||||
[self timeIntervalSinceReferenceDate]+seconds];
|
||||
}
|
||||
|
||||
-dateByAddingTimeInterval:(NSTimeInterval)seconds {
|
||||
return [[self class] dateWithTimeIntervalSinceReferenceDate:
|
||||
[self timeIntervalSinceReferenceDate]+seconds];
|
||||
}
|
||||
|
||||
-(NSCalendarDate *)dateWithCalendarFormat:(NSString *)format timeZone:(NSTimeZone *)timeZone {
|
||||
NSCalendarDate *date = [NSCalendarDate dateWithTimeIntervalSinceReferenceDate:[self timeIntervalSinceReferenceDate]];
|
||||
|
||||
|
@ -14,3 +14,8 @@ FOUNDATION_EXPORT BOOL NSCooperativeThreadsEnabled;
|
||||
|
||||
void NSCooperativeThreadBlocking();
|
||||
void NSCooperativeThreadWaiting();
|
||||
|
||||
FOUNDATION_EXPORT void *NSFrameAddress(NSUInteger level);
|
||||
FOUNDATION_EXPORT unsigned NSCountFrames(void);
|
||||
FOUNDATION_EXPORT void *NSReturnAddress(int level);
|
||||
|
||||
|
@ -53,3 +53,138 @@ void NSCooperativeThreadWaiting() {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#define _NS_FRAME_ADDRESS(x) case x: return __builtin_frame_address(x + 1)
|
||||
#define _NS_RETURN_ADDRESS(x) case x: return __builtin_return_address(x + 1)
|
||||
|
||||
void *NSFrameAddress(NSUInteger level)
|
||||
{
|
||||
unsigned int i = 0;
|
||||
switch (level) {
|
||||
_NS_FRAME_ADDRESS(0);
|
||||
_NS_FRAME_ADDRESS(1);
|
||||
_NS_FRAME_ADDRESS(2);
|
||||
_NS_FRAME_ADDRESS(3);
|
||||
_NS_FRAME_ADDRESS(4);
|
||||
_NS_FRAME_ADDRESS(5);
|
||||
_NS_FRAME_ADDRESS(6);
|
||||
_NS_FRAME_ADDRESS(7);
|
||||
_NS_FRAME_ADDRESS(8);
|
||||
_NS_FRAME_ADDRESS(9);
|
||||
_NS_FRAME_ADDRESS(10);
|
||||
_NS_FRAME_ADDRESS(11);
|
||||
_NS_FRAME_ADDRESS(12);
|
||||
_NS_FRAME_ADDRESS(13);
|
||||
_NS_FRAME_ADDRESS(14);
|
||||
_NS_FRAME_ADDRESS(15);
|
||||
_NS_FRAME_ADDRESS(16);
|
||||
_NS_FRAME_ADDRESS(17);
|
||||
_NS_FRAME_ADDRESS(18);
|
||||
_NS_FRAME_ADDRESS(19);
|
||||
_NS_FRAME_ADDRESS(20);
|
||||
_NS_FRAME_ADDRESS(21);
|
||||
_NS_FRAME_ADDRESS(22);
|
||||
_NS_FRAME_ADDRESS(23);
|
||||
_NS_FRAME_ADDRESS(24);
|
||||
_NS_FRAME_ADDRESS(25);
|
||||
_NS_FRAME_ADDRESS(26);
|
||||
_NS_FRAME_ADDRESS(27);
|
||||
_NS_FRAME_ADDRESS(28);
|
||||
_NS_FRAME_ADDRESS(29);
|
||||
_NS_FRAME_ADDRESS(30);
|
||||
_NS_FRAME_ADDRESS(31);
|
||||
_NS_FRAME_ADDRESS(32);
|
||||
_NS_FRAME_ADDRESS(33);
|
||||
_NS_FRAME_ADDRESS(34);
|
||||
_NS_FRAME_ADDRESS(35);
|
||||
_NS_FRAME_ADDRESS(36);
|
||||
_NS_FRAME_ADDRESS(37);
|
||||
_NS_FRAME_ADDRESS(38);
|
||||
_NS_FRAME_ADDRESS(39);
|
||||
_NS_FRAME_ADDRESS(40);
|
||||
_NS_FRAME_ADDRESS(41);
|
||||
_NS_FRAME_ADDRESS(42);
|
||||
_NS_FRAME_ADDRESS(43);
|
||||
_NS_FRAME_ADDRESS(44);
|
||||
_NS_FRAME_ADDRESS(45);
|
||||
_NS_FRAME_ADDRESS(46);
|
||||
_NS_FRAME_ADDRESS(47);
|
||||
_NS_FRAME_ADDRESS(48);
|
||||
_NS_FRAME_ADDRESS(49);
|
||||
_NS_FRAME_ADDRESS(50);
|
||||
default: return NULL;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
unsigned NSCountFrames(void)
|
||||
{
|
||||
unsigned x = 0;
|
||||
|
||||
while (NSFrameAddress(x + 1) != NULL){
|
||||
x++;
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
void *NSReturnAddress(int level)
|
||||
{
|
||||
switch (level) {
|
||||
_NS_RETURN_ADDRESS(0);
|
||||
_NS_RETURN_ADDRESS(1);
|
||||
_NS_RETURN_ADDRESS(2);
|
||||
_NS_RETURN_ADDRESS(3);
|
||||
_NS_RETURN_ADDRESS(4);
|
||||
_NS_RETURN_ADDRESS(5);
|
||||
_NS_RETURN_ADDRESS(6);
|
||||
_NS_RETURN_ADDRESS(7);
|
||||
_NS_RETURN_ADDRESS(8);
|
||||
_NS_RETURN_ADDRESS(9);
|
||||
_NS_RETURN_ADDRESS(10);
|
||||
_NS_RETURN_ADDRESS(11);
|
||||
_NS_RETURN_ADDRESS(12);
|
||||
_NS_RETURN_ADDRESS(13);
|
||||
_NS_RETURN_ADDRESS(14);
|
||||
_NS_RETURN_ADDRESS(15);
|
||||
_NS_RETURN_ADDRESS(16);
|
||||
_NS_RETURN_ADDRESS(17);
|
||||
_NS_RETURN_ADDRESS(18);
|
||||
_NS_RETURN_ADDRESS(19);
|
||||
_NS_RETURN_ADDRESS(20);
|
||||
_NS_RETURN_ADDRESS(21);
|
||||
_NS_RETURN_ADDRESS(22);
|
||||
_NS_RETURN_ADDRESS(23);
|
||||
_NS_RETURN_ADDRESS(24);
|
||||
_NS_RETURN_ADDRESS(25);
|
||||
_NS_RETURN_ADDRESS(26);
|
||||
_NS_RETURN_ADDRESS(27);
|
||||
_NS_RETURN_ADDRESS(28);
|
||||
_NS_RETURN_ADDRESS(29);
|
||||
_NS_RETURN_ADDRESS(30);
|
||||
_NS_RETURN_ADDRESS(31);
|
||||
_NS_RETURN_ADDRESS(32);
|
||||
_NS_RETURN_ADDRESS(33);
|
||||
_NS_RETURN_ADDRESS(34);
|
||||
_NS_RETURN_ADDRESS(35);
|
||||
_NS_RETURN_ADDRESS(36);
|
||||
_NS_RETURN_ADDRESS(37);
|
||||
_NS_RETURN_ADDRESS(38);
|
||||
_NS_RETURN_ADDRESS(39);
|
||||
_NS_RETURN_ADDRESS(40);
|
||||
_NS_RETURN_ADDRESS(41);
|
||||
_NS_RETURN_ADDRESS(42);
|
||||
_NS_RETURN_ADDRESS(43);
|
||||
_NS_RETURN_ADDRESS(44);
|
||||
_NS_RETURN_ADDRESS(45);
|
||||
_NS_RETURN_ADDRESS(46);
|
||||
_NS_RETURN_ADDRESS(47);
|
||||
_NS_RETURN_ADDRESS(48);
|
||||
_NS_RETURN_ADDRESS(49);
|
||||
_NS_RETURN_ADDRESS(50);
|
||||
default: return NULL;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
@ -111,7 +111,7 @@ void NSSetUncaughtExceptionHandler(NSUncaughtExceptionHandler *proc) {
|
||||
}
|
||||
|
||||
-(NSString *)description {
|
||||
return [NSString stringWithFormat:@"<NSException: %@ %@>",_name,_reason];
|
||||
return _reason;
|
||||
}
|
||||
|
||||
-copyWithZone:(NSZone *)zone {
|
||||
|
@ -58,8 +58,13 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
}
|
||||
|
||||
-(BOOL)isEqualToHost:(NSHost *)host {
|
||||
NSUnimplementedMethod();
|
||||
return 0;
|
||||
for(NSString *address in [self addresses])
|
||||
{
|
||||
if ([[host addresses] containsObject:address] == YES) {
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
-(void)_resolveAddressesIfNeeded {
|
||||
|
@ -51,6 +51,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
-retain {
|
||||
return self;
|
||||
}
|
||||
|
||||
-autorelease {
|
||||
return self;
|
||||
}
|
||||
|
@ -81,6 +81,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
+copyWithZone:(NSZone *)zone;
|
||||
+mutableCopyWithZone:(NSZone *)zone;
|
||||
|
||||
+ (void)poseAsClass:(Class)aClass;
|
||||
|
||||
+(NSString *)description;
|
||||
|
||||
+alloc;
|
||||
|
@ -143,6 +143,14 @@ BOOL NSObjectIsKindOfClass(id object, Class kindOf)
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (void)poseAsClass:(Class)aClass
|
||||
{
|
||||
NSAutoreleasePool * pool = [NSAutoreleasePool new];
|
||||
NSUnimplementedMethod();
|
||||
[pool release];
|
||||
}
|
||||
|
||||
|
||||
+(NSString *)description {
|
||||
return NSStringFromClass(self);
|
||||
}
|
||||
|
@ -531,8 +531,10 @@ static inline BOOL codeIsNameContinue(uint8_t code){
|
||||
NSOldXMLReader *reader=[[self alloc] initWithContentsOfFile:path];
|
||||
NSOldXMLDocument *document;
|
||||
|
||||
if(![reader tokenize])
|
||||
if(![reader tokenize]) {
|
||||
[reader release];
|
||||
return nil;
|
||||
}
|
||||
|
||||
document=[[[NSOldXMLDocument alloc] init] autorelease];
|
||||
[document setRootElement:[reader rootElement]];
|
||||
@ -546,8 +548,10 @@ static inline BOOL codeIsNameContinue(uint8_t code){
|
||||
NSOldXMLReader *reader=[[self alloc] initWithData:data];
|
||||
NSOldXMLDocument *document;
|
||||
|
||||
if(![reader tokenize])
|
||||
if(![reader tokenize]) {
|
||||
[reader release];
|
||||
return nil;
|
||||
}
|
||||
|
||||
document=[[[NSOldXMLDocument alloc] init] autorelease];
|
||||
[document setRootElement:[reader rootElement]];
|
||||
|
@ -47,6 +47,12 @@ enum {
|
||||
NSAnchoredSearch=0x08,
|
||||
NSNumericSearch= 0x40,
|
||||
};
|
||||
|
||||
enum {
|
||||
NSStringEncodingConversionAllowLossy=1,
|
||||
NSStringEncodingConversionExternalRepresentation=2
|
||||
};
|
||||
|
||||
typedef NSUInteger NSStringCompareOptions;
|
||||
typedef NSUInteger NSStringEncodingConversionOptions;
|
||||
|
||||
|
@ -11,6 +11,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
unichar *NSUTF8ToUnicode(const char *utf8,NSUInteger length,
|
||||
NSUInteger *resultLength,NSZone *zone);
|
||||
|
||||
NSUInteger NSGetUTF8CStringWithMaxLength(const unichar *characters,NSUInteger length,NSUInteger *location,char *cString,NSUInteger maxLength);
|
||||
char *NSUnicodeToUTF8(const unichar *characters,NSUInteger length,
|
||||
BOOL lossy,NSUInteger *resultLength,NSZone *zone,BOOL zeroTerminate);
|
||||
|
||||
|
@ -9,12 +9,12 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
#import <Foundation/NSStringSymbol.h>
|
||||
#import <Foundation/NSRaise.h>
|
||||
|
||||
static NSUInteger convertUTF16toUTF8(const unichar *utf16,NSUInteger utf16Length,uint8_t *utf8){
|
||||
NSUInteger NSGetUTF8CStringWithMaxLength(const unichar *characters,NSUInteger length,NSUInteger *location,char *cString,NSUInteger maxLength){
|
||||
NSUInteger utf8Length=0;
|
||||
NSUInteger i;
|
||||
|
||||
for(i=0;i<utf16Length;i++){
|
||||
uint32_t code32=utf16[i];
|
||||
for(i=0;i<length && utf8Length < maxLength;i++){
|
||||
uint32_t code32=characters[i];
|
||||
uint8_t tmp[4];
|
||||
int tmpLength=0;
|
||||
|
||||
@ -36,23 +36,33 @@ static NSUInteger convertUTF16toUTF8(const unichar *utf16,NSUInteger utf16Length
|
||||
tmp[tmpLength++]=0xF0|((code32>>18) & 0x07);
|
||||
}
|
||||
|
||||
if(utf8==NULL)
|
||||
if(cString==NULL)
|
||||
utf8Length+=tmpLength;
|
||||
else{
|
||||
while(--tmpLength>=0)
|
||||
utf8[utf8Length++]=tmp[tmpLength];
|
||||
if (tmpLength + utf8Length <= maxLength){
|
||||
while(--tmpLength>=0) {
|
||||
cString[utf8Length++]=tmp[tmpLength];
|
||||
}
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (location != NULL) {
|
||||
*location=i;
|
||||
}
|
||||
|
||||
return utf8Length;
|
||||
}
|
||||
|
||||
char *NSUnicodeToUTF8(const unichar *characters,NSUInteger length,
|
||||
BOOL lossy,NSUInteger *resultLength,NSZone *zone,BOOL zeroTerminate){
|
||||
NSUInteger utf8Length=convertUTF16toUTF8(characters,length,NULL);
|
||||
NSUInteger utf8Length=NSGetUTF8CStringWithMaxLength(characters,length,NULL, NULL, UINT_MAX);
|
||||
char *utf8=NSZoneMalloc(NULL,(utf8Length+(zeroTerminate?1:0))*sizeof(unsigned char));
|
||||
|
||||
*resultLength=convertUTF16toUTF8(characters,length,(unsigned char *)utf8);
|
||||
*resultLength=NSGetUTF8CStringWithMaxLength(characters,length,NULL, utf8, utf8Length);
|
||||
if(zeroTerminate){
|
||||
utf8[*resultLength]='\0';
|
||||
(*resultLength)++;
|
||||
@ -61,6 +71,7 @@ char *NSUnicodeToUTF8(const unichar *characters,NSUInteger length,
|
||||
return utf8;
|
||||
}
|
||||
|
||||
|
||||
NSUInteger NSConvertUTF8toUTF16(const unsigned char *utf8,NSUInteger utf8Length,unichar *utf16){
|
||||
NSUInteger i,utf16Length=0;
|
||||
uint32_t code32=0;
|
||||
|
@ -177,11 +177,14 @@ NSUInteger NSGetAnyCStringWithMaxLength(NSStringEncoding encoding, const unichar
|
||||
case NSUnicodeStringEncoding:
|
||||
return NSGetUnicodeCStringWithMaxLength(characters,length, location, cString, maxLength);
|
||||
case NSISOLatin1StringEncoding:
|
||||
case NSASCIIStringEncoding:
|
||||
return NSGetISOLatin1CStringWithMaxLength(characters,length, location, cString, maxLength, lossy);
|
||||
case NSMacOSRomanStringEncoding:
|
||||
return NSGetMacOSRomanCStringWithMaxLength(characters,length, location, cString, maxLength, lossy);
|
||||
case NSWindowsCP1252StringEncoding:
|
||||
return NSGetWin1252CStringWithMaxLength(characters,length, location, cString, maxLength, lossy);
|
||||
case NSUTF8StringEncoding:
|
||||
return NSGetUTF8CStringWithMaxLength(characters,length, location, cString, maxLength);
|
||||
default:
|
||||
if(encoding != defaultEncoding()) {
|
||||
NSUnimplementedFunction();
|
||||
|
@ -16,6 +16,7 @@ FOUNDATION_EXPORT NSString * const NSTaskDidTerminateNotification;
|
||||
NSString *launchPath;
|
||||
NSArray *arguments;
|
||||
NSString *currentDirectoryPath;
|
||||
NSDictionary *environment;
|
||||
|
||||
id standardInput;
|
||||
id standardOutput;
|
||||
|
@ -11,6 +11,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
#import <Foundation/NSRaise.h>
|
||||
#import <Foundation/NSRunLoop.h>
|
||||
#import <Foundation/NSFileManager.h>
|
||||
#import <Foundation/NSProcessInfo.h>
|
||||
|
||||
NSString * const NSTaskDidTerminateNotification=@"NSTaskDidTerminateNotification";
|
||||
|
||||
@ -52,6 +53,7 @@ NSString * const NSTaskDidTerminateNotification=@"NSTaskDidTerminateNotification
|
||||
[standardInput release];
|
||||
[standardOutput release];
|
||||
[standardError release];
|
||||
[environment release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@ -68,8 +70,7 @@ NSString * const NSTaskDidTerminateNotification=@"NSTaskDidTerminateNotification
|
||||
}
|
||||
|
||||
-(NSDictionary *)environment {
|
||||
NSInvalidAbstractInvocation();
|
||||
return nil;
|
||||
return environment;
|
||||
}
|
||||
|
||||
-(id)standardError {
|
||||
@ -100,7 +101,8 @@ NSString * const NSTaskDidTerminateNotification=@"NSTaskDidTerminateNotification
|
||||
}
|
||||
|
||||
-(void)setEnvironment:(NSDictionary *)values {
|
||||
NSInvalidAbstractInvocation();
|
||||
[environment autorelease];
|
||||
environment=[values copy];
|
||||
}
|
||||
|
||||
-(void)setStandardInput:(id)input {
|
||||
@ -150,10 +152,11 @@ NSString * const NSTaskDidTerminateNotification=@"NSTaskDidTerminateNotification
|
||||
}
|
||||
|
||||
-(void)waitUntilExit {
|
||||
while(isRunning)
|
||||
while(isRunning) {
|
||||
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
|
||||
beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.25]];
|
||||
}
|
||||
}
|
||||
|
||||
-(int)processIdentifier {
|
||||
NSInvalidAbstractInvocation();
|
||||
|
@ -7,6 +7,7 @@ The above copyright notice and this permission notice shall be included in all c
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
#import "NSValueTransformer_KeyedUnarchiveFromData.h"
|
||||
#import <Foundation/NSKeyedArchiver.h>
|
||||
#import <Foundation/NSData.h>
|
||||
#import <Foundation/NSString.h>
|
||||
|
||||
@implementation NSValueTransformer_KeyedUnarchiveFromData
|
||||
|
0
Foundation/platform_bsd/libmain.m
Normal file
0
Foundation/platform_bsd/libmain.m
Normal file
19
Foundation/platform_darwin/libmain.m
Normal file
19
Foundation/platform_darwin/libmain.m
Normal file
@ -0,0 +1,19 @@
|
||||
/* Copyright (c) 2010 Glenn Ganz
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
#import <Foundation/NSProcessInfo.h>
|
||||
|
||||
extern int *_NSGetArgc(void);
|
||||
extern char ***_NSGetArgv(void);
|
||||
|
||||
FOUNDATION_EXPORT void __attribute__ ((constructor)) libmain(void)
|
||||
{
|
||||
int *i = _NSGetArgc();
|
||||
char ***v=_NSGetArgv();
|
||||
__NSInitializeProcess(*i, (const char **)*v);
|
||||
}
|
57
Foundation/platform_linux/libmain.m
Normal file
57
Foundation/platform_linux/libmain.m
Normal file
@ -0,0 +1,57 @@
|
||||
/* Copyright (c) 2010 Glenn Ganz
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
#import <Foundation/NSProcessInfo.h>
|
||||
#import <stdio.h>
|
||||
#import <string.h>
|
||||
|
||||
#define READ_BUFFER_SIZE 2048
|
||||
|
||||
FOUNDATION_EXPORT void __attribute__ ((constructor)) libmain(void)
|
||||
{
|
||||
|
||||
char **argValues=NULL;
|
||||
static char **nArgValues=NULL;
|
||||
|
||||
FILE *commandLineFile;
|
||||
|
||||
char psinfofile[32] = {0};
|
||||
|
||||
commandLineFile = fopen("/proc/self/cmdline", "r");
|
||||
if (commandLineFile == NULL) {
|
||||
fprintf(stderr, "Error during Cocotron initialization: Failed to open command line file [/proc/self/cmdline]");
|
||||
abort();
|
||||
}
|
||||
|
||||
char buffer[READ_BUFFER_SIZE];
|
||||
int argCount = 0;
|
||||
|
||||
while( fgets(buffer, READ_BUFFER_SIZE, commandLineFile) ) {
|
||||
size_t n = 0;
|
||||
while( n < READ_BUFFER_SIZE && buffer[n] != '\0' ) {
|
||||
argCount++;
|
||||
n += strlen(buffer+n) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
fseek ( commandLineFile , 0 , SEEK_SET );
|
||||
|
||||
nArgValues = (char**)malloc(sizeof(char*) * (argCount));
|
||||
|
||||
int c = 0;
|
||||
while( fgets(buffer, READ_BUFFER_SIZE, commandLineFile) ) {
|
||||
size_t n = 0;
|
||||
while( n < READ_BUFFER_SIZE && buffer[n] != '\0' ) {
|
||||
nArgValues[c] = (char *)strdup(buffer+n);
|
||||
n += strlen(buffer+n) + 1;
|
||||
c++;
|
||||
}
|
||||
}
|
||||
|
||||
__NSInitializeProcess(argCount, (const char **)nArgValues);
|
||||
}
|
51
Foundation/platform_solaris/libmain.m
Normal file
51
Foundation/platform_solaris/libmain.m
Normal file
@ -0,0 +1,51 @@
|
||||
/* Copyright (c) 2010 Glenn Ganz
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
#import <Foundation/NSProcessInfo.h>
|
||||
|
||||
#define _STRUCTURED_PROC 1
|
||||
#import <sys/procfs.h>
|
||||
#import <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
FOUNDATION_EXPORT void __attribute__ ((constructor)) libmain(void)
|
||||
{
|
||||
|
||||
char **argValues = NULL;
|
||||
static char **nArgValues=NULL;
|
||||
char psinfoFile[80];
|
||||
psinfo_t pinfo;
|
||||
int argCount = 0;
|
||||
pid_t p=getpid();
|
||||
|
||||
sprintf(psinfoFile, "/proc/%d/psinfo", p);
|
||||
FILE *f = fopen(psinfoFile, "r");
|
||||
if (f == NULL) {
|
||||
fprintf(stderr, "Error during Cocotron initialization: Failed to open ps info file for pid [%d]", p);
|
||||
abort();
|
||||
}
|
||||
|
||||
fread(&pinfo, sizeof(pinfo), 1, f);
|
||||
fclose(f);
|
||||
|
||||
argValues = (char **)pinfo.pr_argv;
|
||||
while(argValues[argCount] != NULL) {
|
||||
argCount++;
|
||||
}
|
||||
|
||||
nArgValues = (char**)malloc(sizeof(char*) * (argCount));
|
||||
|
||||
for (int i = 0; i < argCount; i++) {
|
||||
nArgValues[i] = (char *)strdup(argValues[i]);
|
||||
}
|
||||
|
||||
__NSInitializeProcess(argCount, (const char **)nArgValues);
|
||||
}
|
@ -14,7 +14,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
|
||||
#import <string.h>
|
||||
|
||||
#define INITIAL_CLASS_ARRAY_SIZE 512
|
||||
|
||||
#ifdef SOLARIS
|
||||
#import <stdio.h>
|
||||
#define PATH_MAX 1024
|
||||
#endif
|
||||
|
||||
@ -31,6 +34,13 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
#import <sys/sysctl.h>
|
||||
#endif
|
||||
|
||||
static Class *unresolvedClasses = NULL;
|
||||
static int unresolvedClassesSize = 0;
|
||||
static Class *sentLoadMessageClasses = NULL;
|
||||
static int sentLoadMessageClassesSize = 0;
|
||||
|
||||
|
||||
|
||||
static OBJCArray *OBJCObjectFileImageArray(void) {
|
||||
static OBJCArray *objectFileImageArray=NULL;
|
||||
|
||||
@ -246,6 +256,144 @@ static void OBJCSymbolTableRegisterSelectors(OBJCSymbolTable *symbolTable){
|
||||
}
|
||||
}
|
||||
|
||||
void OBJCAddToUnResolvedClasses(Class class) {
|
||||
Class superClass = class->super_class;
|
||||
|
||||
//check for root object
|
||||
if(superClass) {
|
||||
for(int i= 0; i < unresolvedClassesSize; i++) {
|
||||
Class currentClass = unresolvedClasses[i];
|
||||
if(currentClass == NULL || currentClass == (Class)-1) {
|
||||
unresolvedClasses[i] = class;
|
||||
return;
|
||||
}
|
||||
}
|
||||
int newCSize = 0;
|
||||
if(unresolvedClassesSize == 0) {
|
||||
newCSize = INITIAL_CLASS_ARRAY_SIZE;
|
||||
}
|
||||
else {
|
||||
newCSize = 2 * unresolvedClassesSize;
|
||||
|
||||
}
|
||||
unresolvedClasses = (Class *)realloc(unresolvedClasses, newCSize * sizeof(Class));
|
||||
|
||||
for(int i = unresolvedClassesSize;i < newCSize;i ++) {
|
||||
unresolvedClasses [i] = NULL;
|
||||
}
|
||||
unresolvedClasses[unresolvedClassesSize] = class;
|
||||
|
||||
unresolvedClassesSize = newCSize;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
BOOL OBJCCheckClassIsResolved(Class class)
|
||||
{
|
||||
if(class->super_class == 0) {
|
||||
//root object
|
||||
return YES;
|
||||
}
|
||||
|
||||
Class superClass;
|
||||
if(!(class->info&CLASS_INFO_LINKED)){
|
||||
return NO;
|
||||
}
|
||||
else {
|
||||
superClass = class_getSuperclass(class);
|
||||
}
|
||||
|
||||
if(superClass != Nil) {
|
||||
return OBJCCheckClassIsResolved(superClass);
|
||||
}
|
||||
else {
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
void OBJCSendLoadMessage(Class class) {
|
||||
|
||||
int i = 0;
|
||||
|
||||
for(;i < sentLoadMessageClassesSize;i++) {
|
||||
if(sentLoadMessageClasses[i] == NULL) {
|
||||
break;
|
||||
}
|
||||
else if(sentLoadMessageClasses[i] == class) {
|
||||
//message already sent
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(class->super_class != 0) {
|
||||
//send load first to the superclass
|
||||
OBJCSendLoadMessage(class->super_class);
|
||||
}
|
||||
|
||||
//check for space and increase size if neeeded
|
||||
if(i == sentLoadMessageClassesSize) {
|
||||
int newCSize = 0;
|
||||
if(sentLoadMessageClassesSize == 0) {
|
||||
newCSize = INITIAL_CLASS_ARRAY_SIZE;
|
||||
}
|
||||
else {
|
||||
newCSize = 2 * sentLoadMessageClassesSize;
|
||||
}
|
||||
sentLoadMessageClasses = (Class *)realloc(sentLoadMessageClasses, newCSize * sizeof(Class));
|
||||
for(int j=sentLoadMessageClassesSize;j < newCSize;j++) {
|
||||
sentLoadMessageClasses [j] = NULL;
|
||||
}
|
||||
sentLoadMessageClasses[sentLoadMessageClassesSize] = class;
|
||||
sentLoadMessageClassesSize = newCSize;
|
||||
}
|
||||
else {
|
||||
sentLoadMessageClasses[i] = class;
|
||||
}
|
||||
|
||||
|
||||
Method m = class_getClassMethod(class, @selector(load));
|
||||
if(m) {
|
||||
IMP imp = method_getImplementation(m);
|
||||
if(imp) {
|
||||
(*imp)(class, @selector(load));
|
||||
}
|
||||
}
|
||||
}
|
||||
void OBJCSendLoadMessages() {
|
||||
|
||||
//until NSObject is not in runtime we don't need to check
|
||||
if(objc_lookUpClass("NSObject") == Nil) {
|
||||
return;
|
||||
}
|
||||
|
||||
for(int i= 0; i < unresolvedClassesSize; i++) {
|
||||
Class class = unresolvedClasses[i];
|
||||
if(class == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(OBJCCheckClassIsResolved(class) == YES) {
|
||||
//remove it from unresolved
|
||||
unresolvedClasses[i] = NULL;
|
||||
}
|
||||
else {
|
||||
//still unresolved classes, wait for more classes
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int i,capacity=objc_getClassList(NULL,0);
|
||||
Class list[capacity];
|
||||
|
||||
objc_getClassList(list,capacity);
|
||||
|
||||
for(i=0;i<capacity;i++){
|
||||
|
||||
OBJCSendLoadMessage(list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void OBJCSymbolTableRegisterClasses(OBJCSymbolTable *symbolTable){
|
||||
unsigned i,count=symbolTable->classCount;
|
||||
|
||||
|
@ -226,6 +226,9 @@ int class_getVersion(Class class) {
|
||||
|
||||
Method class_getClassMethod(Class class, SEL selector)
|
||||
{
|
||||
if (class == Nil) {
|
||||
return NULL;
|
||||
}
|
||||
return class_getInstanceMethod(class->isa, selector);
|
||||
}
|
||||
|
||||
|
@ -12,13 +12,14 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
#import "objc_class.h"
|
||||
#import "ObjCException.h"
|
||||
|
||||
static id nil_message(id object,SEL message,...){
|
||||
return nil;
|
||||
//we must return a 64 bit type for clearing both registers (32 bit systems)
|
||||
static unsigned long long nil_message(id object,SEL message,...) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
IMP objc_msg_lookup(id object,SEL selector) {
|
||||
if(object==nil)
|
||||
return nil_message;
|
||||
return (IMP)nil_message;
|
||||
else {
|
||||
OBJCMethodCache *cache=object->isa->cache;
|
||||
uintptr_t index=(uintptr_t)selector&OBJCMethodCacheMask;
|
||||
|
@ -9,6 +9,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
#import "objc_class.h"
|
||||
|
||||
Class object_getClass(id object) {
|
||||
if (object == nil) {
|
||||
return Nil;
|
||||
}
|
||||
return object->isa;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user