From cfe8d9e88126fa7716295afc2f3e4648b1e84264 Mon Sep 17 00:00:00 2001 From: Richard Frith-Macdonald Date: Mon, 28 Jul 2003 10:53:18 +0000 Subject: [PATCH] Tidyups etc git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@17380 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 9 +++++++++ Headers/gnustep/base/GSMime.h | 3 +++ Headers/gnustep/base/GSXML.h | 2 ++ Source/Additions/GSMime.m | 20 ++++++++++++++++++++ Source/Additions/GSXML.m | 28 ++++++++++++++++++++++++++++ Source/GSFFCallInvocation.m | 10 ++++++++-- Source/GSFFIInvocation.m | 10 ++++++++-- Testing/nsinvocation.m | 2 +- 8 files changed, 79 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index bf0b21298..203a77d62 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2003-07-28 Richard Frith-Macdonald + + * Source/GSFFCALLInvocation.m: Make exception text more meaningful + * Source/GSFFIInvocation.m: ditto + * Source/Additions/GSXML.m: Add a couple of convenience methods to + test node type. + * Source/Additions/GSMime.m: Add convenience method for putting + a new header in a document. + 2003-07-27 Gregory John Casamento & Alexander Malmberg diff --git a/Headers/gnustep/base/GSMime.h b/Headers/gnustep/base/GSMime.h index af40ddff7..5552feebf 100644 --- a/Headers/gnustep/base/GSMime.h +++ b/Headers/gnustep/base/GSMime.h @@ -124,6 +124,9 @@ - (NSArray*) headersNamed: (NSString*)name; - (NSString*) makeBoundary; - (GSMimeHeader*) makeContentID; +- (GSMimeHeader*) makeHeader: (NSString*)name + value: (NSString*)value + parameters: (NSDictionary*)parameters; - (GSMimeHeader*) makeMessageID; - (NSMutableData*) rawMimeData; - (NSMutableData*) rawMimeData: (BOOL)isOuter; diff --git a/Headers/gnustep/base/GSXML.h b/Headers/gnustep/base/GSXML.h index 9b42ce2f1..7440c26f6 100644 --- a/Headers/gnustep/base/GSXML.h +++ b/Headers/gnustep/base/GSXML.h @@ -119,6 +119,8 @@ - (GSXMLAttribute*) firstAttribute; - (GSXMLNode*) firstChild; - (GSXMLNode*) firstChildElement; +- (BOOL) isElement; +- (BOOL) isText; - (void*) lib; - (GSXMLAttribute*) makeAttributeWithName: (NSString*)name value: (NSString*)value; diff --git a/Source/Additions/GSMime.m b/Source/Additions/GSMime.m index 5f9051fc1..4b8d52f32 100644 --- a/Source/Additions/GSMime.m +++ b/Source/Additions/GSMime.m @@ -3776,6 +3776,26 @@ static NSCharacterSet *tokenSet = nil; return hdr; } +/** + * Convenience method to create a new header and add it to the receiver + * replacing any existing header of the same name.
+ * Returns the newly created header.
+ * See [GSMimeHeader-initWithName:value:parameters:] and -setHeader: methods. + */ +- (GSMimeHeader*) makeHeader: (NSString*)name + value: (NSString*)value + parameters: (NSDictionary*)parameters +{ + GSMimeHeader *hdr; + + hdr = [[GSMimeHeader alloc] initWithName: name + value: value + parameters: parameters]; + [self setHeader: hdr]; + RELEASE(hdr); + return hdr; +} + /** * Create new message ID header, set it as the message ID of the document * and return it.
diff --git a/Source/Additions/GSXML.m b/Source/Additions/GSXML.m index 7a8db20c2..ac10d2196 100644 --- a/Source/Additions/GSXML.m +++ b/Source/Additions/GSXML.m @@ -1124,6 +1124,20 @@ static NSMapTable *nodeNames = 0; return nil; } +/** + * Convenience method, equivalent to calling -type and comparing it + * with the result of passing "XML_ELEMENT_NODE" to + * +typeFromDescription: (but faster). + */ +- (BOOL) isElement +{ + if ((int)((xmlNodePtr)(lib))->type == XML_ELEMENT_NODE) + { + return YES; + } + return NO; +} + - (BOOL) isEqual: (id)other { if ([other isKindOfClass: [self class]] == YES @@ -1137,6 +1151,20 @@ static NSMapTable *nodeNames = 0; } } +/** + * Convenience method, equivalent to calling -type and comparing it + * with the result of passing "XML_TEXT_NODE" to + * +typeFromDescription: (but faster). + */ +- (BOOL) isText +{ + if ((int)((xmlNodePtr)(lib))->type == XML_TEXT_NODE) + { + return YES; + } + return NO; +} + /** * Returns a pointer to the raw libxml data used by this document.
* Only for use by libxml experts! diff --git a/Source/GSFFCallInvocation.m b/Source/GSFFCallInvocation.m index 3c0012bed..8c4c9f6e1 100644 --- a/Source/GSFFCallInvocation.m +++ b/Source/GSFFCallInvocation.m @@ -860,8 +860,14 @@ GSInvocationCallback (void *callback_data, va_alist args) sig = [NSMethodSignature signatureWithObjCTypes: sel_get_type(selector)]; } - NSCAssert1(sig, @"No signature for selector %@", - NSStringFromSelector(selector)); + if (sig == nil) + { + [NSException raise: NSInvalidArgumentException + format: @"%s(%s) does not recognize %s", + object_get_class_name(obj), + GSObjCIsInstance(obj) ? "instance" : "class", + selector ? sel_get_name(selector) : "(null)"]; + } invocation = [[GSFFCallInvocation alloc] initWithMethodSignature: sig]; AUTORELEASE(invocation); diff --git a/Source/GSFFIInvocation.m b/Source/GSFFIInvocation.m index 8a358bd9e..de3d960c0 100644 --- a/Source/GSFFIInvocation.m +++ b/Source/GSFFIInvocation.m @@ -475,8 +475,14 @@ GSFFIInvocationCallback(ffi_cif *cif, void *retp, void **args, void *user) sig = [NSMethodSignature signatureWithObjCTypes: sel_get_type(selector)]; } - NSCAssert1(sig, @"No signature for selector %@", - NSStringFromSelector(selector)); + if (sig == nil) + { + [NSException raise: NSInvalidArgumentException + format: @"%s(%s) does not recognize %s", + object_get_class_name(obj), + GSObjCIsInstance(obj) ? "instance" : "class", + selector ? sel_get_name(selector) : "(null)"]; + } invocation = [[GSFFIInvocation alloc] initWithCallback: cif returnp: retp diff --git a/Testing/nsinvocation.m b/Testing/nsinvocation.m index ba2a63481..e74eca8c7 100644 --- a/Testing/nsinvocation.m +++ b/Testing/nsinvocation.m @@ -224,7 +224,7 @@ printf("Calling proxy\n"); printf("ERROR ... expecting 6 and got %d\n", i); printf("Testing NS_INVOCATION ... "); - inv = NS_MESSAGE([Target class], loopInt: 7); + inv = NS_INVOCATION([Target class], loopInt: 7); [inv setTarget: t]; [inv invoke]; [inv getReturnValue: &i];