Skip to content

Commit

Permalink
Replaced all occurrences of (id)[NSNull null] with Nu__null for brevi…
Browse files Browse the repository at this point in the history
…ty and some efficiency.
  • Loading branch information
Dirk Theisen authored and ksjogo committed Apr 13, 2017
1 parent 7a2dc39 commit 56d2f79
Show file tree
Hide file tree
Showing 16 changed files with 86 additions and 86 deletions.
8 changes: 4 additions & 4 deletions objc/NSArray+Nu.m
Expand Up @@ -142,22 +142,22 @@ - (void) addObjectsFromList:(id)list

- (void) addPossiblyNullObject:(id)anObject
{
[self addObject:((anObject == nil) ? (id)[NSNull null] : anObject)];
[self addObject:((anObject == nil) ? Nu__null : anObject)];
}

- (void) insertPossiblyNullObject:(id)anObject atIndex:(int)index
{
[self insertObject:((anObject == nil) ? (id)[NSNull null] : anObject) atIndex:index];
[self insertObject:((anObject == nil) ? Nu__null : anObject) atIndex:index];
}

- (void) replaceObjectAtIndex:(int)index withPossiblyNullObject:(id)anObject
{
[self replaceObjectAtIndex:index withObject:((anObject == nil) ? (id)[NSNull null] : anObject)];
[self replaceObjectAtIndex:index withObject:((anObject == nil) ? Nu__null : anObject)];
}

- (void) sortUsingBlock:(NuBlock *) block
{
[self sortUsingFunction:sortedArrayUsingBlockHelper context:block];
}

@end
@end
4 changes: 2 additions & 2 deletions objc/NSDictionary+Nu.m
Expand Up @@ -22,7 +22,7 @@ + (NSDictionary *) dictionaryWithList:(id) list
key = [key labelName];
}
id value = [[cursor cdr] car];
if (!value || [value isEqual:[NSNull null]]) {
if (!value || [value isEqual:Nu__null]) {
[d removeObjectForKey:key];
} else {
[d setValue:value forKey:key];
Expand Down Expand Up @@ -133,7 +133,7 @@ - (id) lookupObjectForKey:(id)key

- (void) setPossiblyNullObject:(id) anObject forKey:(id) aKey
{
[self setObject:((anObject == nil) ? (id)[NSNull null] : anObject) forKey:aKey];
[self setObject:((anObject == nil) ? Nu__null : anObject) forKey:aKey];
}

@end
6 changes: 3 additions & 3 deletions objc/NSNull+Nu.m
Expand Up @@ -28,7 +28,7 @@ - (NSUInteger) count

- (NSMutableArray *) array
{
return [NSMutableArray array];
return @[];
}

- (NSString *) stringValue
Expand All @@ -41,9 +41,9 @@ - (BOOL) isEqual:(id) other
return ((self == other) || (other == 0)) ? 1l : 0l;
}

- (const char *) cStringUsingEncoding:(NSStringEncoding) encoding
- (const char *) UTF8String
{
return [[self stringValue] cStringUsingEncoding:encoding];
return [[self stringValue] UTF8String];
}

@end
Expand Down
4 changes: 2 additions & 2 deletions objc/NSObject+Nu.m
Expand Up @@ -305,7 +305,7 @@ - (id) handleUnknownMessage:(id) message withContext:(NSMutableDictionary *) con
// If the object responds to methodSignatureForSelector:, we should create and forward an invocation to it.
NSMethodSignature *methodSignature = sel ? [self methodSignatureForSelector:sel] : 0;
if (methodSignature) {
id result = [NSNull null];
id result = Nu__null;
// Create an invocation to forward.
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature];
[invocation setTarget:self];
Expand All @@ -331,7 +331,7 @@ - (id) handleUnknownMessage:(id) message withContext:(NSMutableDictionary *) con
[invocation getReturnValue:buffer];
result = get_nu_value_from_objc_value(buffer, [methodSignature methodReturnType]);
} @catch (id exception) {
result = [NSNull null];
result = Nu__null;
}
free(buffer);
}
Expand Down
2 changes: 1 addition & 1 deletion objc/NSSet+Nu.m
Expand Up @@ -50,7 +50,7 @@ @implementation NSMutableSet(Nu)

- (void) addPossiblyNullObject:(id)anObject
{
[self addObject:((anObject == nil) ? (id)[NSNull null] : anObject)];
[self addObject:((anObject == nil) ? Nu__null : anObject)];
}

@end
Expand Down
4 changes: 2 additions & 2 deletions objc/Nu.m
Expand Up @@ -249,7 +249,7 @@ void NuInit()
initialized = YES;
@autoreleasepool {
// as a convenience, we set a file static variable to nil.
Nu__null = [NSNull null];
Nu__null = Nu__null;

// add enumeration to collection classes
[NSArray include: [NuClass classWithClass:[NuEnumerable class]]];
Expand Down Expand Up @@ -298,7 +298,7 @@ void NuInit()

id _nunull()
{
return [NSNull null];
return Nu__null;
}

id _nustring(const unsigned char *string)
Expand Down
70 changes: 35 additions & 35 deletions objc/NuBridge.m
Expand Up @@ -483,7 +483,7 @@ int set_objc_value_from_nu_value(void *objc_value, id nu_value, const char *type
case 'c':
#endif
{
if (nu_value == [NSNull null]) {
if (nu_value == Nu__null) {
*((int *) objc_value) = 0;
return NO;
}
Expand Down Expand Up @@ -512,7 +512,7 @@ int set_objc_value_from_nu_value(void *objc_value, id nu_value, const char *type
#endif
case 'L':
{
if (nu_value == [NSNull null]) {
if (nu_value == Nu__null) {
*((unsigned long *) objc_value) = 0;
return NO;
}
Expand All @@ -521,7 +521,7 @@ int set_objc_value_from_nu_value(void *objc_value, id nu_value, const char *type
}
case 'l':
{
if (nu_value == [NSNull null]) {
if (nu_value == Nu__null) {
*((long *) objc_value) = 0;
return NO;
}
Expand All @@ -530,7 +530,7 @@ int set_objc_value_from_nu_value(void *objc_value, id nu_value, const char *type
}
case 'Q':
{
if (nu_value == [NSNull null]) {
if (nu_value == Nu__null) {
*((unsigned long long *) objc_value) = 0;
return NO;
}
Expand All @@ -539,7 +539,7 @@ int set_objc_value_from_nu_value(void *objc_value, id nu_value, const char *type
}
case 'q':
{
if (nu_value == [NSNull null]) {
if (nu_value == Nu__null) {
*((long long *) objc_value) = 0;
return NO;
}
Expand Down Expand Up @@ -572,7 +572,7 @@ int set_objc_value_from_nu_value(void *objc_value, id nu_value, const char *type
case ':':
{
// selectors must be strings (symbols could be ok too...)
if (!nu_value || (nu_value == [NSNull null])) {
if (!nu_value || (nu_value == Nu__null)) {
*((SEL *) objc_value) = 0;
return NO;
}
Expand Down Expand Up @@ -647,7 +647,7 @@ int set_objc_value_from_nu_value(void *objc_value, id nu_value, const char *type

case '^':
{
if (!nu_value || (nu_value == [NSNull null])) {
if (!nu_value || (nu_value == Nu__null)) {
*((char ***) objc_value) = NULL;
return NO;
}
Expand Down Expand Up @@ -719,12 +719,12 @@ id get_nu_value_from_objc_value(void *objc_value, const char *typeString)
switch(typeChar) {
case 'v':
{
return [NSNull null];
return Nu__null;
}
case '@':
{
id result = *((id *)objc_value);
return result ? result : (id)[NSNull null];
return result ? result : Nu__null;
}
case '#':
{
Expand Down Expand Up @@ -882,7 +882,7 @@ id get_nu_value_from_objc_value(void *objc_value, const char *typeString)
{
if (!strcmp(typeString, "^v")) {
if (*((unsigned long *)objc_value) == 0)
return [NSNull null];
return Nu__null;
else {
id nupointer = [[[NuPointer alloc] init] autorelease];
[nupointer setPointer:*((void **)objc_value)];
Expand All @@ -899,27 +899,27 @@ id get_nu_value_from_objc_value(void *objc_value, const char *typeString)
// CGImageRef is one. As we find others, we can add them here.
else if (!strcmp(typeString, "^{CGImage=}")) {
id result = *((id *)objc_value);
return result ? result : (id)[NSNull null];
return result ? result : Nu__null;
}
else if (!strcmp(typeString, "^{CGColor=}")) {
id result = *((id *)objc_value);
return result ? result : (id)[NSNull null];
return result ? result : Nu__null;
}
else {
if (*((unsigned long *)objc_value) == 0)
return [NSNull null];
return Nu__null;
else {
id nupointer = [[[NuPointer alloc] init] autorelease];
[nupointer setPointer:*((void **)objc_value)];
[nupointer setTypeString:[NSString stringWithCString:typeString encoding:NSUTF8StringEncoding]];
return nupointer;
}
}
return [NSNull null];
return Nu__null;
}
default:
NSLog (@"UNIMPLEMENTED: unable to wrap object of type %s", typeString);
return [NSNull null];
return Nu__null;
}

}
Expand Down Expand Up @@ -968,15 +968,15 @@ id nu_calling_objc_method_handler(id target, Method m, NSMutableArray *args)
// ensure that methods declared to return void always return void.
char return_type_buffer[BUFSIZE];
method_getReturnType(m, return_type_buffer, BUFSIZE);
return (!strcmp(return_type_buffer, "v")) ? (id)[NSNull null] : result;
return (!strcmp(return_type_buffer, "v")) ? Nu__null : result;
}

id result;
// if we get here, we're going through the ObjC runtime to make the call.
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

SEL s = method_getName(m);
result = [NSNull null];
result = Nu__null;

// dynamically construct the method call

Expand Down Expand Up @@ -1267,7 +1267,7 @@ id add_method_to_class(Class c, NSString *methodName, NSString *signature, NuBlo
IMP imp = construct_method_handler(selector, block, signature_str);
if (imp == NULL) {
NSLog(@"failed to construct handler for %s(%s)", method_name_str, signature_str);
return [NSNull null];
return Nu__null;
}

// save the block in a hash table keyed by the imp.
Expand All @@ -1278,7 +1278,7 @@ id add_method_to_class(Class c, NSString *methodName, NSString *signature, NuBlo
// insert the method handler in the class method table
nu_class_replaceMethod(c, selector, imp, signature_str);
//NSLog(@"setting handler for %s(%s) in class %s", method_name_str, signature_str, class_getName(c));
return [NSNull null];
return Nu__null;
}


Expand Down Expand Up @@ -1368,7 +1368,7 @@ static void prepare_symbols(NuSymbolTable *symbolTable)
[modifiers addObject:@"r"];
}
else if (cursor_car == void_symbol) {
if (![cursor cdr] || ([cursor cdr] == [NSNull null])) {
if (![cursor cdr] || ([cursor cdr] == Nu__null)) {
if (modifiers)
[signature appendString:[[modifiers sortedArrayUsingSelector:@selector(compare:)] componentsJoinedByString:@""]];
[signature appendString:@"v"];
Expand All @@ -1381,7 +1381,7 @@ static void prepare_symbols(NuSymbolTable *symbolTable)
}
}
else if (cursor_car == id_symbol) {
if (![cursor cdr] || ([cursor cdr] == [NSNull null])) {
if (![cursor cdr] || ([cursor cdr] == Nu__null)) {
if (modifiers)
[signature appendString:[[modifiers sortedArrayUsingSelector:@selector(compare:)] componentsJoinedByString:@""]];
[signature appendString:@"@"];
Expand Down Expand Up @@ -1478,17 +1478,17 @@ id help_add_method_to_class(Class classToExtend, id cdr, NSMutableDictionary *co
{
NuSymbolTable *symbolTable = [context objectForKey:SYMBOLS_KEY];

id returnType = [NSNull null];
id returnType = Nu__null;
id selector = [[[NuCell alloc] init] autorelease];
id argumentTypes = [NSNull null];
id argumentNames = [NSNull null];
id argumentTypes = Nu__null;
id argumentNames = Nu__null;
id isSymbol = [symbolTable symbolWithString:@"is"];
id cursor = cdr;
id selector_cursor = nil;
id argumentTypes_cursor = nil;
id argumentNames_cursor = nil;

if (cursor && (cursor != [NSNull null]) && ([cursor car] != isSymbol)) {
if (cursor && (cursor != Nu__null) && ([cursor car] != isSymbol)) {
// scan the return type
if (![[cursor car] atom]) {
returnType = [cursor car] ;
Expand All @@ -1498,10 +1498,10 @@ id help_add_method_to_class(Class classToExtend, id cdr, NSMutableDictionary *co
// The return type specifier must be a list (in parens). If it is missing, leave it as null.
returnType = Nu__null;
}
if (cursor && (cursor != [NSNull null])) {
if (cursor && (cursor != Nu__null)) {
[selector setCar:[cursor car]]; // scan a part of the selector
cursor = [cursor cdr];
if (cursor && (cursor != [NSNull null])) {
if (cursor && (cursor != Nu__null)) {
if ([cursor car] != isSymbol) {
argumentTypes = [[[NuCell alloc] init] autorelease];
argumentNames = [[[NuCell alloc] init] autorelease];
Expand All @@ -1510,10 +1510,10 @@ id help_add_method_to_class(Class classToExtend, id cdr, NSMutableDictionary *co
[argumentTypes setCar:[cursor car]];
cursor = [cursor cdr];
}
if (cursor && (cursor != [NSNull null])) {
if (cursor && (cursor != Nu__null)) {
[argumentNames setCar:[cursor car]];
cursor = [cursor cdr];
if (cursor && (cursor != [NSNull null])) {
if (cursor && (cursor != Nu__null)) {
selector_cursor = selector;
argumentTypes_cursor = argumentTypes;
argumentNames_cursor = argumentNames;
Expand All @@ -1524,7 +1524,7 @@ id help_add_method_to_class(Class classToExtend, id cdr, NSMutableDictionary *co
}
}
// scan each remaining part of the selector
while (cursor && (cursor != [NSNull null]) && ([cursor car] != isSymbol)) {
while (cursor && (cursor != Nu__null) && ([cursor car] != isSymbol)) {
[selector_cursor setCdr:[[[NuCell alloc] init] autorelease]];
[argumentTypes_cursor setCdr:[[[NuCell alloc] init] autorelease]];
[argumentNames_cursor setCdr:[[[NuCell alloc] init] autorelease]];
Expand All @@ -1534,20 +1534,20 @@ id help_add_method_to_class(Class classToExtend, id cdr, NSMutableDictionary *co

[selector_cursor setCar:[cursor car]];
cursor = [cursor cdr];
if (cursor && (cursor != [NSNull null])) {
if (cursor && (cursor != Nu__null)) {
if (![[cursor car] atom]) {
// the argument type specifier must be a list. If it is missing, we'll use a default.
[argumentTypes_cursor setCar:[cursor car]];
cursor = [cursor cdr];
}
if (cursor && (cursor != [NSNull null])) {
if (cursor && (cursor != Nu__null)) {
[argumentNames_cursor setCar:[cursor car]];
cursor = [cursor cdr];
}
}
}

if (cursor && (cursor != [NSNull null])) {
if (cursor && (cursor != Nu__null)) {
//NSLog(@"selector: %@", [selector stringValue]);
//NSLog(@"argument names: %@", [argumentNames stringValue]);
//NSLog(@"argument types:%@", [argumentTypes stringValue]);
Expand All @@ -1559,7 +1559,7 @@ id help_add_method_to_class(Class classToExtend, id cdr, NSMutableDictionary *co
// combine the selectors into the method name
NSMutableString *methodName = [[[NSMutableString alloc] init] autorelease];
selector_cursor = selector;
while (selector_cursor && (selector_cursor != [NSNull null])) {
while (selector_cursor && (selector_cursor != Nu__null)) {
[methodName appendString:[[selector_cursor car] stringValue]];
selector_cursor = [selector_cursor cdr];
}
Expand Down Expand Up @@ -1595,7 +1595,7 @@ id help_add_method_to_class(Class classToExtend, id cdr, NSMutableDictionary *co

// then describe the arguments
argumentTypes_cursor = argumentTypes;
while (argumentTypes_cursor && (argumentTypes_cursor != [NSNull null])) {
while (argumentTypes_cursor && (argumentTypes_cursor != Nu__null)) {
id typeIdentifier = [argumentTypes_cursor car];
[signature appendString:signature_for_identifier(typeIdentifier, symbolTable)];
argumentTypes_cursor = [argumentTypes_cursor cdr];
Expand Down
2 changes: 1 addition & 1 deletion objc/NuBridgedFunction.m
Expand Up @@ -90,7 +90,7 @@ - (id) evalWithArguments:(id) cdr context:(NSMutableDictionary *) context
int status = ffi_prep_cif(cif, FFI_DEFAULT_ABI, argument_count, result_type, argument_types);
if (status != FFI_OK) {
NSLog (@"failed to prepare cif structure");
return [NSNull null];
return Nu__null;
}

id arg_cursor = cdr;
Expand Down

0 comments on commit 56d2f79

Please sign in to comment.