mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +00:00
Various small bugfixes.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3138 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
766b053b50
commit
ba0837b92b
5 changed files with 347 additions and 268 deletions
|
@ -38,6 +38,7 @@
|
|||
int numArgs;
|
||||
NSArgumentInfo *info;
|
||||
BOOL argsRetained;
|
||||
BOOL validReturn;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -162,7 +162,8 @@ static SEL eValSel = @selector(encodeValueOfObjCType:at:);
|
|||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
d = nil;
|
||||
[archiver release];
|
||||
[localException raise];
|
||||
}
|
||||
NS_ENDHANDLER
|
||||
[archiver release];
|
||||
|
@ -280,10 +281,7 @@ static SEL eValSel = @selector(encodeValueOfObjCType:at:);
|
|||
(*tagImp)(dst, tagSel, _C_STRUCT_B);
|
||||
}
|
||||
|
||||
while (*type != _C_STRUCT_E && *type != '=')
|
||||
{
|
||||
type++;
|
||||
}
|
||||
while (*type != _C_STRUCT_E && *type++ != '='); /* skip "<name>=" */
|
||||
|
||||
for (;;)
|
||||
{
|
||||
|
@ -355,6 +353,7 @@ static SEL eValSel = @selector(encodeValueOfObjCType:at:);
|
|||
node->value.I = ++xRefP;
|
||||
}
|
||||
(*tagImp)(dst, tagSel, _C_PTR);
|
||||
(*xRefImp)(dst, xRefSel, node->value.I);
|
||||
type++;
|
||||
buf = *(char**)buf;
|
||||
(*eValImp)(self, eValSel, type, buf);
|
||||
|
|
|
@ -801,13 +801,13 @@ failure:
|
|||
[self deserializeBytes: types
|
||||
length: lt
|
||||
atCursor: cursor];
|
||||
name[lt] = '\0';
|
||||
types[lt] = '\0';
|
||||
|
||||
if (lt) {
|
||||
sel = sel_get_typed_uid(name, types);
|
||||
}
|
||||
else {
|
||||
sel = sel_get_uid(name);
|
||||
sel = sel_get_any_typed_uid(name);
|
||||
}
|
||||
if (sel == 0) {
|
||||
[NSException raise: NSInternalInconsistencyException
|
||||
|
@ -1684,13 +1684,13 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
|
|||
getBytes((void*)name, bytes, ln, length, cursor);
|
||||
name[ln] = '\0';
|
||||
getBytes((void*)types, bytes, lt, length, cursor);
|
||||
name[lt] = '\0';
|
||||
types[lt] = '\0';
|
||||
|
||||
if (lt) {
|
||||
sel = sel_get_typed_uid(name, types);
|
||||
}
|
||||
else {
|
||||
sel = sel_get_uid(name);
|
||||
sel = sel_get_any_typed_uid(name);
|
||||
}
|
||||
if (sel == 0) {
|
||||
[NSException raise: NSInternalInconsistencyException
|
||||
|
@ -2448,7 +2448,7 @@ getBytes(void* dst, void* src, unsigned len, unsigned limit, unsigned *pos)
|
|||
length += ln;
|
||||
}
|
||||
if (lt) {
|
||||
memcpy(bytes+length, type, lt);
|
||||
memcpy(bytes+length, types, lt);
|
||||
length += lt;
|
||||
}
|
||||
return;
|
||||
|
|
|
@ -38,20 +38,25 @@
|
|||
|
||||
- (void) dealloc
|
||||
{
|
||||
if (argsRetained) {
|
||||
if (argsRetained)
|
||||
{
|
||||
[target release];
|
||||
argsRetained = NO;
|
||||
if (argframe && sig) {
|
||||
if (argframe && sig)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 3; i <= numArgs; i++) {
|
||||
if (*info[i].type == _C_CHARPTR) {
|
||||
for (i = 3; i <= numArgs; i++)
|
||||
{
|
||||
if (*info[i].type == _C_CHARPTR)
|
||||
{
|
||||
char *str;
|
||||
|
||||
mframe_get_arg(argframe, &info[i], &str);
|
||||
objc_free(str);
|
||||
}
|
||||
else if (*info[i].type == _C_ID) {
|
||||
else if (*info[i].type == _C_ID)
|
||||
{
|
||||
id obj;
|
||||
|
||||
mframe_get_arg(argframe, &info[i], &obj);
|
||||
|
@ -60,10 +65,12 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
if (argframe) {
|
||||
if (argframe)
|
||||
{
|
||||
mframe_destroy_argframe([sig methodType], argframe);
|
||||
}
|
||||
if (retval) {
|
||||
if (retval)
|
||||
{
|
||||
objc_free(retval);
|
||||
}
|
||||
[sig release];
|
||||
|
@ -77,17 +84,21 @@
|
|||
- (void) getArgument: (void*)buffer
|
||||
atIndex: (int)index
|
||||
{
|
||||
if ((unsigned)index >= numArgs) {
|
||||
if ((unsigned)index >= numArgs)
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"bad invocation argument index"];
|
||||
}
|
||||
if (index == 0) {
|
||||
if (index == 0)
|
||||
{
|
||||
*(id*)buffer = target;
|
||||
}
|
||||
else if (index == 1) {
|
||||
else if (index == 1)
|
||||
{
|
||||
*(SEL*)buffer = selector;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
index++; /* Allow offset for return type info. */
|
||||
mframe_get_arg(argframe, &info[index], buffer);
|
||||
}
|
||||
|
@ -97,9 +108,16 @@
|
|||
{
|
||||
const char *type;
|
||||
|
||||
if (validReturn == NO)
|
||||
{
|
||||
[NSException raise: NSGenericException
|
||||
format: @"getReturnValue with no value set"];
|
||||
}
|
||||
|
||||
type = [sig methodReturnType];
|
||||
|
||||
if (*info[0].type != _C_VOID) {
|
||||
if (*info[0].type != _C_VOID)
|
||||
{
|
||||
int length = info[0].size;
|
||||
#if WORDS_BIGENDIAN
|
||||
if (length < sizeof(void*))
|
||||
|
@ -117,51 +135,63 @@
|
|||
- (void) setArgument: (void*)buffer
|
||||
atIndex: (int)index
|
||||
{
|
||||
if ((unsigned)index >= numArgs) {
|
||||
if ((unsigned)index >= numArgs)
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"bad invocation argument index"];
|
||||
}
|
||||
if (index == 0) {
|
||||
if (index == 0)
|
||||
{
|
||||
[self setTarget: *(id*)buffer];
|
||||
}
|
||||
else if (index == 1) {
|
||||
else if (index == 1)
|
||||
{
|
||||
[self setSelector: *(SEL*)buffer];
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
int i = index+1; /* Allow for return type in 'info' */
|
||||
const char *type = info[i].type;
|
||||
|
||||
if (argsRetained && (*type == _C_ID || *type == _C_CHARPTR)) {
|
||||
if (*type == _C_ID) {
|
||||
if (argsRetained && (*type == _C_ID || *type == _C_CHARPTR))
|
||||
{
|
||||
if (*type == _C_ID)
|
||||
{
|
||||
id old;
|
||||
|
||||
mframe_get_arg(argframe, &info[i], &old);
|
||||
mframe_set_arg(argframe, &info[i], buffer);
|
||||
[*(id*)buffer retain];
|
||||
if (old != nil) {
|
||||
if (old != nil)
|
||||
{
|
||||
[old release];
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
char *oldstr;
|
||||
char *newstr = *(char**)buffer;
|
||||
|
||||
mframe_get_arg(argframe, &info[i], &oldstr);
|
||||
if (newstr == 0) {
|
||||
if (newstr == 0)
|
||||
{
|
||||
mframe_set_arg(argframe, &info[i], buffer);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
char *tmp = objc_malloc(strlen(newstr)+1);
|
||||
|
||||
strcpy(tmp, newstr);
|
||||
mframe_set_arg(argframe, &info[i], tmp);
|
||||
}
|
||||
if (oldstr != 0) {
|
||||
if (oldstr != 0)
|
||||
{
|
||||
objc_free(oldstr);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
mframe_set_arg(argframe, &info[i], buffer);
|
||||
}
|
||||
}
|
||||
|
@ -173,7 +203,8 @@
|
|||
|
||||
type = info[0].type;
|
||||
|
||||
if (*type != _C_VOID) {
|
||||
if (*type != _C_VOID)
|
||||
{
|
||||
int length = info[0].size;
|
||||
|
||||
#if WORDS_BIGENDIAN
|
||||
|
@ -182,6 +213,7 @@
|
|||
#endif
|
||||
memcpy(retval, buffer, length);
|
||||
}
|
||||
validReturn = YES;
|
||||
}
|
||||
|
||||
- (void) setSelector: (SEL)aSelector
|
||||
|
@ -191,7 +223,8 @@
|
|||
|
||||
- (void) setTarget: (id)anObject
|
||||
{
|
||||
if (argsRetained) {
|
||||
if (argsRetained)
|
||||
{
|
||||
[anObject retain];
|
||||
[target release];
|
||||
}
|
||||
|
@ -214,32 +247,41 @@
|
|||
|
||||
- (void)retainArguments
|
||||
{
|
||||
if (argsRetained) {
|
||||
if (argsRetained)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
int i;
|
||||
|
||||
argsRetained = YES;
|
||||
[target retain];
|
||||
if (argframe == 0) {
|
||||
if (argframe == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (i = 3; i <= numArgs; i++) {
|
||||
if (*info[i].type == _C_ID || *info[i].type == _C_CHARPTR) {
|
||||
if (*info[i].type == _C_ID) {
|
||||
for (i = 3; i <= numArgs; i++)
|
||||
{
|
||||
if (*info[i].type == _C_ID || *info[i].type == _C_CHARPTR)
|
||||
{
|
||||
if (*info[i].type == _C_ID)
|
||||
{
|
||||
id old;
|
||||
|
||||
mframe_get_arg(argframe, &info[i], &old);
|
||||
if (old != nil) {
|
||||
if (old != nil)
|
||||
{
|
||||
[old retain];
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
char *str;
|
||||
|
||||
mframe_get_arg(argframe, &info[i], &str);
|
||||
if (str != 0) {
|
||||
if (str != 0)
|
||||
{
|
||||
char *tmp = objc_malloc(strlen(str)+1);
|
||||
|
||||
strcpy(tmp, str);
|
||||
|
@ -270,7 +312,8 @@
|
|||
/*
|
||||
* A message to a nil object returns nil.
|
||||
*/
|
||||
if (anObject == nil) {
|
||||
if (anObject == nil)
|
||||
{
|
||||
memset(retval, '\0', info[0].size); /* Clear return value */
|
||||
return;
|
||||
}
|
||||
|
@ -305,9 +348,11 @@
|
|||
stack_argsize = [sig frameLength];
|
||||
|
||||
returned = __builtin_apply((void(*)(void))imp, argframe, stack_argsize);
|
||||
if (info[0].size) {
|
||||
if (info[0].size)
|
||||
{
|
||||
mframe_decode_return(info[0].type, retval, returned);
|
||||
}
|
||||
validReturn = YES;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -321,8 +366,10 @@
|
|||
|
||||
- (NSString*)description
|
||||
{
|
||||
/* Don't use -[NSString stringWithFormat:] method because it can cause
|
||||
infinite recursion. */
|
||||
/*
|
||||
* Don't use -[NSString stringWithFormat:] method because it can cause
|
||||
* infinite recursion.
|
||||
*/
|
||||
char buffer[1024];
|
||||
|
||||
sprintf (buffer, "<%s %p selector: %s target: %s>", \
|
||||
|
@ -341,26 +388,36 @@
|
|||
int i;
|
||||
|
||||
[aCoder encodeValueOfObjCType: @encode(char*)
|
||||
at: &types
|
||||
withName: @"invocation types"];
|
||||
at: &types];
|
||||
|
||||
[aCoder encodeBycopyObject: target
|
||||
withName: @"target"];
|
||||
[aCoder encodeObject: target];
|
||||
|
||||
[aCoder encodeValueOfObjCType: info[2].type
|
||||
at: &selector
|
||||
withName: @"selector"];
|
||||
at: &selector];
|
||||
|
||||
for (i = 3; i <= numArgs; i++) {
|
||||
for (i = 3; i <= numArgs; i++)
|
||||
{
|
||||
const char *type = info[i].type;
|
||||
void *datum;
|
||||
|
||||
datum = mframe_arg_addr(argframe, &info[i]);
|
||||
|
||||
if (*type == _C_ID)
|
||||
[aCoder encodeBycopyObject: *(id*)datum withName: @"arg"];
|
||||
{
|
||||
[aCoder encodeObject: *(id*)datum];
|
||||
}
|
||||
else
|
||||
[aCoder encodeValueOfObjCType: type at: datum withName: @"arg"];
|
||||
{
|
||||
[aCoder encodeValueOfObjCType: type at: datum];
|
||||
}
|
||||
}
|
||||
if (*info[0].type != _C_VOID)
|
||||
{
|
||||
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &validReturn];
|
||||
if (validReturn)
|
||||
{
|
||||
[aCoder encodeValueOfObjCType: info[0].type at: retval];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -379,11 +436,21 @@
|
|||
|
||||
[aCoder decodeValueOfObjCType: @encode(SEL) at: &selector];
|
||||
|
||||
for (i = 3; i <= numArgs; i++) {
|
||||
for (i = 3; i <= numArgs; i++)
|
||||
{
|
||||
datum = mframe_arg_addr(argframe, &info[i]);
|
||||
[aCoder decodeValueOfObjCType: info[i].type at: datum];
|
||||
}
|
||||
argsRetained = YES;
|
||||
if (*info[0].type != _C_VOID)
|
||||
{
|
||||
[aCoder decodeValueOfObjCType: @encode(BOOL) at: &validReturn];
|
||||
if (validReturn)
|
||||
{
|
||||
[aCoder decodeValueOfObjCType: info[0].type at: retval];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
|
@ -398,26 +465,31 @@
|
|||
NSMethodSignature *newSig;
|
||||
|
||||
types = sel_get_type(aSelector);
|
||||
if (types == 0) {
|
||||
if (types == 0)
|
||||
{
|
||||
types = sel_get_type(sel_get_any_typed_uid(sel_get_name(aSelector)));
|
||||
}
|
||||
if (types == 0) {
|
||||
if (types == 0)
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"Couldn't find encoding type for selector %s.",
|
||||
sel_get_name(aSelector)];
|
||||
}
|
||||
newSig = [NSMethodSignature signatureWithObjCTypes: types];
|
||||
self = [self initWithMethodSignature: newSig];
|
||||
if (self) {
|
||||
if (self)
|
||||
{
|
||||
[self setSelector: aSelector];
|
||||
/*
|
||||
* Copy the argframe we were given.
|
||||
*/
|
||||
if (frame) {
|
||||
if (frame)
|
||||
{
|
||||
int i;
|
||||
|
||||
mframe_get_arg(frame, &info[1], &target);
|
||||
for (i = 1; i <= numArgs; i++) {
|
||||
for (i = 1; i <= numArgs; i++)
|
||||
{
|
||||
mframe_cpy_arg(argframe, frame, &info[i]);
|
||||
}
|
||||
}
|
||||
|
@ -434,7 +506,8 @@
|
|||
numArgs = [aSignature numberOfArguments];
|
||||
info = [aSignature methodInfo];
|
||||
argframe = mframe_create_argframe([sig methodType], &retval);
|
||||
if (retval == 0 && info[0].size > 0) {
|
||||
if (retval == 0 && info[0].size > 0)
|
||||
{
|
||||
retval = objc_malloc(info[0].size);
|
||||
}
|
||||
return self;
|
||||
|
@ -450,12 +523,14 @@
|
|||
va_list ap;
|
||||
|
||||
self = [self initWithArgframe: 0 selector: aSelector];
|
||||
if (self) {
|
||||
if (self)
|
||||
{
|
||||
int i;
|
||||
|
||||
[self setTarget: anObject];
|
||||
va_start (ap, aSelector);
|
||||
for (i = 3; i <= numArgs; i++) {
|
||||
for (i = 3; i <= numArgs; i++)
|
||||
{
|
||||
const char *type = info[i].type;
|
||||
unsigned size = info[i].size;
|
||||
void *datum;
|
||||
|
@ -463,18 +538,23 @@
|
|||
datum = mframe_arg_addr(argframe, &info[i]);
|
||||
|
||||
#define CASE_TYPE(_C,_T) case _C: *(_T*)datum = va_arg (ap, _T); break
|
||||
switch (*type) {
|
||||
switch (*type)
|
||||
{
|
||||
case _C_ID:
|
||||
*(id*)datum = va_arg (ap, id);
|
||||
if (argsRetained)
|
||||
{
|
||||
[*(id*)datum retain];
|
||||
}
|
||||
break;
|
||||
case _C_CHARPTR:
|
||||
*(char**)datum = va_arg (ap, char*);
|
||||
if (argsRetained) {
|
||||
if (argsRetained)
|
||||
{
|
||||
char *old = *(char**)datum;
|
||||
|
||||
if (old != 0) {
|
||||
if (old != 0)
|
||||
{
|
||||
char *tmp = objc_malloc(strlen(old)+1);
|
||||
|
||||
strcpy(tmp, old);
|
||||
|
|
|
@ -283,7 +283,8 @@ static IMP rDatImp; /* To autorelease it. */
|
|||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
obj = nil;
|
||||
[unarchiver release];
|
||||
[localException raise];
|
||||
}
|
||||
NS_ENDHANDLER
|
||||
[unarchiver release];
|
||||
|
@ -639,10 +640,7 @@ static IMP rDatImp; /* To autorelease it. */
|
|||
int offset = 0;
|
||||
|
||||
typeCheck(*type, _C_STRUCT_B);
|
||||
while (*type != _C_STRUCT_E && *type != '=')
|
||||
{
|
||||
type++;
|
||||
}
|
||||
while (*type != _C_STRUCT_E && *type++ != '='); /* skip "<name>=" */
|
||||
for (;;)
|
||||
{
|
||||
(*dValImp)(self, dValSel, type, (char*)address + offset);
|
||||
|
@ -700,16 +698,17 @@ static IMP rDatImp; /* To autorelease it. */
|
|||
}
|
||||
|
||||
/*
|
||||
* Allocate memory for object to be decoded into.
|
||||
* Allocate memory for object to be decoded into and
|
||||
* add it to the crossref map.
|
||||
*/
|
||||
size = objc_sizeof_type(++type);
|
||||
*(void**)address = NSZoneMalloc(zone, size);
|
||||
arrayAddItem(ptrMap, *(void**)address);
|
||||
|
||||
/*
|
||||
* Decode value and add memory to map for crossrefs.
|
||||
*/
|
||||
(*dValImp)(self, dValSel, type, *(void**)address);
|
||||
arrayAddItem(ptrMap, *(void**)address);
|
||||
|
||||
/*
|
||||
* Allocate, initialise, and autorelease an NSData
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue