* Source/DKArgument.m

Source/DKMethod.m
  Source/DKMethodCall.m:
  Replace side-effect ridden NSAsserts.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/dbuskit/trunk@30958 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Niels Grewe 2010-07-13 21:53:49 +00:00
parent 284f5f44e0
commit 539eccf050
3 changed files with 70 additions and 55 deletions

View File

@ -52,6 +52,33 @@ NSString *DKArgumentDirectionIn = @"in";
NSString *DKArgumentDirectionOut = @"out"; NSString *DKArgumentDirectionOut = @"out";
/*
* Macros to call D-Bus function and check whether they returned OOM:
*/
#define DK_MARSHALLING_RAISE_OOM [NSException raise: @"DKArgumentMarshallingException"\
format: @"Out of memory when marshalling arument."]
#define DK_ITER_APPEND(iter, type, addr) do {\
if (NO == (BOOL)dbus_message_iter_append_basic(iter, type, (void*)addr))\
{\
DK_MARSHALLING_RAISE_OOM; \
}\
} while (0)
#define DK_ITER_OPEN_CONTAINER(iter, type, sig, subIter) do {\
if (NO == (BOOL)dbus_message_iter_open_container(iter, type, sig, subIter))\
{\
DK_MARSHALLING_RAISE_OOM; \
}\
} while (0)
#define DK_ITER_CLOSE_CONTAINER(iter, subIter) do {\
if (NO == (BOOL)dbus_message_iter_close_container(iter, subIter))\
{\
DK_MARSHALLING_RAISE_OOM; \
}\
} while (0)
static Class static Class
DKObjCClassForDBusType(int type) DKObjCClassForDBusType(int type)
@ -886,9 +913,12 @@ DKDBusTypeForUnboxingObject(id object)
atIndex: index]; atIndex: index];
} }
NSAssert1([self unboxValue: value intoBuffer: (long long int*)(void*)&buffer], if (NO == [self unboxValue: value intoBuffer: (long long*)(void*)&buffer])
@"Could not unbox object '%@' into D-Bus format", {
value); [NSException raise: @"DKArgumentUnboxingException"
format: @"Could not unbox object '%@' into D-Bus format",
value];
}
} }
else else
{ {
@ -903,19 +933,20 @@ DKDBusTypeForUnboxingObject(id object)
} }
} }
NSAssert(dbus_message_iter_append_basic(iter, DBusType, (void*)&buffer), DK_ITER_APPEND(iter, DBusType, &buffer);
@"Out of memory when marshalling D-Bus data.");
} }
- (void) marshallObject: (id)object - (void) marshallObject: (id)object
intoIterator: (DBusMessageIter*)iter intoIterator: (DBusMessageIter*)iter
{ {
long long int buffer = 0; long long int buffer = 0;
NSAssert1([self unboxValue: object intoBuffer: &buffer], if (NO == [self unboxValue: object intoBuffer: &buffer])
@"Could not unbox object '%@' into D-Bus format", {
object); [NSException raise: @"DKArgumentUnboxingException"
NSAssert(dbus_message_iter_append_basic(iter, DBusType, (void*)&buffer), format: @"Could not unbox object '%@' into D-Bus format",
@"Out of memory when marshalling D-Bus data."); object];
}
DK_ITER_APPEND(iter, DBusType, &buffer);
} }
@end @end
@ -1294,11 +1325,7 @@ DKDBusTypeForUnboxingObject(id object)
@"Cannot enumerate contents of %@ when creating D-Bus array.", @"Cannot enumerate contents of %@ when creating D-Bus array.",
object); object);
NSAssert(dbus_message_iter_open_container(iter, DK_ITER_OPEN_CONTAINER(iter, DBUS_TYPE_ARRAY, [[theChild DBusTypeSignature] UTF8String], &subIter);
DBUS_TYPE_ARRAY,
[[theChild DBusTypeSignature] UTF8String],
&subIter),
@"Out of memory when creating D-Bus iterator for container.");
elementEnum = [object objectEnumerator]; elementEnum = [object objectEnumerator];
NS_DURING NS_DURING
@ -1319,8 +1346,7 @@ DKDBusTypeForUnboxingObject(id object)
} }
NS_ENDHANDLER NS_ENDHANDLER
NSAssert(dbus_message_iter_close_container(iter, &subIter), DK_ITER_CLOSE_CONTAINER(iter, &subIter);
@"Out of memory when closing D-Bus container.");
} }
@end @end
@ -1430,11 +1456,8 @@ DKDBusTypeForUnboxingObject(id object)
@"Cannot marshall non key/value dictionary '%@' to D-Bus iterator.", @"Cannot marshall non key/value dictionary '%@' to D-Bus iterator.",
object); object);
NSAssert(dbus_message_iter_open_container(iter, DK_ITER_OPEN_CONTAINER(iter, DBUS_TYPE_ARRAY, [[pairArgument DBusTypeSignature] UTF8String], &subIter);
DBUS_TYPE_ARRAY,
[[pairArgument DBusTypeSignature] UTF8String],
&subIter),
@"Out of memory when creating D-Bus iterator for container.");
keys = [object allKeys]; keys = [object allKeys];
keyEnum = [keys objectEnumerator]; keyEnum = [keys objectEnumerator];
@ -1456,8 +1479,7 @@ DKDBusTypeForUnboxingObject(id object)
} }
NS_ENDHANDLER NS_ENDHANDLER
NSAssert(dbus_message_iter_close_container(iter, &subIter), DK_ITER_CLOSE_CONTAINER(iter, &subIter);
@"Out of memory when closing D-Bus container.");
} }
@end @end
@ -1507,11 +1529,7 @@ DKDBusTypeForUnboxingObject(id object)
structEnum = [object objectEnumerator]; structEnum = [object objectEnumerator];
NSAssert(dbus_message_iter_open_container(iter, DK_ITER_OPEN_CONTAINER(iter, DBUS_TYPE_STRUCT, NULL, &subIter);
DBUS_TYPE_STRUCT,
NULL, // contained_signature set to NULL as per libdbus documentation
&subIter),
@"Out of memory when opening D-Bus container.");
NS_DURING NS_DURING
{ {
@ -1532,9 +1550,7 @@ DKDBusTypeForUnboxingObject(id object)
} }
NS_ENDHANDLER NS_ENDHANDLER
NSAssert(dbus_message_iter_close_container(iter, &subIter), DK_ITER_CLOSE_CONTAINER(iter, &subIter);
@"Out of memory when closing D-Bus container.");
} }
@end @end
@ -1667,11 +1683,7 @@ DKDBusTypeForUnboxingObject(id object)
@"Could not marshall object %@ as D-Bus variant type", @"Could not marshall object %@ as D-Bus variant type",
subArg); subArg);
NSAssert(dbus_message_iter_open_container(iter, DK_ITER_OPEN_CONTAINER(iter, DBUS_TYPE_ARRAY, [[subArg DBusTypeSignature] UTF8String], &subIter);
DBUS_TYPE_ARRAY,
[[subArg DBusTypeSignature] UTF8String],
&subIter),
@"Out of memory when creating D-Bus iterator for container.");
NS_DURING NS_DURING
{ {
@ -1685,8 +1697,7 @@ DKDBusTypeForUnboxingObject(id object)
} }
NS_ENDHANDLER NS_ENDHANDLER
NSAssert(dbus_message_iter_close_container(iter, &subIter), DK_ITER_CLOSE_CONTAINER(iter, &subIter);
@"Out of memory when closing D-Bus container.");
} }
@end @end
@ -1761,11 +1772,7 @@ DKDBusTypeForUnboxingObject(id object)
intoIterator: (DBusMessageIter*)iter intoIterator: (DBusMessageIter*)iter
{ {
DBusMessageIter subIter; DBusMessageIter subIter;
NSAssert(dbus_message_iter_open_container(iter, DK_ITER_OPEN_CONTAINER(iter, DBUS_TYPE_DICT_ENTRY, NULL, &subIter);
DBUS_TYPE_DICT_ENTRY,
NULL, // contained_signature set to NULL as per libdbus documentation
&subIter),
@"Out of memory when opening D-Bus container.");
NS_DURING NS_DURING
{ {
[[self keyArgument] marshallObject: key [[self keyArgument] marshallObject: key
@ -1781,7 +1788,6 @@ DKDBusTypeForUnboxingObject(id object)
} }
NS_ENDHANDLER NS_ENDHANDLER
NSAssert(dbus_message_iter_close_container(iter, &subIter), DK_ITER_CLOSE_CONTAINER(iter, &subIter);
@"Out of memory when closing D-Bus container.");
} }
@end @end

View File

@ -272,9 +272,12 @@ DKMethod *_DKMethodIntrospect;
* Proceed to the next value in the message, but raise an exception if * Proceed to the next value in the message, but raise an exception if
* we are missing some. * we are missing some.
*/ */
NSAssert1(dbus_message_iter_next(iter), if (NO == (BOOL)dbus_message_iter_next(iter))
@"D-Bus message too short when unmarshalling return value for '%@'.", {
name); [NSException raise: @"DKMethodUnmarshallingException"
format: @"D-Bus message too short when unmarshalling return value for '%@'.",
name];
}
index++; index++;
} }
[inv setReturnValue: &returnValues]; [inv setReturnValue: &returnValues];
@ -361,10 +364,13 @@ DKMethod *_DKMethodIntrospect;
* Proceed to the next value in the message, but raise an exception if * Proceed to the next value in the message, but raise an exception if
* we are missing some arguments. * we are missing some arguments.
*/ */
NSAssert2(dbus_message_iter_next(iter), if (NO == (BOOL)dbus_message_iter_next(iter))
@"D-Bus message too short when unmarshalling arguments for invocation of '%@' on '%@'.", {
NSStringFromSelector([inv selector]), [NSException raise: @"DKMethodUnmarshallingException"
[inv target]); format: @"D-Bus message too short when unmarshalling arguments for invocation of '%@' on '%@'.",
NSStringFromSelector([inv selector]),
[inv target]];
}
index++; index++;
} }
} }

View File

@ -221,8 +221,11 @@
// we are operating asynchronously. // we are operating asynchronously.
NS_DURING NS_DURING
{ {
NSAssert(dbus_message_iter_init(reply, &iter), if (NO ==(BOOL)dbus_message_iter_init(reply, &iter))
@"Out of memory when creating D-Bus message iterator."); {
[NSException raise: @"DKMethodCallException"
format: @"Out of memory when creating D-Bus message iterator."];
}
[method unmarshallFromIterator: &iter [method unmarshallFromIterator: &iter
intoInvocation: invocation intoInvocation: invocation
messageType: DBUS_MESSAGE_TYPE_METHOD_RETURN messageType: DBUS_MESSAGE_TYPE_METHOD_RETURN