- some POSIX pthread functions

- some CFByteOrder implementation
- CFHost implementation with asynchronous resolver
- CFPreferences skeletons
- CIImage category in NSCIImageRep
- NSTabView resizes item view even if autoresizing is off
- NSCustomObject -description
- NSNibLoading use of autorelease pool to reduce memory pressure
- NSNib use of autorelease pool to reduce memory pressure
- NSIBObjectData warning if it can't create  custom instance instead of NSArray exception (adding nil)
- changed NSBox to non-opaque, doesn't fill with background color
- NSTableHeaderView use of setControlView:
- NSMatrix use of setControlView:
- NSAnimation/NSViewAnimation fixes to behave properly with timer
- NSSheetContext check for nil
- NSGraphicsStyle_uxtheme fix for menu separators
- NSEvent -userData method added
- minor cleanup of NSInvocation
- NSDateFormatter fixes and update
- NSArray+KVC.m fix for nil values
This commit is contained in:
Christopher Lloyd 2010-03-08 19:43:05 +00:00
parent 7a3666e54f
commit 98eb99c63a
34 changed files with 1124 additions and 83 deletions

View File

@ -9,7 +9,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#import <Foundation/NSDate.h>
#import <AppKit/AppKitExport.h>
@class NSMutableArray,NSArray;
@class NSMutableArray,NSArray,NSTimer;
typedef enum {
NSAnimationEaseInOut,
@ -37,6 +37,8 @@ APPKIT_EXPORT NSString * const NSAnimationProgressMarkNotification;
NSMutableArray *_progressMarks;
float _currentValue;
NSArray *_runLoopModes;
BOOL _isAnimating;
NSTimer *_timer;
}
-initWithDuration:(NSTimeInterval)duration animationCurve:(NSAnimationCurve)curve;

View File

@ -10,6 +10,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#import <AppKit/NSRaise.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSValue.h>
#import <Foundation/NSTimer.h>
NSString * const NSAnimationProgressMarkNotification=@"NSAnimationProgressMarkNotification";
@ -107,8 +108,7 @@ NSString * const NSAnimationProgressMarkNotification=@"NSAnimationProgressMarkNo
}
-(BOOL)isAnimating {
NSUnimplementedMethod();
return NO;
return _isAnimating;
}
-(NSArray *)runLoopModesForAnimating {
@ -127,12 +127,31 @@ NSString * const NSAnimationProgressMarkNotification=@"NSAnimationProgressMarkNo
NSUnimplementedMethod();
}
// This isn't correct, we're just faking start/stop/end behavior w/o any real animation
-(void)timer:(NSTimer *)timer {
if([_delegate respondsToSelector:@selector(animationDidEnd:)])
[_delegate performSelector:@selector(animationDidEnd:) withObject:self];
_isAnimating=NO;
_timer=nil;
[self autorelease];
}
-(void)startAnimation {
NSUnimplementedMethod();
if(!_isAnimating){
[self retain];
_isAnimating=YES;
_timer=[NSTimer scheduledTimerWithTimeInterval:_duration target:self selector:@selector(timer:) userInfo:nil repeats:NO];
}
}
-(void)stopAnimation {
NSUnimplementedMethod();
if(_isAnimating){
_isAnimating=NO;
[_timer invalidate];
_timer=nil;
[self autorelease];
}
}
-(void)startWhenAnimation:(NSAnimation *)animation reachesProgress:(NSAnimationProgress)progress {

View File

@ -21,7 +21,7 @@ NSString * const NSViewAnimationFadeOutEffect=@"NSViewAnimationFadeOutEffect";
-initWithViewAnimations:(NSArray *)animations {
[super initWithDuration:1.0 animationCurve:NSAnimationEaseInOut];
_animations=nil;
_animations=[animations retain];
return self;
}

View File

@ -218,11 +218,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
NSUnimplementedMethod();
}
-(BOOL)isOpaque {
return YES;
}
-(void)drawRect:(NSRect)rect {
NSRect grooveRect=_bounds;
NSRect titleRect=[self titleRect];
@ -259,8 +254,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
break;
}
[[NSColor controlColor] setFill];
NSRectFill(rect);
// [[NSColor controlColor] setFill];
// NSRectFill(rect);
switch(_borderType){
case NSNoBorder:
@ -280,15 +275,18 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
}
if(drawTitle){
#if 0
[[NSColor windowBackgroundColor] setFill];
titleRect.origin.x-=TEXTGAP;
titleRect.size.width+=TEXTGAP*2;
NSRectFill(titleRect);
#endif
titleRect.origin.x+=TEXTGAP;
titleRect.size.width-=TEXTGAP*2;
// Ask the cell to draw itself now
// TODO: Should we be doing some sort of clipping setup here?
[_titleCell setControlView:self];
[_titleCell drawWithFrame: titleRect inView: self];
}
}

8
AppKit/NSCIImageRep.h Normal file
View File

@ -0,0 +1,8 @@
#import <AppKit/NSImageRep.h>
#import <QuartzCore/CIImage.h>
@class NSBitmapImageRep;
@interface CIImage(CIImageRepAdditions)
-initWithBitmapImageRep:(NSBitmapImageRep *)bitmapImageRep;
@end

11
AppKit/NSCIImageRep.m Normal file
View File

@ -0,0 +1,11 @@
#import <AppKit/NSCIImageRep.h>
#import <AppKit/NSRaise.h>
#import <AppKit/NSBitmapImageRep.h>
@implementation CIImage(CIImageRepAdditions)
-initWithBitmapImageRep:(NSBitmapImageRep *)bitmapImageRep {
return [self initWithCGImage:[bitmapImageRep CGImage]];
}
@end

View File

@ -189,6 +189,7 @@ enum {
-(short)subtype;
-(NSInteger)data1;
-(NSInteger)data2;
-(void *)userData;
@end

View File

@ -188,6 +188,10 @@ static NSTimer *_periodicTimer=nil;
return 0;
}
-(void *)userData {
[NSException raise:NSInternalInconsistencyException format:@"No userData in %@",[self class]];
return 0;
}
@end

View File

@ -79,6 +79,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
}
-(void *)userData {
if(_type!=NSMouseEntered && _type!=NSMouseExited){
[NSException raise:NSInternalInconsistencyException format:@"-[%@ userData] not valid for type %d",isa,_type];
return NULL;
}
return _userData;
}

View File

@ -690,6 +690,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
NSCell *cell=[self cellAtRow:row column:column];
NSRect cellFrame=[self cellFrameAtRow:row column:column];
[cell setControlView:self];
[cell setState:NSOffState];
[cell setHighlighted:NO];
[cell drawWithFrame:cellFrame inView:self];
@ -842,6 +843,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
if([self getRow:&row column:&column ofCell:cell]){
NSRect frame=[self cellFrameAtRow:row column:column];
[self lockFocus];
[cell setControlView:self];
[cell drawWithFrame:frame inView:self];
[self unlockFocus];
[[self window] flushWindow];
@ -864,6 +866,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
if(NSIntersectsRect(frame,rect)){
NSCell *cell=[self cellAtRow:row column:col];
[cell setControlView:self];
[cell drawWithFrame:frame inView:self];
}
}
@ -1041,6 +1044,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
[self _setSelectedIndexFromCell:cell];
//[self setNeedsDisplay:YES];
[cell setControlView:self];
[cell drawWithFrame:cellFrame inView:self];
}
}

View File

@ -11,6 +11,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
@implementation NSSheetContext
-initWithSheet:(NSWindow *)sheet modalDelegate:modalDelegate didEndSelector:(SEL)didEndSelector contextInfo:(void *)contextInfo frame:(NSRect)frame {
if(sheet==nil)
[NSException raise:NSInvalidArgumentException format:@"sheet==nil"];
_sheet=[sheet retain];
_modalDelegate=modalDelegate;
_didEndSelector=didEndSelector;

View File

@ -301,7 +301,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
return _selectedItem;
}
-(void)resizeSubviewsWithOldSize:(NSSize)oldSize {
-(void)setFrame:(NSRect)frame {
/* A tab view will autoresize the selected view regardless of whether autoresizesSubviews is enabled
We do it here because resizeSubviewsWithOldSize: won't be called if autoresizesSubviews is off. */
[super setFrame:frame];
if(_selectedItem!=nil)
[[_selectedItem view] setFrame:[self contentRect]];
}
@ -315,6 +319,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
[self addSubview:itemView];
[itemView setFrame:[self contentRect]];
}
[self setNeedsDisplay:YES];
}
}
@ -335,6 +340,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
[self addSubview:[item view]];
[[item view] setFrame:[self contentRect]];
}
[self setNeedsDisplay:YES];
_selectedItem=item;
if ([item initialFirstResponder])

View File

@ -101,6 +101,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
columnRect.size.width = [column width] + spacing.width;
[[column headerCell] setHighlighted:[_tableView isColumnSelected:[[_tableView tableColumns] indexOfObject:column]]];
[[column headerCell] setControlView:self];
[[column headerCell] drawWithFrame:columnRect inView:self];
columnRect.origin.x += [column width] + spacing.width;
}

View File

@ -5,8 +5,8 @@
#import <AppKit/NSColor.h>
#import "Win32DeviceContextWindow.h"
#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#undef WINVER
#define WINVER 0x0501
#import <uxtheme.h>
#import <tmschema.h>
@ -259,11 +259,13 @@ static inline RECT transformToRECT(O2AffineTransform matrix,NSRect rect) {
[super drawButtonImage:image inRect:rect enabled:enabled mixed:mixed];
}
#if 0
// these menu ones don't appear to work
-(void)drawMenuSeparatorInRect:(NSRect)rect {
if(![self drawPartId:MP_SEPARATOR stateId:MS_NORMAL uxthClassId:uxthMENU inRect:rect])
[super drawMenuSeparatorInRect:rect];
}
#endif
-(void)drawMenuBranchArrowAtPoint:(NSPoint)point selected:(BOOL)selected {
NSSize size=[self sizeOfMenuBranchArrow];

View File

@ -69,4 +69,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
}
#endif
-(NSString *)description {
return [NSString stringWithFormat:@"<%@:%p:class name=%@>",isa,self,_className];
}
@end

View File

@ -61,9 +61,13 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
else if([nibObject isKindOfClass:[NSCustomObject class]]){
id replacement=[nibObject createCustomInstance];
[keyed replaceObject:nibObject withObject:replacement];
[namedObjects replaceObjectAtIndex:i withObject:replacement];
[replacement release];
if(replacement==nil)
NSLog(@"Custom instance creation failed for %@",nibObject);
else {
[keyed replaceObject:nibObject withObject:replacement];
[namedObjects replaceObjectAtIndex:i withObject:replacement];
[replacement release];
}
}
}
_namesKeys=namedObjects;

View File

@ -89,6 +89,7 @@ NSString * const NSNibTopLevelObjects=@"NSNibTopLevelObjects";
}
-(BOOL)instantiateNibWithExternalNameTable:(NSDictionary *)nameTable {
NSAutoreleasePool *pool=[NSAutoreleasePool new];
_nameTable=[nameTable retain];
NSKeyedUnarchiver *unarchiver=[[[NSKeyedUnarchiver alloc] initForReadingWithData:_data] autorelease];
NSIBObjectData *objectData;
@ -150,6 +151,8 @@ NSString * const NSNibTopLevelObjects=@"NSNibTopLevelObjects";
[_nameTable release];
_nameTable=nil;
[pool release];
return (objectData!=nil);
}

View File

@ -37,11 +37,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
-(void)establishConnection
{
//NSLog(@"binding between %@.%@ and %@.%@", [_source className], _binding, [_destination className], _keyPath);
//NSLog(@"binding between %@.%@ and %@.%@ options=%@", [_source className], _binding, [_destination className], _keyPath,_options);
[_source bind:_binding
toObject:_destination
withKeyPath:_keyPath
options:_options];
[_source bind:_binding toObject:_destination withKeyPath:_keyPath options:_options];
}
@end

View File

@ -1,16 +1,15 @@
/* Copyright (c) 2006-2007 Christopher J. W. Lloyd
/* Copyright (c) 2006-2007 Christopher J. W. Lloyd <cjwl@objc.net>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
// Original - Christopher Lloyd <cjwl@objc.net>
#import <AppKit/NSNibLoading.h>
#import <AppKit/NSNib.h>
#import <Foundation/NSString.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSAutoreleasePool.h>
#import <AppKit/NSRaise.h>
@implementation NSObject(NSNibLoading)
@ -23,9 +22,13 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
@implementation NSBundle(NSNibLoading)
+(BOOL)loadNibFile:(NSString *)path externalNameTable:(NSDictionary *)nameTable withZone:(NSZone *)zone {
NSAutoreleasePool *pool=[NSAutoreleasePool new];
NSNib *nib=[[[NSNib allocWithZone:zone] initWithContentsOfFile:path] autorelease];
return [nib instantiateNibWithExternalNameTable:nameTable];
BOOL result=[nib instantiateNibWithExternalNameTable:nameTable];
[pool release];
return result;
}
+(BOOL)loadNibNamed:(NSString *)name owner:owner {
@ -44,9 +47,13 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
}
-(BOOL)loadNibFile:(NSString *)path externalNameTable:(NSDictionary *)nameTable withZone:(NSZone *)zone {
NSAutoreleasePool *pool=[NSAutoreleasePool new];
NSNib *nib=[[[NSNib allocWithZone:zone] initWithContentsOfFile:path] autorelease];
return [nib instantiateNibWithExternalNameTable:nameTable];
BOOL result=[nib instantiateNibWithExternalNameTable:nameTable];
[pool release];
return result;
}
@end

37
CFNetwork/CFHost.h Normal file
View File

@ -0,0 +1,37 @@
#import <CoreFoundation/CoreFoundation.h>
#import <CFNetwork/CFNetworkExport.h>
typedef struct __CFHost *CFHostRef;
enum CFHostInfoType {
kCFHostAddresses =0,
kCFHostNames =1,
kCFHostReachability =2,
};
typedef enum CFHostInfoType CFHostInfoType;
typedef void (*CFHostClientCallBack)(CFHostRef host,CFHostInfoType infoType,const CFStreamError *streamError,void *info);
typedef struct CFHostClientContext {
CFIndex version;
void *info;
CFAllocatorRetainCallBack retain;
CFAllocatorReleaseCallBack release;
CFAllocatorCopyDescriptionCallBack copyDescription;
} CFHostClientContext;
CFNETWORK_EXPORT CFTypeID CFHostGetTypeID();
CFNETWORK_EXPORT CFHostRef CFHostCreateCopy(CFAllocatorRef alloc,CFHostRef self);
CFNETWORK_EXPORT CFHostRef CFHostCreateWithAddress(CFAllocatorRef allocator,CFDataRef address);
CFNETWORK_EXPORT CFHostRef CFHostCreateWithName(CFAllocatorRef allocator,CFStringRef name);
CFNETWORK_EXPORT CFArrayRef CFHostGetAddressing(CFHostRef self,Boolean *hasBeenResolved);
CFNETWORK_EXPORT CFArrayRef CFHostGetNames(CFHostRef self,Boolean *hasBeenResolved);
CFNETWORK_EXPORT CFDataRef CFHostGetReachability(CFHostRef self,Boolean *hasBeenResolved);
CFNETWORK_EXPORT Boolean CFHostSetClient(CFHostRef self,CFHostClientCallBack callback,CFHostClientContext *context);
CFNETWORK_EXPORT Boolean CFHostStartInfoResolution(CFHostRef self,CFHostInfoType infoType,CFStreamError *streamError);
CFNETWORK_EXPORT void CFHostCancelInfoResolution(CFHostRef theHost,CFHostInfoType infoType);
CFNETWORK_EXPORT void CFHostScheduleWithRunLoop(CFHostRef self,CFRunLoopRef runLoop,CFStringRef mode);
CFNETWORK_EXPORT void CFHostUnscheduleFromRunLoop(CFHostRef self,CFRunLoopRef runLoop,CFStringRef mode);

536
CFNetwork/CFHost.m Normal file
View File

@ -0,0 +1,536 @@
#import <CFNetwork/CFHost.h>
#import <Foundation/NSRaise.h>
#import <Foundation/NSRunLoop.h>
#import <Foundation/NSHandleMonitor_win32.h>
#import <Foundation/NSDebug.h>
#ifdef WINDOWS
#undef WINVER
#define WINVER 0x501
#import <windows.h>
#import <winsock2.h>
#import <ws2tcpip.h>
#endif
#import <pthread.h>
#import <process.h>
#if defined(WIN32) || defined(LINUX)
#define MAXHOSTNAMELEN 512
#endif
typedef enum {
CFHostRequestInQueue,
CFHostRequestInProgress,
CFHostRequestDone,
CFHostRequestDeallocate,
} CFHostRequestState;
typedef struct {
CFHostRequestState _state;
char *_name;
struct addrinfo *_addressList;
#ifdef WINDOWS
HANDLE _event;
#endif
} CFHostRequest;
@interface __CFHost : NSObject {
CFStringRef _name;
CFHostClientCallBack _callback;
CFHostClientContext _context;
Boolean _hasResolvedAddressing;
CFArrayRef _addressing;
CFHostRequest *_request;
#ifdef WINDOWS
HANDLE _event;
NSHandleMonitor_win32 *_monitor;
#endif
}
@end
@implementation __CFHost
#ifdef WINDOWS
typedef struct {
CRITICAL_SECTION queueLock;
HANDLE queueEvent;
int queueCapacity,queueCount;
CFHostRequest **queue;
} CFAddressResolverThreadInfo;
static int preXP_getaddrinfo(const char *host,const char *service,const struct addrinfo *hints,struct addrinfo **result){
struct addrinfo *list=NULL;
struct addrinfo *current=NULL;
struct hostent *hp;
if((hp=gethostbyname(host))==NULL)
return EAI_FAIL;
switch(hp->h_addrtype){
case AF_INET:;
uint32_t **addr_list;
addr_list=(uint32_t **)hp->h_addr_list;
for(;*addr_list!=NULL;addr_list++){
struct addrinfo *node=NSZoneCalloc(NULL,1,sizeof(struct addrinfo));
struct sockaddr_in *ipv4=NSZoneCalloc(NULL,1,sizeof(struct sockaddr_in));
node->ai_family=AF_INET;
node->ai_addrlen=sizeof(struct sockaddr_in);
node->ai_addr=(struct sockaddr *)ipv4;
ipv4->sin_family=AF_INET;
ipv4->sin_addr.s_addr=**addr_list;
if(list==NULL)
list=current=node;
else {
current->ai_next=node;
current=node;
}
}
break;
}
*result=list;
return 0;
}
static void preXP_freeaddrinfo(struct addrinfo *info){
struct addrinfo *next;
for(;info!=NULL;info=next){
next=info->ai_next;
NSZoneFree(NULL,info->ai_addr);
NSZoneFree(NULL,info);
}
}
static int any_getaddrinfo(const char *host,const char *service,const struct addrinfo *hints,struct addrinfo **result){
HANDLE library=LoadLibrary("WS2_32");
typeof(getaddrinfo) *function=(typeof(getaddrinfo) *)GetProcAddress(library,"getaddrinfo");
if(function==NULL){
return preXP_getaddrinfo(host,service,hints,result);
}
else {
return function(host,service,hints,result);
}
}
static void any_freeaddrinfo(struct addrinfo *info){
HANDLE library=LoadLibrary("WS2_32");
typeof(freeaddrinfo) *function=(typeof(freeaddrinfo) *)GetProcAddress(library,"freeaddrinfo");
if(function==NULL){
return preXP_freeaddrinfo(info);
}
else {
return function(info);
}
}
static struct addrinfo *blockingRequest(CFHostRequest *request){
struct addrinfo *result;
if(any_getaddrinfo(request->_name,NULL,NULL,&result)!=0)
return NULL;
return result;
}
static unsigned addressResolverThread(void *arg){
CFAddressResolverThreadInfo *info=(CFAddressResolverThreadInfo *)arg;
while(YES){
Boolean queueEmpty;
EnterCriticalSection(&(info->queueLock));
queueEmpty=(info->queueCount==0)?TRUE:FALSE;
LeaveCriticalSection(&(info->queueLock));
if(queueEmpty)
WaitForSingleObject(info->queueEvent,INFINITE);
CFHostRequest *request=NULL;
EnterCriticalSection(&(info->queueLock));
while(info->queueCount>0 && request==NULL){
request=info->queue[0];
info->queueCount--;
int i;
for(i=0;i<info->queueCount;i++)
info->queue[i]=info->queue[i+1];
}
if(request!=NULL)
request->_state=CFHostRequestInProgress;
LeaveCriticalSection(&(info->queueLock));
if(request!=NULL){
struct addrinfo *addressList=blockingRequest(request);
HANDLE event=NULL;
EnterCriticalSection(&(info->queueLock));
request->_addressList=addressList;
if(request->_state==CFHostRequestInProgress){
request->_state=CFHostRequestDone;
event=request->_event;
request=NULL;
}
LeaveCriticalSection(&(info->queueLock));
if(request!=NULL){
if(request->_addressList!=NULL)
any_freeaddrinfo(request->_addressList);
NSZoneFree(NULL,request->_name);
NSZoneFree(NULL,request);
}
if(event!=NULL){
SetEvent(event);
}
}
}
}
-(void)handleMonitorIndicatesSignaled:(NSHandleMonitor_win32 *)monitor {
if(_request==NULL){
NSLog(@"CFHost request is NULL %s %d",__FILE__,__LINE__);
return;
}
CloseHandle(_request->_event);
_request->_event=NULL;
[_monitor invalidate];
[_monitor setDelegate:nil];
[_monitor autorelease];
_monitor=nil;
if(_addressing!=NULL){
CFRelease(_addressing);
_addressing=NULL;
}
if(_request->_addressList==NULL){
if(NSDebugEnabled)
NSLog(@"Host %@ did not resolve",_name);
}
else {
int i;
_addressing=CFArrayCreateMutable(NULL,0,&kCFTypeArrayCallBacks);
struct addrinfo *check=_request->_addressList,*next;
for(;check!=NULL;check=next){
next=check->ai_next;
CFDataRef data=CFDataCreate(NULL,(void *)check->ai_addr,check->ai_addrlen);
CFArrayAppendValue(_addressing,data);
CFRelease(data);
}
}
if(_request->_addressList!=NULL)
any_freeaddrinfo(_request->_addressList);
NSZoneFree(NULL,_request->_name);
NSZoneFree(NULL,_request);
_request=NULL;
if(_callback!=NULL)
_callback(self,kCFHostAddresses,NULL,_context.info);
}
-(void)handleMonitorIndicatesAbandoned:(NSHandleMonitor_win32 *)monitor {
}
static pthread_mutex_t asyncCreationLock=PTHREAD_MUTEX_INITIALIZER;
static CFAddressResolverThreadInfo *asyncInfo;
static CFAddressResolverThreadInfo *startResolverThreadIfNeeded(){
pthread_mutex_lock(&asyncCreationLock);
if(asyncInfo==NULL){
asyncInfo=NSZoneMalloc(NULL,sizeof(CFAddressResolverThreadInfo));
InitializeCriticalSection(&(asyncInfo->queueLock));
asyncInfo->queueEvent=CreateEvent(NULL,FALSE,FALSE,NULL);
asyncInfo->queueCapacity=1;
asyncInfo->queueCount=0;
asyncInfo->queue=NSZoneMalloc(NULL,sizeof(CFHostRequest *)*asyncInfo->queueCapacity);
unsigned threadAddr;
_beginthreadex(NULL,0,addressResolverThread,asyncInfo,0,&threadAddr);
}
pthread_mutex_unlock(&asyncCreationLock);
return asyncInfo;
}
#if 1
#define SYNCHRONOUS 0
#else
#warning disable
#define SYNCHRONOUS 1
#endif
static void queueHostToAddressResolver(CFHostRef host){
if(SYNCHRONOUS){
int addressCount=0;
struct addrinfo *addressList=blockingRequest(host->_request);
host->_request->_state=CFHostRequestDone;
host->_request->_addressList=addressList;
SetEvent(host->_request->_event);
}
else {
CFAddressResolverThreadInfo *info=startResolverThreadIfNeeded();
EnterCriticalSection(&(info->queueLock));
if(info->queueCount+1>=info->queueCapacity){
info->queueCapacity*=2;
info->queue=NSZoneRealloc(NULL,info->queue,sizeof(CFHostRequest *)*info->queueCapacity);
}
info->queue[info->queueCount++]=host->_request;
LeaveCriticalSection(&(info->queueLock));
SetEvent(info->queueEvent);
}
}
static void cancelHostInAddressResolverIfNeeded(CFHostRef self){
if(self->_request==NULL)
return;
if(SYNCHRONOUS){
}
else {
CFAddressResolverThreadInfo *info;
if((info=asyncInfo)==NULL)
return;
EnterCriticalSection(&(info->queueLock));
if(self->_request->_state==CFHostRequestInProgress){
self->_request->_state=CFHostRequestDeallocate;
self->_request=NULL;
}
else {
int i;
for(i=0;i<info->queueCount;i++)
if(info->queue[i]==self->_request){
info->queueCount--;
for(;i<info->queueCount;i++)
info->queue[i]=info->queue[i+1];
break;
}
}
LeaveCriticalSection(&(info->queueLock));
if(self->_request!=NULL){
NSZoneFree(NULL,self->_request->_name);
NSZoneFree(NULL,self->_request);
self->_request=NULL;
}
}
}
#else
static void queueHostToAddressResolver(CFHostRef host){
}
static void cancelHostInAddressResolverIfNeeded(CFHostRef host){
}
#endif
CFTypeID CFHostGetTypeID() {
NSUnimplementedFunction();
return 0;
}
CFHostRef CFHostCreateCopy(CFAllocatorRef alloc,CFHostRef self) {
NSUnimplementedFunction();
return 0;
}
CFHostRef CFHostCreateWithAddress(CFAllocatorRef allocator,CFDataRef address) {
NSUnimplementedFunction();
return 0;
}
CFHostRef CFHostCreateWithName(CFAllocatorRef allocator,CFStringRef name) {
CFHostRef result=[__CFHost allocWithZone:NULL];
result->_name=CFStringCreateCopy(allocator,name);
return result;
}
-(void)dealloc {
CFRelease(_name);
if(self->_context.info!=NULL && self->_context.release!=NULL)
self->_context.release(self->_context.info);
CFRelease(_addressing);
#ifdef WINDOWS
if(self->_event!=NULL)
CloseHandle(self->_event);
[self->_monitor setDelegate:nil];
[self->_monitor invalidate];
[self->_monitor release];
#endif
[super dealloc];
}
CFArrayRef CFHostGetAddressing(CFHostRef self,Boolean *hasBeenResolved) {
if(hasBeenResolved!=NULL)
*hasBeenResolved=self->_hasResolvedAddressing;
return self->_addressing;
}
CFArrayRef CFHostGetNames(CFHostRef self,Boolean *hasBeenResolved) {
NSUnimplementedFunction();
return 0;
}
CFDataRef CFHostGetReachability(CFHostRef self,Boolean *hasBeenResolved) {
NSUnimplementedFunction();
return 0;
}
Boolean CFHostSetClient(CFHostRef self,CFHostClientCallBack callback,CFHostClientContext *context) {
if(self->_context.info!=NULL && self->_context.release!=NULL)
self->_context.release(self->_context.info);
self->_callback=callback;
if(context!=NULL)
self->_context=*context;
else {
self->_context.version=0;
self->_context.info=NULL;
self->_context.retain=NULL;
self->_context.release=NULL;
self->_context.copyDescription=NULL;
}
if(self->_callback!=NULL){
if(self->_context.info!=NULL && self->_context.retain!=NULL)
self->_context.info=(void *)self->_context.retain(self->_context.info);
}
return TRUE;
}
static void CFHostCreateEventIfNeeded(CFHostRef self){
if(self->_event==NULL){
self->_event=CreateEvent(NULL,FALSE,FALSE,NULL);
self->_monitor=[[NSHandleMonitor_win32 handleMonitorWithHandle:self->_event] retain];
[self->_monitor setDelegate:self];
[self->_monitor setCurrentActivity:Win32HandleSignaled];
}
}
Boolean CFHostStartInfoResolution(CFHostRef self,CFHostInfoType infoType,CFStreamError *streamError) {
switch(infoType){
case kCFHostAddresses:
if(self->_hasResolvedAddressing){
NSLog(@"CFHostStartInfoResolution, addressing already resolved");
return TRUE;
}
if(self->_callback!=NULL){
if(self->_request!=NULL){
NSLog(@"CFHostStartInfoResolution already started");
return FALSE;
}
char *cStringName=NSZoneMalloc(NULL,MAXHOSTNAMELEN+1);
// this encoding is probably wrong but CFStringGetCString can do it
if(!CFStringGetCString(self->_name,cStringName,MAXHOSTNAMELEN,kCFStringEncodingISOLatin1)){
NSLog(@"CFStringGetCString failed for CFHostRef name %@",self->_name);
NSZoneFree(NULL,cStringName);
return FALSE;
}
self->_request=NSZoneMalloc(NULL,sizeof(CFHostRequest));
self->_request->_state=CFHostRequestInQueue;
self->_request->_name=cStringName;
self->_request->_addressList=NULL;
CFHostCreateEventIfNeeded(self);
self->_request->_event=self->_event;
queueHostToAddressResolver(self);
return TRUE;
}
else {
NSUnimplementedFunction();
return FALSE;
}
case kCFHostNames:
NSUnimplementedFunction();
return FALSE;
case kCFHostReachability:
NSUnimplementedFunction();
return FALSE;
default:
[NSException raise:NSInvalidArgumentException format:@"CFHostStartInfoResolution CFHostInfoType is not valid (%d)",infoType];
return FALSE;
}
}
void CFHostCancelInfoResolution(CFHostRef self,CFHostInfoType infoType) {
switch(infoType){
case kCFHostAddresses:
cancelHostInAddressResolverIfNeeded(self);
break;
case kCFHostNames:
NSUnimplementedFunction();
break;
case kCFHostReachability:
NSUnimplementedFunction();
break;
default:
[NSException raise:NSInvalidArgumentException format:@"CFHostCancelInfoResolution CFHostInfoType is not valid (%d)",infoType];
break;
}
}
void CFHostScheduleWithRunLoop(CFHostRef self,CFRunLoopRef runLoop,CFStringRef mode) {
if(runLoop!=CFRunLoopGetCurrent())
NSUnimplementedFunction();
CFHostCreateEventIfNeeded(self);
[(NSRunLoop *)runLoop addInputSource:self->_monitor forMode:(NSString *)mode];
}
void CFHostUnscheduleFromRunLoop(CFHostRef self,CFRunLoopRef runLoop,CFStringRef mode) {
if(runLoop!=CFRunLoopGetCurrent())
NSUnimplementedFunction();
[(NSRunLoop *)runLoop removeInputSource:self->_monitor forMode:(NSString *)mode];
}
@end

View File

@ -0,0 +1,26 @@
#ifdef __cplusplus
#if defined(__WIN32__)
#if defined(CFNETWORK_INSIDE_BUILD)
#define CFNETWORK_EXPORT extern "C" __declspec(dllexport)
#else
#define CFNETWORK_EXPORT extern "C" __declspec(dllimport)
#endif
#else
#define CFNETWORK_EXPORT extern "C"
#endif
#else
#if defined(__WIN32__)
#if defined(CFNETWORK_INSIDE_BUILD)
#define CFNETWORK_EXPORT __declspec(dllexport) extern
#else
#define CFNETWORK_EXPORT __declspec(dllimport) extern
#endif
#else
#define CFNETWORK_EXPORT extern
#endif
#endif // __cplusplus

View File

@ -47,3 +47,12 @@ COREFOUNDATION_EXPORT uint64_t CFSwapInt64HostToBig(uint64_t value);
COREFOUNDATION_EXPORT uint64_t CFSwapInt64HostToLittle(uint64_t value);
COREFOUNDATION_EXPORT uint64_t CFSwapInt64LittleToHost(uint64_t value);
COREFOUNDATION_EXPORT uint16_t OSReadBigInt16(const void *ptr,size_t offset);
COREFOUNDATION_EXPORT uint32_t OSReadBigInt32(const void *ptr,size_t offset);
COREFOUNDATION_EXPORT void OSWriteBigInt16(void *ptr,size_t offset,uint16_t value);
COREFOUNDATION_EXPORT void OSWriteBigInt32(void *ptr,size_t offset,uint32_t value);
COREFOUNDATION_EXPORT uint32_t OSSwapInt32(uint32_t value);
COREFOUNDATION_EXPORT uint64_t OSSwapInt64(uint64_t valueX);
COREFOUNDATION_EXPORT uint64_t OSSwapBigToHostInt64(uint64_t value);
COREFOUNDATION_EXPORT uint32_t OSSwapHostToBigInt32(uint32_t value);
COREFOUNDATION_EXPORT uint64_t OSSwapHostToBigInt64(uint64_t value);

View File

@ -0,0 +1,123 @@
#import <CoreFoundation/CFByteOrder.h>
Float32 CFConvertFloat32SwappedToHost(CFSwappedFloat32 value) {
union {
CFSwappedFloat32 w;
Float32 f;
} swap;
swap.w=value;
#ifdef __LITTLE_ENDIAN__
swap.w.v=CFSwapInt32(swap.w.v);
#endif
return swap.f;
}
uint32_t CFSwapInt32(uint32_t value) {
uint32_t result;
result=value<<24;
result|=(value<<8)&0x00FF0000;
result|=(value>>8)&0x0000FF00;
result|=value>>24;
return result;
}
uint16_t OSReadBigInt16(const void *ptr,size_t offset){
const uint8_t *bytes=ptr+offset;
uint16_t result;
result=bytes[0];
result<<=8;
result|=bytes[1];
return result;
}
uint32_t OSReadBigInt32(const void *ptr,size_t offset){
const uint8_t *bytes=ptr+offset;
uint32_t result;
result=bytes[0];
result<<=8;
result|=bytes[1];
result<<=8;
result|=bytes[2];
result<<=8;
result|=bytes[3];
return result;
}
void OSWriteBigInt16(void *ptr,size_t offset,uint16_t value){
uint8_t *bytes=ptr+offset;
bytes[0]=(value>>8)&0xFF;
bytes[1]=value&0xFF;
}
void OSWriteBigInt32(void *ptr,size_t offset,uint32_t value){
uint8_t *bytes=ptr+offset;
bytes[0]=(value>>24)&0xFF;
bytes[1]=(value>>16)&0xFF;
bytes[2]=(value>>8)&0xFF;
bytes[3]=value&0xFF;
}
uint32_t OSSwapInt32(uint32_t value){
uint32_t result;
result=value<<24;
result|=(value<<8)&0x00FF0000;
result|=(value>>8)&0x0000FF00;
result|=value>>24;
return result;
}
uint64_t OSSwapInt64(uint64_t valueX){
union {
uint64_t word;
uint8_t bytes[8];
} value,result;
value.word=valueX;
result.bytes[0]=value.bytes[7];
result.bytes[1]=value.bytes[6];
result.bytes[2]=value.bytes[5];
result.bytes[3]=value.bytes[4];
result.bytes[4]=value.bytes[3];
result.bytes[5]=value.bytes[2];
result.bytes[6]=value.bytes[1];
result.bytes[7]=value.bytes[0];
return result.word;
}
uint64_t OSSwapBigToHostInt64(uint64_t value){
#ifdef __LITTLE_ENDIAN__
return OSSwapInt64(value);
#else
return value;
#endif
}
uint32_t OSSwapHostToBigInt32(uint32_t value){
#ifdef __LITTLE_ENDIAN__
return OSSwapInt32(value);
#else
return value;
#endif
}
uint64_t OSSwapHostToBigInt64(uint64_t value){
#ifdef __LITTLE_ENDIAN__
return OSSwapInt64(value);
#else
return value;
#endif
}

View File

@ -1 +1,82 @@
#import <CoreFoundation/CFPreferences.h>
#import <Foundation/NSRaise.h>
const CFStringRef kCFPreferencesCurrentApplication=(CFStringRef)@"kCFPreferencesCurrentApplication";
const CFStringRef kCFPreferencesCurrentHost=(CFStringRef)@"kCFPreferencesCurrentHost";
const CFStringRef kCFPreferencesCurrentUser=(CFStringRef)@"kCFPreferencesCurrentUser";
const CFStringRef kCFPreferencesAnyApplication=(CFStringRef)@"kCFPreferencesAnyApplication";
const CFStringRef kCFPreferencesAnyHost=(CFStringRef)@"kCFPreferencesAnyHost";
const CFStringRef kCFPreferencesAnyUser=(CFStringRef)@"kCFPreferencesAnyUser";
void CFPreferencesAddSuitePreferencesToApp(CFStringRef application,CFStringRef suite) {
NSUnimplementedFunction();
}
Boolean CFPreferencesAppSynchronize(CFStringRef application) {
NSUnimplementedFunction();
return NO;
}
Boolean CFPreferencesAppValueIsForced(CFStringRef key,CFStringRef application) {
NSUnimplementedFunction();
return NO;
}
CFArrayRef CFPreferencesCopyApplicationList(CFStringRef user,CFStringRef host) {
NSUnimplementedFunction();
return nil;
}
CFPropertyListRef CFPreferencesCopyAppValue(CFStringRef key,CFStringRef application) {
NSUnimplementedFunction();
return nil;
}
Boolean CFPreferencesGetAppBooleanValue(CFStringRef key,CFStringRef application,Boolean *validKey) {
NSUnimplementedFunction();
return NO;
}
CFIndex CFPreferencesGetAppIntegerValue(CFStringRef key,CFStringRef application,Boolean *validKey) {
NSUnimplementedFunction();
return 0;
}
CFArrayRef CFPreferencesCopyKeyList(CFStringRef application,CFStringRef user,CFStringRef host) {
NSUnimplementedFunction();
return nil;
}
CFDictionaryRef CFPreferencesCopyMultiple(CFArrayRef keysToFetch,CFStringRef application,CFStringRef user,CFStringRef host) {
NSUnimplementedFunction();
return nil;
}
CFPropertyListRef CFPreferencesCopyValue(CFStringRef key,CFStringRef application,CFStringRef user,CFStringRef host) {
NSUnimplementedFunction();
return nil;
}
void CFPreferencesSetAppValue(CFStringRef key,CFPropertyListRef value,CFStringRef application) {
NSUnimplementedFunction();
}
void CFPreferencesSetMultiple(CFDictionaryRef dictionary,CFArrayRef removeTheseKeys,CFStringRef application,CFStringRef user,CFStringRef host) {
NSUnimplementedFunction();
}
void CFPreferencesSetValue(CFStringRef key,CFPropertyListRef value,CFStringRef application,CFStringRef user,CFStringRef host) {
NSUnimplementedFunction();
}
void CFPreferencesRemoveSuitePreferencesFromApp(CFStringRef application,CFStringRef suite) {
NSUnimplementedFunction();
}
Boolean CFPreferencesSynchronize(CFStringRef application,CFStringRef user,CFStringRef host) {
NSUnimplementedFunction();
return NO;
}

View File

@ -0,0 +1,52 @@
#ifdef WINDOWS
#ifndef PTHREAD_H
#define PTHREAD_H
#import <stdint.h>
#import <CoreFoundation/CFBase.h>
typedef void *pthread_t;
typedef uint32_t pthread_key_t;
typedef long pthread_mutex_t;
typedef struct {
pthread_mutex_t mutex;
int state;
} pthread_once_t;
typedef void *pthread_cond_t;
typedef void *pthread_condattr_t;
typedef void *pthread_attr_t;
typedef void *pthread_mutexattr_t;
#define PTHREAD_ONCE_INIT {0,0}
#define PTHREAD_MUTEX_INITIALIZER 0
COREFOUNDATION_EXPORT int pthread_key_create(pthread_key_t *key, void (*destructor)(void*));
COREFOUNDATION_EXPORT int pthread_key_delete(pthread_key_t key);
COREFOUNDATION_EXPORT int pthread_create(pthread_t *thread,const pthread_attr_t *attr,void *(*start_routine)(void *),void *arg);
COREFOUNDATION_EXPORT pthread_t pthread_self(void);
COREFOUNDATION_EXPORT void *pthread_getw32threadhandle_np(pthread_t thread);
COREFOUNDATION_EXPORT void *pthread_getspecific(pthread_key_t key);
COREFOUNDATION_EXPORT int pthread_setspecific(pthread_key_t key, const void *value);
COREFOUNDATION_EXPORT int pthread_equal(pthread_t t1, pthread_t t2);
COREFOUNDATION_EXPORT int pthread_once(pthread_once_t *once,void (*function)(void));
COREFOUNDATION_EXPORT int pthread_mutex_init(pthread_mutex_t *mutex,const pthread_mutexattr_t *attr);
COREFOUNDATION_EXPORT int pthread_mutex_lock(volatile pthread_mutex_t *mutex);
COREFOUNDATION_EXPORT int pthread_mutex_trylock(volatile pthread_mutex_t *mutex);
COREFOUNDATION_EXPORT int pthread_mutex_unlock(volatile pthread_mutex_t *mutex);
COREFOUNDATION_EXPORT int pthread_cond_init(pthread_cond_t *cond,const pthread_condattr_t *attr);
COREFOUNDATION_EXPORT int pthread_cond_signal(pthread_cond_t *cond);
COREFOUNDATION_EXPORT int pthread_cond_wait(pthread_cond_t *cond,pthread_mutex_t *mutex);
#endif
#endif

View File

@ -0,0 +1,72 @@
#ifdef WINDOWS
#import "pthread.h"
#import <windows.h>
#import <errno.h>
int pthread_mutex_init(pthread_mutex_t *mutex,const pthread_mutexattr_t *attr) {
*mutex=PTHREAD_MUTEX_INITIALIZER;
return 0;
}
int pthread_mutex_lock(pthread_mutex_t volatile *mutex) {
while(InterlockedCompareExchange(mutex,1,0)==1){
;
}
return 0;
}
int pthread_mutex_trylock(pthread_mutex_t volatile *mutex) {
if(InterlockedCompareExchange(mutex,1,0)==1)
return EBUSY;
return 0;
}
int pthread_mutex_unlock(pthread_mutex_t volatile *mutex) {
InterlockedExchange(mutex,0);
return 0;
}
int pthread_once(pthread_once_t *once,void (*function)(void)) {
pthread_mutex_lock(&(once->mutex));
if(once->state==0){
function();
once->state=1;
}
pthread_mutex_unlock(&(once->mutex));
return 0;
}
void *pthread_getspecific(pthread_key_t key) {
if(key==TLS_OUT_OF_INDEXES)
return NULL;
void *result=TlsGetValue(key);
if(result==NULL){
if(GetLastError()==0)
; // no error
else
; // error
}
return result;
}
int pthread_setspecific(pthread_key_t key, const void *value) {
if(TlsSetValue(key,(void *)value)==0){
return EINVAL;
}
return 0;
}
int pthread_key_create(pthread_key_t *key,void (*destructor)(void*)) {
#warning implement destructor
if((*key=TlsAlloc())==TLS_OUT_OF_INDEXES)
return EAGAIN;
return 0;
}
#endif

View File

@ -0,0 +1,3 @@
int sched_yield(void);

View File

@ -34,7 +34,7 @@ const NSTimeInterval NSTimeIntervalSince1970 = (NSTimeInterval)978307200.0;
static NSDate *staticInstance=nil;
if(!staticInstance)
staticInstance=[[self allocWithZone:NULL]
initWithTimeIntervalSinceReferenceDate:-(2010.0L*365*24*60*60)];
initWithTimeIntervalSinceReferenceDate:-(2010.0L*365.0*24.0*60.0*60.0)];
return staticInstance;
}
@ -42,7 +42,7 @@ const NSTimeInterval NSTimeIntervalSince1970 = (NSTimeInterval)978307200.0;
static NSDate *staticInstance=nil;
if(!staticInstance)
staticInstance=[[self allocWithZone:NULL]
initWithTimeIntervalSinceReferenceDate:2010.0L*365*24*60*60];
initWithTimeIntervalSinceReferenceDate:2010.0L*365.0*24.0*60.0*60.0];
return staticInstance;
}

View File

@ -8,11 +8,30 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#import <Foundation/NSFormatter.h>
#import <Foundation/NSDate.h>
#import <CoreFoundation/CFDateFormatter.h>
typedef enum {
NSDateFormatterBehaviorDefault = 0,
NSDateFormatterBehavior10_0 = 1000,
NSDateFormatterBehavior10_4 = 1040,
} NSDateFormatterBehavior;
typedef enum {
NSDateFormatterNoStyle = kCFDateFormatterNoStyle,
NSDateFormatterShortStyle = kCFDateFormatterShortStyle,
NSDateFormatterMediumStyle = kCFDateFormatterMediumStyle,
NSDateFormatterLongStyle = kCFDateFormatterLongStyle,
NSDateFormatterFullStyle = kCFDateFormatterFullStyle
} NSDateFormatterStyle;
@interface NSDateFormatter : NSFormatter {
NSString *_dateFormat;
BOOL _allowsNaturalLanguage;
NSDictionary *_locale;
NSDateFormatterBehavior _behavior;
NSDateFormatterStyle _dateStyle;
NSDateFormatterStyle _timeStyle;
NSString *_dateFormat10_0;
NSString *_dateFormat;
BOOL _allowsNaturalLanguage;
NSDictionary *_locale;
}
-initWithDateFormat:(NSString *)format allowNaturalLanguage:(BOOL)flag; // shouldn't this be "allows" ?

View File

@ -18,6 +18,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#import <Foundation/NSCharacterSet.h>
#import <Foundation/NSKeyedUnarchiver.h>
#import <Foundation/NSCalendar.h>
#import <Foundation/NSNumber.h>
@implementation NSDateFormatter
@ -27,7 +28,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
-initWithDateFormat:(NSString *)format allowNaturalLanguage:(BOOL)flag locale:(NSDictionary *)locale {
[super init];
_dateFormat = [format retain];
_behavior=NSDateFormatterBehavior10_0;
_dateFormat10_0 = [format copy];
_dateFormat = [format copy];
_allowsNaturalLanguage = flag;
_locale = [locale retain];
@ -35,6 +38,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
}
-(void)dealloc {
[_dateFormat10_0 release];
[_dateFormat release];
[_locale release];
@ -45,9 +49,12 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
[super initWithCoder:coder];
if([coder isKindOfClass:[NSKeyedUnarchiver class]]){
/* attributes in key NS.attributes
"formatBehavior" is key in attributes
*/
NSDictionary *attributes=[coder decodeObjectForKey:@"NS.attributes"];
_dateFormat10_0=[[attributes objectForKey:@"dateFormat_10_0"] copy];
_behavior=[[attributes objectForKey:@"formatterBehavior"] intValue];
_dateStyle=[[attributes objectForKey:@"dateStyle"] intValue];
_timeStyle=[[attributes objectForKey:@"timeStyle"] intValue];
_dateFormat=[[coder decodeObjectForKey:@"NS.format"] retain];
_allowsNaturalLanguage=[coder decodeBoolForKey:@"NS.natural"];
}
@ -95,19 +102,13 @@ NSWeekDayNameArray];
}
-(NSString *)stringForObjectValue:(id)object {
if ([object isKindOfClass:[NSDate class]]) {
NSTimeZone *zone;
if ([object isKindOfClass:[NSCalendarDate class]])
zone = [object timeZone];
else
zone = [NSTimeZone defaultTimeZone];
// will adjust time zone
return NSStringWithDateFormatLocale([object timeIntervalSinceReferenceDate], _dateFormat, _locale, zone);
}
if([object isKindOfClass:[NSDate class]])
return NSStringWithDateFormatLocale([object timeIntervalSinceReferenceDate], _dateFormat10_0, _locale, [NSTimeZone defaultTimeZone]);
if([object isKindOfClass:[NSCalendarDate class]])
return NSStringWithDateFormatLocale([object timeIntervalSinceReferenceDate], _dateFormat10_0, _locale, [object timeZone]);
return nil;
return nil;
}
-(NSAttributedString *)attributedStringForObjectValue:(id)object
@ -120,7 +121,7 @@ NSWeekDayNameArray];
}
-(BOOL)getObjectValue:(id *)object forString:(NSString *)string errorDescription:(NSString **)error {
*object = NSCalendarDateWithStringDateFormatLocale(string, _dateFormat, _locale);
*object = NSCalendarDateWithStringDateFormatLocale(string, _dateFormat10_0, _locale);
if (*object == nil) {
// FIX localization
if(error!=NULL)

View File

@ -23,15 +23,15 @@ id objc_msg_sendv(id self, SEL selector, unsigned arg_size, void *arg_frame);
@implementation NSInvocation
-(void)buildFrame {
NSInteger i,count=[_signature numberOfArguments];
NSInteger i,count=[_signature numberOfArguments];
NSUInteger align;
NSGetSizeAndAlignment([_signature methodReturnType],&_returnSize,&align);
_returnValue=NSZoneCalloc([self zone],MAX(_returnSize, sizeof(long)),1);
_returnValue=NSZoneCalloc(NULL,MAX(_returnSize, sizeof(long)),1);
_argumentFrameSize=0;
_argumentSizes=NSZoneCalloc([self zone],count,sizeof(NSUInteger));
_argumentOffsets=NSZoneCalloc([self zone],count,sizeof(NSUInteger));
_argumentSizes=NSZoneCalloc(NULL,count,sizeof(NSUInteger));
_argumentOffsets=NSZoneCalloc(NULL,count,sizeof(NSUInteger));
for(i=0;i<count;i++){
NSUInteger naturalSize;
@ -48,23 +48,22 @@ id objc_msg_sendv(id self, SEL selector, unsigned arg_size, void *arg_frame);
}
-initWithMethodSignature:(NSMethodSignature *)signature {
if(!signature)
{
[NSException raise:NSInvalidArgumentException
format:@"nil signature in NSInvocation creation"];
}
if(signature==nil){
[self dealloc];
[NSException raise:NSInvalidArgumentException format:@"nil signature in NSInvocation creation"];
return nil;
}
_signature=[signature retain];
[self buildFrame];
_argumentFrame=NSZoneCalloc([self zone],_argumentFrameSize,1);
_argumentFrame=NSZoneCalloc(NULL,_argumentFrameSize,1);
return self;
}
-initWithMethodSignature:(NSMethodSignature *)signature
arguments:(void *)arguments {
-initWithMethodSignature:(NSMethodSignature *)signature arguments:(void *)arguments {
unsigned i;
uint8_t *stackFrame=arguments;
@ -96,7 +95,7 @@ id objc_msg_sendv(id self, SEL selector, unsigned arg_size, void *arg_frame);
char *ptr;
[self getArgument:&ptr atIndex:i];
NSZoneFree([self zone], ptr);
NSZoneFree(NULL, ptr);
break;
}
@ -106,10 +105,10 @@ id objc_msg_sendv(id self, SEL selector, unsigned arg_size, void *arg_frame);
}
}
NSZoneFree([self zone],_returnValue);
NSZoneFree([self zone],_argumentSizes);
NSZoneFree([self zone],_argumentOffsets);
NSZoneFree([self zone],_argumentFrame);
NSZoneFree(NULL,_returnValue);
NSZoneFree(NULL,_argumentSizes);
NSZoneFree(NULL,_argumentOffsets);
NSZoneFree(NULL,_argumentFrame);
[_signature release];
NSDeallocateObject(self);
return;
@ -135,7 +134,7 @@ static void *bufferForType(void *buffer,const char *type){
[self buildFrame];
_argumentFrame=NSZoneCalloc([self zone],_argumentFrameSize,1);
_argumentFrame=NSZoneCalloc(NULL,_argumentFrameSize,1);
if([_signature methodReturnLength]>0){
type=[_signature methodReturnType];
@ -183,8 +182,7 @@ static void *bufferForType(void *buffer,const char *type){
return [[[self allocWithZone:NULL] initWithMethodSignature:signature] autorelease];
}
+(NSInvocation *)invocationWithMethodSignature:(NSMethodSignature *)signature
arguments:(void *)arguments {
+(NSInvocation *)invocationWithMethodSignature:(NSMethodSignature *)signature arguments:(void *)arguments {
return [[[self allocWithZone:NULL] initWithMethodSignature:signature arguments:arguments] autorelease];
}
@ -275,7 +273,7 @@ static void byteCopy(void *src,void *dst,NSUInteger length){
[self getArgument:&ptr atIndex:i];
length = strlen(ptr);
copy = NSZoneCalloc([self zone], length+1, 1);
copy = NSZoneCalloc(NULL, length+1, 1);
byteCopy(ptr, copy, length);
[self setArgument:&copy atIndex:i];
break;
@ -368,7 +366,7 @@ static void byteCopy(void *src,void *dst,NSUInteger length){
int (*function)()=msgSendv;
int value=function(target,[self selector],_argumentFrameSize,_argumentFrame);
[self setReturnValue:&value];
[self setReturnValue:&value];
}
break;
@ -400,7 +398,7 @@ static void byteCopy(void *src,void *dst,NSUInteger length){
case 'v':{
void (*function)()=msgSendv;
function(target,[self selector],_argumentFrameSize,_argumentFrame);
function(target,[self selector],_argumentFrameSize,_argumentFrame);
}
break;

View File

@ -53,8 +53,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
while((obj=[en nextObject]))
{
id val=[obj valueForKey:key];
if(!val)
if(!val){
val=[NSNull null];
}
[array addObject:val];
}
return array;
@ -74,8 +75,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
salary of the array's elements.
*/
NSString *operator, *parameter;
[[keyPath substringFromIndex:1] _KVC_partBeforeDot:&operator
afterDot:&parameter];
[[keyPath substringFromIndex:1] _KVC_partBeforeDot:&operator afterDot:&parameter];
// find operator selector (e.g. _kvo_operator_avg: for @avg)
SEL operatorSelector=NSSelectorFromString([NSString stringWithFormat:@"_kvo_operator_%@:", operator]);
@ -90,16 +90,20 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
Otherwise, valueForKeyPath behaves similarly to valueForKey and produces a
new NSArray whose elements correspond to the results of invoking
valueForKeyPath on each element of this array.
*/ NSMutableArray *array=[NSMutableArray array];
*/
NSMutableArray *array=[NSMutableArray array];
id en=[self objectEnumerator];
id obj;
while((obj=[en nextObject]))
{
id val=[obj valueForKeyPath:keyPath];
if(!val)
if(val==nil)
val=[NSNull null];
[array addObject:val];
}
return array;
}

View File

@ -144,11 +144,12 @@ static inline void XXHashRemove(RefCountTable *table,RefCountBucket *remove) {
}
static inline RefCountTable *refTable(void) {
static RefCountTable *table=NULL;
static RefCountTable *refCountTable=NULL;
if(table==NULL)
table=CreateRefCountTable();
return table;
if(refCountTable==NULL)
refCountTable=CreateRefCountTable();
return refCountTable;
}
void NSIncrementExtraRefCount(id object) {