@implementation libxmlSAXDriver
-static libxmlSAXDriver *activeDriver = nil;
+static libxmlSAXDriver *activeDriver = nil; // THREAD
+
+#define SETUP_ACTDRIVER \
+ { if (activeDriver != nil) { \
+ NSLog(@"ERROR(%s): %@ there is an active driver set (0x%08X), " \
+ @"override!", \
+ __PRETTY_FUNCTION__, self, activeDriver);\
+ }\
+ activeDriver = self;}
+
+#define TEARDOWN_ACTDRIVER \
+ { if (activeDriver == self) activeDriver = nil; \
+ else if (activeDriver != nil) { \
+ NSLog(@"ERROR(%s): %@ activeDriver global var mixed up 0x%08X, " \
+ @"probably a THREAD issue.", \
+ __PRETTY_FUNCTION__, self, activeDriver); } }
static void
_startElement(libxmlSAXDriver *self, const xmlChar *name, const xmlChar **atts);
}
}
- if (activeDriver != nil) {
- NSLog(@"ERROR(%s): %@ there is an active driver set (%@), override !",
- __PRETTY_FUNCTION__, self, activeDriver);
- }
- activeDriver = self;
+ SETUP_ACTDRIVER;
self->ctxt = xmlCreateMemoryParserCtxt((void *)start, len);
NSLog(@"%s: couldn't create memory parser ctx (src=0x%08X, len=%d) !",
__PRETTY_FUNCTION__, src, len);
-
- if (activeDriver == self)
- activeDriver = nil;
+
+ TEARDOWN_ACTDRIVER;
ui = nil;
- e = (id)[SaxParseException exceptionWithName:@"SaxIOException"
- reason:@"couldn't create memory parser context"
- userInfo:ui];
+ e = (id)[SaxParseException
+ exceptionWithName:@"SaxIOException"
+ reason:@"couldn't create memory parser context"
+ userInfo:ui];
[self->errorHandler fatalError:e];
return;
((xmlParserCtxtPtr)self->ctxt)->sax = oldsax;
((xmlParserCtxtPtr)self->ctxt)->userData = NULL;
xmlFreeParserCtxt(ctxt);
-
- if (activeDriver == self)
- activeDriver = nil;
-
- if (src) {
+
+ TEARDOWN_ACTDRIVER;
+
+ if (src != NULL) {
free(src);
src = NULL;
}
[_sysId cString];
}
- if (activeDriver != nil) {
- NSLog(@"WARNING(%s): %@ there is an active driver set (%@), override !",
- __PRETTY_FUNCTION__, self, activeDriver);
- }
- activeDriver = self;
+ SETUP_ACTDRIVER;
xmlParseDocument(self->ctxt);
- if (activeDriver == self)
- activeDriver = nil;
+ TEARDOWN_ACTDRIVER;
if (((xmlParserCtxtPtr)self->ctxt)->input != NULL && [_sysId length] > 0) {
((xmlParserInputPtr)((xmlParserCtxtPtr)self->ctxt)->input)->filename =