Tidy more GNUstep extensions.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@15137 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2002-11-27 12:52:29 +00:00
parent 571308fc25
commit 97ee138a2b
26 changed files with 1614 additions and 1078 deletions

View file

@ -1,3 +1,10 @@
2002-11-27 Richard Frith-Macdonald <rfm@gnu.org>
* Source/Additions/GSObjCRuntime.m: New file with GNUstep extensions
from NSObjCRuntime, plus renamed behavior functions, plus a few other
runtime manipulation functions. EXPERIMENTAL
* Headers/gnustep/base/GSObjCRuntime.h: declarations for above.
2002-11-26 Richard Frith-Macdonald <rfm@gnu.org>
* Source/Additions/GCObject.m: Attempt to make garbage collecting

View file

@ -0,0 +1,308 @@
/** Interface to ObjC runtime for GNUStep
Copyright (C) 1995, 1997, 2000, 2002 Free Software Foundation, Inc.
Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
Date: 1995
Written by: Richard Frith-Macdonald <rfm@gnu.org>
Date: 2002
This file is part of the GNUstep Base 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., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
AutogsdocSource: Additions/NSObjCRuntime.m
*/
#ifndef __GSObjCRuntime_h_GNUSTEP_BASE_INCLUDE
#define __GSObjCRuntime_h_GNUSTEP_BASE_INCLUDE
#include <objc/objc.h>
#include <objc/objc-api.h>
#include <stdarg.h>
#ifdef GNUSTEP_WITH_DLL
#if BUILD_libgnustep_base_DLL
# define GS_EXPORT __declspec(dllexport)
# define GS_DECLARE __declspec(dllexport)
#else
# define GS_EXPORT extern __declspec(dllimport)
# define GS_DECLARE __declspec(dllimport)
#endif
#else /* GNUSTEP_WITH[OUT]_DLL */
# define GS_EXPORT extern
# define GS_DECLARE
#endif
@class NSArray;
@class NSDictionary;
@class NSObject;
@class NSString;
@class NSValue;
#ifndef YES
#define YES 1
#endif
#ifndef NO
#define NO 0
#endif
#ifndef nil
#define nil 0
#endif
#define FOUNDATION_EXPORT
#define FOUNDATION_STATIC_INLINE static inline
#ifndef NO_GNUSTEP
/*
* Functions for accessing instance variables directly -
* We can copy an ivar into arbitrary data,
* Get the type encoding for a named ivar,
* and copy a value into an ivar.
*/
GS_EXPORT BOOL GSFindInstanceVariable(id obj, const char *name,
const char **type, unsigned int *size, int *offset);
GS_EXPORT void GSGetVariable(id obj, int offset, unsigned int size, void *data);
GS_EXPORT void GSSetVariable(id obj, int offset, unsigned int size,
const void *data);
GS_EXPORT void GSObjCAddClassBehavior(Class receiver, Class behavior);
GS_EXPORT NSValue*
GSObjCMakeClass(NSString *name, NSString *superName, NSDictionary *iVars);
GS_EXPORT void GSObjCAddClasses(NSArray *classes);
/*
* Functions for key-value encoding ... they access values in an object
* either by selector or directly, but do so using NSNumber for the
* scalar types of data.
*/
GS_EXPORT id GSGetValue(NSObject *self, NSString *key, SEL sel,
const char *type, unsigned size, int offset);
GS_EXPORT void GSSetValue(NSObject *self, NSString *key, id val, SEL sel,
const char *type, unsigned size, int offset);
#include <base/objc-gnu2next.h>
/*
* GSObjCClass() return the class of an instance.
* The argument to this function must NOT be nil.
*/
FOUNDATION_STATIC_INLINE Class
GSObjCClass(id obj)
{
return obj->class_pointer;
}
/*
* GSObjCIsInstance() tests to see if an id is an instance.
* The argument to this function must NOT be nil.
*/
FOUNDATION_STATIC_INLINE BOOL
GSObjCIsInstance(id obj)
{
return CLS_ISCLASS(obj->class_pointer);
}
/*
* GSObjCIsKindOf() tests to see if a class inherits from another class
* The argument to this function must NOT be nil.
*/
FOUNDATION_STATIC_INLINE BOOL
GSObjCIsKindOf(Class this, Class other)
{
while (this != Nil)
{
if (this == other)
{
return YES;
}
this = class_get_super_class(this);
}
return NO;
}
/** ## deprecated ##
*/
FOUNDATION_STATIC_INLINE const char*
GSObjCName(Class this)
{
return class_get_class_name(this);
}
/** ## deprecated ##
*/
FOUNDATION_STATIC_INLINE const char*
GSObjCSelectorName(SEL this)
{
if (this == 0)
return 0;
return sel_get_name(this);
}
/** ## deprecated ##
*/
FOUNDATION_STATIC_INLINE const char*
GSObjCSelectorTypes(SEL this)
{
return sel_get_type(this);
}
/**
* Given a class name, return the corresponding class or
* a nul pointer if the class cannot be found. <br />
* If the argument is nil, return a nul pointer.
*/
FOUNDATION_STATIC_INLINE Class
GSClassFromName(const char *name)
{
if (name == 0)
return 0;
return objc_lookup_class(name);
}
/**
* Return the name of the supplied class, or a nul pointer if no class
* was supplied.
*/
FOUNDATION_STATIC_INLINE const char*
GSNameFromClass(Class this)
{
if (this == 0)
return 0;
return class_get_class_name(this);
}
/**
* Return the name of the supplied selector, or a nul pointer if no selector
* was supplied.
*/
FOUNDATION_STATIC_INLINE const char*
GSNameFromSelector(SEL this)
{
if (this == 0)
return 0;
return sel_get_name(this);
}
/**
* Return a selector matching the specified name, or nil if no name is
* supplied. The returned selector could be any one with the name.<br />
* If no selector exists, returns nil.
*/
FOUNDATION_STATIC_INLINE SEL
GSSelectorFromName(const char *name)
{
if (name == 0)
{
return 0;
}
else
{
return sel_get_any_uid(name);
}
}
/**
* Return the selector for the specified name and types. Returns a nul
* pointer if the name is nul. Uses any available selector if the types
* argument is nul. <br />
* Creates a new selector if necessary.
*/
FOUNDATION_STATIC_INLINE SEL
GSSelectorFromNameAndTypes(const char *name, const char *types)
{
if (name == 0)
{
return 0;
}
else
{
SEL s;
if (types == 0)
{
s = sel_get_any_typed_uid(name);
}
else
{
s = sel_get_typed_uid(name, types);
}
if (s == 0)
{
if (types == 0)
{
s = sel_register_name(name);
}
else
{
s = sel_register_typed_name(name, types);
}
}
return s;
}
}
/**
* Return the type information from the specified selector.
* May return a nul pointer if the selector was a nul pointer or if it
* was not typed.
*/
FOUNDATION_STATIC_INLINE const char*
GSTypesFromSelector(SEL this)
{
if (this == 0)
return 0;
return sel_get_type(this);
}
FOUNDATION_STATIC_INLINE Class
GSObjCSuper(Class this)
{
return class_get_super_class(this);
}
FOUNDATION_STATIC_INLINE int
GSObjCVersion(Class this)
{
return class_get_version(this);
}
/*
* Return the zone in which an object belongs, without using the zone method
*/
#include <Foundation/NSZone.h>
GS_EXPORT NSZone *GSObjCZone(NSObject *obj);
/*
* Quickly return autoreleased data.
*/
void *_fastMallocBuffer(unsigned size);
/* Getting a system error message on a variety of systems */
GS_EXPORT const char *GSLastErrorStr(long error_id);
#endif
#endif /* __GSObjCRuntime_h_GNUSTEP_BASE_INCLUDE */

View file

@ -28,29 +28,7 @@
#ifndef __NSObjCRuntime_h_GNUSTEP_BASE_INCLUDE
#define __NSObjCRuntime_h_GNUSTEP_BASE_INCLUDE
#include <objc/objc.h>
#include <objc/objc-api.h>
#include <stdarg.h>
#ifdef GNUSTEP_WITH_DLL
#if BUILD_libgnustep_base_DLL
# define GS_EXPORT __declspec(dllexport)
# define GS_DECLARE __declspec(dllexport)
#else
# define GS_EXPORT extern __declspec(dllimport)
# define GS_DECLARE __declspec(dllimport)
#endif
#else /* GNUSTEP_WITH[OUT]_DLL */
# define GS_EXPORT extern
# define GS_DECLARE
#endif
@class NSObject;
@class NSString;
#include <gnustep/base/GSObjCRuntime.h>
GS_EXPORT NSString *NSStringFromSelector(SEL aSelector);
GS_EXPORT SEL NSSelectorFromString(NSString *aSelectorName);
@ -85,245 +63,4 @@ GS_EXPORT void NSLogv (NSString *format, va_list args);
#define nil 0
#endif
#define FOUNDATION_EXPORT
#define FOUNDATION_STATIC_INLINE static inline
#ifndef NO_GNUSTEP
/*
* Functions for accessing instance variables directly -
* We can copy an ivar into arbitrary data,
* Get the type encoding for a named ivar,
* and copy a value into an ivar.
*/
GS_EXPORT BOOL GSFindInstanceVariable(id obj, const char *name,
const char **type, unsigned int *size, int *offset);
GS_EXPORT void GSGetVariable(id obj, int offset, unsigned int size, void *data);
GS_EXPORT void GSSetVariable(id obj, int offset, unsigned int size,
const void *data);
/*
* Functions for key-value encoding ... they access values in an object
* either by selector or directly, but do so using NSNumber for the
* scalar types of data.
*/
GS_EXPORT id GSGetValue(NSObject *self, NSString *key, SEL sel,
const char *type, unsigned size, int offset);
GS_EXPORT void GSSetValue(NSObject *self, NSString *key, id val, SEL sel,
const char *type, unsigned size, int offset);
/*
* The following three functions are deprecated and will be removed in future
*/
GS_EXPORT BOOL GSInstanceVariableInfo(id obj, NSString *iVarName,
const char **type, unsigned *size, unsigned *offset);
GS_EXPORT BOOL GSGetInstanceVariable(id obj, NSString *name, void* data);
GS_EXPORT BOOL GSSetInstanceVariable(id obj, NSString *name, const void* data);
#include <base/objc-gnu2next.h>
/*
* GSObjCClass() return the class of an instance.
* The argument to this function must NOT be nil.
*/
FOUNDATION_STATIC_INLINE Class
GSObjCClass(id obj)
{
return obj->class_pointer;
}
/*
* GSObjCIsInstance() tests to see if an id is an instance.
* The argument to this function must NOT be nil.
*/
FOUNDATION_STATIC_INLINE BOOL
GSObjCIsInstance(id obj)
{
return CLS_ISCLASS(obj->class_pointer);
}
/*
* GSObjCIsKindOf() tests to see if a class inherits from another class
* The argument to this function must NOT be nil.
*/
FOUNDATION_STATIC_INLINE BOOL
GSObjCIsKindOf(Class this, Class other)
{
while (this != Nil)
{
if (this == other)
{
return YES;
}
this = class_get_super_class(this);
}
return NO;
}
/** ## deprecated ##
*/
FOUNDATION_STATIC_INLINE const char*
GSObjCName(Class this)
{
return class_get_class_name(this);
}
/** ## deprecated ##
*/
FOUNDATION_STATIC_INLINE const char*
GSObjCSelectorName(SEL this)
{
if (this == 0)
return 0;
return sel_get_name(this);
}
/** ## deprecated ##
*/
FOUNDATION_STATIC_INLINE const char*
GSObjCSelectorTypes(SEL this)
{
return sel_get_type(this);
}
/**
* Given a class name, return the corresponding class or
* a nul pointer if the class cannot be found. <br />
* If the argument is nil, return a nul pointer.
*/
FOUNDATION_STATIC_INLINE Class
GSClassFromName(const char *name)
{
if (name == 0)
return 0;
return objc_lookup_class(name);
}
/**
* Return the name of the supplied class, or a nul pointer if no class
* was supplied.
*/
FOUNDATION_STATIC_INLINE const char*
GSNameFromClass(Class this)
{
if (this == 0)
return 0;
return class_get_class_name(this);
}
/**
* Return the name of the supplied selector, or a nul pointer if no selector
* was supplied.
*/
FOUNDATION_STATIC_INLINE const char*
GSNameFromSelector(SEL this)
{
if (this == 0)
return 0;
return sel_get_name(this);
}
/**
* Return a selector matching the specified name, or nil if no name is
* supplied. The returned selector could be any one with the name.<br />
* If no selector exists, returns nil.
*/
FOUNDATION_STATIC_INLINE SEL
GSSelectorFromName(const char *name)
{
if (name == 0)
{
return 0;
}
else
{
return sel_get_any_uid(name);
}
}
/**
* Return the selector for the specified name and types. Returns a nul
* pointer if the name is nul. Uses any available selector if the types
* argument is nul. <br />
* Creates a new selector if necessary.
*/
FOUNDATION_STATIC_INLINE SEL
GSSelectorFromNameAndTypes(const char *name, const char *types)
{
if (name == 0)
{
return 0;
}
else
{
SEL s;
if (types == 0)
{
s = sel_get_any_typed_uid(name);
}
else
{
s = sel_get_typed_uid(name, types);
}
if (s == 0)
{
if (types == 0)
{
s = sel_register_name(name);
}
else
{
s = sel_register_typed_name(name, types);
}
}
return s;
}
}
/**
* Return the type information from the specified selector.
* May return a nul pointer if the selector was a nul pointer or if it
* was not typed.
*/
FOUNDATION_STATIC_INLINE const char*
GSTypesFromSelector(SEL this)
{
if (this == 0)
return 0;
return sel_get_type(this);
}
FOUNDATION_STATIC_INLINE Class
GSObjCSuper(Class this)
{
return class_get_super_class(this);
}
FOUNDATION_STATIC_INLINE int
GSObjCVersion(Class this)
{
return class_get_version(this);
}
/*
* Return the zone in which an object belongs, without using the zone method
*/
#include <Foundation/NSZone.h>
GS_EXPORT NSZone *GSObjCZone(NSObject *obj);
/*
* Quickly return autoreleased data.
*/
void *_fastMallocBuffer(unsigned size);
/* Getting a system error message on a variety of systems */
GS_EXPORT const char *GSLastErrorStr(long error_id);
#endif
#endif /* __NSObjCRuntime_h_GNUSTEP_BASE_INCLUDE */

View file

@ -27,7 +27,7 @@
#include <Foundation/NSRange.h>
#include <Foundation/NSString.h>
#include <gnustep/base/behavior.h>
#include <gnustep/base/GSObjCRuntime.h>
#include <gnustep/base/GCObject.h>
@implementation GCArray
@ -39,7 +39,7 @@ static Class gcClass = 0;
if (gcClass == 0)
{
gcClass = [GCObject class];
behavior_class_add_class(self, gcClass);
GSObjCAddClassBehavior(self, gcClass);
}
}
@ -210,7 +210,7 @@ static Class gcClass = 0;
if (beenHere == NO)
{
beenHere = YES;
behavior_class_add_class(self, [GCArray class]);
GSObjCAddClassBehavior(self, [GCArray class]);
}
}

View file

@ -26,7 +26,7 @@
#include <Foundation/NSException.h>
#include <Foundation/NSString.h>
#include <gnustep/base/behavior.h>
#include <gnustep/base/GSObjCRuntime.h>
#include <gnustep/base/GCObject.h>
typedef struct {
@ -148,7 +148,7 @@ static Class gcClass = 0;
if (gcClass == 0)
{
gcClass = [GCObject class];
behavior_class_add_class(self, gcClass);
GSObjCAddClassBehavior(self, gcClass);
}
}
@ -350,7 +350,7 @@ static Class gcClass = 0;
if (beenHere == NO)
{
beenHere = YES;
behavior_class_add_class(self, [GCDictionary class]);
GSObjCAddClassBehavior(self, [GCDictionary class]);
}
}

View file

@ -31,6 +31,7 @@ include $(GNUSTEP_MAKEFILES)/common.make
SUBPROJECT_NAME=Additions
Additions_OBJC_FILES =\
GSObjCRuntime.m \
GCObject.m \
GCArray.m \
GCDictionary.m \

File diff suppressed because it is too large Load diff

View file

@ -119,6 +119,7 @@ DistributedObjects.h \
GCObject.h \
GSFileHandle.h \
GSLocale.h \
GSObjCRuntime.h \
GSUnion.h \
GSIArray.h \
GSIMap.h \

View file

@ -27,7 +27,7 @@
#include <config.h>
#include <base/preface.h>
#include <Foundation/NSArray.h>
#include <base/behavior.h>
#include <base/GSObjCRuntime.h>
#include <Foundation/NSException.h>
#include <Foundation/NSPortCoder.h>
#include <Foundation/NSDebug.h>
@ -327,7 +327,7 @@ static SEL eqSel;
if (self == [GSMutableArray class])
{
[self setVersion: 1];
behavior_class_add_class(self, [GSArray class]);
GSObjCAddClassBehavior(self, [GSArray class]);
}
}

View file

@ -23,7 +23,6 @@
#include <config.h>
#include <Foundation/NSSet.h>
#include <base/behavior.h>
#include <Foundation/NSAutoreleasePool.h>
#include <Foundation/NSException.h>
#include <Foundation/NSUtilities.h>

View file

@ -31,7 +31,7 @@
#include <Foundation/NSPortCoder.h>
#include <Foundation/NSDebug.h>
#include <base/behavior.h>
#include <base/GSObjCRuntime.h>
/*
* The 'Fastmap' stuff provides an inline implementation of a mapping
@ -273,7 +273,7 @@ static SEL objSel;
{
if (self == [GSMutableDictionary class])
{
behavior_class_add_class(self, [GSDictionary class]);
GSObjCAddClassBehavior(self, [GSDictionary class]);
}
}

View file

@ -98,8 +98,6 @@ typedef unsigned long long uintmax_t;
#endif
#endif
#include <base/behavior.h>
#include <base/Unicode.h>
struct printf_info

View file

@ -24,7 +24,7 @@
#include <config.h>
#include <Foundation/NSSet.h>
#include <base/behavior.h>
#include <base/GSObjCRuntime.h>
#include <Foundation/NSAutoreleasePool.h>
#include <Foundation/NSArray.h>
#include <Foundation/NSException.h>
@ -458,7 +458,7 @@ static Class mutableSetClass;
{
if (self == [GSMutableSet class])
{
behavior_class_add_class(self, [GSSet class]);
GSObjCAddClassBehavior(self, [GSSet class]);
}
}

View file

@ -46,7 +46,7 @@
#include <Foundation/NSDebug.h>
#include <Foundation/NSObjCRuntime.h>
#include <base/GSFormat.h>
#include <base/behavior.h>
#include <base/GSObjCRuntime.h>
#include <limits.h>
#include "GSPrivate.h"
@ -3608,7 +3608,7 @@ transmute(ivars self, NSString *aString)
{
if (self == [NXConstantString class])
{
behavior_class_add_class(self, [GSCString class]);
GSObjCAddClassBehavior(self, [GSCString class]);
NSConstantStringClass = self;
}
}

View file

@ -30,7 +30,6 @@
*/
#include <config.h>
#include <base/behavior.h>
#include <Foundation/NSArray.h>
#include <Foundation/NSCoder.h>
#include <Foundation/NSData.h>

View file

@ -40,7 +40,7 @@
#include <Foundation/NSException.h>
#include <Foundation/NSUserDefaults.h>
#include <Foundation/NSDebug.h>
#include <base/behavior.h>
#include <base/GSObjCRuntime.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
@ -302,7 +302,7 @@ GSBreakTime(NSTimeInterval when, int *year, int *month, int *day,
absAbrIMP = (NSString* (*)(id,SEL,id))
[absClass instanceMethodForSelector: abrSEL];
behavior_class_add_class(self, [NSGDate class]);
GSObjCAddClassBehavior(self, [NSGDate class]);
}
}

View file

@ -27,7 +27,6 @@
#include <config.h>
#include <base/preface.h>
#include <base/behavior.h>
#include <Foundation/NSData.h>
#include <Foundation/NSCoder.h>
#include <Foundation/NSSerialization.h>

View file

@ -25,7 +25,6 @@
*/
#include <config.h>
#include <base/behavior.h>
#include <Foundation/NSSet.h>
#include <Foundation/NSCoder.h>
#include <Foundation/NSArray.h>

View file

@ -65,7 +65,7 @@
*/
#include <config.h>
#include <base/behavior.h>
#include <base/GSObjCRuntime.h>
#include <Foundation/NSObjCRuntime.h>
#include <Foundation/NSByteOrder.h>
#include <Foundation/NSCoder.h>
@ -2878,7 +2878,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
{
if (self == [NSMutableDataMalloc class])
{
behavior_class_add_class(self, [NSDataMalloc class]);
GSObjCAddClassBehavior(self, [NSDataMalloc class]);
}
}

View file

@ -41,7 +41,7 @@
#include <Foundation/NSPortCoder.h>
#include <Foundation/NSUserDefaults.h>
#include <base/preface.h>
#include <base/behavior.h>
#include <base/GSObjCRuntime.h>
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
@ -1346,7 +1346,7 @@ GSTimeNow(void)
if (self == [GSDateSingle class])
{
[self setVersion: 1];
behavior_class_add_class(self, [NSGDate class]);
GSObjCAddClassBehavior(self, [NSGDate class]);
}
}

View file

@ -26,7 +26,6 @@
*/
#include <config.h>
#include <base/behavior.h>
#include <Foundation/NSDictionary.h>
#include <Foundation/NSArray.h>
#include <Foundation/NSData.h>

View file

@ -76,785 +76,3 @@ NSGetSizeAndAlignment(const char *typePtr, unsigned *sizep, unsigned *alignp)
return typePtr;
}
/**
* This function is used to locate information about the instance
* variable of obj called name. It returns YES if the variable
* was found, NO otherwise. If it returns YES, then the values
* pointed to by type, size, and offset will be set (except where
* they are null pointers).
*/
BOOL
GSFindInstanceVariable(id obj, const char *name,
const char **type, unsigned int *size, int *offset)
{
Class class;
struct objc_ivar_list *ivars;
struct objc_ivar *ivar = 0;
class = [obj class];
while (class != nil && ivar == 0)
{
ivars = class->ivars;
class = class->super_class;
if (ivars != 0)
{
int i;
for (i = 0; i < ivars->ivar_count; i++)
{
if (strcmp(ivars->ivar_list[i].ivar_name, name) == 0)
{
ivar = &ivars->ivar_list[i];
break;
}
}
}
}
if (ivar == 0)
{
return NO;
}
if (type)
*type = ivar->ivar_type;
if (size)
*size = objc_sizeof_type(ivar->ivar_type);
if (offset)
*offset = ivar->ivar_offset;
return YES;
}
/**
* This function performs no checking ... you should use it only where
* you are providing information from a call to GSFindInstanceVariable()
* and you know that the data area provided is the correct size.
*/
void
GSGetVariable(id obj, int offset, unsigned int size, void *data)
{
memcpy(data, ((void*)obj) + offset, size);
}
/**
* This function performs no checking ... you should use it only where
* you are providing information from a call to GSFindInstanceVariable()
* and you know that the data area provided is the correct size.
*/
void
GSSetVariable(id obj, int offset, unsigned int size, const void *data)
{
memcpy(((void*)obj) + offset, data, size);
}
/** ## deprecated ##
*/
BOOL
GSInstanceVariableInfo(id obj, NSString *iVarName,
const char **type, unsigned *size, unsigned *offset)
{
const char *name = [iVarName UTF8String];
return GSFindInstanceVariable(obj, name, type, size, offset);
}
/** ## deprecated ##
*/
BOOL
GSGetInstanceVariable(id obj, NSString *name, void *data)
{
const char *cName = [name UTF8String];
int offset;
unsigned int size;
if (GSFindInstanceVariable(obj, cName, 0, &size, &offset) == YES)
{
GSGetVariable(obj, offset, size, data);
return YES;
}
return NO;
}
/** ## deprecated ##
*/
BOOL
GSSetInstanceVariable(id obj, NSString *name, const void *data)
{
const char *cName = [name UTF8String];
int offset;
unsigned int size;
if (GSFindInstanceVariable(obj, cName, 0, &size, &offset) == YES)
{
GSSetVariable(obj, offset, size, data);
return YES;
}
return NO;
}
#include <Foundation/NSValue.h>
#include <Foundation/NSKeyValueCoding.h>
/**
* This is used internally by the key-value coding methods, to get a
* value from an object either via an accessor method (if sel is
* supplied), or via direct access (if type, size, and offset are
* supplied).<br />
* Automatic conversion between NSNumber and C scalar types is performed.<br />
* If type is null and can't be determined from the selector, the
* [NSObject-handleQueryWithUnboundKey:] method is called to try
* to get a value.
*/
id
GSGetValue(NSObject *self, NSString *key, SEL sel,
const char *type, unsigned size, int offset)
{
if (sel != 0)
{
NSMethodSignature *sig = [self methodSignatureForSelector: sel];
if ([sig numberOfArguments] != 2)
{
[NSException raise: NSInvalidArgumentException
format: @"key-value get method has wrong number of args"];
}
type = [sig methodReturnType];
}
if (type == NULL)
{
return [self handleQueryWithUnboundKey: key];
}
else
{
id val = nil;
switch (*type)
{
case _C_ID:
case _C_CLASS:
{
id v;
if (sel == 0)
{
v = *(id *)((char *)self + offset);
}
else
{
id (*imp)(id, SEL) =
(id (*)(id, SEL))[self methodForSelector: sel];
v = (*imp)(self, sel);
}
val = v;
}
break;
case _C_CHR:
{
signed char v;
if (sel == 0)
{
v = *(char *)((char *)self + offset);
}
else
{
signed char (*imp)(id, SEL) =
(signed char (*)(id, SEL))[self methodForSelector: sel];
v = (*imp)(self, sel);
}
val = [NSNumber numberWithChar: v];
}
break;
case _C_UCHR:
{
unsigned char v;
if (sel == 0)
{
v = *(unsigned char *)((char *)self + offset);
}
else
{
unsigned char (*imp)(id, SEL) =
(unsigned char (*)(id, SEL))[self methodForSelector:
sel];
v = (*imp)(self, sel);
}
val = [NSNumber numberWithUnsignedChar: v];
}
break;
case _C_SHT:
{
short v;
if (sel == 0)
{
v = *(short *)((char *)self + offset);
}
else
{
short (*imp)(id, SEL) =
(short (*)(id, SEL))[self methodForSelector: sel];
v = (*imp)(self, sel);
}
val = [NSNumber numberWithShort: v];
}
break;
case _C_USHT:
{
unsigned short v;
if (sel == 0)
{
v = *(unsigned short *)((char *)self + offset);
}
else
{
unsigned short (*imp)(id, SEL) =
(unsigned short (*)(id, SEL))[self methodForSelector:
sel];
v = (*imp)(self, sel);
}
val = [NSNumber numberWithUnsignedShort: v];
}
break;
case _C_INT:
{
int v;
if (sel == 0)
{
v = *(int *)((char *)self + offset);
}
else
{
int (*imp)(id, SEL) =
(int (*)(id, SEL))[self methodForSelector: sel];
v = (*imp)(self, sel);
}
val = [NSNumber numberWithInt: v];
}
break;
case _C_UINT:
{
unsigned int v;
if (sel == 0)
{
v = *(unsigned int *)((char *)self + offset);
}
else
{
unsigned int (*imp)(id, SEL) =
(unsigned int (*)(id, SEL))[self methodForSelector:
sel];
v = (*imp)(self, sel);
}
val = [NSNumber numberWithUnsignedInt: v];
}
break;
case _C_LNG:
{
long v;
if (sel == 0)
{
v = *(long *)((char *)self + offset);
}
else
{
long (*imp)(id, SEL) =
(long (*)(id, SEL))[self methodForSelector: sel];
v = (*imp)(self, sel);
}
val = [NSNumber numberWithLong: v];
}
break;
case _C_ULNG:
{
unsigned long v;
if (sel == 0)
{
v = *(unsigned long *)((char *)self + offset);
}
else
{
unsigned long (*imp)(id, SEL) =
(unsigned long (*)(id, SEL))[self methodForSelector:
sel];
v = (*imp)(self, sel);
}
val = [NSNumber numberWithUnsignedLong: v];
}
break;
#ifdef _C_LNG_LNG
case _C_LNG_LNG:
{
long long v;
if (sel == 0)
{
v = *(long long *)((char *)self + offset);
}
else
{
long long (*imp)(id, SEL) =
(long long (*)(id, SEL))[self methodForSelector: sel];
v = (*imp)(self, sel);
}
val = [NSNumber numberWithLongLong: v];
}
break;
#endif
#ifdef _C_ULNG_LNG
case _C_ULNG_LNG:
{
unsigned long long v;
if (sel == 0)
{
v = *(unsigned long long *)((char *)self + offset);
}
else
{
unsigned long long (*imp)(id, SEL) =
(unsigned long long (*)(id, SEL))[self
methodForSelector: sel];
v = (*imp)(self, sel);
}
val = [NSNumber numberWithUnsignedLongLong: v];
}
break;
#endif
case _C_FLT:
{
float v;
if (sel == 0)
{
v = *(float *)((char *)self + offset);
}
else
{
float (*imp)(id, SEL) =
(float (*)(id, SEL))[self methodForSelector: sel];
v = (*imp)(self, sel);
}
val = [NSNumber numberWithFloat: v];
}
break;
case _C_DBL:
{
double v;
if (sel == 0)
{
v = *(double *)((char *)self + offset);
}
else
{
double (*imp)(id, SEL) =
(double (*)(id, SEL))[self methodForSelector: sel];
v = (*imp)(self, sel);
}
val = [NSNumber numberWithDouble: v];
}
break;
case _C_VOID:
{
void (*imp)(id, SEL) =
(void (*)(id, SEL))[self methodForSelector: sel];
(*imp)(self, sel);
}
val = nil;
break;
default:
[NSException raise: NSInvalidArgumentException
format: @"key-value get method has unsupported type"];
}
return val;
}
}
/**
* This is used internally by the key-value coding methods, to set a
* value in an object either via an accessor method (if sel is
* supplied), or via direct access (if type, size, and offset are
* supplied).<br />
* Automatic conversion between NSNumber and C scalar types is performed.<br />
* If type is null and can't be determined from the selector, the
* [NSObject-handleTakeValue:forUnboundKey:] method is called to try
* to set a value.
*/
void
GSSetValue(NSObject *self, NSString *key, id val, SEL sel,
const char *type, unsigned size, int offset)
{
if (sel != 0)
{
NSMethodSignature *sig = [self methodSignatureForSelector: sel];
if ([sig numberOfArguments] != 3)
{
[NSException raise: NSInvalidArgumentException
format: @"key-value set method has wrong number of args"];
}
type = [sig getArgumentTypeAtIndex: 2];
}
if (type == NULL)
{
[self handleTakeValue: val forUnboundKey: key];
}
else
{
switch (*type)
{
case _C_ID:
case _C_CLASS:
{
id v = val;
if (sel == 0)
{
id *ptr = (id *)((char *)self + offset);
[*ptr autorelease];
*ptr = [v retain];
}
else
{
void (*imp)(id, SEL, id) =
(void (*)(id, SEL, id))[self methodForSelector: sel];
(*imp)(self, sel, val);
}
}
break;
case _C_CHR:
{
char v = [val charValue];
if (sel == 0)
{
char *ptr = (char *)((char *)self + offset);
*ptr = v;
}
else
{
void (*imp)(id, SEL, char) =
(void (*)(id, SEL, char))[self methodForSelector: sel];
(*imp)(self, sel, v);
}
}
break;
case _C_UCHR:
{
unsigned char v = [val unsignedCharValue];
if (sel == 0)
{
unsigned char *ptr = (unsigned char*)((char *)self + offset);
*ptr = v;
}
else
{
void (*imp)(id, SEL, unsigned char) =
(void (*)(id, SEL, unsigned char))[self methodForSelector:
sel];
(*imp)(self, sel, v);
}
}
break;
case _C_SHT:
{
short v = [val shortValue];
if (sel == 0)
{
short *ptr = (short*)((char *)self + offset);
*ptr = v;
}
else
{
void (*imp)(id, SEL, short) =
(void (*)(id, SEL, short))[self methodForSelector: sel];
(*imp)(self, sel, v);
}
}
break;
case _C_USHT:
{
unsigned short v = [val unsignedShortValue];
if (sel == 0)
{
unsigned short *ptr;
ptr = (unsigned short*)((char *)self + offset);
*ptr = v;
}
else
{
void (*imp)(id, SEL, unsigned short) =
(void (*)(id, SEL, unsigned short))[self methodForSelector:
sel];
(*imp)(self, sel, v);
}
}
break;
case _C_INT:
{
int v = [val intValue];
if (sel == 0)
{
int *ptr = (int*)((char *)self + offset);
*ptr = v;
}
else
{
void (*imp)(id, SEL, int) =
(void (*)(id, SEL, int))[self methodForSelector: sel];
(*imp)(self, sel, v);
}
}
break;
case _C_UINT:
{
unsigned int v = [val unsignedIntValue];
if (sel == 0)
{
unsigned int *ptr = (unsigned int*)((char *)self + offset);
*ptr = v;
}
else
{
void (*imp)(id, SEL, unsigned int) =
(void (*)(id, SEL, unsigned int))[self methodForSelector:
sel];
(*imp)(self, sel, v);
}
}
break;
case _C_LNG:
{
long v = [val longValue];
if (sel == 0)
{
long *ptr = (long*)((char *)self + offset);
*ptr = v;
}
else
{
void (*imp)(id, SEL, long) =
(void (*)(id, SEL, long))[self methodForSelector: sel];
(*imp)(self, sel, v);
}
}
break;
case _C_ULNG:
{
unsigned long v = [val unsignedLongValue];
if (sel == 0)
{
unsigned long *ptr = (unsigned long*)((char *)self + offset);
*ptr = v;
}
else
{
void (*imp)(id, SEL, unsigned long) =
(void (*)(id, SEL, unsigned long))[self methodForSelector:
sel];
(*imp)(self, sel, v);
}
}
break;
#ifdef _C_LNG_LNG
case _C_LNG_LNG:
{
long long v = [val longLongValue];
if (sel == 0)
{
long long *ptr = (long long*)((char *)self + offset);
*ptr = v;
}
else
{
void (*imp)(id, SEL, long long) =
(void (*)(id, SEL, long long))[self methodForSelector: sel];
(*imp)(self, sel, v);
}
}
break;
#endif
#ifdef _C_ULNG_LNG
case _C_ULNG_LNG:
{
unsigned long long v = [val unsignedLongLongValue];
if (sel == 0)
{
unsigned long long *ptr = (unsigned long long*)((char*)self +
offset);
*ptr = v;
}
else
{
void (*imp)(id, SEL, unsigned long long) =
(void (*)(id, SEL, unsigned long long))[self
methodForSelector: sel];
(*imp)(self, sel, v);
}
}
break;
#endif
case _C_FLT:
{
float v = [val floatValue];
if (sel == 0)
{
float *ptr = (float*)((char *)self + offset);
*ptr = v;
}
else
{
void (*imp)(id, SEL, float) =
(void (*)(id, SEL, float))[self methodForSelector: sel];
(*imp)(self, sel, v);
}
}
break;
case _C_DBL:
{
double v = [val doubleValue];
if (sel == 0)
{
double *ptr = (double*)((char *)self + offset);
*ptr = v;
}
else
{
void (*imp)(id, SEL, double) =
(void (*)(id, SEL, double))[self methodForSelector: sel];
(*imp)(self, sel, v);
}
}
break;
default:
[NSException raise: NSInvalidArgumentException
format: @"key-value set method has unsupported type"];
}
}
}
/* Getting a system error message on a variety of systems */
#ifdef __MINGW__
LPTSTR GetErrorMsg(DWORD msgId)
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, msgId,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR)&lpMsgBuf, 0, NULL);
return (LPTSTR)lpMsgBuf;
}
#else
#ifndef HAVE_STRERROR
const char*
strerror(int eno)
{
extern char* sys_errlist[];
extern int sys_nerr;
if (eno < 0 || eno >= sys_nerr)
{
return("unknown error number");
}
return(sys_errlist[eno]);
}
#endif
#endif /* __MINGW__ */
const char *GSLastErrorStr(long error_id)
{
#ifdef __MINGW__
return GetErrorMsg(GetLastError());
#else
return strerror(error_id);
#endif
}

View file

@ -25,7 +25,6 @@
*/
#include <config.h>
#include <base/behavior.h>
#include <Foundation/NSSet.h>
#include <Foundation/NSCoder.h>
#include <Foundation/NSArray.h>

View file

@ -76,8 +76,6 @@
#include <fcntl.h>
#include <stdio.h>
#include <base/behavior.h>
#include <base/Unicode.h>
#include "GSPrivate.h"

View file

@ -36,7 +36,6 @@ function may be incorrect
* Some functions are not implemented
*/
#include <config.h>
#include <base/behavior.h>
#include <Foundation/NSObject.h>
#include <Foundation/NSCoder.h>
#include <Foundation/NSArray.h>

View file

@ -27,7 +27,6 @@
*/
#include <config.h>
#include <base/behavior.h>
#include <Foundation/NSArray.h>
#include <Foundation/NSData.h>
#include <Foundation/NSEnumerator.h>