Cleanups plus minor OSX compatibility tweak

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@31781 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2010-12-27 07:03:50 +00:00
parent d4558f5db1
commit b4d407b26e
8 changed files with 45 additions and 41 deletions

View file

@ -1,3 +1,16 @@
2010-12-27 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSPrivate.h:
* Source/NSCalendarDate.m:
* Source/NSDate.m:
* Source/NSProcessInfo.m:
* Source/NSRunLoop.m:
Change GSTimeNow() to GSPrivateTimeNow() to indicate scope of function.
* Source/NSThread.m:
Remove duplicate declaration of obbjc thread callback.
* Source/NSXMLParser.m:
Try to duplicate OSX behavior in handling start of document.
2010-12-26 Richard Frith-Macdonald <rfm@gnu.org> 2010-12-26 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSString.m: * Source/NSString.m:

View file

@ -49,6 +49,7 @@
*/ */
#define GREGORIAN_REFERENCE 730486 #define GREGORIAN_REFERENCE 730486
NSTimeInterval GSPrivateTimeNow() GS_ATTRIB_PRIVATE;
#include "GNUstepBase/GSObjCRuntime.h" #include "GNUstepBase/GSObjCRuntime.h"

View file

@ -284,7 +284,7 @@ GSBreakTime(NSTimeInterval when, int *year, int *month, int *day,
* Returns the current time (seconds since reference date) as an NSTimeInterval. * Returns the current time (seconds since reference date) as an NSTimeInterval.
*/ */
NSTimeInterval NSTimeInterval
GSTimeNow(void) GSPrivateTimeNow(void)
{ {
NSTimeInterval t; NSTimeInterval t;
#if !defined(__MINGW__) #if !defined(__MINGW__)
@ -321,7 +321,7 @@ GSTimeNow(void)
diff, ctime(&now)); diff, ctime(&now));
/* Get time again ... should be OK now. /* Get time again ... should be OK now.
*/ */
t = GSTimeNow(); t = GSPrivateTimeNow();
} }
} }
} }

View file

@ -54,8 +54,6 @@ const NSTimeInterval NSTimeIntervalSince1970 = 978307200.0;
extern NSTimeInterval GSTimeNow(); // In NSCalendarDate.m
static BOOL debug = NO; static BOOL debug = NO;
static Class abstractClass = nil; static Class abstractClass = nil;
static Class concreteClass = nil; static Class concreteClass = nil;
@ -160,7 +158,7 @@ otherTime(NSDate* other)
*/ */
+ (NSTimeInterval) timeIntervalSinceReferenceDate + (NSTimeInterval) timeIntervalSinceReferenceDate
{ {
return GSTimeNow(); return GSPrivateTimeNow();
} }
/** /**
@ -169,7 +167,7 @@ otherTime(NSDate* other)
+ (id) date + (id) date
{ {
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()] return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
initWithTimeIntervalSinceReferenceDate: GSTimeNow()]); initWithTimeIntervalSinceReferenceDate: GSPrivateTimeNow()]);
} }
/** /**
@ -1060,7 +1058,7 @@ otherTime(NSDate* other)
*/ */
- (id) init - (id) init
{ {
return [self initWithTimeIntervalSinceReferenceDate: GSTimeNow()]; return [self initWithTimeIntervalSinceReferenceDate: GSPrivateTimeNow()];
} }
/** /**
@ -1111,7 +1109,7 @@ otherTime(NSDate* other)
{ {
// Get the current time, add the secs and init thyself // Get the current time, add the secs and init thyself
return [self initWithTimeIntervalSinceReferenceDate: return [self initWithTimeIntervalSinceReferenceDate:
GSTimeNow() + secsToBeAdded]; GSPrivateTimeNow() + secsToBeAdded];
} }
/** /**
@ -1248,7 +1246,7 @@ otherTime(NSDate* other)
*/ */
- (NSTimeInterval) timeIntervalSinceNow - (NSTimeInterval) timeIntervalSinceNow
{ {
return otherTime(self) - GSTimeNow(); return otherTime(self) - GSPrivateTimeNow();
} }
/** /**
@ -1416,7 +1414,7 @@ otherTime(NSDate* other)
- (NSTimeInterval) timeIntervalSinceNow - (NSTimeInterval) timeIntervalSinceNow
{ {
return _seconds_since_ref - GSTimeNow(); return _seconds_since_ref - GSPrivateTimeNow();
} }
- (NSTimeInterval) timeIntervalSinceReferenceDate - (NSTimeInterval) timeIntervalSinceReferenceDate

View file

@ -1013,10 +1013,8 @@ int main(int argc, char *argv[], char *env[])
[gnustep_global_lock lock]; [gnustep_global_lock lock];
if (host == nil) if (host == nil)
{ {
extern NSTimeInterval GSTimeNow(void);
pid = [self processIdentifier]; pid = [self processIdentifier];
start = (unsigned long)GSTimeNow(); start = (unsigned long)GSPrivateTimeNow();
host = [[self hostName] stringByReplacingString: @"." withString: @"_"]; host = [[self hostName] stringByReplacingString: @"." withString: @"_"];
IF_NO_GC(RETAIN(host);) IF_NO_GC(RETAIN(host);)
} }

View file

@ -947,7 +947,6 @@ updateTimer(NSTimer *t, NSDate *d, NSTimeInterval now)
_currentMode = mode; _currentMode = mode;
NS_DURING NS_DURING
{ {
extern NSTimeInterval GSTimeNow(void);
GSIArray timers = context->timers; GSIArray timers = context->timers;
NSTimeInterval now; NSTimeInterval now;
NSDate *earliest; NSDate *earliest;
@ -969,7 +968,7 @@ updateTimer(NSTimer *t, NSDate *d, NSTimeInterval now)
* just keep firing the timer repeatedly and never return from * just keep firing the timer repeatedly and never return from
* this method. * this method.
*/ */
now = GSTimeNow(); now = GSPrivateTimeNow();
/* Fire housekeeping timer as necessary /* Fire housekeeping timer as necessary
*/ */

View file

@ -88,12 +88,6 @@
#define PTHREAD_MIN_PRIORITY 0 #define PTHREAD_MIN_PRIORITY 0
#endif #endif
#if !defined(__GNUSTEP_RUNTIME__) && !defined(NeXT_RUNTIME)
typedef void (*objc_thread_callback) (void);
objc_thread_callback objc_set_thread_callback (objc_thread_callback func);
#endif
extern NSTimeInterval GSTimeNow(void);
@interface NSAutoreleasePool (NSThread) @interface NSAutoreleasePool (NSThread)
+ (void) _endThread: (NSThread*)thread; + (void) _endThread: (NSThread*)thread;
@ -157,7 +151,7 @@ GSSleepUntilIntervalSinceReferenceDate(NSTimeInterval when)
NSTimeInterval delay; NSTimeInterval delay;
// delay is always the number of seconds we still need to wait // delay is always the number of seconds we still need to wait
delay = when - GSTimeNow(); delay = when - GSPrivateTimeNow();
if (delay <= 0.0) if (delay <= 0.0)
{ {
sched_yield(); sched_yield();
@ -173,7 +167,7 @@ GSSleepUntilIntervalSinceReferenceDate(NSTimeInterval when)
request.tv_sec = (time_t)32768; request.tv_sec = (time_t)32768;
request.tv_nsec = (long)0; request.tv_nsec = (long)0;
nanosleep(&request, 0); nanosleep(&request, 0);
delay = when - GSTimeNow(); delay = when - GSPrivateTimeNow();
} }
if (delay > 0) if (delay > 0)
{ {
@ -212,7 +206,7 @@ GSSleepUntilIntervalSinceReferenceDate(NSTimeInterval when)
#else #else
sleep (30*60); sleep (30*60);
#endif #endif
delay = when - GSTimeNow(); delay = when - GSPrivateTimeNow();
} }
/* /*
@ -244,7 +238,7 @@ GSSleepUntilIntervalSinceReferenceDate(NSTimeInterval when)
sleep ((NSInteger)delay); sleep ((NSInteger)delay);
#endif /* HAVE_USLEEP */ #endif /* HAVE_USLEEP */
#endif /* __MINGW__ */ #endif /* __MINGW__ */
delay = when - GSTimeNow(); delay = when - GSPrivateTimeNow();
} }
#endif /* HAVE_NANOSLEEP */ #endif /* HAVE_NANOSLEEP */
} }
@ -600,7 +594,7 @@ unregisterActiveThread(NSThread *thread)
+ (void) sleepForTimeInterval: (NSTimeInterval)ti + (void) sleepForTimeInterval: (NSTimeInterval)ti
{ {
GSSleepUntilIntervalSinceReferenceDate(GSTimeNow() + ti); GSSleepUntilIntervalSinceReferenceDate(GSPrivateTimeNow() + ti);
} }
/** /**

View file

@ -632,6 +632,7 @@ typedef struct NSXMLParserIvarsType
BOOL shouldReportNamespacePrefixes; BOOL shouldReportNamespacePrefixes;
BOOL shouldResolveExternalEntities; BOOL shouldResolveExternalEntities;
BOOL acceptHTML; // be lazy with bad tag nesting BOOL acceptHTML; // be lazy with bad tag nesting
BOOL hasStarted;
IMP didEndElement; IMP didEndElement;
IMP didEndMappingPrefix; IMP didEndMappingPrefix;
IMP didStartElement; IMP didStartElement;
@ -925,15 +926,14 @@ static SEL foundIgnorableSel;
if (this->didEndElement != 0) if (this->didEndElement != 0)
{ {
NSString *qualified = nil; NSString *qualified = tag;
NSString *uri = nil; NSString *uri = @"";
if (this->shouldProcessNamespaces) if (this->shouldProcessNamespaces)
{ {
NSRange r = [tag rangeOfString: @":"]; NSRange r = [tag rangeOfString: @":"];
NSString *p = @""; NSString *p = @"";
qualified = tag;
if (r.length > 0) if (r.length > 0)
{ {
p = [tag substringToIndex: r.location]; p = [tag substringToIndex: r.location];
@ -979,15 +979,19 @@ static SEL foundIgnorableSel;
} }
if (!flag) if (!flag)
{ {
if ([tag isEqualToString: @"?xml"]) if (NO == this->hasStarted)
{ {
#if EXTRA_DEBUG #if EXTRA_DEBUG
NSLog(@"parserDidStartDocument: "); NSLog(@"parserDidStartDocument: ");
#endif #endif
this->hasStarted = YES;
if ([_del respondsToSelector: @selector(parserDidStartDocument:)]) if ([_del respondsToSelector: @selector(parserDidStartDocument:)])
{ {
[_del parserDidStartDocument: self]; [_del parserDidStartDocument: self];
} }
}
if ([tag isEqualToString: @"?xml"])
{
return; return;
} }
else if ([tag hasPrefix: @"?"]) else if ([tag hasPrefix: @"?"])
@ -1069,12 +1073,12 @@ NSLog(@"_processTag <%@%@ %@>", flag?@"/": @"", tag, attributes);
if (this->didStartElement != 0) if (this->didStartElement != 0)
{ {
qualified = tag;
if (this->shouldProcessNamespaces) if (this->shouldProcessNamespaces)
{ {
NSRange r = [tag rangeOfString: @":"]; NSRange r = [tag rangeOfString: @":"];
NSString *p = @""; NSString *p = @"";
qualified = tag;
if (r.length > 0) if (r.length > 0)
{ {
p = [tag substringToIndex: r.location]; p = [tag substringToIndex: r.location];
@ -1084,8 +1088,7 @@ NSLog(@"_processTag <%@%@ %@>", flag?@"/": @"", tag, attributes);
} }
else else
{ {
qualified = nil; uri = @"";
uri = nil;
} }
(*this->didStartElement)(_del, (*this->didStartElement)(_del,
didStartElementSel, self, tag, uri, qualified, attributes); didStartElementSel, self, tag, uri, qualified, attributes);
@ -1262,14 +1265,6 @@ NSLog(@"_processTag <%@%@ %@>", flag?@"/": @"", tag, attributes);
const unsigned char *vp = this->cp; // value pointer const unsigned char *vp = this->cp; // value pointer
int c; int c;
if (!this->acceptHTML
&& (this->cend - this->cp < 6
|| strncmp((char *)this->cp, "<?xml ", 6) != 0))
{
// not a valid XML document start
return [self _parseError: @"missing <?xml > preamble"
code: NSXMLParserDocumentStartError];
}
/* Start by accumulating ignorable whitespace. /* Start by accumulating ignorable whitespace.
*/ */
this->ignorable = YES; this->ignorable = YES;
@ -1570,6 +1565,12 @@ NSLog(@"_processTag <%@%@ %@>", flag?@"/": @"", tag, attributes);
code: NSXMLParserGTRequiredError]; code: NSXMLParserGTRequiredError];
} }
// process // process
if ([tag isEqualToString: @"xml"]
&& tp != [this->data bytes])
{
return [self _parseError: @"bad <?xml > preamble"
code: NSXMLParserDocumentStartError];
}
[self _processTag: tag [self _processTag: tag
isEnd: NO isEnd: NO
withAttributes: parameters]; // single <?tag ...?> withAttributes: parameters]; // single <?tag ...?>