Index: src/OFXMLElementBuilder.h ================================================================== --- src/OFXMLElementBuilder.h +++ src/OFXMLElementBuilder.h @@ -38,11 +38,11 @@ * * \param builder The builder which built an OFXMLElement * \param elem The OFXMLElement the OFXMLElementBuilder built */ - (void)elementBuilder: (OFXMLElementBuilder*)builder - didBuildElement: (OFXMLElement*)elem; + didBuildElement: (OFXMLElement*)element; #ifdef OF_HAVE_OPTIONAL_PROTOCOLS @optional #endif /** Index: src/OFXMLElementBuilder.m ================================================================== --- src/OFXMLElementBuilder.m +++ src/OFXMLElementBuilder.m @@ -68,40 +68,40 @@ - (void)parser: (OFXMLParser*)parser didStartElement: (OFString*)name withPrefix: (OFString*)prefix namespace: (OFString*)ns - attributes: (OFArray*)attrs + attributes: (OFArray*)attributes { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFXMLElement *elem; - OFXMLAttribute **attrs_c; - size_t i, attrs_cnt; - IMP add_attr; - - elem = [OFXMLElement elementWithName: name - namespace: ns]; - - attrs_c = [attrs cArray]; - attrs_cnt = [attrs count]; - add_attr = [elem methodForSelector: @selector(addAttribute:)]; - - for (i = 0; i < attrs_cnt; i++) { - if ([attrs_c[i] namespace] == nil && - [[attrs_c[i] name] isEqual: @"xmlns"]) + OFXMLElement *element; + OFXMLAttribute **cArray; + size_t i, count; + IMP addAttribute; + + element = [OFXMLElement elementWithName: name + namespace: ns]; + + cArray = [attributes cArray]; + count = [attributes count]; + addAttribute = [element methodForSelector: @selector(addAttribute:)]; + + for (i = 0; i < count; i++) { + if ([cArray[i] namespace] == nil && + [[cArray[i] name] isEqual: @"xmlns"]) continue; - if ([[attrs_c[i] namespace] + if ([[cArray[i] namespace] isEqual: @"http://www.w3.org/2000/xmlns/"]) - [elem setPrefix: [attrs_c[i] name] - forNamespace: [attrs_c[i] stringValue]]; + [element setPrefix: [cArray[i] name] + forNamespace: [cArray[i] stringValue]]; - add_attr(elem, @selector(addAttribute:), attrs_c[i]); + addAttribute(element, @selector(addAttribute:), cArray[i]); } - [[stack lastObject] addChild: elem]; - [stack addObject: elem]; + [[stack lastObject] addChild: element]; + [stack addObject: element]; [pool release]; } - (void)parser: (OFXMLParser*)parser @@ -123,50 +123,51 @@ [stack removeNObjects: 1]; } - (void)parser: (OFXMLParser*)parser - foundCharacters: (OFString*)str + foundCharacters: (OFString*)characters { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFXMLElement *elem = [OFXMLElement elementWithCharacters: str]; + OFXMLElement *element = + [OFXMLElement elementWithCharacters: characters]; if ([stack count] == 0) [delegate elementBuilder: self - didBuildElement: elem]; + didBuildElement: element]; else - [[stack lastObject] addChild: elem]; + [[stack lastObject] addChild: element]; [pool release]; } - (void)parser: (OFXMLParser*)parser - foundCDATA: (OFString*)cdata + foundCDATA: (OFString*)CDATA { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFXMLElement *elem = [OFXMLElement elementWithCDATA: cdata]; + OFXMLElement *element = [OFXMLElement elementWithCDATA: CDATA]; if ([stack count] == 0) [delegate elementBuilder: self - didBuildElement: elem]; + didBuildElement: element]; else - [[stack lastObject] addChild: elem]; + [[stack lastObject] addChild: element]; [pool release]; } - (void)parser: (OFXMLParser*)parser foundComment: (OFString*)comment { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFXMLElement *elem = [OFXMLElement elementWithComment: comment]; + OFXMLElement *element = [OFXMLElement elementWithComment: comment]; if ([stack count] == 0) [delegate elementBuilder: self - didBuildElement: elem]; + didBuildElement: element]; else - [[stack lastObject] addChild: elem]; + [[stack lastObject] addChild: element]; [pool release]; } @end Index: src/OFXMLParser.h ================================================================== --- src/OFXMLParser.h +++ src/OFXMLParser.h @@ -25,11 +25,11 @@ #if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS) typedef void (^of_xml_parser_processing_instructions_block_t)( OFXMLParser *parser, OFString *pi); typedef void (^of_xml_parser_element_start_block_t)(OFXMLParser *parser, - OFString *name, OFString *prefix, OFString *ns, OFArray *attrs); + OFString *name, OFString *prefix, OFString *ns, OFArray *attributes); typedef void (^of_xml_parser_element_end_block_t)(OFXMLParser *parser, OFString *name, OFString *prefix, OFString *ns); typedef void (^of_xml_parser_string_block_t)(OFXMLParser *parser, OFString *string); typedef OFString* (^of_xml_parser_unknown_entity_block_t)(OFXMLParser *parser, @@ -61,17 +61,18 @@ * * \param parser The parser which found a new tag * \param name The name of the tag which just started * \param prefix The prefix of the tag which just started or nil * \param ns The namespace of the tag which just started or nil - * \param attrs The attributes included in the tag which just started or nil + * \param attributes The attributes included in the tag which just started or + * nil */ - (void)parser: (OFXMLParser*)parser didStartElement: (OFString*)name withPrefix: (OFString*)prefix namespace: (OFString*)ns - attributes: (OFArray*)attrs; + attributes: (OFArray*)attributes; /** * This callback is called when the XML parser found the end of a tag. * * \param parser The parser which found the end of a tag @@ -89,23 +90,23 @@ * * In case there are comments or CDATA, it is possible that this callback is * called multiple times in a row. * * \param parser The parser which found a string - * \param string The string the XML parser found + * \param characters The characters the XML parser found */ - (void)parser: (OFXMLParser*)parser - foundCharacters: (OFString*)string; + foundCharacters: (OFString*)characters; /** * This callback is called when the XML parser found CDATA. * * \param parser The parser which found a string - * \param cdata The CDATA the XML parser found + * \param CDATA The CDATA the XML parser found */ - (void)parser: (OFXMLParser*)parser - foundCDATA: (OFString*)cdata; + foundCDATA: (OFString*)CDATA; /** * This callback is called when the XML parser found a comment. * * \param parser The parser which found a comment @@ -161,14 +162,14 @@ } state; OFMutableString *cache; OFString *name; OFString *prefix; OFMutableArray *namespaces; - OFMutableArray *attrs; - OFString *attrName; - OFString *attrPrefix; - char delim; + OFMutableArray *attributes; + OFString *attributeName; + OFString *attributePrefix; + char delimiter; OFMutableArray *previous; #if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS) of_xml_parser_processing_instructions_block_t processingInstructionsHandler; of_xml_parser_element_start_block_t elementStartHandler; @@ -304,22 +305,22 @@ #endif /** * Parses a buffer with the specified size. * - * \param buf The buffer to parse - * \param size The size of the buffer + * \param buffer The buffer to parse + * \param length The length of the buffer */ -- (void)parseBuffer: (const char*)buf - withSize: (size_t)size; +- (void)parseBuffer: (const char*)buffer + withLength: (size_t)length; /** * Parses the specified string. * - * \param str The string to parse + * \param string The string to parse */ -- (void)parseString: (OFString*)str; +- (void)parseString: (OFString*)string; /** * Parses the specified stream. * * \param stream The stream to parse Index: src/OFXMLParser.m ================================================================== --- src/OFXMLParser.m +++ src/OFXMLParser.m @@ -36,11 +36,11 @@ #import "macros.h" typedef void (*state_function)(id, SEL, const char*, size_t*, size_t*); static SEL selectors[OF_XMLPARSER_NUM_STATES]; -static state_function lookup_table[OF_XMLPARSER_NUM_STATES]; +static state_function lookupTable[OF_XMLPARSER_NUM_STATES]; static OF_INLINE OFString* transform_string(OFMutableString *cache, OFObject *delegate) { @@ -52,44 +52,45 @@ } static OFString* namespace_for_prefix(OFString *prefix, OFArray *namespaces) { - OFDictionary **carray = [namespaces cArray]; + OFDictionary **cArray = [namespaces cArray]; ssize_t i; if (prefix == nil) prefix = @""; for (i = [namespaces count] - 1; i >= 0; i--) { OFString *tmp; - if ((tmp = [carray[i] objectForKey: prefix]) != nil) + if ((tmp = [cArray[i] objectForKey: prefix]) != nil) return tmp; } return nil; } static OF_INLINE void -resolve_attr_namespace(OFXMLAttribute *attr, OFString *prefix, OFString *ns, - OFArray *namespaces, Class isa) +resolve_attribute_namespace(OFXMLAttribute *attribute, OFString *prefix, + OFString *ns, OFArray *namespaces, Class isa) { - OFString *attr_ns; - OFString *attr_prefix = attr->ns; + OFString *attributeNS; + OFString *attributePrefix = attribute->ns; - if (attr_prefix == nil) + if (attributePrefix == nil) return; - attr_ns = namespace_for_prefix(attr_prefix, namespaces); - - if ((attr_prefix != nil && attr_ns == nil)) - @throw [OFUnboundNamespaceException newWithClass: isa - prefix: attr_prefix]; - - [attr->ns release]; - attr->ns = [attr_ns retain]; + attributeNS = namespace_for_prefix(attributePrefix, namespaces); + + if ((attributePrefix != nil && attributeNS == nil)) + @throw [OFUnboundNamespaceException + newWithClass: isa + prefix: attributePrefix]; + + [attribute->ns release]; + attribute->ns = [attributeNS retain]; } @implementation OFXMLParser #if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS) @synthesize processingInstructionsHandler, elementStartHandler; @@ -99,11 +100,11 @@ + (void)initialize { size_t i; - const SEL sels[] = { + const SEL selectors_[] = { @selector(_parseOutsideTagWithBuffer:i:last:), @selector(_parseTagOpenedWithBuffer:i:last:), @selector(_parseInProcessingInstructionsWithBuffer:i:last:), @selector(_parseInTagNameWithBuffer:i:last:), @selector(_parseInCloseTagNameWithBuffer:i:last:), @@ -120,18 +121,18 @@ @selector(_parseInCommentOpeningWithBuffer:i:last:), @selector(_parseInComment1WithBuffer:i:last:), @selector(_parseInComment2WithBuffer:i:last:), @selector(_parseInDoctypeWithBuffer:i:last:), }; - memcpy(selectors, sels, sizeof(sels)); + memcpy(selectors, selectors_, sizeof(selectors_)); for (i = 0; i < OF_XMLPARSER_NUM_STATES; i++) { if (![self instancesRespondToSelector: selectors[i]]) @throw [OFInitializationFailedException newWithClass: self]; - lookup_table[i] = (state_function) + lookupTable[i] = (state_function) [self instanceMethodForSelector: selectors[i]]; } } + parser @@ -175,13 +176,13 @@ [cache release]; [name release]; [prefix release]; [namespaces release]; - [attrs release]; - [attrName release]; - [attrPrefix release]; + [attributes release]; + [attributeName release]; + [attributePrefix release]; [previous release]; #if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS) [elementStartHandler release]; [elementEndHandler release]; [charactersHandler release]; @@ -193,29 +194,27 @@ [super dealloc]; } - (id )delegate { - return [[(id)delegate retain] autorelease]; + OF_GETTER(delegate, YES) } - (void)setDelegate: (id )delegate_ { - [(id)delegate_ retain]; - [(id)delegate release]; - delegate = delegate_; + OF_SETTER(delegate, delegate_, YES, NO) } - (void)parseBuffer: (const char*)buf - withSize: (size_t)size + withLength: (size_t)length { size_t i, last = 0; - for (i = 0; i < size; i++) { + for (i = 0; i < length; i++) { size_t j = i; - lookup_table[state](self, selectors[state], buf, &i, &last); + lookupTable[state](self, selectors[state], buf, &i, &last); /* Ensure we don't count this character twice */ if (i != j) continue; @@ -224,35 +223,35 @@ lastCarriageReturn = (buf[i] == '\r'); } /* In OF_XMLPARSER_IN_TAG, there can be only spaces */ - if (size - last > 0 && state != OF_XMLPARSER_IN_TAG) + if (length - last > 0 && state != OF_XMLPARSER_IN_TAG) [cache appendCStringWithoutUTF8Checking: buf + last - length: size - last]; + length: length - last]; } -- (void)parseString: (OFString*)str +- (void)parseString: (OFString*)string { - [self parseBuffer: [str cString] - withSize: [str cStringLength]]; + [self parseBuffer: [string cString] + withLength: [string cStringLength]]; } - (void)parseStream: (OFStream*)stream { - char *buf = [self allocMemoryWithSize: of_pagesize]; + char *buffer = [self allocMemoryWithSize: of_pagesize]; @try { while (![stream isAtEndOfStream]) { - size_t len = [stream readNBytes: of_pagesize - intoBuffer: buf]; + size_t length = [stream readNBytes: of_pagesize + intoBuffer: buffer]; - [self parseBuffer: buf - withSize: len]; + [self parseBuffer: buffer + withLength: length]; } } @finally { - [self freeMemory: buf]; + [self freeMemory: buffer]; } } - (void)parseFile: (OFString*)path { @@ -271,43 +270,43 @@ * looked up in +[initialize] and put in a lookup table to speed things up. * One dispatch for every character would be way too slow! */ /* Not in a tag */ -- (void)_parseOutsideTagWithBuffer: (const char*)buf +- (void)_parseOutsideTagWithBuffer: (const char*)buffer i: (size_t*)i last: (size_t*)last { - size_t len; + size_t length; - if ((finishedParsing || [previous count] < 1) && buf[*i] != ' ' && - buf[*i] != '\t' && buf[*i] != '\n' && buf[*i] != '\r' && - buf[*i] != '<') + if ((finishedParsing || [previous count] < 1) && buffer[*i] != ' ' && + buffer[*i] != '\t' && buffer[*i] != '\n' && buffer[*i] != '\r' && + buffer[*i] != '<') @throw [OFMalformedXMLException newWithClass: isa parser: self]; - if (buf[*i] != '<') + if (buffer[*i] != '<') return; - if ((len = *i - *last) > 0) - [cache appendCStringWithoutUTF8Checking: buf + *last - length: len]; + if ((length = *i - *last) > 0) + [cache appendCStringWithoutUTF8Checking: buffer + *last + length: length]; if ([cache cStringLength] > 0) { - OFString *str; + OFString *characters; OFAutoreleasePool *pool; pool = [[OFAutoreleasePool alloc] init]; - str = transform_string(cache, self); + characters = transform_string(cache, self); #if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS) if (charactersHandler != NULL) - charactersHandler(self, str); + charactersHandler(self, characters); else #endif [delegate parser: self - foundCharacters: str]; + foundCharacters: characters]; [pool release]; } [cache setToCString: ""]; @@ -315,19 +314,19 @@ *last = *i + 1; state = OF_XMLPARSER_TAG_OPENED; } /* Tag was just opened */ -- (void)_parseTagOpenedWithBuffer: (const char*)buf +- (void)_parseTagOpenedWithBuffer: (const char*)buffer i: (size_t*)i last: (size_t*)last { - if (finishedParsing && buf[*i] != '!' && buf[*i] != '?') + if (finishedParsing && buffer[*i] != '!' && buffer[*i] != '?') @throw [OFMalformedXMLException newWithClass: isa parser: self]; - switch (buf[*i]) { + switch (buffer[*i]) { case '?': *last = *i + 1; state = OF_XMLPARSER_IN_PROCESSING_INSTRUCTIONS; level = 0; break; @@ -350,16 +349,16 @@ } /* */ - (BOOL)_parseXMLProcessingInstructions: (OFString*)pi { - const char *pi_c; - size_t i, last, pi_len; - int xstate = 0; - OFString *attr = nil; - OFString *val = nil; - char xdelim = 0; + const char *cString; + size_t i, last, length; + int piState = 0; + OFString *attribute = nil; + OFString *value = nil; + char piDelimiter = 0; if (!acceptProlog) return NO; acceptProlog = NO; @@ -366,86 +365,86 @@ pi = [pi substringFromIndex: 3 toIndex: [pi length]]; pi = [pi stringByDeletingLeadingAndTrailingWhitespaces]; - pi_c = [pi cString]; - pi_len = [pi cStringLength]; - - for (i = last = 0; i < pi_len; i++) { - switch (xstate) { - case 0: - if (pi_c[i] == ' ' || pi_c[i] == '\t' || - pi_c[i] == '\r' || pi_c[i] == '\n') - continue; - - last = i; - xstate = 1; - i--; - - break; - case 1: - if (pi_c[i] != '=') - continue; - - attr = [OFString stringWithCString: pi_c + last - length: i - last]; - last = i + 1; - xstate = 2; - - break; - case 2: - if (pi_c[i] != '\'' && pi_c[i] != '"') - return NO; - - xdelim = pi_c[i]; - last = i + 1; - xstate = 3; - - break; - case 3: - if (pi_c[i] != xdelim) - continue; - - val = [OFString stringWithCString: pi_c + last - length: i - last]; - - if ([attr isEqual: @"version"]) - if (![val hasPrefix: @"1."]) - return NO; - - if ([attr isEqual: @"encoding"]) - if ([val caseInsensitiveCompare: @"utf-8"] != - OF_ORDERED_SAME) - return NO; - - last = i + 1; - xstate = 0; - - break; - } - } - - if (xstate != 0) + cString = [pi cString]; + length = [pi cStringLength]; + + for (i = last = 0; i < length; i++) { + switch (piState) { + case 0: + if (cString[i] == ' ' || cString[i] == '\t' || + cString[i] == '\r' || cString[i] == '\n') + continue; + + last = i; + piState = 1; + i--; + + break; + case 1: + if (cString[i] != '=') + continue; + + attribute = [OFString stringWithCString: cString + last + length: i - last]; + last = i + 1; + piState = 2; + + break; + case 2: + if (cString[i] != '\'' && cString[i] != '"') + return NO; + + piDelimiter = cString[i]; + last = i + 1; + piState = 3; + + break; + case 3: + if (cString[i] != piDelimiter) + continue; + + value = [OFString stringWithCString: cString + last + length: i - last]; + + if ([attribute isEqual: @"version"]) + if (![value hasPrefix: @"1."]) + return NO; + + if ([attribute isEqual: @"encoding"]) + if ([value caseInsensitiveCompare: @"utf-8"] != + OF_ORDERED_SAME) + return NO; + + last = i + 1; + piState = 0; + + break; + } + } + + if (piState != 0) return NO; return YES; } /* Inside processing instructions */ -- (void)_parseInProcessingInstructionsWithBuffer: (const char*)buf +- (void)_parseInProcessingInstructionsWithBuffer: (const char*)buffer i: (size_t*)i last: (size_t*)last { - if (buf[*i] == '?') + if (buffer[*i] == '?') level = 1; - else if (level == 1 && buf[*i] == '>') { + else if (level == 1 && buffer[*i] == '>') { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFMutableString *pi; size_t len; - [cache appendCStringWithoutUTF8Checking: buf + *last + [cache appendCStringWithoutUTF8Checking: buffer + *last length: *i - *last]; pi = [[cache mutableCopy] autorelease]; len = [pi length]; [pi deleteCharactersFromIndex: len - 1 @@ -478,40 +477,41 @@ } else level = 0; } /* Inside a tag, no name yet */ -- (void)_parseInTagNameWithBuffer: (const char*)buf +- (void)_parseInTagNameWithBuffer: (const char*)buffer i: (size_t*)i last: (size_t*)last { - const char *cache_c, *tmp; - size_t len, cache_len; + const char *cacheCString, *tmp; + size_t length, cacheLength; - if (buf[*i] != ' ' && buf[*i] != '\t' && buf[*i] != '\n' && - buf[*i] != '\r' && buf[*i] != '>' && buf[*i] != '/') + if (buffer[*i] != ' ' && buffer[*i] != '\t' && buffer[*i] != '\n' && + buffer[*i] != '\r' && buffer[*i] != '>' && buffer[*i] != '/') return; - if ((len = *i - *last) > 0) - [cache appendCStringWithoutUTF8Checking: buf + *last - length: len]; - - cache_c = [cache cString]; - cache_len = [cache cStringLength]; - - if ((tmp = memchr(cache_c, ':', cache_len)) != NULL) { + if ((length = *i - *last) > 0) + [cache appendCStringWithoutUTF8Checking: buffer + *last + length: length]; + + cacheCString = [cache cString]; + cacheLength = [cache cStringLength]; + + if ((tmp = memchr(cacheCString, ':', cacheLength)) != NULL) { name = [[OFString alloc] initWithCString: tmp + 1 - length: cache_len - - (tmp - cache_c) - 1]; - prefix = [[OFString alloc] initWithCString: cache_c - length: tmp - cache_c]; + length: cacheLength - + (tmp - cacheCString) - + 1]; + prefix = [[OFString alloc] initWithCString: cacheCString + length: tmp - cacheCString]; } else { name = [cache copy]; prefix = nil; } - if (buf[*i] == '>' || buf[*i] == '/') { + if (buffer[*i] == '>' || buffer[*i] == '/') { OFAutoreleasePool *pool; OFString *ns; ns = namespace_for_prefix(prefix, namespaces); @@ -531,11 +531,11 @@ didStartElement: name withPrefix: prefix namespace: ns attributes: nil]; - if (buf[*i] == '/') { + if (buffer[*i] == '/') { #if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS) if (elementEndHandler != NULL) elementEndHandler(self, name, prefix, ns); else #endif @@ -550,17 +550,17 @@ [name release]; [prefix release]; name = prefix = nil; - state = (buf[*i] == '/' + state = (buffer[*i] == '/' ? OF_XMLPARSER_EXPECT_CLOSE : OF_XMLPARSER_OUTSIDE_TAG); } else state = OF_XMLPARSER_IN_TAG; - if (buf[*i] != '/') { + if (buffer[*i] != '/') { OFAutoreleasePool *pool; pool = [[OFAutoreleasePool alloc] init]; [namespaces addObject: [OFMutableDictionary dictionary]]; [pool release]; @@ -569,35 +569,36 @@ [cache setToCString: ""]; *last = *i + 1; } /* Inside a close tag, no name yet */ -- (void)_parseInCloseTagNameWithBuffer: (const char*)buf +- (void)_parseInCloseTagNameWithBuffer: (const char*)buffer i: (size_t*)i last: (size_t*)last { OFAutoreleasePool *pool; - const char *cache_c, *tmp; - size_t len, cache_len; + const char *cacheCString, *tmp; + size_t length, cacheLength; OFString *ns; - if (buf[*i] != ' ' && buf[*i] != '\t' && buf[*i] != '\n' && - buf[*i] != '\r' && buf[*i] != '>') + if (buffer[*i] != ' ' && buffer[*i] != '\t' && buffer[*i] != '\n' && + buffer[*i] != '\r' && buffer[*i] != '>') return; - if ((len = *i - *last) > 0) - [cache appendCStringWithoutUTF8Checking: buf + *last - length: len]; - cache_c = [cache cString]; - cache_len = [cache cStringLength]; + if ((length = *i - *last) > 0) + [cache appendCStringWithoutUTF8Checking: buffer + *last + length: length]; + cacheCString = [cache cString]; + cacheLength = [cache cStringLength]; - if ((tmp = memchr(cache_c, ':', cache_len)) != NULL) { + if ((tmp = memchr(cacheCString, ':', cacheLength)) != NULL) { name = [[OFString alloc] initWithCString: tmp + 1 - length: cache_len - - (tmp - cache_c) - 1]; - prefix = [[OFString alloc] initWithCString: cache_c - length: tmp - cache_c]; + length: cacheLength - + (tmp - cacheCString) - + 1]; + prefix = [[OFString alloc] initWithCString: cacheCString + length: tmp - cacheCString]; } else { name = [cache copy]; prefix = nil; } @@ -632,65 +633,66 @@ [name release]; [prefix release]; name = prefix = nil; *last = *i + 1; - state = (buf[*i] == '>' + state = (buffer[*i] == '>' ? OF_XMLPARSER_OUTSIDE_TAG : OF_XMLPARSER_EXPECT_SPACE_OR_CLOSE); if ([previous count] == 0) finishedParsing = YES; } /* Inside a tag, name found */ -- (void)_parseInTagWithBuffer: (const char*)buf +- (void)_parseInTagWithBuffer: (const char*)buffer i: (size_t*)i last: (size_t*)last { OFAutoreleasePool *pool; OFString *ns; - OFXMLAttribute **attrs_c; - size_t j, attrs_cnt; + OFXMLAttribute **attributesCArray; + size_t j, attributesCount; - if (buf[*i] != '>' && buf[*i] != '/') { - if (buf[*i] != ' ' && buf[*i] != '\t' && buf[*i] != '\n' && - buf[*i] != '\r') { + if (buffer[*i] != '>' && buffer[*i] != '/') { + if (buffer[*i] != ' ' && buffer[*i] != '\t' && + buffer[*i] != '\n' && buffer[*i] != '\r') { *last = *i; state = OF_XMLPARSER_IN_ATTR_NAME; (*i)--; } return; } - attrs_c = [attrs cArray]; - attrs_cnt = [attrs count]; + attributesCArray = [attributes cArray]; + attributesCount = [attributes count]; ns = namespace_for_prefix(prefix, namespaces); if (prefix != nil && ns == nil) @throw [OFUnboundNamespaceException newWithClass: isa prefix: prefix]; - for (j = 0; j < attrs_cnt; j++) - resolve_attr_namespace(attrs_c[j], prefix, ns, namespaces, isa); + for (j = 0; j < attributesCount; j++) + resolve_attribute_namespace(attributesCArray[j], prefix, ns, + namespaces, isa); pool = [[OFAutoreleasePool alloc] init]; #if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS) if (elementStartHandler != NULL) - elementStartHandler(self, name, prefix, ns, attrs); + elementStartHandler(self, name, prefix, ns, attributes); else #endif [delegate parser: self didStartElement: name withPrefix: prefix namespace: ns - attributes: attrs]; + attributes: attributes]; - if (buf[*i] == '/') { + if (buffer[*i] == '/') { #if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS) if (elementEndHandler != NULL) elementEndHandler(self, name, prefix, ns); else #endif @@ -709,162 +711,163 @@ [pool release]; [name release]; [prefix release]; - [attrs release]; + [attributes release]; name = prefix = nil; - attrs = nil; + attributes = nil; *last = *i + 1; - state = (buf[*i] == '/' + state = (buffer[*i] == '/' ? OF_XMLPARSER_EXPECT_CLOSE : OF_XMLPARSER_OUTSIDE_TAG); } /* Looking for attribute name */ -- (void)_parseInAttributeNameWithBuffer: (const char*)buf +- (void)_parseInAttributeNameWithBuffer: (const char*)buffer i: (size_t*)i last: (size_t*)last { - const char *cache_c, *tmp; - size_t len, cache_len; + const char *cacheCString, *tmp; + size_t length, cacheLength; - if (buf[*i] != '=') + if (buffer[*i] != '=') return; - if ((len = *i - *last) > 0) - [cache appendCStringWithoutUTF8Checking: buf + *last - length: len]; + if ((length = *i - *last) > 0) + [cache appendCStringWithoutUTF8Checking: buffer + *last + length: length]; [cache deleteLeadingAndTrailingWhitespaces]; - cache_c = [cache cString]; - cache_len = [cache cStringLength]; - - if ((tmp = memchr(cache_c, ':', cache_len)) != NULL) { - attrName = [[OFString alloc] initWithCString: tmp + 1 - length: cache_len - - (tmp - cache_c) - - 1]; - attrPrefix = [[OFString alloc] initWithCString: cache_c - length: tmp - cache_c]; + cacheCString = [cache cString]; + cacheLength = [cache cStringLength]; + + if ((tmp = memchr(cacheCString, ':', cacheLength)) != NULL) { + attributeName = [[OFString alloc] + initWithCString: tmp + 1 + length: cacheLength - (tmp - cacheCString) - 1]; + attributePrefix = [[OFString alloc] + initWithCString: cacheCString + length: tmp - cacheCString]; } else { - attrName = [cache copy]; - attrPrefix = nil; + attributeName = [cache copy]; + attributePrefix = nil; } [cache setToCString: ""]; *last = *i + 1; state = OF_XMLPARSER_EXPECT_DELIM; } /* Expecting delimiter */ -- (void)_parseExpectDelimiterWithBuffer: (const char*)buf +- (void)_parseExpectDelimiterWithBuffer: (const char*)buffer i: (size_t*)i last: (size_t*)last { *last = *i + 1; - if (buf[*i] == ' ' || buf[*i] == '\t' || buf[*i] == '\n' || - buf[*i] == '\r') + if (buffer[*i] == ' ' || buffer[*i] == '\t' || buffer[*i] == '\n' || + buffer[*i] == '\r') return; - if (buf[*i] != '\'' && buf[*i] != '"') + if (buffer[*i] != '\'' && buffer[*i] != '"') @throw [OFMalformedXMLException newWithClass: isa parser: self]; - delim = buf[*i]; + delimiter = buffer[*i]; state = OF_XMLPARSER_IN_ATTR_VALUE; } /* Looking for attribute value */ -- (void)_parseInAttributeValueWithBuffer: (const char*)buf +- (void)_parseInAttributeValueWithBuffer: (const char*)buffer i: (size_t*)i last: (size_t*)last { OFAutoreleasePool *pool; - OFString *attr_val; - size_t len; + OFString *attributeValue; + size_t length; - if (buf[*i] != delim) + if (buffer[*i] != delimiter) return; - if ((len = *i - *last) > 0) - [cache appendCStringWithoutUTF8Checking: buf + *last - length: len]; + if ((length = *i - *last) > 0) + [cache appendCStringWithoutUTF8Checking: buffer + *last + length: length]; pool = [[OFAutoreleasePool alloc] init]; - attr_val = transform_string(cache, self); + attributeValue = transform_string(cache, self); - if (attrPrefix == nil && [attrName isEqual: @"xmlns"]) - [[namespaces lastObject] setObject: attr_val + if (attributePrefix == nil && [attributeName isEqual: @"xmlns"]) + [[namespaces lastObject] setObject: attributeValue forKey: @""]; - if ([attrPrefix isEqual: @"xmlns"]) - [[namespaces lastObject] setObject: attr_val - forKey: attrName]; - - if (attrs == nil) - attrs = [[OFMutableArray alloc] init]; - - [attrs addObject: [OFXMLAttribute attributeWithName: attrName - namespace: attrPrefix - stringValue: attr_val]]; + if ([attributePrefix isEqual: @"xmlns"]) + [[namespaces lastObject] setObject: attributeValue + forKey: attributeName]; + + if (attributes == nil) + attributes = [[OFMutableArray alloc] init]; + + [attributes addObject: + [OFXMLAttribute attributeWithName: attributeName + namespace: attributePrefix + stringValue: attributeValue]]; [pool release]; [cache setToCString: ""]; - [attrName release]; - [attrPrefix release]; - attrName = attrPrefix = nil; + [attributeName release]; + [attributePrefix release]; + attributeName = attributePrefix = nil; *last = *i + 1; state = OF_XMLPARSER_IN_TAG; } /* Expecting closing '>' */ -- (void)_parseExpectCloseWithBuffer: (const char*)buf +- (void)_parseExpectCloseWithBuffer: (const char*)buffer i: (size_t*)i last: (size_t*)last { - if (buf[*i] == '>') { + if (buffer[*i] == '>') { *last = *i + 1; state = OF_XMLPARSER_OUTSIDE_TAG; } else @throw [OFMalformedXMLException newWithClass: isa parser: self]; } /* Expecting closing '>' or space */ -- (void)_parseExpectSpaceOrCloseWithBuffer: (const char*)buf +- (void)_parseExpectSpaceOrCloseWithBuffer: (const char*)buffer i: (size_t*)i last: (size_t*)last { - if (buf[*i] == '>') { + if (buffer[*i] == '>') { *last = *i + 1; state = OF_XMLPARSER_OUTSIDE_TAG; - } else if (buf[*i] != ' ' && buf[*i] != '\t' && buf[*i] != '\n' && - buf[*i] != '\r') + } else if (buffer[*i] != ' ' && buffer[*i] != '\t' && + buffer[*i] != '\n' && buffer[*i] != '\r') @throw [OFMalformedXMLException newWithClass: isa parser: self]; } /* In ') { + if (buffer[*i] != '>') { state = OF_XMLPARSER_IN_CDATA_1; - level = (buf[*i] == ']' ? 1 : 0); + level = (buffer[*i] == ']' ? 1 : 0); return; } pool = [[OFAutoreleasePool alloc] init]; - [cache appendCStringWithoutUTF8Checking: buf + *last + [cache appendCStringWithoutUTF8Checking: buffer + *last length: *i - *last]; - cdata = [[cache mutableCopy] autorelease]; - len = [cdata length]; + CDATA = [[cache mutableCopy] autorelease]; + length = [CDATA length]; - [cdata deleteCharactersFromIndex: len - 2 - toIndex: len]; + [CDATA deleteCharactersFromIndex: length - 2 + toIndex: length]; /* * Class swizzle the string to be immutable. We pass it as OFString*, so * it can't be modified anyway. But not swizzling it would create a * real copy each time -[copy] is called. */ - cdata->isa = [OFString class]; + CDATA->isa = [OFString class]; #if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS) if (CDATAHandler != NULL) - CDATAHandler(self, cdata); + CDATAHandler(self, CDATA); else #endif [delegate parser: self - foundCDATA: cdata]; + foundCDATA: CDATA]; [pool release]; [cache setToCString: ""]; @@ -949,57 +952,57 @@ *last = *i + 1; state = OF_XMLPARSER_OUTSIDE_TAG; } /* Comment */ -- (void)_parseInCommentOpeningWithBuffer: (const char*)buf +- (void)_parseInCommentOpeningWithBuffer: (const char*)buffer i: (size_t*)i last: (size_t*)last { - if (buf[*i] != '-') + if (buffer[*i] != '-') @throw [OFMalformedXMLException newWithClass: isa parser: self]; *last = *i + 1; state = OF_XMLPARSER_IN_COMMENT_1; level = 0; } -- (void)_parseInComment1WithBuffer: (const char*)buf +- (void)_parseInComment1WithBuffer: (const char*)buffer i: (size_t*)i last: (size_t*)last { - if (buf[*i] == '-') + if (buffer[*i] == '-') level++; else level = 0; if (level == 2) state = OF_XMLPARSER_IN_COMMENT_2; } -- (void)_parseInComment2WithBuffer: (const char*)buf +- (void)_parseInComment2WithBuffer: (const char*)buffer i: (size_t*)i last: (size_t*)last { OFAutoreleasePool *pool; OFMutableString *comment; - size_t len; + size_t length; - if (buf[*i] != '>') + if (buffer[*i] != '>') @throw [OFMalformedXMLException newWithClass: isa parser: self]; pool = [[OFAutoreleasePool alloc] init]; - [cache appendCStringWithoutUTF8Checking: buf + *last + [cache appendCStringWithoutUTF8Checking: buffer + *last length: *i - *last]; comment = [[cache mutableCopy] autorelease]; - len = [comment length]; + length = [comment length]; - [comment deleteCharactersFromIndex: len - 2 - toIndex: len]; + [comment deleteCharactersFromIndex: length - 2 + toIndex: length]; /* * Class swizzle the string to be immutable. We pass it as OFString*, so * it can't be modified anyway. But not swizzling it would create a * real copy each time -[copy] is called. @@ -1021,24 +1024,24 @@ *last = *i + 1; state = OF_XMLPARSER_OUTSIDE_TAG; } /* In */ -- (void)_parseInDoctypeWithBuffer: (const char*)buf +- (void)_parseInDoctypeWithBuffer: (const char*)buffer i: (size_t*)i last: (size_t*)last { - if ((level < 6 && buf[*i] != "OCTYPE"[level]) || - (level == 6 && buf[*i] != ' ' && buf[*i] != '\t' && - buf[*i] != '\n' && buf[*i] != '\r')) + if ((level < 6 && buffer[*i] != "OCTYPE"[level]) || + (level == 6 && buffer[*i] != ' ' && buffer[*i] != '\t' && + buffer[*i] != '\n' && buffer[*i] != '\r')) @throw [OFMalformedXMLException newWithClass: isa parser: self]; - if (level < 7 || buf[*i] == '<') + if (level < 7 || buffer[*i] == '<') level++; - if (buf[*i] == '>') { + if (buffer[*i] == '>') { if (level == 7) state = OF_XMLPARSER_OUTSIDE_TAG; else level--; } @@ -1077,11 +1080,11 @@ - (void)parser: (OFXMLParser*)parser didStartElement: (OFString*)name withPrefix: (OFString*)prefix namespace: (OFString*)ns - attributes: (OFArray*)attrs + attributes: (OFArray*)attributes { } - (void)parser: (OFXMLParser*)parser didEndElement: (OFString*)name @@ -1089,16 +1092,16 @@ namespace: (OFString*)ns { } - (void)parser: (OFXMLParser*)parser - foundCharacters: (OFString*)string + foundCharacters: (OFString*)characters { } - (void)parser: (OFXMLParser*)parser - foundCDATA: (OFString*)cdata + foundCDATA: (OFString*)CDATA { } - (void)parser: (OFXMLParser*)parser foundComment: (OFString*)comment Index: src/asprintf.m ================================================================== --- src/asprintf.m +++ src/asprintf.m @@ -19,29 +19,29 @@ #include #include #include int -vasprintf(char **strp, const char *fmt, va_list args) +vasprintf(char **cString, const char *format, va_list arguments) { - int size; + int length; - if ((size = vsnprintf(NULL, 0, fmt, args)) < 0) - return size; - if ((*strp = malloc((size_t)size + 1)) == NULL) + if ((length = vsnprintf(NULL, 0, format, arguments)) < 0) + return length; + if ((*cString = malloc((size_t)length + 1)) == NULL) return -1; - return vsnprintf(*strp, (size_t)size + 1, fmt, args); + return vsnprintf(*cString, (size_t)length + 1, format, arguments); } int -asprintf(char **strp, const char *fmt, ...) +asprintf(char **cString, const char *format, ...) { int ret; - va_list args; + va_list arguments; - va_start(args, fmt); - ret = vasprintf(strp, fmt, args); + va_start(arguments, format); + ret = vasprintf(cString, format, arguments); va_end(args); return ret; } Index: src/base64.h ================================================================== --- src/base64.h +++ src/base64.h @@ -27,10 +27,10 @@ #ifdef __cplusplus extern "C" { #endif extern const char of_base64_table[64]; -extern OFString *of_base64_encode(const char *buf, size_t len); -extern BOOL of_base64_decode(OFDataArray *data, const char *str, size_t len); +extern OFString *of_base64_encode(const char*, size_t); +extern BOOL of_base64_decode(OFDataArray*, const char*, size_t); #ifdef __cplusplus } #endif Index: src/base64.m ================================================================== --- src/base64.m +++ src/base64.m @@ -38,23 +38,23 @@ 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1 }; OFString* -of_base64_encode(const char *data, size_t len) +of_base64_encode(const char *data, size_t length) { OFMutableString *ret = [OFMutableString string]; - uint8_t *buf = (uint8_t*)data; + uint8_t *buffer = (uint8_t*)data; size_t i; uint8_t rest; char tb[4]; uint32_t sb; - rest = len % 3; + rest = length % 3; - for (i = 0; i < len - rest; i += 3) { - sb = (buf[i] << 16) | (buf[i + 1] << 8) | buf[i + 2]; + for (i = 0; i < length - rest; i += 3) { + sb = (buffer[i] << 16) | (buffer[i + 1] << 8) | buffer[i + 2]; tb[0] = of_base64_encode_table[(sb & 0xFC0000) >> 18]; tb[1] = of_base64_encode_table[(sb & 0x03F000) >> 12]; tb[2] = of_base64_encode_table[(sb & 0x000FC0) >> 6]; tb[3] = of_base64_encode_table[sb & 0x00003F]; @@ -63,20 +63,20 @@ length: 4]; } switch (rest) { case 1: - tb[0] = of_base64_encode_table[buf[i] >> 2]; - tb[1] = of_base64_encode_table[(buf[i] & 3) << 4]; + tb[0] = of_base64_encode_table[buffer[i] >> 2]; + tb[1] = of_base64_encode_table[(buffer[i] & 3) << 4]; tb[2] = tb[3] = '='; [ret appendCStringWithoutUTF8Checking: tb length: 4]; break; case 2: - sb = (buf[i] << 16) | (buf[i + 1] << 8); + sb = (buffer[i] << 16) | (buffer[i + 1] << 8); tb[0] = of_base64_encode_table[(sb & 0xFC0000) >> 18]; tb[1] = of_base64_encode_table[(sb & 0x03F000) >> 12]; tb[2] = of_base64_encode_table[(sb & 0x000FC0) >> 6]; tb[3] = '='; @@ -95,62 +95,62 @@ ret->isa = [OFString class]; return ret; } BOOL -of_base64_decode(OFDataArray *data, const char *str, size_t len) +of_base64_decode(OFDataArray *data, const char *cString, size_t len) { - const uint8_t *buf = (const uint8_t*)str; + const uint8_t *buffer = (const uint8_t*)cString; size_t i; if ((len & 3) != 0) return NO; for (i = 0; i < len; i += 4) { uint32_t sb = 0; - uint8_t cnt = 3; + uint8_t count = 3; char db[3]; char tmp; - if (buf[i] > 0x7F || buf[i + 1] > 0x7F || - buf[i + 2] > 0x7F || buf[i + 3] > 0x7F) + if (buffer[i] > 0x7F || buffer[i + 1] > 0x7F || + buffer[i + 2] > 0x7F || buffer[i + 3] > 0x7F) return NO; - if (buf[i] == '=' || buf[i + 1] == '=' || - (buf[i + 2] == '=' && buf[i + 3] != '=')) + if (buffer[i] == '=' || buffer[i + 1] == '=' || + (buffer[i + 2] == '=' && buffer[i + 3] != '=')) return NO; - if (buf[i + 2] == '=') - cnt--; - if (buf[i + 3] == '=') - cnt--; + if (buffer[i + 2] == '=') + count--; + if (buffer[i + 3] == '=') + count--; - if ((tmp = of_base64_decode_table[buf[i]]) == -1) + if ((tmp = of_base64_decode_table[buffer[i]]) == -1) return NO; sb |= tmp << 18; - if ((tmp = of_base64_decode_table[buf[i + 1]]) == -1) + if ((tmp = of_base64_decode_table[buffer[i + 1]]) == -1) return NO; sb |= tmp << 12; - if ((tmp = of_base64_decode_table[buf[i + 2]]) == -1) + if ((tmp = of_base64_decode_table[buffer[i + 2]]) == -1) return NO; sb |= tmp << 6; - if ((tmp = of_base64_decode_table[buf[i + 3]]) == -1) + if ((tmp = of_base64_decode_table[buffer[i + 3]]) == -1) return NO; sb |= tmp; db[0] = (sb & 0xFF0000) >> 16; db[1] = (sb & 0x00FF00) >> 8; db[2] = sb & 0x0000FF; - [data addNItems: cnt + [data addNItems: count fromCArray: db]; } return YES; } Index: src/foundation-compat.m ================================================================== --- src/foundation-compat.m +++ src/foundation-compat.m @@ -53,30 +53,30 @@ static void __attribute__((constructor)) init(void) { Class NSAutoreleasePool = objc_getClass("NSAutoreleasePool"); Class NSObject = objc_getClass("NSObject"); - Method alloc_method; - Method addObject_method; - Method autorelease_method; + Method allocMethod; + Method addObjectMethod; + Method autoreleaseMethod; if (NSAutoreleasePool == Nil || NSObject == Nil) return; - alloc_method = class_getClassMethod(NSAutoreleasePool, + allocMethod = class_getClassMethod(NSAutoreleasePool, @selector(alloc)); - addObject_method = class_getClassMethod(NSAutoreleasePool, + addObjectMethod = class_getClassMethod(NSAutoreleasePool, @selector(addObject:)); - autorelease_method = class_getInstanceMethod(NSObject, + autoreleaseMethod = class_getInstanceMethod(NSObject, @selector(autorelease)); - if (alloc_method == NULL || addObject_method == NULL || - autorelease_method == NULL) + if (allocMethod == NULL || addObjectMethod == NULL || + autoreleaseMethod == NULL) return; class_replaceMethod(NSAutoreleasePool->isa, @selector(alloc), - (IMP)alloc, method_getTypeEncoding(alloc_method)); + (IMP)alloc, method_getTypeEncoding(allocMethod)); class_replaceMethod(NSAutoreleasePool->isa, @selector(addObject:), - (IMP)addObject, method_getTypeEncoding(addObject_method)); + (IMP)addObject, method_getTypeEncoding(addObjectMethod)); class_replaceMethod(NSObject, @selector(autorelease), - (IMP)autorelease, method_getTypeEncoding(autorelease_method)); + (IMP)autorelease, method_getTypeEncoding(autoreleaseMethod)); } Index: src/macros.h ================================================================== --- src/macros.h +++ src/macros.h @@ -200,15 +200,15 @@ # define of_bswap32(i) of_bswap32_const(i) # define of_bswap64(i) of_bswap64_const(i) #endif static OF_INLINE void -of_bswap32_vec(uint32_t *buf, size_t len) +of_bswap32_vec(uint32_t *buffer, size_t length) { - while (len--) { - *buf = of_bswap32(*buf); - buf++; + while (length--) { + *buffer = of_bswap32(*buffer); + buffer++; } } #ifdef OF_BIG_ENDIAN # define of_bswap16_if_be(i) of_bswap16(i) @@ -226,13 +226,13 @@ # define of_bswap32_if_le(i) of_bswap32(i) # define of_bswap64_if_le(i) of_bswap64(i) # define of_bswap32_vec_if_be(buf, len) #endif -#define OF_ROL(val, bits) \ - (((val) << ((bits) % (sizeof(val) * 8))) | \ - (val) >> (sizeof(val) * 8 - ((bits) % (sizeof(val) * 8)))) +#define OF_ROL(value, bits) \ + (((value) << ((bits) % (sizeof(value) * 8))) | \ + (value) >> (sizeof(value) * 8 - ((bits) % (sizeof(value) * 8)))) #define OF_HASH_INIT(hash) hash = 0 #define OF_HASH_ADD(hash, byte) \ { \ hash += (uint8_t)byte; \ Index: src/objc_sync.m ================================================================== --- src/objc_sync.m +++ src/objc_sync.m @@ -26,21 +26,21 @@ # import #endif #import "threading.h" -struct locks_s { - id obj; +struct lock_s { + id object; size_t count; size_t recursion; of_thread_t thread; of_mutex_t mutex; }; static of_mutex_t mutex; -static struct locks_s *locks = NULL; -static ssize_t num_locks = 0; +static struct lock_s *locks = NULL; +static ssize_t numLocks = 0; #define SYNC_ERR(f) \ { \ fprintf(stderr, "WARNING: %s failed in line %d!\n" \ "WARNING: This might result in a race " \ @@ -53,22 +53,22 @@ { return of_mutex_new(&mutex); } int -objc_sync_enter(id obj) +objc_sync_enter(id object) { ssize_t i; if (obj == nil) return 0; if (!of_mutex_lock(&mutex)) SYNC_ERR("of_mutex_lock(&mutex)"); - for (i = num_locks - 1; i >= 0; i--) { - if (locks[i].obj == obj) { + for (i = numLocks - 1; i >= 0; i--) { + if (locks[i].object == object) { if (of_thread_is_current(locks[i].thread)) locks[i].recursion++; else { /* Make sure objc_sync_exit doesn't free it */ locks[i].count++; @@ -98,62 +98,62 @@ return 0; } } if (locks == NULL) { - if ((locks = malloc(sizeof(struct locks_s))) == NULL) { + if ((locks = malloc(sizeof(struct lock_s))) == NULL) { of_mutex_unlock(&mutex); SYNC_ERR("malloc(...)"); } } else { - struct locks_s *new_locks; + struct lock_s *new_locks; - if ((new_locks = realloc(locks, (num_locks + 1) * - sizeof(struct locks_s))) == NULL) { + if ((new_locks = realloc(locks, (numLocks + 1) * + sizeof(struct lock_s))) == NULL) { of_mutex_unlock(&mutex); SYNC_ERR("realloc(...)"); } locks = new_locks; } - locks[num_locks].obj = obj; - locks[num_locks].count = 1; - locks[num_locks].recursion = 0; - locks[num_locks].thread = of_thread_current(); - - if (!of_mutex_new(&locks[num_locks].mutex)) { - of_mutex_unlock(&mutex); - SYNC_ERR("of_mutex_new(&locks[num_locks].mutex"); - } - - if (!of_mutex_lock(&locks[num_locks].mutex)) { - of_mutex_unlock(&mutex); - SYNC_ERR("of_mutex_lock(&locks[num_locks].mutex"); - } - - num_locks++; + locks[numLocks].object = object; + locks[numLocks].count = 1; + locks[numLocks].recursion = 0; + locks[numLocks].thread = of_thread_current(); + + if (!of_mutex_new(&locks[numLocks].mutex)) { + of_mutex_unlock(&mutex); + SYNC_ERR("of_mutex_new(&locks[numLocks].mutex"); + } + + if (!of_mutex_lock(&locks[numLocks].mutex)) { + of_mutex_unlock(&mutex); + SYNC_ERR("of_mutex_lock(&locks[numLocks].mutex"); + } + + numLocks++; if (!of_mutex_unlock(&mutex)) SYNC_ERR("of_mutex_unlock(&mutex)"); return 0; } int -objc_sync_exit(id obj) +objc_sync_exit(id object) { ssize_t i; - if (obj == nil) + if (object == nil) return 0; if (!of_mutex_lock(&mutex)) SYNC_ERR("of_mutex_lock(&mutex)"); - for (i = num_locks - 1; i >= 0; i--) { - if (locks[i].obj == obj) { + for (i = numLocks - 1; i >= 0; i--) { + if (locks[i].object == object) { if (locks[i].recursion > 0 && of_thread_is_current(locks[i].thread)) { locks[i].recursion--; if (!of_mutex_unlock(&mutex)) @@ -168,26 +168,26 @@ } locks[i].count--; if (locks[i].count == 0) { - struct locks_s *new_locks = NULL; + struct lock_s *new_locks = NULL; if (!of_mutex_free(&locks[i].mutex)) { of_mutex_unlock(&mutex); SYNC_ERR( "of_mutex_free(&locks[i].mutex"); } - num_locks--; - locks[i] = locks[num_locks]; + numLocks--; + locks[i] = locks[numLocks]; - if (num_locks == 0) { + if (numLocks == 0) { free(locks); new_locks = NULL; } else if ((new_locks = realloc(locks, - num_locks * sizeof(struct locks_s))) == + numLocks * sizeof(struct lock_s))) == NULL) { of_mutex_unlock(&mutex); SYNC_ERR("realloc(...)"); } Index: src/of_asprintf.m ================================================================== --- src/of_asprintf.m +++ src/of_asprintf.m @@ -25,20 +25,20 @@ #import "OFString.h" #import "OFAutoreleasePool.h" #import "asprintf.h" -#define MAX_SUBFMT_LEN 64 +#define MAX_SUBFORMAT_LEN 64 struct context { - const char *fmt; - size_t fmt_len; - char subfmt[MAX_SUBFMT_LEN + 1]; - size_t subfmt_len; - va_list args; - char *buf; - size_t buf_len; + const char *format; + size_t formatLen; + char subformat[MAX_SUBFORMAT_LEN + 1]; + size_t subformatLen; + va_list arguments; + char *buffer; + size_t bufferLen; size_t i, last; enum { STATE_STRING, STATE_FORMAT_FLAGS, STATE_FORMAT_FIELD_WIDTH, @@ -53,55 +53,56 @@ LENGTH_MODIFIER_LL, LENGTH_MODIFIER_J, LENGTH_MODIFIER_Z, LENGTH_MODIFIER_T, LENGTH_MODIFIER_CAPITAL_L - } len_mod; -}; - -static bool -append_str(struct context *ctx, const char *astr, size_t astr_len) -{ - char *nbuf; - - if (astr_len == 0) - return true; - - if ((nbuf = realloc(ctx->buf, ctx->buf_len + astr_len + 1)) == NULL) - return false; - - memcpy(nbuf + ctx->buf_len, astr, astr_len); - - ctx->buf = nbuf; - ctx->buf_len += astr_len; - - return true; -} - -static bool -append_subfmt(struct context *ctx, const char *asubfmt, size_t asubfmt_len) -{ - if (ctx->subfmt_len + asubfmt_len > MAX_SUBFMT_LEN) - return false; - - memcpy(ctx->subfmt + ctx->subfmt_len, asubfmt, asubfmt_len); - ctx->subfmt_len += asubfmt_len; - ctx->subfmt[ctx->subfmt_len] = 0; - - return true; -} - -static bool -state_string(struct context *ctx) -{ - if (ctx->fmt[ctx->i] == '%') { - if (ctx->i > 0) - if (!append_str(ctx, ctx->fmt + ctx->last, - ctx->i - ctx->last)) - return false; - - if (!append_subfmt(ctx, ctx->fmt + ctx->i, 1)) + } lengthModifier; +}; + +static bool +appendString(struct context *ctx, const char *append, size_t appendLen) +{ + char *nBuf; + + if (appendLen == 0) + return true; + + if ((nBuf = realloc(ctx->buffer, + ctx->bufferLen + appendLen + 1)) == NULL) + return false; + + memcpy(nBuf + ctx->bufferLen, append, appendLen); + + ctx->buffer = nBuf; + ctx->bufferLen += appendLen; + + return true; +} + +static bool +appendSubformat(struct context *ctx, const char *subformat, size_t subformatLen) +{ + if (ctx->subformatLen + subformatLen > MAX_SUBFORMAT_LEN) + return false; + + memcpy(ctx->subformat + ctx->subformatLen, subformat, subformatLen); + ctx->subformatLen += subformatLen; + ctx->subformat[ctx->subformatLen] = 0; + + return true; +} + +static bool +stringState(struct context *ctx) +{ + if (ctx->format[ctx->i] == '%') { + if (ctx->i > 0) + if (!appendString(ctx, ctx->format + ctx->last, + ctx->i - ctx->last)) + return false; + + if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; ctx->last = ctx->i + 1; ctx->state = STATE_FORMAT_FLAGS; } @@ -108,19 +109,19 @@ return true; } static bool -state_format_flags(struct context *ctx) +formatFlagsState(struct context *ctx) { - switch (ctx->fmt[ctx->i]) { + switch (ctx->format[ctx->i]) { case '-': case '+': case ' ': case '#': case '0': - if (!append_subfmt(ctx, ctx->fmt + ctx->i, 1)) + if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; break; default: ctx->state = STATE_FORMAT_FIELD_WIDTH; @@ -131,15 +132,15 @@ return true; } static bool -state_format_field_width(struct context *ctx) +formatFieldWidthState(struct context *ctx) { - if ((ctx->fmt[ctx->i] >= '0' && ctx->fmt[ctx->i] <= '9') || - ctx->fmt[ctx->i] == '*' || ctx->fmt[ctx->i] == '.') { - if (!append_subfmt(ctx, ctx->fmt + ctx->i, 1)) + if ((ctx->format[ctx->i] >= '0' && ctx->format[ctx->i] <= '9') || + ctx->format[ctx->i] == '*' || ctx->format[ctx->i] == '.') { + if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; } else { ctx->state = STATE_FORMAT_LENGTH_MODIFIER; ctx->i--; } @@ -146,70 +147,72 @@ return true; } static bool -state_format_length_modifier(struct context *ctx) +formatLengthModifierState(struct context *ctx) { /* Only one allowed */ - switch (ctx->fmt[ctx->i]) { + switch (ctx->format[ctx->i]) { case 'h': /* and also hh */ - if (ctx->fmt_len > ctx->i + 1 && ctx->fmt[ctx->i + 1] == 'h') { - if (!append_subfmt(ctx, ctx->fmt + ctx->i, 2)) + if (ctx->formatLen > ctx->i + 1 && + ctx->format[ctx->i + 1] == 'h') { + if (!appendSubformat(ctx, ctx->format + ctx->i, 2)) return false; ctx->i++; - ctx->len_mod = LENGTH_MODIFIER_HH; + ctx->lengthModifier = LENGTH_MODIFIER_HH; } else { - if (!append_subfmt(ctx, ctx->fmt + ctx->i, 1)) + if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; - ctx->len_mod = LENGTH_MODIFIER_H; + ctx->lengthModifier = LENGTH_MODIFIER_H; } break; case 'l': /* and also ll */ - if (ctx->fmt_len > ctx->i + 1 && ctx->fmt[ctx->i + 1] == 'l') { - if (!append_subfmt(ctx, ctx->fmt + ctx->i, 2)) + if (ctx->formatLen > ctx->i + 1 && + ctx->format[ctx->i + 1] == 'l') { + if (!appendSubformat(ctx, ctx->format + ctx->i, 2)) return false; ctx->i++; - ctx->len_mod = LENGTH_MODIFIER_LL; + ctx->lengthModifier = LENGTH_MODIFIER_LL; } else { - if (!append_subfmt(ctx, ctx->fmt + ctx->i, 1)) + if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; - ctx->len_mod = LENGTH_MODIFIER_L; + ctx->lengthModifier = LENGTH_MODIFIER_L; } break; case 'j': - if (!append_subfmt(ctx, ctx->fmt + ctx->i, 1)) + if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; - ctx->len_mod = LENGTH_MODIFIER_J; + ctx->lengthModifier = LENGTH_MODIFIER_J; break; case 'z': - if (!append_subfmt(ctx, ctx->fmt + ctx->i, 1)) + if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; - ctx->len_mod = LENGTH_MODIFIER_Z; + ctx->lengthModifier = LENGTH_MODIFIER_Z; break; case 't': - if (!append_subfmt(ctx, ctx->fmt + ctx->i, 1)) + if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; - ctx->len_mod = LENGTH_MODIFIER_T; + ctx->lengthModifier = LENGTH_MODIFIER_T; break; case 'L': - if (!append_subfmt(ctx, ctx->fmt + ctx->i, 1)) + if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; - ctx->len_mod = LENGTH_MODIFIER_CAPITAL_L; + ctx->lengthModifier = LENGTH_MODIFIER_CAPITAL_L; break; default: ctx->i--; @@ -219,75 +222,76 @@ ctx->state = STATE_FORMAT_CONVERSION_SPECIFIER; return true; } static bool -state_format_conversion_specifier(struct context *ctx) +formatConversionSpecifierState(struct context *ctx) { char *tmp = NULL; - int tmp_len = 0; + int tmpLen = 0; - if (!append_subfmt(ctx, ctx->fmt + ctx->i, 1)) + if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; - switch (ctx->fmt[ctx->i]) { + switch (ctx->format[ctx->i]) { case '@':; OFAutoreleasePool *pool; - ctx->subfmt[ctx->subfmt_len - 1] = 's'; + ctx->subformat[ctx->subformatLen - 1] = 's'; @try { pool = [[OFAutoreleasePool alloc] init]; } @catch (id e) { [e release]; return false; } @try { - id obj; + id object; - if ((obj = va_arg(ctx->args, id)) != nil) - tmp_len = asprintf(&tmp, ctx->subfmt, - [[obj description] cString]); + if ((object = va_arg(ctx->arguments, id)) != nil) + tmpLen = asprintf(&tmp, ctx->subformat, + [[object description] cString]); else - tmp_len = asprintf(&tmp, ctx->subfmt, "(nil)"); + tmpLen = asprintf(&tmp, ctx->subformat, + "(nil)"); } @catch (id e) { - free(ctx->buf); + free(ctx->buffer); @throw e; } @finally { [pool release]; } break; case 'd': case 'i': - switch (ctx->len_mod) { + switch (ctx->lengthModifier) { case LENGTH_MODIFIER_NONE: case LENGTH_MODIFIER_HH: case LENGTH_MODIFIER_H: - tmp_len = asprintf(&tmp, ctx->subfmt, - va_arg(ctx->args, int)); + tmpLen = asprintf(&tmp, ctx->subformat, + va_arg(ctx->arguments, int)); break; case LENGTH_MODIFIER_L: - tmp_len = asprintf(&tmp, ctx->subfmt, - va_arg(ctx->args, long)); + tmpLen = asprintf(&tmp, ctx->subformat, + va_arg(ctx->arguments, long)); break; case LENGTH_MODIFIER_LL: - tmp_len = asprintf(&tmp, ctx->subfmt, - va_arg(ctx->args, long long)); + tmpLen = asprintf(&tmp, ctx->subformat, + va_arg(ctx->arguments, long long)); break; case LENGTH_MODIFIER_J: - tmp_len = asprintf(&tmp, ctx->subfmt, - va_arg(ctx->args, intmax_t)); + tmpLen = asprintf(&tmp, ctx->subformat, + va_arg(ctx->arguments, intmax_t)); break; case LENGTH_MODIFIER_Z: - tmp_len = asprintf(&tmp, ctx->subfmt, - va_arg(ctx->args, ssize_t)); + tmpLen = asprintf(&tmp, ctx->subformat, + va_arg(ctx->arguments, ssize_t)); break; case LENGTH_MODIFIER_T: - tmp_len = asprintf(&tmp, ctx->subfmt, - va_arg(ctx->args, ptrdiff_t)); + tmpLen = asprintf(&tmp, ctx->subformat, + va_arg(ctx->arguments, ptrdiff_t)); break; default: return false; } @@ -294,36 +298,36 @@ break; case 'o': case 'u': case 'x': case 'X': - switch (ctx->len_mod) { + switch (ctx->lengthModifier) { case LENGTH_MODIFIER_NONE: case LENGTH_MODIFIER_HH: case LENGTH_MODIFIER_H: - tmp_len = asprintf(&tmp, ctx->subfmt, - va_arg(ctx->args, unsigned int)); + tmpLen = asprintf(&tmp, ctx->subformat, + va_arg(ctx->arguments, unsigned int)); break; case LENGTH_MODIFIER_L: - tmp_len = asprintf(&tmp, ctx->subfmt, - va_arg(ctx->args, unsigned long)); + tmpLen = asprintf(&tmp, ctx->subformat, + va_arg(ctx->arguments, unsigned long)); break; case LENGTH_MODIFIER_LL: - tmp_len = asprintf(&tmp, ctx->subfmt, - va_arg(ctx->args, unsigned long long)); + tmpLen = asprintf(&tmp, ctx->subformat, + va_arg(ctx->arguments, unsigned long long)); break; case LENGTH_MODIFIER_J: - tmp_len = asprintf(&tmp, ctx->subfmt, - va_arg(ctx->args, uintmax_t)); + tmpLen = asprintf(&tmp, ctx->subformat, + va_arg(ctx->arguments, uintmax_t)); break; case LENGTH_MODIFIER_Z: - tmp_len = asprintf(&tmp, ctx->subfmt, - va_arg(ctx->args, size_t)); + tmpLen = asprintf(&tmp, ctx->subformat, + va_arg(ctx->arguments, size_t)); break; case LENGTH_MODIFIER_T: - tmp_len = asprintf(&tmp, ctx->subfmt, - va_arg(ctx->args, ptrdiff_t)); + tmpLen = asprintf(&tmp, ctx->subformat, + va_arg(ctx->arguments, ptrdiff_t)); break; default: return false; } @@ -334,191 +338,194 @@ case 'E': case 'g': case 'G': case 'a': case 'A': - switch (ctx->len_mod) { + switch (ctx->lengthModifier) { case LENGTH_MODIFIER_NONE: case LENGTH_MODIFIER_L: - tmp_len = asprintf(&tmp, ctx->subfmt, - va_arg(ctx->args, double)); + tmpLen = asprintf(&tmp, ctx->subformat, + va_arg(ctx->arguments, double)); break; case LENGTH_MODIFIER_CAPITAL_L: - tmp_len = asprintf(&tmp, ctx->subfmt, - va_arg(ctx->args, long double)); + tmpLen = asprintf(&tmp, ctx->subformat, + va_arg(ctx->arguments, long double)); break; default: return false; } break; case 'c': - switch (ctx->len_mod) { + switch (ctx->lengthModifier) { case LENGTH_MODIFIER_NONE: - tmp_len = asprintf(&tmp, ctx->subfmt, - va_arg(ctx->args, int)); + tmpLen = asprintf(&tmp, ctx->subformat, + va_arg(ctx->arguments, int)); break; case LENGTH_MODIFIER_L: #if WINT_MAX >= INT_MAX - tmp_len = asprintf(&tmp, ctx->subfmt, - va_arg(ctx->args, wint_t)); + tmpLen = asprintf(&tmp, ctx->subformat, + va_arg(ctx->arguments, wint_t)); #else - tmp_len = asprintf(&tmp, ctx->subfmt, - va_arg(ctx->args, int)); + tmpLen = asprintf(&tmp, ctx->subformat, + va_arg(ctx->arguments, int)); #endif break; default: return false; } break; case 's': - switch (ctx->len_mod) { + switch (ctx->lengthModifier) { case LENGTH_MODIFIER_NONE: - tmp_len = asprintf(&tmp, ctx->subfmt, - va_arg(ctx->args, const char*)); + tmpLen = asprintf(&tmp, ctx->subformat, + va_arg(ctx->arguments, const char*)); break; case LENGTH_MODIFIER_L: - tmp_len = asprintf(&tmp, ctx->subfmt, - va_arg(ctx->args, const wchar_t*)); + tmpLen = asprintf(&tmp, ctx->subformat, + va_arg(ctx->arguments, const wchar_t*)); break; default: return false; } break; case 'p': - if (ctx->len_mod != LENGTH_MODIFIER_NONE) + if (ctx->lengthModifier != LENGTH_MODIFIER_NONE) return false; - tmp_len = asprintf(&tmp, ctx->subfmt, va_arg(ctx->args, void*)); + tmpLen = asprintf(&tmp, ctx->subformat, + va_arg(ctx->arguments, void*)); break; case 'n': - switch (ctx->len_mod) { + switch (ctx->lengthModifier) { case LENGTH_MODIFIER_NONE: - *va_arg(ctx->args, int*) = (int)ctx->buf_len; + *va_arg(ctx->arguments, int*) = (int)ctx->bufferLen; break; case LENGTH_MODIFIER_HH: - *va_arg(ctx->args, signed char*) = - (signed char)ctx->buf_len; + *va_arg(ctx->arguments, signed char*) = + (signed char)ctx->bufferLen; break; case LENGTH_MODIFIER_H: - *va_arg(ctx->args, short*) = (short)ctx->buf_len; + *va_arg(ctx->arguments, short*) = (short)ctx->bufferLen; break; case LENGTH_MODIFIER_L: - *va_arg(ctx->args, long*) = (long)ctx->buf_len; + *va_arg(ctx->arguments, long*) = (long)ctx->bufferLen; break; case LENGTH_MODIFIER_LL: - *va_arg(ctx->args, long long*) = - (long long)ctx->buf_len; + *va_arg(ctx->arguments, long long*) = + (long long)ctx->bufferLen; break; case LENGTH_MODIFIER_J: - *va_arg(ctx->args, intmax_t*) = (intmax_t)ctx->buf_len; + *va_arg(ctx->arguments, intmax_t*) = + (intmax_t)ctx->bufferLen; break; case LENGTH_MODIFIER_Z: - *va_arg(ctx->args, size_t*) = ctx->buf_len; + *va_arg(ctx->arguments, size_t*) = ctx->bufferLen; break; case LENGTH_MODIFIER_T: - *va_arg(ctx->args, ptrdiff_t*) = - (ptrdiff_t)ctx->buf_len; + *va_arg(ctx->arguments, ptrdiff_t*) = + (ptrdiff_t)ctx->bufferLen; break; default: return false; } break; case '%': - if (ctx->len_mod != LENGTH_MODIFIER_NONE) + if (ctx->lengthModifier != LENGTH_MODIFIER_NONE) return false; - if (!append_str(ctx, "%", 1)) + if (!appendString(ctx, "%", 1)) return false; break; default: return false; } - if (tmp_len == -1) + if (tmpLen == -1) return false; if (tmp != NULL) { - if (!append_str(ctx, tmp, tmp_len)) { + if (!appendString(ctx, tmp, tmpLen)) { free(tmp); return false; } free(tmp); } - memset(ctx->subfmt, 0, MAX_SUBFMT_LEN); - ctx->subfmt_len = 0; - ctx->len_mod = LENGTH_MODIFIER_NONE; + memset(ctx->subformat, 0, MAX_SUBFORMAT_LEN); + ctx->subformatLen = 0; + ctx->lengthModifier = LENGTH_MODIFIER_NONE; ctx->last = ctx->i + 1; ctx->state = STATE_STRING; return true; } static bool (*states[])(struct context*) = { - state_string, - state_format_flags, - state_format_field_width, - state_format_length_modifier, - state_format_conversion_specifier + stringState, + formatFlagsState, + formatFieldWidthState, + formatLengthModifierState, + formatConversionSpecifierState }; int -of_vasprintf(char **ret, const char *fmt, va_list args) +of_vasprintf(char **cString, const char *format, va_list arguments) { struct context ctx; - ctx.fmt = fmt; - ctx.fmt_len = strlen(fmt); - memset(ctx.subfmt, 0, MAX_SUBFMT_LEN + 1); - ctx.subfmt_len = 0; - va_copy(ctx.args, args); - ctx.buf_len = 0; + ctx.format = format; + ctx.formatLen = strlen(format); + memset(ctx.subformat, 0, MAX_SUBFORMAT_LEN + 1); + ctx.subformatLen = 0; + va_copy(ctx.arguments, arguments); + ctx.bufferLen = 0; ctx.last = 0; ctx.state = STATE_STRING; - ctx.len_mod = LENGTH_MODIFIER_NONE; + ctx.lengthModifier = LENGTH_MODIFIER_NONE; - if ((ctx.buf = malloc(1)) == NULL) + if ((ctx.buffer = malloc(1)) == NULL) return -1; - for (ctx.i = 0; ctx.i < ctx.fmt_len; ctx.i++) { + for (ctx.i = 0; ctx.i < ctx.formatLen; ctx.i++) { if (!states[ctx.state](&ctx)) { - free(ctx.buf); + free(ctx.buffer); return -1; } } if (ctx.state != STATE_STRING) { - free(ctx.buf); + free(ctx.buffer); return -1; } - if (!append_str(&ctx, ctx.fmt + ctx.last, ctx.fmt_len - ctx.last)) { - free(ctx.buf); + if (!appendString(&ctx, ctx.format + ctx.last, + ctx.formatLen - ctx.last)) { + free(ctx.buffer); return -1; } - ctx.buf[ctx.buf_len] = 0; + ctx.buffer[ctx.bufferLen] = 0; - *ret = ctx.buf; - return (ctx.buf_len <= INT_MAX ? (int)ctx.buf_len : INT_MAX); + *cString = ctx.buffer; + return (ctx.bufferLen <= INT_MAX ? (int)ctx.bufferLen : -1); } int -of_asprintf(char **ret, const char *fmt, ...) -{ - va_list args; - int r; - - va_start(args, fmt); - r = of_vasprintf(ret, fmt, args); - va_end(args); - - return r; +of_asprintf(char **cString, const char *format, ...) +{ + va_list arguments; + int ret; + + va_start(arguments, format); + ret = of_vasprintf(cString, format, arguments); + va_end(arguments); + + return ret; } Index: src/threading.h ================================================================== --- src/threading.h +++ src/threading.h @@ -284,16 +284,16 @@ } static OF_INLINE BOOL of_tlskey_set(of_tlskey_t key, id obj) { - void *p = (obj != nil ? (void*)obj : NULL); + void *ptr = (obj != nil ? (void*)obj : NULL); #if defined(OF_HAVE_PTHREADS) - return !pthread_setspecific(key, p); + return !pthread_setspecific(key, ptr); #elif defined(_WIN32) - return TlsSetValue(key, p); + return TlsSetValue(key, ptr); #endif } static OF_INLINE BOOL of_tlskey_free(of_tlskey_t key) @@ -304,82 +304,82 @@ return TlsFree(key); #endif } static OF_INLINE BOOL -of_spinlock_new(of_spinlock_t *s) +of_spinlock_new(of_spinlock_t *spinlock) { #if defined(OF_ATOMIC_OPS) - *s = 0; + *spinlock = 0; return YES; #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) - return !pthread_spin_init(s, 0); + return !pthread_spin_init(spinlock, 0); #else - return of_mutex_new(s); + return of_mutex_new(spinlock); #endif } static OF_INLINE BOOL -of_spinlock_trylock(of_spinlock_t *s) +of_spinlock_trylock(of_spinlock_t *spinlock) { #if defined(OF_ATOMIC_OPS) - return of_atomic_cmpswap_int(s, 0, 1); + return of_atomic_cmpswap_int(spinlock, 0, 1); #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) - return !pthread_spin_trylock(s); + return !pthread_spin_trylock(spinlock); #else - return of_mutex_trylock(s); + return of_mutex_trylock(spinlock); #endif } static OF_INLINE BOOL -of_spinlock_lock(of_spinlock_t *s) +of_spinlock_lock(of_spinlock_t *spinlock) { #if defined(OF_ATOMIC_OPS) # if defined(OF_HAVE_SCHED_YIELD) || defined(_WIN32) int i; for (i = 0; i < OF_SPINCOUNT; i++) - if (of_spinlock_trylock(s)) + if (of_spinlock_trylock(spinlock)) return YES; - while (!of_spinlock_trylock(s)) + while (!of_spinlock_trylock(spinlock)) # ifndef _WIN32 sched_yield(); # else Sleep(0); # endif # else - while (!of_spinlock_trylock(s)); -# endif - - return YES; -#elif defined(OF_HAVE_PTHREAD_SPINLOCKS) - return !pthread_spin_lock(s); -#else - return of_mutex_lock(s); -#endif -} - -static OF_INLINE BOOL -of_spinlock_unlock(of_spinlock_t *s) -{ -#if defined(OF_ATOMIC_OPS) - *s = 0; - return YES; -#elif defined(OF_HAVE_PTHREAD_SPINLOCKS) - return !pthread_spin_unlock(s); -#else - return of_mutex_unlock(s); -#endif -} - -static OF_INLINE BOOL -of_spinlock_free(of_spinlock_t *s) -{ -#if defined(OF_ATOMIC_OPS) - return YES; -#elif defined(OF_HAVE_PTHREAD_SPINLOCKS) - return !pthread_spin_destroy(s); -#else - return of_mutex_free(s); + while (!of_spinlock_trylock(spinlock)); +# endif + + return YES; +#elif defined(OF_HAVE_PTHREAD_SPINLOCKS) + return !pthread_spin_lock(spinlock); +#else + return of_mutex_lock(spinlock); +#endif +} + +static OF_INLINE BOOL +of_spinlock_unlock(of_spinlock_t *spinlock) +{ +#if defined(OF_ATOMIC_OPS) + *spinlock = 0; + return YES; +#elif defined(OF_HAVE_PTHREAD_SPINLOCKS) + return !pthread_spin_unlock(spinlock); +#else + return of_mutex_unlock(spinlock); +#endif +} + +static OF_INLINE BOOL +of_spinlock_free(of_spinlock_t *spinlock) +{ +#if defined(OF_ATOMIC_OPS) + return YES; +#elif defined(OF_HAVE_PTHREAD_SPINLOCKS) + return !pthread_spin_destroy(spinlock); +#else + return of_mutex_free(spinlock); #endif } Index: tests/OFXMLParserTests.m ================================================================== --- tests/OFXMLParserTests.m +++ tests/OFXMLParserTests.m @@ -351,14 +351,14 @@ if ([parser finishedParsing]) abort(); if (j + 2 > len) [parser parseBuffer: str + j - withSize: 1]; + withLength: 1]; else [parser parseBuffer: str + j - withSize: 2]; + withLength: 2]; } TEST(@"Checking if everything was parsed", i == 32 && [parser lineNumber] == 18)