mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 08:41:03 +00:00
Initial revision
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@251 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
d440f74548
commit
0658b3861e
21 changed files with 1999 additions and 0 deletions
103
Source/NSCTemplateValue.m
Normal file
103
Source/NSCTemplateValue.m
Normal file
|
@ -0,0 +1,103 @@
|
|||
/* NSValue.h - Object encapsulation for C types.
|
||||
Copyright (C) 1993,1994 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
||||
Date: Mar 1995
|
||||
|
||||
This file is part of the GNU Objective C Class Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <foundation/NSConcreteValue.h>
|
||||
#include <foundation/NSString.h>
|
||||
#include <foundation/NSException.h>
|
||||
#include <foundation/NSCoder.h>
|
||||
#include <objects/stdobjects.h>
|
||||
|
||||
/* This file should be run through a preprocessor with the macro TYPE_ORDER
|
||||
defined to a number from 0 to 4 cooresponding to each value type */
|
||||
#if TYPE_ORDER == 0
|
||||
# define NSCTemplateValue NSNonretainedObjectValue
|
||||
# define TYPE_METHOD nonretainedObjectValue
|
||||
# define TYPE_NAME id
|
||||
#elif TYPE_ORDER == 1
|
||||
# define NSCTemplateValue NSPointValue
|
||||
# define TYPE_METHOD pointValue
|
||||
# define TYPE_NAME NSPoint
|
||||
#elif TYPE_ORDER == 2
|
||||
# define NSCTemplateValue NSPointerValue
|
||||
# define TYPE_METHOD pointerValue
|
||||
# define TYPE_NAME void *
|
||||
#elif TYPE_ORDER == 3
|
||||
# define NSCTemplateValue NSRectValue
|
||||
# define TYPE_METHOD rectValue
|
||||
# define TYPE_NAME NSRect
|
||||
#elif TYPE_ORDER == 4
|
||||
# define NSCTemplateValue NSSizeValue
|
||||
# define TYPE_METHOD sizeValue
|
||||
# define TYPE_NAME NSSize
|
||||
#endif
|
||||
|
||||
@implementation NSCTemplateValue
|
||||
|
||||
// Allocating and Initializing
|
||||
|
||||
- initValue:(const void *)value
|
||||
withObjCType:(const char *)type
|
||||
{
|
||||
typedef _dt = data;
|
||||
self = [super init];
|
||||
data = *(_dt *)value;
|
||||
return self;
|
||||
}
|
||||
|
||||
// Accessing Data
|
||||
- (void)getValue:(void *)value
|
||||
{
|
||||
if (!value) {
|
||||
[NSException raise:NSInvalidArgumentException
|
||||
format:@"Cannot copy value into NULL buffer"];
|
||||
/* NOT REACHED */
|
||||
}
|
||||
memcpy( value, &data, objc_sizeof_type([self objCType]) );
|
||||
}
|
||||
|
||||
- (const char *)objCType
|
||||
{
|
||||
typedef _dt = data;
|
||||
return @encode(_dt);
|
||||
}
|
||||
|
||||
- (TYPE_NAME)TYPE_METHOD
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
// NSCoding
|
||||
- (void)encodeWithCoder:(NSCoder *)coder
|
||||
{
|
||||
//FIXME [super encodeWithCoder:coder];
|
||||
[coder encodeValueOfObjCType:[self objCType] at:&data];
|
||||
}
|
||||
|
||||
- (id)initWithCoder:(NSCoder *)coder
|
||||
{
|
||||
//FIXME self = [super initWithCoder:coder];
|
||||
[coder decodeValueOfObjCType:[self objCType] at:&data];
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
209
Source/NSConcreteNumber.m
Normal file
209
Source/NSConcreteNumber.m
Normal file
|
@ -0,0 +1,209 @@
|
|||
/* NSConcreteNumber - Object encapsulation of numbers
|
||||
|
||||
Copyright (C) 1993,1994 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
||||
Date: Mar 1995
|
||||
|
||||
This file is part of the GNU Objective C Class Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <foundation/NSConcreteNumber.h>
|
||||
#include <foundation/NSString.h>
|
||||
#include <foundation/NSException.h>
|
||||
#include <foundation/NSCoder.h>
|
||||
|
||||
/* This file should be run through a preprocessor with the macro TYPE_ORDER
|
||||
defined to a number from 0 to 12 cooresponding to each number type */
|
||||
#if TYPE_ORDER == 0
|
||||
# define NumberTemplate NSBoolNumber
|
||||
# define TYPE_METHOD boolValue
|
||||
# define TYPE_FORMAT @"%uc"
|
||||
#elif TYPE_ORDER == 1
|
||||
# define NumberTemplate NSUCharNumber
|
||||
# define TYPE_METHOD unsignedCharValue
|
||||
# define TYPE_FORMAT @"%uc"
|
||||
#elif TYPE_ORDER == 2
|
||||
# define NumberTemplate NSCharNumber
|
||||
# define TYPE_METHOD charValue
|
||||
# define TYPE_FORMAT @"%c"
|
||||
#elif TYPE_ORDER == 3
|
||||
# define NumberTemplate NSUShortNumber
|
||||
# define TYPE_METHOD unsignedShortValue
|
||||
# define TYPE_FORMAT @"%hu"
|
||||
#elif TYPE_ORDER == 4
|
||||
# define NumberTemplate NSShortNumber
|
||||
# define TYPE_METHOD shortValue
|
||||
# define TYPE_FORMAT @"%hd"
|
||||
#elif TYPE_ORDER == 5
|
||||
# define NumberTemplate NSUIntNumber
|
||||
# define TYPE_METHOD unsignedIntValue
|
||||
# define TYPE_FORMAT @"%u"
|
||||
#elif TYPE_ORDER == 6
|
||||
# define NumberTemplate NSIntNumber
|
||||
# define TYPE_METHOD intValue
|
||||
# define TYPE_FORMAT @"%d"
|
||||
#elif TYPE_ORDER == 7
|
||||
# define NumberTemplate NSULongNumber
|
||||
# define TYPE_METHOD unsignedLongValue
|
||||
# define TYPE_FORMAT @"%lu"
|
||||
#elif TYPE_ORDER == 8
|
||||
# define NumberTemplate NSLongNumber
|
||||
# define TYPE_METHOD longValue
|
||||
# define TYPE_FORMAT @"%ld"
|
||||
#elif TYPE_ORDER == 9
|
||||
# define NumberTemplate NSULongLongNumber
|
||||
# define TYPE_METHOD unsignedLongLongValue
|
||||
# define TYPE_FORMAT @"%llu"
|
||||
#elif TYPE_ORDER == 10
|
||||
# define NumberTemplate NSLongLongNumber
|
||||
# define TYPE_METHOD longLongValue
|
||||
# define TYPE_FORMAT @"%lld"
|
||||
#elif TYPE_ORDER == 11
|
||||
# define NumberTemplate NSFloatNumber
|
||||
# define TYPE_METHOD floatValue
|
||||
# define TYPE_FORMAT @"%f"
|
||||
#elif TYPE_ORDER == 12
|
||||
# define NumberTemplate NSDoubleNumber
|
||||
# define TYPE_METHOD doubleValue
|
||||
# define TYPE_FORMAT @"%g"
|
||||
#endif
|
||||
|
||||
@implementation NumberTemplate
|
||||
|
||||
- initValue:(const void *)value withObjCType:(const char *)type;
|
||||
{
|
||||
typedef _dt = data;
|
||||
self = [super init];
|
||||
data = *(_dt *)value;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)boolValue
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
- (char)charValue
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
- (double)doubleValue
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
- (float)floatValue
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
- (int)intValue
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
- (long long)longLongValue
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
- (long)longValue
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
- (short)shortValue
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
- (NSString *)stringValue
|
||||
{
|
||||
return [NSString stringWithFormat:TYPE_FORMAT, data];
|
||||
}
|
||||
|
||||
- (unsigned char)unsignedCharValue
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
- (unsigned int)unsignedIntValue
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
- (unsigned long long)unsignedLongLongValue
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
- (unsigned long)unsignedLongValue
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
- (unsigned short)unsignedShortValue
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
- (NSComparisonResult)compare:(NSNumber *)otherNumber
|
||||
{
|
||||
typedef _dt = data;
|
||||
_dt other_data = [otherNumber TYPE_METHOD];
|
||||
|
||||
if (data == other_data)
|
||||
return NSOrderedSame;
|
||||
else
|
||||
return (data < other_data) ? NSOrderedAscending : NSOrderedDescending;
|
||||
}
|
||||
|
||||
// Override these from NSValue
|
||||
- (void)getValue:(void *)value
|
||||
{
|
||||
if (!value) {
|
||||
[NSException raise:NSInvalidArgumentException
|
||||
format:@"Cannot copy value into NULL pointer"];
|
||||
/* NOT REACHED */
|
||||
}
|
||||
memcpy( value, &data, objc_sizeof_type([self objCType]) );
|
||||
}
|
||||
|
||||
- (const char *)objCType
|
||||
{
|
||||
typedef _dt = data;
|
||||
return @encode(_dt);
|
||||
}
|
||||
|
||||
// NSCoding
|
||||
- (void)encodeWithCoder:(NSCoder *)coder
|
||||
{
|
||||
//FIXME [super encodeWithCoder:coder];
|
||||
[coder encodeValueOfObjCType:[self objCType] at:&data];
|
||||
}
|
||||
|
||||
- (id)initWithCoder:(NSCoder *)coder
|
||||
{
|
||||
//FIXME self = [super initWithCoder:coder];
|
||||
[coder decodeValueOfObjCType:[self objCType] at:&data];
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
160
Source/NSConcreteValue.m
Normal file
160
Source/NSConcreteValue.m
Normal file
|
@ -0,0 +1,160 @@
|
|||
/* NSConcreteValue.h - Object encapsulation for C types.
|
||||
Copyright (C) 1993,1994 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
||||
Date: Mar 1995
|
||||
|
||||
This file is part of the GNU Objective C Class Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <foundation/NSConcreteValue.h>
|
||||
#include <foundation/NSString.h>
|
||||
#include <foundation/NSException.h>
|
||||
#include <foundation/NSCoder.h>
|
||||
#include <foundation/NSZone.h>
|
||||
#include <objects/stdobjects.h>
|
||||
|
||||
/* This is the real, general purpose value object. I've implemented all the
|
||||
methods here (like pointValue) even though most likely, other concrete
|
||||
subclasses were created to handle these types */
|
||||
|
||||
#define NS_RAISE_MALLOC \
|
||||
[NSException raise:NSMallocException \
|
||||
format:@"No memory left to allocate"]
|
||||
|
||||
#define NS_CHECK_MALLOC(ptr) \
|
||||
if (!ptr) {NS_RAISE_MALLOC;}
|
||||
|
||||
@implementation NSConcreteValue
|
||||
|
||||
// NSCopying
|
||||
- deepen
|
||||
{
|
||||
void *old_ptr;
|
||||
int size;
|
||||
|
||||
size = objc_sizeof_type([objctype cString]);
|
||||
old_ptr = data;
|
||||
data = (void *)NSZoneMalloc([self zone], size);
|
||||
NS_CHECK_MALLOC(data)
|
||||
memcpy(data, old_ptr, size);
|
||||
|
||||
objctype = [objctype copyWithZone:[self zone]];
|
||||
return self;
|
||||
}
|
||||
|
||||
// Allocating and Initializing
|
||||
|
||||
- initValue:(const void *)value
|
||||
withObjCType:(const char *)type
|
||||
{
|
||||
int size;
|
||||
|
||||
if (!value || !type) {
|
||||
[NSException raise:NSInvalidArgumentException
|
||||
format:@"Cannot create with NULL value or NULL type"];
|
||||
/* NOT REACHED */
|
||||
}
|
||||
|
||||
self = [super init];
|
||||
|
||||
// FIXME: objc_sizeof_type will abort when it finds an invalid type, when
|
||||
// we really want to just raise an exception
|
||||
size = objc_sizeof_type(type);
|
||||
if (size <= 0) {
|
||||
[NSException raise:NSInternalInconsistencyException
|
||||
format:@"Invalid Objective-C type"];
|
||||
/* NOT REACHED */
|
||||
}
|
||||
|
||||
data = (void *)NSZoneMalloc([self zone], size);
|
||||
NS_CHECK_MALLOC(data)
|
||||
memcpy(data, value, size);
|
||||
|
||||
objctype = [[NSString stringWithCString:type] retain];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[objctype release];
|
||||
NSZoneFree([self zone], data);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
// Accessing Data
|
||||
- (void)getValue:(void *)value
|
||||
{
|
||||
if (!value) {
|
||||
[NSException raise:NSInvalidArgumentException
|
||||
format:@"Cannot copy value into NULL buffer"];
|
||||
/* NOT REACHED */
|
||||
}
|
||||
memcpy( value, data, objc_sizeof_type([objctype cString]) );
|
||||
}
|
||||
|
||||
- (const char *)objCType
|
||||
{
|
||||
return [objctype cString];
|
||||
}
|
||||
|
||||
// FIXME: need to check to make sure these hold the right values...
|
||||
- (id)nonretainedObjectValue
|
||||
{
|
||||
return *((id *)data);
|
||||
}
|
||||
|
||||
- (void *)pointerValue
|
||||
{
|
||||
return *((void **)data);
|
||||
}
|
||||
|
||||
- (NSRect)rectValue
|
||||
{
|
||||
return *((NSRect *)data);
|
||||
}
|
||||
|
||||
- (NSSize)sizeValue
|
||||
{
|
||||
return *((NSSize *)data);
|
||||
}
|
||||
|
||||
- (NSPoint)pointValue
|
||||
{
|
||||
return *((NSPoint *)data);
|
||||
}
|
||||
|
||||
// NSCoding
|
||||
- (void)encodeWithCoder:(NSCoder *)coder
|
||||
{
|
||||
|
||||
//FIXME [super encodeWithCoder:coder];
|
||||
// FIXME: Do we need to check for encoding void, void * or will
|
||||
// NSCoder do this for us?
|
||||
[coder encodeObject:objctype];
|
||||
[coder encodeValueOfObjCType:[objctype cString] at:&data];
|
||||
}
|
||||
|
||||
- (id)initWithCoder:(NSCoder *)coder
|
||||
{
|
||||
//FIXME self = [super initWithCoder:coder];
|
||||
objctype = [[coder decodeObject] retain];
|
||||
[coder decodeValueOfObjCType:[objctype cString] at:&data];
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
265
Source/NSNumber.m
Normal file
265
Source/NSNumber.m
Normal file
|
@ -0,0 +1,265 @@
|
|||
/* NSNumber - Object encapsulation of numbers
|
||||
|
||||
Copyright (C) 1993,1994 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
||||
Date: Mar 1995
|
||||
|
||||
This file is part of the GNU Objective C Class Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <objects/stdobjects.h>
|
||||
#include <foundation/NSException.h>
|
||||
#include <foundation/NSString.h>
|
||||
#include <foundation/NSConcreteNumber.h>
|
||||
#include <foundation/NSCoder.h>
|
||||
|
||||
@implementation NSNumber
|
||||
|
||||
/* Returns the concrete class associated with the type encoding. Note
|
||||
that we don't allow NSNumber to instantiate any class but its own
|
||||
concrete subclasses (see check at end of method) */
|
||||
+ (Class)valueClassWithObjCType:(const char *)type
|
||||
{
|
||||
Class theClass = Nil;
|
||||
|
||||
switch (*type) {
|
||||
case _C_CHR:
|
||||
theClass = [NSCharNumber class];
|
||||
case _C_UCHR:
|
||||
theClass = [NSUCharNumber class];
|
||||
case _C_SHT:
|
||||
theClass = [NSShortNumber class];
|
||||
case _C_USHT:
|
||||
theClass = [NSUShortNumber class];
|
||||
case _C_INT:
|
||||
theClass = [NSIntNumber class];
|
||||
case _C_UINT:
|
||||
theClass = [NSUIntNumber class];
|
||||
case _C_LNG:
|
||||
theClass = [NSLongNumber class];
|
||||
case _C_ULNG:
|
||||
theClass = [NSULongNumber class];
|
||||
case 'q':
|
||||
theClass = [NSLongLongNumber class];
|
||||
case 'Q':
|
||||
theClass = [NSULongLongNumber class];
|
||||
case _C_FLT:
|
||||
theClass = [NSFloatNumber class];
|
||||
case _C_DBL:
|
||||
theClass = [NSDoubleNumber class];
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (theClass == Nil && self == [NSNumber class]) {
|
||||
[NSException raise:NSInvalidArgumentException
|
||||
format:@"Invalid number type"];
|
||||
/* NOT REACHED */
|
||||
} else if (theClass == Nil)
|
||||
theClass = [super valueClassWithObjCType:type];
|
||||
|
||||
return theClass;
|
||||
}
|
||||
|
||||
+ (NSNumber *)numberWithBool:(BOOL)value
|
||||
{
|
||||
return [[[NSBoolNumber alloc] initValue:&value withObjCType:NULL]
|
||||
autorelease];
|
||||
}
|
||||
|
||||
+ (NSNumber *)numberWithChar:(char)value
|
||||
{
|
||||
return [[[NSCharNumber alloc] initValue:&value withObjCType:NULL]
|
||||
autorelease];
|
||||
}
|
||||
|
||||
+ (NSNumber *)numberWithDouble:(double)value
|
||||
{
|
||||
return [[[NSDoubleNumber alloc] initValue:&value withObjCType:NULL]
|
||||
autorelease];
|
||||
}
|
||||
|
||||
+ (NSNumber *)numberWithFloat:(float)value
|
||||
{
|
||||
return [[[NSFloatNumber alloc] initValue:&value withObjCType:NULL]
|
||||
autorelease];
|
||||
}
|
||||
|
||||
+ (NSNumber *)numberWithInt:(int)value
|
||||
{
|
||||
return [[[NSIntNumber alloc] initValue:&value withObjCType:NULL]
|
||||
autorelease];
|
||||
}
|
||||
|
||||
+ (NSNumber *)numberWithLong:(long)value
|
||||
{
|
||||
return [[[NSNumber alloc] initValue:&value withObjCType:NULL] autorelease];
|
||||
}
|
||||
|
||||
+ (NSNumber *)numberWithLongLong:(long long)value
|
||||
{
|
||||
return [[[NSLongLongNumber alloc] initValue:&value withObjCType:NULL]
|
||||
autorelease];
|
||||
}
|
||||
|
||||
+ (NSNumber *)numberWithShort:(short)value
|
||||
{
|
||||
return [[[NSShortNumber alloc] initValue:&value withObjCType:NULL]
|
||||
autorelease];
|
||||
}
|
||||
|
||||
+ (NSNumber *)numberWithUnsignedChar:(unsigned char)value
|
||||
{
|
||||
return [[[NSUCharNumber alloc] initValue:&value withObjCType:NULL]
|
||||
autorelease];
|
||||
}
|
||||
|
||||
+ (NSNumber *)numberWithUnsignedInt:(unsigned int)value
|
||||
{
|
||||
return [[[NSUIntNumber alloc] initValue:&value withObjCType:NULL]
|
||||
autorelease];
|
||||
}
|
||||
|
||||
+ (NSNumber *)numberWithUnsignedLong:(unsigned long)value
|
||||
{
|
||||
return [[[NSULongNumber alloc] initValue:&value withObjCType:NULL]
|
||||
autorelease];
|
||||
}
|
||||
|
||||
+ (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value
|
||||
{
|
||||
return [[[NSULongLongNumber alloc] initValue:&value withObjCType:NULL]
|
||||
autorelease];
|
||||
}
|
||||
|
||||
+ (NSNumber *)numberWithUnsignedShort:(unsigned short)value
|
||||
{
|
||||
return [[[NSUShortNumber alloc] initValue:&value withObjCType:NULL]
|
||||
autorelease];
|
||||
}
|
||||
|
||||
/* All the rest of these methods must be implemented by a subclass */
|
||||
- (BOOL)boolValue
|
||||
{
|
||||
[self doesNotRecognizeSelector:_cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (char)charValue
|
||||
{
|
||||
[self doesNotRecognizeSelector:_cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (double)doubleValue
|
||||
{
|
||||
[self doesNotRecognizeSelector:_cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (float)floatValue
|
||||
{
|
||||
[self doesNotRecognizeSelector:_cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (int)intValue
|
||||
{
|
||||
[self doesNotRecognizeSelector:_cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (long long)longLongValue
|
||||
{
|
||||
[self doesNotRecognizeSelector:_cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (long)longValue
|
||||
{
|
||||
[self doesNotRecognizeSelector:_cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (short)shortValue
|
||||
{
|
||||
[self doesNotRecognizeSelector:_cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (NSString *)stringValue
|
||||
{
|
||||
[self doesNotRecognizeSelector:_cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (unsigned char)unsignedCharValue
|
||||
{
|
||||
[self doesNotRecognizeSelector:_cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (unsigned int)unsignedIntValue
|
||||
{
|
||||
[self doesNotRecognizeSelector:_cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (unsigned long long)unsignedLongLongValue
|
||||
{
|
||||
[self doesNotRecognizeSelector:_cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (unsigned long)unsignedLongValue
|
||||
{
|
||||
[self doesNotRecognizeSelector:_cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (unsigned short)unsignedShortValue
|
||||
{
|
||||
[self doesNotRecognizeSelector:_cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (NSComparisonResult)compare:(NSNumber *)otherNumber
|
||||
{
|
||||
[self doesNotRecognizeSelector:_cmd];
|
||||
return 0;
|
||||
}
|
||||
|
||||
// NSCoding (done by subclasses)
|
||||
- classForCoder
|
||||
{
|
||||
return [self class];
|
||||
}
|
||||
|
||||
- (void)encodeWithCoder:(NSCoder *)coder
|
||||
{
|
||||
//FIXME [super encodeWithCoder:coder];
|
||||
}
|
||||
|
||||
- (id)initWithCoder:(NSCoder *)coder
|
||||
{
|
||||
//FIXME self = [super initWithCoder:coder];
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
56
Source/NSRange.m
Normal file
56
Source/NSRange.m
Normal file
|
@ -0,0 +1,56 @@
|
|||
/* NSRange - range functions
|
||||
|
||||
*/
|
||||
|
||||
#include <foundation/NSString.h>
|
||||
|
||||
NSRange
|
||||
NSMakeRange(float location, float length)
|
||||
{
|
||||
NSRange range;
|
||||
range.location = location;
|
||||
range.length = length;
|
||||
return range;
|
||||
}
|
||||
|
||||
/* Query a Range */
|
||||
BOOL
|
||||
NSEqualRanges(NSRange range1, NSRange range2)
|
||||
{
|
||||
return ((range1.location == range2.location)
|
||||
&& (range1.length == range2.length));
|
||||
}
|
||||
|
||||
/* Compute a Range from Two Other Ranges */
|
||||
NSRange
|
||||
NSUnionRange(NSRange aRange, NSRange bRange)
|
||||
{
|
||||
NSRange range;
|
||||
|
||||
range.location = MIN(aRange.location, bRange.location);
|
||||
range.length = MAX(NSMaxRange(aRange), NSMaxRange(bRange))
|
||||
- range.location;
|
||||
return range;
|
||||
}
|
||||
|
||||
NSRange
|
||||
NSIntersectionRange (NSRange aRange, NSRange bRange)
|
||||
{
|
||||
NSRange range;
|
||||
|
||||
if (NSMaxRange(aRange) < bRange.location
|
||||
|| NSMaxRange(bRange) < aRange.location)
|
||||
return NSMakeRange(0, 0);
|
||||
|
||||
range.location = MAX(aRange.location, bRange.location);
|
||||
range.length = MIN(NSMaxRange(aRange), NSMaxRange(bRange))
|
||||
- range.location;
|
||||
return range;
|
||||
}
|
||||
|
||||
NSString *
|
||||
NSStringFromRange(NSRange range)
|
||||
{
|
||||
return [NSString stringWithFormat:@"{location = %d, length = %d}",
|
||||
range.location, range.length];
|
||||
}
|
140
Source/dld-load.h
Normal file
140
Source/dld-load.h
Normal file
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
dld-load - Definitions and translations for dynamic loading with GNU dld.
|
||||
|
||||
Copyright (C) 1995, Adam Fedor.
|
||||
|
||||
BUGS:
|
||||
- object files loaded by dld must be loaded with 'ld -r' rather
|
||||
than 'gcc -nostdlib', because dld can't handle multiple symbols
|
||||
like multiple CTOR_LISTS. So here we construct our own CTOR
|
||||
list and return it when asked for (Ack! Pthet!).
|
||||
- __dld_construct_ctor_list may find a constructor that belongs
|
||||
to another module whose name is a super-string of the desired
|
||||
module name.
|
||||
|
||||
$Id$
|
||||
*/
|
||||
|
||||
#ifndef __dld_load_h_INCLUDE
|
||||
#define __dld_load_h_INCLUDE
|
||||
|
||||
#include <dld/defs.h>
|
||||
|
||||
/* This is the GNU gcc name for the CTOR list */
|
||||
#define DLD_CTOR_LIST "___CTOR_LIST__"
|
||||
|
||||
/* The compiler generates a constructor function for each class. The function
|
||||
has the prefix given below.
|
||||
*/
|
||||
#define GLOBAL_PREFIX "_GLOBAL_$I$"
|
||||
|
||||
/* Types defined appropriately for the dynamic linker */
|
||||
typedef char* dl_handle_t;
|
||||
typedef unsigned long dl_symbol_t;
|
||||
|
||||
static void **dld_ctor_list = 0;
|
||||
|
||||
static void**
|
||||
__dld_construct_ctor_list(dl_handle_t module)
|
||||
{
|
||||
int i, ctors, length;
|
||||
|
||||
length = 100;
|
||||
ctors = 1;
|
||||
if (dld_ctor_list)
|
||||
free(dld_ctor_list);
|
||||
dld_ctor_list = (void **) __objc_xmalloc(length * sizeof(void *));
|
||||
/* Find all symbols with the GLOBAL_PREFIX prefix */
|
||||
for (i=0; i < TABSIZE; i++) {
|
||||
struct glosym *sym_entry = _dld_symtab[i];
|
||||
for (; sym_entry; sym_entry = sym_entry->link) {
|
||||
if (strstr(sym_entry->name, GLOBAL_PREFIX)
|
||||
&& strstr(sym_entry->defined_by->filename, module)) {
|
||||
dld_ctor_list[ctors] = (void **)sym_entry->value;
|
||||
ctors++;
|
||||
if (ctors > length) {
|
||||
length *= 2;
|
||||
dld_ctor_list = (void **) __objc_xrealloc(dld_ctor_list,
|
||||
length * sizeof(void *));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
dld_ctor_list[ctors] = (void **)0;
|
||||
dld_ctor_list[0] = (void **)(ctors - 1);
|
||||
|
||||
return dld_ctor_list;
|
||||
}
|
||||
|
||||
/* Do any initialization necessary. Return 0 on success (or
|
||||
if no initialization needed.
|
||||
*/
|
||||
static int
|
||||
__objc_dynamic_init(const char* exec_path)
|
||||
{
|
||||
return dld_init(exec_path);
|
||||
}
|
||||
|
||||
/* Link in the module given by the name 'module'. Return a handle which can
|
||||
be used to get information about the loded code.
|
||||
*/
|
||||
static dl_handle_t
|
||||
__objc_dynamic_link(const char* module, int mode, const char* debug_file)
|
||||
{
|
||||
int error;
|
||||
dl_handle_t handle;
|
||||
|
||||
error = dld_link(module);
|
||||
if (error)
|
||||
return NULL;
|
||||
handle = (dl_handle_t)__objc_xmalloc (strlen(module) + 1);
|
||||
strcpy(handle, module);
|
||||
return handle;
|
||||
}
|
||||
|
||||
/* Return the address of a symbol given by the name 'symbol' from the module
|
||||
associated with 'handle'
|
||||
*/
|
||||
static dl_symbol_t
|
||||
__objc_dynamic_find_symbol(dl_handle_t handle, const char* symbol)
|
||||
{
|
||||
if (strcmp(symbol, DLD_CTOR_LIST) == 0) {
|
||||
return (dl_symbol_t)__dld_construct_ctor_list(handle);
|
||||
}
|
||||
return dld_get_bare_symbol(symbol);
|
||||
}
|
||||
|
||||
/* remove the code from memory associated with the module 'handle' */
|
||||
static int
|
||||
__objc_dynamic_unlink(dl_handle_t handle)
|
||||
{
|
||||
int error;
|
||||
error = dld_unlink_by_file(handle, 0);
|
||||
free(handle);
|
||||
return error;
|
||||
}
|
||||
|
||||
/* Print an error message (prefaced by 'error_string') relevant to the
|
||||
last error encountered
|
||||
*/
|
||||
static void
|
||||
__objc_dynamic_error(FILE *error_stream, const char *error_string)
|
||||
{
|
||||
/* dld won't print to error stream, sorry */
|
||||
dld_perror(error_string);
|
||||
}
|
||||
|
||||
/* Debugging: define these if they are available */
|
||||
static int
|
||||
__objc_dynamic_undefined_symbol_count(void)
|
||||
{
|
||||
return dld_undefined_sym_count;
|
||||
}
|
||||
|
||||
static char**
|
||||
__objc_dynamic_list_undefined_symbols(void)
|
||||
{
|
||||
return dld_list_undefined_sym();
|
||||
}
|
||||
|
||||
#endif /* __dld_load_h_INCLUDE */
|
77
Source/hpux-load.h
Normal file
77
Source/hpux-load.h
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
hpux-load - Definitions and translations for dynamic loading with HP-UX
|
||||
|
||||
Copyright (C) 1995, Adam Fedor.
|
||||
|
||||
$Id$
|
||||
*/
|
||||
|
||||
#ifndef __hpux_load_h_INCLUDE
|
||||
#define __hpux_load_h_INCLUDE
|
||||
|
||||
#include <dl.h>
|
||||
|
||||
/* Types defined appropriately for the dynamic linker */
|
||||
typedef shl_t dl_handle_t;
|
||||
typedef void* dl_symbol_t;
|
||||
|
||||
/* Do any initialization necessary. Return 0 on success (or
|
||||
if no initialization needed.
|
||||
*/
|
||||
static int
|
||||
__objc_dynamic_init(const char* exec_path)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Link in the module given by the name 'module'. Return a handle which can
|
||||
be used to get information about the loded code.
|
||||
*/
|
||||
static dl_handle_t
|
||||
__objc_dynamic_link(const char* module, int mode, const char* debug_file)
|
||||
{
|
||||
return (dl_handle_t)shl_load(module, 0, 0);
|
||||
}
|
||||
|
||||
/* Return the address of a symbol given by the name 'symbol' from the module
|
||||
associated with 'handle'
|
||||
*/
|
||||
static dl_symbol_t
|
||||
__objc_dynamic_find_symbol(dl_handle_t handle, const char* symbol)
|
||||
{
|
||||
int ok;
|
||||
void *value;
|
||||
ok = shl_findsym(&handle, symbol, 0, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
/* remove the code from memory associated with the module 'handle' */
|
||||
static int
|
||||
__objc_dynamic_unlink(dl_handle_t handle)
|
||||
{
|
||||
return shl_unload(handle);
|
||||
}
|
||||
|
||||
/* Print an error message (prefaced by 'error_string') relevant to the
|
||||
last error encountered
|
||||
*/
|
||||
static void
|
||||
__objc_dynamic_error(FILE *error_stream, const char *error_string)
|
||||
{
|
||||
fprintf(error_stream, "%s\n", error_string);
|
||||
}
|
||||
|
||||
/* Debugging: define these if they are available */
|
||||
static int
|
||||
__objc_dynamic_undefined_symbol_count(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char**
|
||||
__objc_dynamic_list_undefined_symbols(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif /* __HPUX_LOAD_INCLUDE__ */
|
73
Source/null-load.h
Normal file
73
Source/null-load.h
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
null-load - NULL dynamic loader. Doesn't do anything.
|
||||
|
||||
Copyright (C) 1995, Adam Fedor.
|
||||
|
||||
$Id$
|
||||
*/
|
||||
|
||||
#ifndef __null_load_h_INCLUDE
|
||||
#define __null_load_h_INCLUDE
|
||||
|
||||
|
||||
/* Types defined appropriately for the dynamic linker */
|
||||
typedef void* dl_handle_t;
|
||||
typedef void* dl_symbol_t;
|
||||
|
||||
/* Do any initialization necessary. Return 0 on success (or
|
||||
if no initialization needed.
|
||||
*/
|
||||
static int
|
||||
__objc_dynamic_init(const char* exec_path)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Link in the module given by the name 'module'. Return a handle which can
|
||||
be used to get information about the loded code.
|
||||
*/
|
||||
static dl_handle_t
|
||||
__objc_dynamic_link(const char* module, int mode, const char* debug_file)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Return the address of a symbol given by the name 'symbol' from the module
|
||||
associated with 'handle'
|
||||
*/
|
||||
static dl_symbol_t
|
||||
__objc_dynamic_find_symbol(dl_handle_t handle, const char* symbol)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* remove the code from memory associated with the module 'handle' */
|
||||
static int
|
||||
__objc_dynamic_unlink(dl_handle_t handle)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Print an error message (prefaced by 'error_string') relevant to the
|
||||
last error encountered
|
||||
*/
|
||||
static void
|
||||
__objc_dynamic_error(FILE *error_stream, const char *error_string)
|
||||
{
|
||||
fprintf(error_stream, "%s\n", error_string);
|
||||
}
|
||||
|
||||
/* Debugging: define these if they are available */
|
||||
static int
|
||||
__objc_dynamic_undefined_symbol_count(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char**
|
||||
__objc_dynamic_list_undefined_symbols(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif /* __null_load_h_INCLUDE */
|
224
Source/objc-load.c
Normal file
224
Source/objc-load.c
Normal file
|
@ -0,0 +1,224 @@
|
|||
/*
|
||||
objc-load - Dynamically load in Obj-C modules (Classes, Categories)
|
||||
|
||||
Written by Adam Fedor, Pedja Bogdanovich
|
||||
|
||||
$Id$
|
||||
|
||||
BUGS:
|
||||
- unloading modules not implemented
|
||||
- would like to raise exceptions without having to turn this into
|
||||
a .m file (right now NSBundle does this for us, ok?)
|
||||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <objc/objc-api.h>
|
||||
#include <objc/list.h>
|
||||
#include <foundation/objc-load.h>
|
||||
|
||||
/* include the interface to the dynamic linker */
|
||||
#include "dynamic-load.h"
|
||||
|
||||
/* From the objc runtime -- needed when invalidating the dtable */
|
||||
extern void __objc_install_premature_dtable(Class);
|
||||
extern void sarray_free(struct sarray*);
|
||||
extern struct sarray *__objc_uninstalled_dtable;
|
||||
|
||||
extern char *objc_find_executable(const char *name);
|
||||
|
||||
/* This is the GNU name for the CTOR list */
|
||||
#define CTOR_LIST "___CTOR_LIST__"
|
||||
|
||||
/* External variables needed to find the path to the executable program. */
|
||||
extern char **NSArgv;
|
||||
|
||||
/* dynamic_loaded is YES if the dynamic loader was sucessfully initialized. */
|
||||
static BOOL dynamic_loaded;
|
||||
|
||||
/* Our current callback function */
|
||||
void (*_objc_load_load_callback)(Class, Category*) = 0;
|
||||
|
||||
/* List of modules we have loaded (by handle) */
|
||||
static struct objc_list *dynamic_handles = NULL;
|
||||
|
||||
/* Check to see if there are any undefined symbols. Print them out.
|
||||
*/
|
||||
static int
|
||||
objc_check_undefineds(FILE *errorStream)
|
||||
{
|
||||
int count = __objc_dynamic_undefined_symbol_count();
|
||||
|
||||
if (count != 0) {
|
||||
int i;
|
||||
char **undefs;
|
||||
undefs = __objc_dynamic_list_undefined_symbols();
|
||||
if (errorStream)
|
||||
fprintf(errorStream, "Undefined symbols:\n");
|
||||
for (i=0; i < count; i++)
|
||||
if (errorStream)
|
||||
fprintf(errorStream, " %s\n", undefs[i]);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *
|
||||
objc_executable_location()
|
||||
{
|
||||
return objc_find_executable(NSArgv[0]);
|
||||
}
|
||||
|
||||
/* Invalidate the dtable so it will be rebuild when a message is sent to
|
||||
the object */
|
||||
static void
|
||||
objc_invalidate_dtable(Class class)
|
||||
{
|
||||
Class s;
|
||||
|
||||
if (class->dtable == __objc_uninstalled_dtable)
|
||||
return;
|
||||
sarray_free(class->dtable);
|
||||
__objc_install_premature_dtable(class);
|
||||
for (s=class->subclass_list; s; s=s->sibling_class)
|
||||
objc_invalidate_dtable(s);
|
||||
}
|
||||
|
||||
/* Initialize for dynamic loading */
|
||||
static int
|
||||
objc_initialize_loading(FILE *errorStream)
|
||||
{
|
||||
char *path;
|
||||
|
||||
dynamic_loaded = NO;
|
||||
path = objc_executable_location();
|
||||
#ifdef DEBUG
|
||||
printf("Debug (objc-load): initializing dynamic loader for %s\n", path);
|
||||
#endif
|
||||
if (__objc_dynamic_init(path)) {
|
||||
if (errorStream)
|
||||
__objc_dynamic_error(errorStream, "Error (objc-load): Cannot initialize dynamic linker");
|
||||
return 1;
|
||||
} else
|
||||
dynamic_loaded = YES;
|
||||
free(path);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* A callback received from the Object initializer (_objc_exec_class).
|
||||
Do what we need to do and call our own callback.
|
||||
*/
|
||||
static void
|
||||
objc_load_callback(Class class, Category* category)
|
||||
{
|
||||
/* Invalidate the dtable, so it will be rebuilt correctly */
|
||||
if (class != 0 && category != 0) {
|
||||
objc_invalidate_dtable(class);
|
||||
objc_invalidate_dtable(class->class_pointer);
|
||||
}
|
||||
|
||||
if (_objc_load_load_callback)
|
||||
_objc_load_load_callback(class, category);
|
||||
}
|
||||
|
||||
long
|
||||
objc_load_module(
|
||||
const char *filename,
|
||||
FILE *errorStream,
|
||||
void (*loadCallback)(Class, Category*),
|
||||
void **header,
|
||||
char *debugFilename)
|
||||
|
||||
{
|
||||
typedef void (*void_fn)();
|
||||
void_fn *ctor_list;
|
||||
dl_handle_t handle;
|
||||
int i;
|
||||
|
||||
if (!dynamic_loaded)
|
||||
if (objc_initialize_loading(errorStream))
|
||||
return 1;
|
||||
|
||||
/* Link in the object file */
|
||||
#ifdef DEBUG
|
||||
printf("Debug (objc-load): Linking file %s\n", filename);
|
||||
#endif
|
||||
handle = __objc_dynamic_link(filename, 1, debugFilename);
|
||||
if (handle == 0) {
|
||||
if (errorStream)
|
||||
__objc_dynamic_error(errorStream, "Error (objc-load)");
|
||||
return 1;
|
||||
}
|
||||
dynamic_handles = list_cons(handle, dynamic_handles);
|
||||
|
||||
/* If there are any undefined symbols, we can't load the bundle */
|
||||
if (objc_check_undefineds(errorStream)) {
|
||||
__objc_dynamic_unlink(handle);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Get the constructor list and load in the objects */
|
||||
ctor_list = (void_fn *)__objc_dynamic_find_symbol(handle, CTOR_LIST);
|
||||
if (!ctor_list) {
|
||||
if (errorStream)
|
||||
fprintf(errorStream, "Error (objc-load): Cannot load objects (no CTOR list)\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
_objc_load_load_callback = loadCallback;
|
||||
_objc_load_callback = objc_load_callback;
|
||||
#ifdef DEBUG
|
||||
printf("Debug (objc-load): %d modules\n", (int)ctor_list[0]);
|
||||
#endif
|
||||
for (i=1; ctor_list[i]; i++) {
|
||||
#ifdef DEBUG
|
||||
printf("Debug (objc-load): Invoking CTOR %p\n", ctor_list[i]);
|
||||
#endif
|
||||
ctor_list[i]();
|
||||
}
|
||||
_objc_load_callback = 0;
|
||||
_objc_load_load_callback = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
long
|
||||
objc_unload_module(
|
||||
FILE *errorStream,
|
||||
void (*unloadCallback)(Class, Category*))
|
||||
{
|
||||
if (!dynamic_loaded)
|
||||
return 1;
|
||||
|
||||
if (errorStream)
|
||||
fprintf(errorStream, "Warning: unloading modules not implemented\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
long objc_loadModules(char *files[],FILE *errorStream,
|
||||
void (*callback)(Class,Category*),
|
||||
void **header,
|
||||
char *debugFilename)
|
||||
{
|
||||
while (*files) {
|
||||
if (objc_load_module(*files, errorStream, callback,
|
||||
(void *)header, debugFilename))
|
||||
return 1;
|
||||
files++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
long
|
||||
objc_unloadModules(
|
||||
FILE *errorStream,
|
||||
void (*unloadCallback)(Class, Category*))
|
||||
{
|
||||
if (!dynamic_loaded)
|
||||
return 1;
|
||||
|
||||
if (errorStream)
|
||||
fprintf(errorStream, "Warning: unloading modules not implemented\n");
|
||||
return 0;
|
||||
}
|
85
Source/simple-load.h
Normal file
85
Source/simple-load.h
Normal file
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
simple-load - Definitions and translations for dynamic loading with
|
||||
the simple dynamic liading library (dl).
|
||||
|
||||
Copyright (C) 1995, Adam Fedor.
|
||||
|
||||
BUGS:
|
||||
- In SunOS 4.1, dlopen will only resolve references into the main
|
||||
module and not into other modules loaded earlier. dlopen will exit
|
||||
if there are undefined symbols. Later versions (e.g. 5.3) fix this
|
||||
with RTLD_GLOBAL.
|
||||
|
||||
$Id$
|
||||
*/
|
||||
|
||||
#ifndef __sunos_load_h_INCLUDE
|
||||
#define __sunos_load_h_INCLUDE
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
#ifndef RTLD_GLOBAL
|
||||
#define RTLD_GLOBAL 0
|
||||
#endif
|
||||
|
||||
/* Types defined appropriately for the dynamic linker */
|
||||
typedef void* dl_handle_t;
|
||||
typedef void* dl_symbol_t;
|
||||
|
||||
/* Do any initialization necessary. Return 0 on success (or
|
||||
if no initialization needed.
|
||||
*/
|
||||
static int
|
||||
__objc_dynamic_init(const char* exec_path)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Link in the module given by the name 'module'. Return a handle which can
|
||||
be used to get information about the loded code.
|
||||
*/
|
||||
static dl_handle_t
|
||||
__objc_dynamic_link(const char* module, int mode, const char* debug_file)
|
||||
{
|
||||
return (dl_handle_t)dlopen(module, RTLD_LAZY | RTLD_GLOBAL);
|
||||
}
|
||||
|
||||
/* Return the address of a symbol given by the name 'symbol' from the module
|
||||
associated with 'handle'
|
||||
*/
|
||||
static dl_symbol_t
|
||||
__objc_dynamic_find_symbol(dl_handle_t handle, const char* symbol)
|
||||
{
|
||||
return dlsym(handle, symbol);
|
||||
}
|
||||
|
||||
/* remove the code from memory associated with the module 'handle' */
|
||||
static int
|
||||
__objc_dynamic_unlink(dl_handle_t handle)
|
||||
{
|
||||
return dlclose(handle);
|
||||
}
|
||||
|
||||
/* Print an error message (prefaced by 'error_string') relevant to the
|
||||
last error encountered
|
||||
*/
|
||||
static void
|
||||
__objc_dynamic_error(FILE *error_stream, const char *error_string)
|
||||
{
|
||||
fprintf(error_stream, "%s:%s\n", error_string, dlerror());
|
||||
}
|
||||
|
||||
/* Debugging: define these if they are available */
|
||||
static int
|
||||
__objc_dynamic_undefined_symbol_count(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char**
|
||||
__objc_dynamic_list_undefined_symbols(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif /* __sunos_load_h_INCLUDE */
|
Loading…
Add table
Add a link
Reference in a new issue