Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

streamlining for Lion/iOS5 runtimes. Dropping GNUstep support.

  • Loading branch information...
commit 6be192c177dba5ec3d0556cdcfb5c0de03afd84f 1 parent f477014
@timburks authored
View
26,860 ...u.xcodeproj/project.xcworkspace/xcuserdata/tim.xcuserdatad/UserInterfaceState.xcuserstate
10,429 additions, 16,431 deletions not shown
View
6 MacOS/Nu-framework/Nu.xcodeproj/xcuserdata/tim.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist
@@ -9,11 +9,11 @@
continueAfterRunningActions = "No"
isPathRelative = "0"
filePath = "/Volumes/Users/tim/Desktop/Repositories/nu/objc/NuClass.m"
- timestampString = "329615877.019981"
+ timestampString = "329696440.2529"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
- startingLineNumber = "294"
- endingLineNumber = "294"
+ startingLineNumber = "295"
+ endingLineNumber = "295"
landmarkName = "-instanceVariableNames"
landmarkType = "5">
</FileBreakpoint>
View
1  MacOS/Nu-framework/NuApp/NuAppDelegate.m
@@ -17,7 +17,6 @@
#import "NuException.h"
#import "NuExtensions.h"
#import "NuHandler.h"
-#import "mach_override.h"
#import "NuMacro_0.h"
#import "NuMacro_1.h"
#import "NuMain.h"
View
1  include/Nu/Nu.h
@@ -28,7 +28,6 @@ limitations under the License.
#import <Nu/NuException.h>
#import <Nu/NuExtensions.h>
#import <Nu/NuHandler.h>
-#import <Nu/mach_override.h>
#import <Nu/NuMacro_0.h>
#import <Nu/NuMacro_1.h>
#import <Nu/NuMain.h>
View
17 main/main.m
@@ -1,6 +1,6 @@
/*!
@file main.m
-@copyright Copyright (c) 2007 Radtastical Inc.
+@copyright Copyright (c) 2007,2011 Radtastical Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -14,7 +14,6 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
-#if defined(DARWIN)
int NuMain(int argc, const char *argv[]);
@@ -23,18 +22,4 @@ int main(int argc, const char *argv[])
return NuMain(argc, argv);
}
-#else
-int NuMain(int argc, const char *argv[], const char *envp[]);
-
-#if defined(FREEBSD)
-#include "GNUstepBase/GSConfig.h"
-int gnustep_base_user_main(int argc, const char* argv[], const char *envp[])
-#else
-int main(int argc, const char *argv[], const char *envp[])
-#endif
-{
- return NuMain(argc, argv, envp);
-}
-
-#endif
View
17 objc/Nu.m
@@ -98,21 +98,12 @@ void NuMain_exceptionHandler(NSException* e)
exit(1);
}
-
-#ifdef DARWIN
int NuMain(int argc, const char *argv[])
-#else
-int NuMain(int argc, const char *argv[], const char *envp[])
-#endif
{
#ifdef IPHONE
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
#endif
- #ifdef GNUSTEP
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- [NSProcessInfo initializeWithArguments:(char **) argv count:argc environment:(char **) envp];
- #endif
void NuInit();
NuInit();
@@ -239,10 +230,6 @@ int NuMain(int argc, const char *argv[], const char *envp[])
NSLog(@"%@: %@", [exception name], [exception reason]);
}
- #ifdef GNUSTEP
- [pool release];
- #endif
-
#ifdef IPHONE
[pool release];
#endif
@@ -273,8 +260,8 @@ void NuInit()
#ifdef DARWIN
// note known placeholder classes
- extern void nu_note_placeholders();
- nu_note_placeholders();
+// extern void nu_note_placeholders();
+// nu_note_placeholders();
#endif
// check UTF8 support in PCRE
View
6 objc/NuBridge.m
@@ -1357,9 +1357,6 @@ id add_method_to_class(Class c, NSString *methodName, NSString *signature, NuBlo
return [NSNull null];
}
-#ifdef GNUSTEP
-#define __USE_GNU
-#endif
#include <dlfcn.h>
@implementation NuBridgedFunction
@@ -1403,6 +1400,7 @@ - (id) evalWithArguments:(id) cdr context:(NSMutableDictionary *) context
{
//NSLog(@"----------------------------------------");
//NSLog(@"calling C function %s with signature %s", name, signature);
+ id result;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
char *return_type_identifier = strdup(signature);
@@ -1447,7 +1445,7 @@ - (id) evalWithArguments:(id) cdr context:(NSMutableDictionary *) context
arg_cursor = [arg_cursor cdr];
}
ffi_call(cif, FFI_FN(function), result_value, argument_values);
- id result = get_nu_value_from_objc_value(result_value, return_type_identifier);
+ result = get_nu_value_from_objc_value(result_value, return_type_identifier);
// free the value structures
for (i = 0; i < argument_count; i++) {
View
18 objc/NuCell.m
@@ -37,11 +37,12 @@ + (id) cellWithCar:(id)car cdr:(id)cdr
- (id) init
{
- [super init];
- car = Nu__null;
- cdr = Nu__null;
- file = -1;
- line = -1;
+ if ((self = [super init])) {
+ car = Nu__null;
+ cdr = Nu__null;
+ file = -1;
+ line = -1;
+ }
return self;
}
@@ -497,9 +498,10 @@ - (void)encodeWithCoder:(NSCoder *)coder
- (id) initWithCoder:(NSCoder *)coder
{
- [super init];
- car = [[coder decodeObject] retain];
- cdr = [[coder decodeObject] retain];
+ if ((self = [super init])) {
+ car = [[coder decodeObject] retain];
+ cdr = [[coder decodeObject] retain];
+ }
return self;
}
View
9 objc/NuClass.m
@@ -61,9 +61,10 @@ - (id) initWithClassNamed:(NSString *) string
- (id) initWithClass:(Class) class
{
- [super init];
- c = class;
- isRegistered = YES; // unless we explicitly set otherwise
+ if ((self = [super init])) {
+ c = class;
+ isRegistered = YES; // unless we explicitly set otherwise
+ }
return self;
}
@@ -292,7 +293,7 @@ @implementation NuClass (Experiments)
- (NSArray *) instanceVariableNames {
NSMutableArray *names = [NSMutableArray array];
- int ivarCount;
+ unsigned int ivarCount;
Ivar *ivarList = class_copyIvarList(c, &ivarCount);
NSLog(@"%d ivars", ivarCount);
View
16 objc/NuExtensions.h
@@ -116,9 +116,7 @@ limitations under the License.
- (id) lookupObjectForKey:(id)key;
/*! Add an object to a dictionary, automatically converting nil into [NSNull null]. */
- (void) setPossiblyNullObject:(id) anObject forKey:(id) aKey;
-#ifdef GNUSTEP
-- (void) setValue:(id) value forKey:(id) key;
-#endif
+
@end
/*!
@@ -185,10 +183,6 @@ limitations under the License.
/*! Iterate over each character in a string, evaluating the provided block for each character. */
- (id) each:(id) block;
-#ifdef GNUSTEP
-+ (NSString *) stringWithCString:(const char *) cString encoding:(NSStringEncoding) encoding;
-- (const char *) cStringUsingEncoding:(NSStringEncoding) encoding;
-#endif
@end
/*!
@@ -294,14 +288,6 @@ limitations under the License.
- (NSString *) typeString;
@end
-#ifdef GNUSTEP
-@interface NSObject (morestuff)
-- (void)willChangeValueForKey:(NSString *)key;
-- (void)didChangeValueForKey:(NSString *)key;
-+ (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector;
-@end
-#endif
-
/*!
@class NuAutomaticIvars
@abstract Include this class to get handleUnknownMessage:withContext: to emulate ivar accessors.
View
120 objc/NuExtensions.m
@@ -301,12 +301,6 @@ - (void) setPossiblyNullObject:(id) anObject forKey:(id) aKey
[self setObject:((anObject == nil) ? (id)[NSNull null] : anObject) forKey:aKey];
}
-#ifdef GNUSTEP
-- (void) setValue:(id) value forKey:(id) key
-{
- [self setObject:value forKey:key];
-}
-#endif
@end
@interface NuStringEnumerator : NSEnumerator
@@ -516,30 +510,6 @@ - (id) objectEnumerator
return [NuStringEnumerator enumeratorWithString:self];
}
-#ifdef GNUSTEP
-/*
-+ (NSString *) stringWithCString:(const char *) cString encoding:(NSStringEncoding) encoding
-{
- return [[[NSString alloc] initWithCString:cString] autorelease];
-}
-
-- (const char *) cStringUsingEncoding:(NSStringEncoding) encoding
-{
- return [self cString];
-}
-*/
-
-- (NSString *) stringByReplacingOccurrencesOfString:(NSString *) before withString:(NSString *) after
-{
- return [self stringByReplacingString:before withString:after];
-}
-
-+ (NSString *) stringWithContentsOfFile:(NSString *) filePath encoding:(NSStringEncoding) encoding error:(NSError **) error
-{
- return [NSString stringWithContentsOfFile:filePath];
-}
-#endif
-
- (id) each:(id) block
{
id args = [[NuCell alloc] init];
@@ -934,28 +904,6 @@ - (id) loadNuFile:(NSString *) nuFileName withContext:(NSMutableDictionary *) co
@end
-#ifdef DARWIN
-#ifndef IPHONE
-#import <Cocoa/Cocoa.h>
-
-@implementation NSView(Nu)
-
-- (id) nuRetain
-{
- extern void nu_disableNSLog();
- extern void nu_enableNSLog();
- // Send
- // "NSView not correctly initialized. Did you forget to call super?”
- // into a black hole.
- nu_disableNSLog();
- id result = [self nuRetain];
- nu_enableNSLog();
- return result;
-}
-
-@end
-#endif
-#endif
@implementation NSMethodSignature(Nu)
@@ -979,74 +927,6 @@ - (NSString *) typeString
@end
-#ifdef GNUSTEP
-@implementation NXConstantString (extra)
-- (const char *) cStringUsingEncoding:(NSStringEncoding) encoding
-{
- return [self cString];
-}
-
-@end
-
-@implementation NSObject (morestuff)
-
-- (void)willChangeValueForKey:(NSString *)key
-{
-}
-
-- (void)didChangeValueForKey:(NSString *)key
-{
-}
-
-+ (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
-{
- register const char *types = NULL;
-
- if (aSelector == NULL) // invalid selector
- return nil;
-
- if (types == NULL) {
- // lookup method for selector
- struct objc_method *mth;
- mth = (object_is_instance(self) ?
- class_get_instance_method(self->class_pointer, aSelector)
- : class_get_class_method(self->class_pointer, aSelector));
- if (mth) types = mth->method_types;
- }
-
- if (types == NULL) {
- /* construct a id-signature */
- register const char *sel;
- if ((sel = sel_get_name(aSelector))) {
- register int colCount = 0;
- static char *idSigs[] = {
- "@@:", "@@:@", "@@:@@", "@@:@@@", "@@:@@@@", "@@:@@@@@",
- "@@:@@@@@@", "@@:@@@@@@", "@@:@@@@@@@", "@@:@@@@@@@@"
- };
-
- while (*sel) {
- if (*sel == ':')
- colCount++;
- sel++;
- }
- types = idSigs[colCount];
- }
- else
- return nil;
- }
-
- // NSLog(@"types: %s", types);
- return [NSMethodSignature signatureWithObjCTypes:types];
-}
-
-@end
-
-const char *stringValue(id object)
-{
- return [[object stringValue] cString];
-}
-#endif
-
@implementation NuAutomaticIvars
- (id) handleUnknownMessage:(NuCell *) message withContext:(id) context
View
6 objc/NuObjCRuntime.h
@@ -52,8 +52,6 @@ Protocol **class_copyProtocolList(Class cls, unsigned int *outCount);
Method_t class_getInstanceMethod(Class cls, SEL name);
Ivar_t class_getInstanceVariable(Class cls, const char *name);
-// defined as a macro in GNUstep
-// struct objc_method_list *class_nextMethodList( Class cls, void **methods);
const char *ivar_getName(Ivar_t v);
unsigned method_getArgumentInfo(struct objc_method *m, int arg, const char **type, int *offset);
@@ -129,7 +127,3 @@ void nu_markEndOfObjCTypeString(char *type, size_t len);
// This makes it safe to insert nil into container classes
void nu_swizzleContainerClasses();
-#ifdef GNUSTEP
-// defined as a macro in GNUstep
-// Method_t class_getClassMethod (MetaClass class, SEL op);
-#endif
View
3  objc/NuObjCRuntime.m
@@ -248,9 +248,6 @@ IMP nu_class_replaceMethod(Class cls, SEL name, IMP imp, const char *types)
#endif
method_list->method_list[0].method_types = strdup(types);
method_list->method_list[0].method_imp = imp;
-#ifdef GNUSTEP
- method_list->method_next = NULL;
-#endif
class_addMethods(cls, method_list);
return imp;
}
View
4 objc/NuObject.h
@@ -16,10 +16,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
-#ifdef GNUSTEP
-#define bool char
-#endif
-
#import <Foundation/Foundation.h>
@class NuBlock;
@class NuClass;
View
6 objc/NuObject.m
@@ -212,9 +212,6 @@ - (id) sendMessage:(id)cdr withContext:(NSMutableDictionary *)context
#else
Method_t m = 0;
#endif
-#ifdef GNUSTEP
- if (sel) {
-#endif
// instead of isMemberOfClass:, which may be blocked by an NSProtocolChecker
BOOL isAClass = (object_getClass(self) == [NuClass class]);
if (isAClass) {
@@ -240,9 +237,6 @@ - (id) sendMessage:(id)cdr withContext:(NSMutableDictionary *)context
#endif
if (!m) m = class_getClassMethod(object_getClass(self), sel);
}
-#ifdef GNUSTEP
- }
-#endif
id result = Nu__null;
if (m) {
// We have a method that matches the selector.
View
37 objc/NuOperator.m
@@ -1533,28 +1533,6 @@ - (id) callWithArguments:(id)cdr context:(NSMutableDictionary *)context
@interface Nu_load_operator : NuOperator {}
@end
-#ifdef GNUSTEP
-id loadNuLibraryFile(NSString *nuFileName, id parser, id context, id symbolTable)
-{
- NSString *fullPath = [NSString stringWithFormat:@"/usr/local/share/libNu/nu/%@.nu", nuFileName];
- if ([NSFileManager fileExistsNamed:fullPath]) {
- NSString *string = [NSString stringWithContentsOfFile:fullPath];
- id value = Nu__null;
- if (string) {
- id body = [parser parse:string asIfFromFilename:[fullPath cStringUsingEncoding:NSUTF8StringEncoding]];
- value = [body evalWithContext:context];
- return [symbolTable symbolWithCString:"t"];
- }
- else {
- return nil;
- }
- }
- else {
- return nil;
- }
-}
-#endif
-
@implementation Nu_load_operator
- (id) callWithArguments:(id)cdr context:(NSMutableDictionary *)context
{
@@ -1567,16 +1545,6 @@ - (id) callWithArguments:(id)cdr context:(NSMutableDictionary *)context
if ([split count] == 2) {
id frameworkName = [split objectAtIndex:0];
id nuFileName = [split objectAtIndex:1];
- #ifdef GNUSTEP
- if ([frameworkName isEqual:@"Nu"]) {
- if (loadNuLibraryFile(nuFileName, parser, context, symbolTable) == nil) {
- [NSException raise:@"NuLoadFailed" format:@"unable to load %@", nuFileName];
- }
- else {
- return [symbolTable symbolWithCString:"t"];
- }
- }
- #endif
NSBundle *framework = [NSBundle frameworkWithName:frameworkName];
if ([framework loadNuFile:nuFileName withContext:context])
return [symbolTable symbolWithCString:"t"];
@@ -1622,11 +1590,6 @@ - (id) callWithArguments:(id)cdr context:(NSMutableDictionary *)context
if ([Nu loadNuFile:resourceName fromBundleWithIdentifier:@"nu.programming.framework" withContext:context])
return [symbolTable symbolWithCString:"t"];
- #ifdef GNUSTEP
- if (loadNuLibraryFile(resourceName, parser, context, symbolTable))
- return [symbolTable symbolWithCString:"t"];
- #endif
-
// if no file was found, try to load a framework with the given name
if ([NSBundle frameworkWithName:resourceName])
return [symbolTable symbolWithCString:"t"];
View
109 objc/NuOverrides.m
@@ -1,109 +0,0 @@
-/*!
-@file overrides.m
-@description Overrides to system library functions.
-@copyright Copyright (c) 2007 Radtastical Inc.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-#if defined(DARWIN) && !defined(IPHONE) && !defined(SNOWLEOPARD)
-
-#include "mach_override.h"
-#include "Foundation/Foundation.h"
-
-#ifdef __x86_64__
-
-// Since mach_override is not yet available for x86_64,
-// use a quick-and-dirty substitute.
-
-#include <mach-o/dyld.h>
-
-static void *ptrToNSLog = 0;
-static unsigned char firstByteOfNSLog = 0;
-
-void nu_disableNSLog()
-{
- int err = 0;
- if (ptrToNSLog == 0) {
- _dyld_lookup_and_bind("_NSLog", (void*) &ptrToNSLog, NULL);
- if (ptrToNSLog) {
- err = vm_protect( mach_task_self(),
- (vm_address_t) ptrToNSLog,
- sizeof(long), false, (VM_PROT_ALL | VM_PROT_COPY) );
- if (err)
- err = vm_protect( mach_task_self(),
- (vm_address_t) ptrToNSLog, sizeof(long), false,
- (VM_PROT_DEFAULT | VM_PROT_COPY) );
- }
- }
- if (!ptrToNSLog || err) {
- NSLog(@"failed to control NSLog");
- }
- else if (!firstByteOfNSLog) {
- firstByteOfNSLog = *((unsigned char *)ptrToNSLog);
- // this is not guaranteed to be atomic, so it's thread-unsafe
- *((unsigned char *)ptrToNSLog) = 0xc3; // ret
- }
-}
-
-void nu_enableNSLog()
-{
- if (ptrToNSLog) {
- *((unsigned char *)ptrToNSLog) = firstByteOfNSLog;
- firstByteOfNSLog = 0;
- }
-}
-
-#else
-
-typedef void (*NSLogPtr)(NSString *format, ...);
-static NSLogPtr g_originalNSLog;
-static BOOL g_enableNSLog;
-
-static void NuLog(void *format, ...)
-{
- if (g_enableNSLog) {
- va_list ap;
- va_start (ap, format);
- NSLogv (format, ap);
- va_end (ap);
- }
- return;
-}
-
-void nu_disableNSLog()
-{
- kern_return_t err;
- static int initialized = 0;
- if (!initialized) {
- initialized = 1;
- err = mach_override( "_NSLog", NULL, (void*)&NuLog, (void**)&g_originalNSLog);
- }
- g_enableNSLog = false;
-}
-
-void nu_enableNSLog()
-{
- g_enableNSLog = true;
-}
-#endif
-#else
-
-void nu_disableNSLog()
-{
-}
-
-void nu_enableNSLog()
-{
-}
-
-#endif
View
4 objc/NuParser.m
@@ -15,10 +15,6 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
-#ifdef GNUSTEP
-#define true 1
-#define false 0
-#endif
#import "NuParser.h"
#import "NuSymbol.h"
View
353 objc/NuProtocol.m
@@ -1,353 +0,0 @@
-/*!
-@file protocol.m
-@description Nu support for protocols.
-@copyright Copyright (c) 2007 Radtastical Inc.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-#ifdef GNUSTEP
-#define true 1
-#define false 0
-#import <objc/objc.h>
-#import <objc/objc-api.h>
-#endif
-
-#import <Foundation/Foundation.h>
-#include "NuClass.h"
-#include "NuExtensions.h"
-
-#ifdef DARWIN
-#include "objc/runtime.h"
-#include "mach_override.h"
-#endif
-
-#ifdef GNUSTEP
-struct objc_method_description_list
-{
- int count;
- struct objc_method_description list[1];
-};
-#endif
-
-#ifndef IPHONE
-#ifndef __DARWIN_10_6_AND_LATER
-#ifndef __x86_64__
-#ifndef SNOWLEOPARD
-
-@interface Protocol : NSObject
-{
- @public
- char *protocol_name;
- struct objc_protocol_list *protocol_list;
- struct objc_method_description_list *instance_methods;
- struct objc_method_description_list *class_methods;
-}
-
-- (const char *) name;
-+ (Protocol *) protocolWithName:(NSString *) name;
-+ (Protocol *) protocolNamed:(NSString *) name;
-+ (NSArray *) all;
-- (Protocol *) initWithName:(NSString *) name;
-- (NSArray *) methodDescriptions;
-- (NSComparisonResult) compare:(Protocol *) other;
-- (NSArray *) protocols;
-- (void) addInstanceMethod:(NSString *)name withSignature:(NSString *)signature;
-- (void) addClassMethod:(NSString *)name withSignature:(NSString *)signature;
-@end
-
-// When we create protocols at runtime, we put them here.
-static NSMutableDictionary *nuProtocols;
-
-@implementation Protocol (Nu)
-
-+ (Protocol *) protocolWithName:(NSString *) name
-{
- return [[[Protocol alloc] initWithName:name] autorelease];
-}
-
-+ (Protocol *) protocolNamed:(NSString *) name
-{
- Protocol *protocol = objc_getProtocol([name cStringUsingEncoding:NSUTF8StringEncoding]);
- if (protocol) return protocol;
- return nil;
-}
-
-+ (NSArray *) all
-{
- unsigned int count;
- Protocol **protocolList = objc_copyProtocolList(&count);
- NSMutableArray *array = [NSMutableArray array];
- for (int i = 0; i < count; i++) {
- [array addObject:protocolList[i]];
- }
- free(protocolList);
- return array;
-}
-
-- (Protocol *) initWithName:(NSString *) name
-{
- [super init];
- protocol_name = strdup([name cStringUsingEncoding:NSUTF8StringEncoding]);
- protocol_list = NULL;
- instance_methods = NULL;
- class_methods = NULL;
-
- if (!nuProtocols)
- nuProtocols = [[NSMutableDictionary alloc] init];
- [nuProtocols setPossiblyNullObject:self forKey:name];
- return self;
-}
-
-static void addMethodDescriptionsToArray(Protocol *protocol, BOOL isRequiredMethod, BOOL isInstanceMethod, NSMutableArray *array)
-{
- unsigned int count;
- struct objc_method_description *method_descriptions =
- protocol_copyMethodDescriptionList(protocol, isRequiredMethod, isInstanceMethod, &count);
- for (int i = 0; i < count; i++) {
- #ifdef DARWIN
- NSString *name = [NSString stringWithCString:sel_getName(method_descriptions[i].name) encoding:NSASCIIStringEncoding];
- #else
- NSString *name = [NSString stringWithCString:sel_get_name(method_descriptions[i].name) encoding:NSASCIIStringEncoding];
- #endif
- NSString *signature = [NSString stringWithCString:method_descriptions[i].types encoding:NSASCIIStringEncoding];
- NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:name, @"name",
- signature, @"signature",
- [NSNumber numberWithInt:(isRequiredMethod ? 1 : 0)], @"required",
- [NSNumber numberWithInt:(isInstanceMethod ? 1 : 0)], @"instance",
- nil];
- [array addObject:dictionary];
- }
- free(method_descriptions);
-}
-
-- (NSArray *) methodDescriptions
-{
- NSMutableArray *array = [NSMutableArray array];
- addMethodDescriptionsToArray(self, true, true, array);
- addMethodDescriptionsToArray(self, true, false, array);
- addMethodDescriptionsToArray(self, false, true, array);
- addMethodDescriptionsToArray(self, false, false, array);
- return array;
-}
-
-- (NSComparisonResult) compare:(Protocol *) other
-{
- return strcmp([self name], [other name]);
-}
-
-- (NSArray *) protocols
-{
- NSMutableArray *array = [NSMutableArray array];
- unsigned int count;
- Protocol **protocolList = protocol_copyProtocolList(self, &count);
- for (int i = 0; i < count; i++) {
- [array addObject:protocolList[i]];
- }
- free(protocolList);
- return array;
-}
-
-- (void) addInstanceMethod:(NSString *)name withSignature:(NSString *)signature
-{
- #ifdef DARWIN
- SEL sel = sel_registerName([name cStringUsingEncoding:NSUTF8StringEncoding]);
- #else
- SEL sel = sel_register_name([name cStringUsingEncoding:NSUTF8StringEncoding]);
- #endif
- const char *types = [signature cStringUsingEncoding:NSUTF8StringEncoding];
-
- struct objc_method_description_list *oldList = self->instance_methods;
-
- //NSLog(@"old instance method list is %d", oldList);
- if (oldList) {
- struct objc_method_description_list *newList = (struct objc_method_description_list *) malloc
- (sizeof(struct objc_method_description_list) + oldList->count * (sizeof (struct objc_method_description)));
- memcpy(newList, oldList,
- (sizeof(struct objc_method_description_list) + (oldList->count-1) * (sizeof (struct objc_method_description))));
- newList->list[oldList->count].name = sel;
- newList->list[oldList->count].types = strdup(types);
- newList->count++;
- //free(oldList); leak. It seems that we can't free the lists created when protocols are loaded from compiled objects.
- self->instance_methods = newList;
- }
- else {
- struct objc_method_description_list *newList = (struct objc_method_description_list *) malloc
- (sizeof(struct objc_method_description_list));
- newList->list[0].name = sel;
- newList->list[0].types = strdup(types);
- newList->count = 1;
- self->instance_methods = newList;
- }
-}
-
-- (void) addClassMethod:(NSString *)name withSignature:(NSString *)signature
-{
- #ifdef DARWIN
- SEL sel = sel_registerName([name cStringUsingEncoding:NSUTF8StringEncoding]);
- #else
- SEL sel = sel_register_name([name cStringUsingEncoding:NSUTF8StringEncoding]);
- #endif
- const char *types = [signature cStringUsingEncoding:NSUTF8StringEncoding];
-
- struct objc_method_description_list *oldList = self->class_methods;
- //NSLog(@"old class method list is %d", oldList);
- if (oldList) {
- struct objc_method_description_list *newList = (struct objc_method_description_list *) malloc
- (sizeof(struct objc_method_description_list) + oldList->count * (sizeof (struct objc_method_description)));
- memcpy(newList, oldList,
- (sizeof(struct objc_method_description_list) + (oldList->count-1) * (sizeof (struct objc_method_description))));
- newList->list[oldList->count].name = sel;
- newList->list[oldList->count].types = strdup(types);
- newList->count++;
- //free(oldList);
- self->class_methods = newList;
- }
- else {
- struct objc_method_description_list *newList = (struct objc_method_description_list *) malloc
- (sizeof(struct objc_method_description_list));
- newList->list[0].name = sel;
- newList->list[0].types = strdup(types);
- newList->count = 1;
- self->class_methods = newList;
- }
-}
-
-@end
-
-@implementation NuClass (Protocols)
-
-- (BOOL) addProtocol:(Protocol *)p
-{
- return class_addProtocol(self->c, p);
-}
-
-- (BOOL) conformsToProtocol:(Protocol *)p
-{
- return class_conformsToProtocol(self->c, p);
-}
-
-- (NSArray *) protocols
-{
- NSMutableArray *array = [NSMutableArray array];
- unsigned int count;
- Protocol **protocolList = class_copyProtocolList(self->c, &count);
- for (int i = 0; i < count; i++) {
- [array addObject:protocolList[i]];
- }
- free(protocolList);
- return array;
-}
-
-@end
-
-typedef Protocol *(*objc_getProtocol_ptr)(const char *name);
-static objc_getProtocol_ptr original_objc_getProtocol;
-
-Protocol *nu_objc_getProtocol(const char *name)
-{
- // NSLog(@"nu_objc_getProtocol %s", name);
- Protocol *p = (*original_objc_getProtocol)(name);
- if (p) return p;
- else if (nuProtocols) {
- // lookup protocol in our dictionary
- id key = [NSString stringWithCString:name encoding:NSUTF8StringEncoding];
- return [nuProtocols objectForKey:key];
- } else
- return nil;
-}
-
-typedef Protocol **(*objc_copyProtocolList_ptr)(unsigned int *outCount);
-static objc_copyProtocolList_ptr original_objc_copyProtocolList;
-
-Protocol **nu_objc_copyProtocolList(unsigned int *outCount)
-{
- //NSLog(@"nu_objc_copyProtocolList");
- Protocol **originalProtocolList = (*original_objc_copyProtocolList)(outCount);
- if (!nuProtocols || ([nuProtocols count] == 0)) {
- return originalProtocolList;
- }
- Protocol **newProtocolList = (Protocol **) malloc ((*outCount + [nuProtocols count]) * sizeof (Protocol *));
- for (int i = 0; i < *outCount; i++) {
- newProtocolList[i] = originalProtocolList[i];
- }
- id myProtocolArray = [nuProtocols allValues];
- for (int i = 0; i < [nuProtocols count]; i++) {
- newProtocolList[i+*outCount] = [myProtocolArray objectAtIndex:i];
- }
- free(originalProtocolList);
- *outCount += [nuProtocols count];
- return newProtocolList;
-}
-#endif
-
-void nu_initProtocols()
-{
- #ifndef __x86_64__
- #ifndef SNOWLEOPARD
- static int initialized = 0;
- if (!initialized) {
- initialized = 1;
- nuProtocols = nil;
- // We wish that Protocal inherited from NSObject instead of Object, so we make it so.
- // This makes it easier to manipulate Protocols from Nu.
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- [[NuClass classWithClass:[Protocol class]] setSuperclass:[NuClass classWithClass:[NSObject class]]];
- [pool release];
- #ifdef DARWIN
- // Since Apple doesn't have an API to add new protocols, we make our own.
- // We replace these functions with our own versions to include the protocols we create at runtime.
- mach_override("_objc_getProtocol", NULL, (void*)&nu_objc_getProtocol, (void**)&original_objc_getProtocol);
- mach_override("_objc_copyProtocolList", NULL, (void*)&nu_objc_copyProtocolList, (void**)&original_objc_copyProtocolList);
- #endif
- }
- #endif
- #endif
-}
-#ifdef DARWIN
-// bonus: I found this in the ObjC2.0 runtime.
-@interface NuImage : NSObject
-{
-}
-
-@end
-
-@implementation NuImage
-
-+ (NSArray *) all
-{
- NSMutableArray *array = [NSMutableArray array];
- unsigned int count;
- const char **names = objc_copyImageNames(&count);
- for (int i = 0; i < count; i++) {
- [array addObject:[NSString stringWithCString:names[i] encoding:NSUTF8StringEncoding]];
- }
- return array;
-}
-
-+ (NSArray *) classNamesForImageName:(NSString *) imageName
-{
- NSMutableArray *array = [NSMutableArray array];
- unsigned int count;
- const char **names = objc_copyClassNamesForImage([imageName cStringUsingEncoding:NSUTF8StringEncoding], &count);
- for (int i = 0; i < count; i++) {
- [array addObject:[NSString stringWithCString:names[i] encoding:NSUTF8StringEncoding]];
- }
- return array;
-}
-
-@end
-#endif
-#endif
-#endif
-#endif
View
9 objc/NuTypes.h
@@ -1,9 +0,0 @@
-
-#ifdef GNUSTEP
-
-#define bool char
-
-#define true 1
-#define false 0
-
-#endif
Please sign in to comment.
Something went wrong with that request. Please try again.