mirror of
https://github.com/gnustep/libs-gsweb.git
synced 2025-02-22 19:21:23 +00:00
o fixes in NSLog category
o added NSMutableData -replaceOccurrencesOfData:withData:range: o added NSData -rangeOfData:range: o added NSData -base64Representation o added NSData -initWithBase64Representation: git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@18142 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
1e4a2c3607
commit
222535d36e
2 changed files with 325 additions and 78 deletions
|
@ -449,4 +449,42 @@ typedef enum _NSNumFmtType
|
||||||
errorDescription:(NSString**)error;
|
errorDescription:(NSString**)error;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
//====================================================================
|
||||||
|
@interface NSData (Base64)
|
||||||
|
/**
|
||||||
|
* Returns an NSString object containing an ASCII base64 representation
|
||||||
|
* of the receiver. <br />
|
||||||
|
* If you need the hexadecimal representation as raw byte data, use code
|
||||||
|
* like -
|
||||||
|
* <example>
|
||||||
|
* hexData = [[sourceData base64Representation]
|
||||||
|
* dataUsingEncoding: NSASCIIStringEncoding];
|
||||||
|
* </example>
|
||||||
|
*/
|
||||||
|
- (NSString*) base64Representation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialises the receiver with the supplied string data which contains
|
||||||
|
* a base64 coding of the bytes. The parsing of the string is
|
||||||
|
* fairly tolerant, ignoring whitespace.<br />
|
||||||
|
* If the string does not contain one or more valid base64 characters
|
||||||
|
* then an exception is raised.
|
||||||
|
*/
|
||||||
|
- (id) initWithBase64Representation: (NSString*)string;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
//====================================================================
|
||||||
|
@interface NSData (Search)
|
||||||
|
- (NSRange) rangeOfData: (NSData *)data
|
||||||
|
range: (NSRange)aRange;
|
||||||
|
@end
|
||||||
|
|
||||||
|
//====================================================================
|
||||||
|
@interface NSMutableData (Replace)
|
||||||
|
- (unsigned int) replaceOccurrencesOfData: (NSData*)replace
|
||||||
|
withData: (NSData*)by
|
||||||
|
range: (NSRange)searchRange;
|
||||||
|
@end
|
||||||
|
|
||||||
#endif // _GSWebUtils_h__
|
#endif // _GSWebUtils_h__
|
||||||
|
|
|
@ -35,6 +35,7 @@ RCS_ID("$Id$")
|
||||||
#include "GSWeb.h"
|
#include "GSWeb.h"
|
||||||
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "stacktrace.h"
|
#include "stacktrace.h"
|
||||||
#include "attach.h"
|
#include "attach.h"
|
||||||
|
@ -203,6 +204,21 @@ NSTimeInterval NSTimeIntervalFromTimeVal(struct timeval* tv)
|
||||||
return interval;
|
return interval;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void NSTimeIntervalSleep(NSTimeInterval ti)
|
||||||
|
{
|
||||||
|
struct timespec ts;
|
||||||
|
struct timespec remaining;
|
||||||
|
ts.tv_sec=(time_t)ti;
|
||||||
|
ts.tv_nsec=(long)((ti-ts.tv_sec)*100000000.0);
|
||||||
|
remaining.tv_sec=0;
|
||||||
|
remaining.tv_nsec=0;
|
||||||
|
NSDebugFLog(@"ts.tv_sec=%ld ts.tv_nsec=%ld",(long)ts.tv_sec,ts.tv_nsec);
|
||||||
|
if (nanosleep(&ts,&remaining)==-1)
|
||||||
|
{
|
||||||
|
NSDebugFLog(@"remaining tv_sec=%ld tv_nsec=%ld",(long)remaining.tv_sec,remaining.tv_nsec);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
NSString* pidproccontent(NSString* path)
|
NSString* pidproccontent(NSString* path)
|
||||||
{
|
{
|
||||||
NSString* content=nil;
|
NSString* content=nil;
|
||||||
|
@ -855,6 +871,28 @@ extern struct PTHREAD_HANDLE* nub_get_active_thread(void);
|
||||||
|
|
||||||
NSString *NSLockException = @"NSLockException";
|
NSString *NSLockException = @"NSLockException";
|
||||||
|
|
||||||
|
NSString* MessageForMutexLockError(int errorNo)
|
||||||
|
{
|
||||||
|
NSDebugFLog(@"errorNo=%d",errorNo);
|
||||||
|
switch(errorNo)
|
||||||
|
{
|
||||||
|
case EINVAL:
|
||||||
|
return @"EINVAL the mutex has not been properly initialized.";
|
||||||
|
break;
|
||||||
|
case EDEADLK:
|
||||||
|
return @"EDEADLK the mutex is already locked by the calling thread";
|
||||||
|
break;
|
||||||
|
case EBUSY:
|
||||||
|
return @"the mutex could not be acquired or destroyed because it was currently locked.";
|
||||||
|
break;
|
||||||
|
case EPERM:
|
||||||
|
return @"EPERM the calling thread does not own the mutex";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return [NSString stringWithFormat:@"Unknown %d",errorNo];
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
};
|
||||||
//====================================================================
|
//====================================================================
|
||||||
@implementation NSLock (NSLockBD)
|
@implementation NSLock (NSLockBD)
|
||||||
|
|
||||||
|
@ -869,6 +907,15 @@ NSString *NSLockException = @"NSLockException";
|
||||||
-(BOOL)isLocked
|
-(BOOL)isLocked
|
||||||
{
|
{
|
||||||
BOOL isLocked=YES;
|
BOOL isLocked=YES;
|
||||||
|
if (!_mutex->owner)
|
||||||
|
isLocked=NO;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NSDebugMLog(@"Locked by _mutex->owner=%p _mutex->depth=%d (this thread=%p)",
|
||||||
|
(void*)_mutex->owner,(int)_mutex->depth,
|
||||||
|
(void*)objc_thread_id());
|
||||||
|
};
|
||||||
|
/*
|
||||||
if ([self tmptryLock])
|
if ([self tmptryLock])
|
||||||
{
|
{
|
||||||
isLocked=NO;
|
isLocked=NO;
|
||||||
|
@ -876,10 +923,11 @@ NSString *NSLockException = @"NSLockException";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NSDebugMLog(@"Locked by _mutex->owner=%p (our ThreadID=%p)",
|
NSDebugMLog(@"Locked by _mutex->owner=%p _mutex->depth=%d (this thread=%p)",
|
||||||
(void*)_mutex->owner,
|
(void*)_mutex->owner,(int)_mutex->depth,
|
||||||
(void*)objc_thread_id());
|
(void*)objc_thread_id());
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
return isLocked;
|
return isLocked;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -900,18 +948,21 @@ NSString *NSLockException = @"NSLockException";
|
||||||
BOOL locked=NO;
|
BOOL locked=NO;
|
||||||
int result=0;
|
int result=0;
|
||||||
// LOGObjectFnStart();
|
// LOGObjectFnStart();
|
||||||
// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id());
|
NSDebugMLLog(@"low",@"BEF self=%p _mutex=%p _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",
|
||||||
result=objc_mutex_trylock(_mutex);
|
self,(void*)_mutex,(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id());
|
||||||
// NSDebugMLLog(@"low",@"result=%d",result);
|
if (!_mutex->owner)
|
||||||
if (result != 0 && result!=1)
|
{
|
||||||
locked=NO;
|
result=objc_mutex_trylock(_mutex);
|
||||||
else
|
// NSDebugMLLog(@"low",@"result=%d",result);
|
||||||
locked=YES;
|
if (result != 0 && result!=1)
|
||||||
|
locked=NO;
|
||||||
|
else
|
||||||
|
locked=YES;
|
||||||
|
};
|
||||||
// NSDebugMLLog(@"low",@"locked=%d",(int)locked);
|
// NSDebugMLLog(@"low",@"locked=%d",(int)locked);
|
||||||
if (locked)
|
if (locked)
|
||||||
{
|
{
|
||||||
//NSDebugMLLog(@"low",@"AFT _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id());
|
//NSDebugMLLog(@"low",@"AFT _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -945,14 +996,17 @@ NSString *NSLockException = @"NSLockException";
|
||||||
BOOL locked=NO;
|
BOOL locked=NO;
|
||||||
int result=0;
|
int result=0;
|
||||||
// LOGObjectFnStart();
|
// LOGObjectFnStart();
|
||||||
// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id());
|
// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id());
|
||||||
result=objc_mutex_trylock(_mutex);
|
if (!_mutex->owner)
|
||||||
// NSDebugMLLog(@"low",@"result=%d",result);
|
{
|
||||||
if (result != 0 && result!=1)
|
result=objc_mutex_trylock(_mutex);
|
||||||
locked=NO;
|
// NSDebugMLLog(@"low",@"result=%d",result);
|
||||||
else
|
if (result != 0 && result!=1)
|
||||||
locked=YES;
|
locked=NO;
|
||||||
// LOGObjectFnStop();
|
else
|
||||||
|
locked=YES;
|
||||||
|
// LOGObjectFnStop();
|
||||||
|
};
|
||||||
return locked;
|
return locked;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -975,36 +1029,50 @@ NSString *NSLockException = @"NSLockException";
|
||||||
int result=0;
|
int result=0;
|
||||||
int tryCount=0;
|
int tryCount=0;
|
||||||
// LOGObjectFnStart();
|
// LOGObjectFnStart();
|
||||||
// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id());
|
NSDebugMLLog(@"low",@"BEF self=%p _mutex=%p _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",
|
||||||
result=objc_mutex_trylock(_mutex);
|
self,(void*)_mutex,(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id());
|
||||||
// NSDebugMLLog(@"low",@"result=%d",result);
|
if (!_mutex->owner)
|
||||||
if (result != 0 && result!=1)
|
{
|
||||||
locked=NO;
|
result=objc_mutex_trylock(_mutex);
|
||||||
else
|
// NSDebugMLLog(@"low",@"result=%d",result);
|
||||||
locked=YES;
|
if (result != 0 && result!=1)
|
||||||
|
locked=NO;
|
||||||
|
else
|
||||||
|
locked=YES;
|
||||||
|
};
|
||||||
// NSDebugMLLog(@"low",@"[NSDate date]=%@ limit=%@",[NSDate date],limit);
|
// NSDebugMLLog(@"low",@"[NSDate date]=%@ limit=%@",[NSDate date],limit);
|
||||||
while (!locked && [[NSDate date]compare:limit]==NSOrderedAscending)
|
while (!locked && [[NSDate date]compare:limit]==NSOrderedAscending)
|
||||||
{
|
{
|
||||||
tryCount++;
|
tryCount++;
|
||||||
//NSDebugMLLog(@"low",@"tmplockBeforeDate wait");
|
//NSDebugMLLog(@"low",@"tmplockBeforeDate wait");
|
||||||
usleep(100);
|
NSTimeIntervalSleep(0.010);
|
||||||
//NSDebugMLLog(@"low",@"BEF _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id());
|
//NSDebugMLLog(@"low",@"BEF _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id());
|
||||||
result=objc_mutex_trylock(_mutex);
|
if (!_mutex->owner)
|
||||||
//NSDebugMLLog(@"low",@"result=%d",result);
|
|
||||||
if (result != 0 && result!=1)
|
|
||||||
{
|
{
|
||||||
if (tryCount%10==0)
|
result=objc_mutex_trylock(_mutex);
|
||||||
NSLog(@"Try lock for %d micro-secondes",100*tryCount);
|
//NSDebugMLLog(@"low",@"result=%d",result);
|
||||||
locked=NO;
|
if (result != 0 && result!=1)
|
||||||
|
{
|
||||||
|
if (tryCount%10==0)
|
||||||
|
NSLog(@"Try lock for %d ms. lock current owner=%p this thread=%p",
|
||||||
|
10*tryCount,(void*)_mutex->owner,(void*)objc_thread_id());
|
||||||
|
locked=NO;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
locked=YES;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
locked=YES;
|
{
|
||||||
|
if (tryCount%10==0)
|
||||||
|
NSLog(@"Try lock for %d ms. lock current owner=%p this thread=%p",
|
||||||
|
10*tryCount,(void*)_mutex->owner,(void*)objc_thread_id());
|
||||||
|
locked=NO;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
// NSDebugMLLog(@"low",@"locked=%d",(int)locked);
|
// NSDebugMLLog(@"low",@"locked=%d",(int)locked);
|
||||||
if (locked)
|
if (locked)
|
||||||
{
|
{
|
||||||
//NSDebugMLLog(@"low",@"AFT _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id());
|
//NSDebugMLLog(@"low",@"AFT _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1037,36 +1105,51 @@ NSString *NSLockException = @"NSLockException";
|
||||||
int result=0;
|
int result=0;
|
||||||
int tryCount=0;
|
int tryCount=0;
|
||||||
// LOGObjectFnStart();
|
// LOGObjectFnStart();
|
||||||
// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id());
|
NSDebugMLLog(@"low",@"BEF self=%p _mutex=%p _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",
|
||||||
result=objc_mutex_trylock(_mutex);
|
self,(void*)_mutex,(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id());
|
||||||
// NSDebugMLLog(@"low",@"result=%d",result);
|
if (!_mutex->owner)
|
||||||
if (result != 0 && result!=1)
|
{
|
||||||
locked=NO;
|
result=objc_mutex_trylock(_mutex);
|
||||||
else
|
// NSDebugMLLog(@"low",@"result=%d",result);
|
||||||
locked=YES;
|
if (result != 0 && result!=1)
|
||||||
|
locked=NO;
|
||||||
|
else
|
||||||
|
locked=YES;
|
||||||
|
};
|
||||||
|
|
||||||
// NSDebugMLLog(@"low",@"[NSDate date]=%@ limit=%@",[NSDate date],limit);
|
// NSDebugMLLog(@"low",@"[NSDate date]=%@ limit=%@",[NSDate date],limit);
|
||||||
while (!locked && [[NSDate date]compare:limit]==NSOrderedAscending)
|
while (!locked && [[NSDate date]compare:limit]==NSOrderedAscending)
|
||||||
{
|
{
|
||||||
tryCount++;
|
tryCount++;
|
||||||
//NSDebugMLLog(@"low",@"tmplockBeforeDate wait");
|
//NSDebugMLLog(@"low",@"tmplockBeforeDate wait");
|
||||||
usleep(100);
|
NSTimeIntervalSleep(0.010);
|
||||||
//NSDebugMLLog(@"low",@"BEF _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id());
|
//NSDebugMLLog(@"low",@"BEF _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id());
|
||||||
result=objc_mutex_trylock(_mutex);
|
if (!_mutex->owner)
|
||||||
//NSDebugMLLog(@"low",@"result=%d",result);
|
|
||||||
if (result != 0 && result!=1)
|
|
||||||
{
|
{
|
||||||
if (tryCount%10==0)
|
result=objc_mutex_trylock(_mutex);
|
||||||
NSLog(@"Try lock for %d micro-secondes",100*tryCount);
|
//NSDebugMLLog(@"low",@"result=%d",result);
|
||||||
locked=NO;
|
if (result != 0 && result!=1)
|
||||||
|
{
|
||||||
|
if (tryCount%10==0)
|
||||||
|
NSLog(@"Try lock for %d ms. lock current owner=%p this thread=%p",
|
||||||
|
10*tryCount,(void*)_mutex->owner,(void*)objc_thread_id());
|
||||||
|
locked=NO;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
locked=YES;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
locked=YES;
|
{
|
||||||
|
if (tryCount%10==0)
|
||||||
|
NSLog(@"Try lock for %d ms. lock current owner=%p this thread=%p",
|
||||||
|
10*tryCount,(void*)_mutex->owner,(void*)objc_thread_id());
|
||||||
|
locked=NO;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
// NSDebugMLLog(@"low",@"locked=%d",(int)locked);
|
// NSDebugMLLog(@"low",@"locked=%d",(int)locked);
|
||||||
if (locked)
|
if (locked)
|
||||||
{
|
{
|
||||||
//NSDebugMLLog(@"low",@"AFT _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id());
|
//NSDebugMLLog(@"low",@"AFT _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1101,8 +1184,21 @@ NSString *NSLockException = @"NSLockException";
|
||||||
{
|
{
|
||||||
int result=0;
|
int result=0;
|
||||||
// LOGObjectFnStart();
|
// LOGObjectFnStart();
|
||||||
// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id());
|
NSDebugMLLog(@"low",@"BEF self=%p _mutex=%p _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",
|
||||||
if (_mutex->owner!=objc_thread_id())
|
self,(void*)_mutex,(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id());
|
||||||
|
if (!_mutex->owner)
|
||||||
|
{
|
||||||
|
LOGException(@"NSLockException unlock: failed to unlock mutex (not locked). Called from %s in %s %d",
|
||||||
|
fn ? fn : "Unknown",
|
||||||
|
file ? file : "Unknown",
|
||||||
|
line);
|
||||||
|
[NSException raise:NSLockException
|
||||||
|
format:@"unlock: failed to lock mutex (not locked). Called from %s in %s %d",
|
||||||
|
fn ? fn : "Unknown",
|
||||||
|
file ? file : "Unknown",
|
||||||
|
line];
|
||||||
|
}
|
||||||
|
else if (_mutex->owner!=objc_thread_id())
|
||||||
{
|
{
|
||||||
LOGException(@"NSLockException unlock: failed to unlock mutex (not owner). Called from %s in %s %d",
|
LOGException(@"NSLockException unlock: failed to unlock mutex (not owner). Called from %s in %s %d",
|
||||||
fn ? fn : "Unknown",
|
fn ? fn : "Unknown",
|
||||||
|
@ -1117,17 +1213,23 @@ NSString *NSLockException = @"NSLockException";
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result=objc_mutex_unlock(_mutex);
|
result=objc_mutex_unlock(_mutex);
|
||||||
//NSDebugMLLog(@"low",@"AFT _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id());
|
//NSDebugMLLog(@"low",@"AFT _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id());
|
||||||
//NSDebugMLLog(@"low",@"result=%d",result);
|
//NSDebugMLLog(@"low",@"result=%d",result);
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
{
|
{
|
||||||
|
NSDebugMLLog(@"low",@"AFT self=%p _mutex=%p _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",
|
||||||
|
self,(void*)_mutex,(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id());
|
||||||
//NSDebugMLLog(@"low",@"UNLOCK PROBLEM");
|
//NSDebugMLLog(@"low",@"UNLOCK PROBLEM");
|
||||||
LOGException(@"NSLockException unlock: failed to unlock mutex (result!=0). Called from %s in %s %d",
|
LOGException(@"NSLockException unlock: failed to unlock mutex (result %d!=0).%@. Called from %s in %s %d",
|
||||||
|
result,
|
||||||
|
MessageForMutexLockError(result),
|
||||||
fn ? fn : "Unknown",
|
fn ? fn : "Unknown",
|
||||||
file ? file : "Unknown",
|
file ? file : "Unknown",
|
||||||
line);
|
line);
|
||||||
[NSException raise:NSLockException
|
[NSException raise:NSLockException
|
||||||
format:@"unlock: failed to lock mutex (result!=0). Called from %s in %s %d",
|
format:@"unlock: failed to unlock mutex (result %d!=0).%@. Called from %s in %s %d",
|
||||||
|
result,
|
||||||
|
MessageForMutexLockError(result),
|
||||||
fn ? fn : "Unknown",
|
fn ? fn : "Unknown",
|
||||||
file ? file : "Unknown",
|
file ? file : "Unknown",
|
||||||
line];
|
line];
|
||||||
|
@ -1178,7 +1280,7 @@ NSString *NSRecursiveLockException = @"NSRecursiveLockException";
|
||||||
BOOL locked=NO;
|
BOOL locked=NO;
|
||||||
int result=0;
|
int result=0;
|
||||||
// LOGObjectFnStart();
|
// LOGObjectFnStart();
|
||||||
// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id());
|
// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id());
|
||||||
if (!_mutex->owner || _mutex->owner==objc_thread_id())
|
if (!_mutex->owner || _mutex->owner==objc_thread_id())
|
||||||
{
|
{
|
||||||
result=objc_mutex_trylock(_mutex);
|
result=objc_mutex_trylock(_mutex);
|
||||||
|
@ -1199,7 +1301,7 @@ NSString *NSRecursiveLockException = @"NSRecursiveLockException";
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
locked=YES;
|
locked=YES;
|
||||||
//NSDebugMLLog(@"low",@"AFT _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id());
|
//NSDebugMLLog(@"low",@"AFT _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1236,7 +1338,7 @@ NSString *NSRecursiveLockException = @"NSRecursiveLockException";
|
||||||
BOOL locked=NO;
|
BOOL locked=NO;
|
||||||
int result=0;
|
int result=0;
|
||||||
// LOGObjectFnStart();
|
// LOGObjectFnStart();
|
||||||
// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id());
|
// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id());
|
||||||
if (!_mutex->owner || _mutex->owner==objc_thread_id())
|
if (!_mutex->owner || _mutex->owner==objc_thread_id())
|
||||||
{
|
{
|
||||||
result=objc_mutex_trylock(_mutex);
|
result=objc_mutex_trylock(_mutex);
|
||||||
|
@ -1275,7 +1377,7 @@ NSString *NSRecursiveLockException = @"NSRecursiveLockException";
|
||||||
int tryCount=0;
|
int tryCount=0;
|
||||||
int result=0;
|
int result=0;
|
||||||
// LOGObjectFnStart();
|
// LOGObjectFnStart();
|
||||||
// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id());
|
// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id());
|
||||||
if (!_mutex->owner || _mutex->owner==objc_thread_id())
|
if (!_mutex->owner || _mutex->owner==objc_thread_id())
|
||||||
{
|
{
|
||||||
tryCount++;
|
tryCount++;
|
||||||
|
@ -1293,8 +1395,8 @@ NSString *NSRecursiveLockException = @"NSRecursiveLockException";
|
||||||
{
|
{
|
||||||
tryCount++;
|
tryCount++;
|
||||||
//NSDebugMLLog(@"low",@"tmplockBeforeDate wait");
|
//NSDebugMLLog(@"low",@"tmplockBeforeDate wait");
|
||||||
usleep(100);
|
NSTimeIntervalSleep(0.010);
|
||||||
//NSDebugMLLog(@"low",@"BEF _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id());
|
//NSDebugMLLog(@"low",@"BEF _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id());
|
||||||
if (!_mutex->owner || _mutex->owner==objc_thread_id())
|
if (!_mutex->owner || _mutex->owner==objc_thread_id())
|
||||||
{
|
{
|
||||||
notOwner=NO;
|
notOwner=NO;
|
||||||
|
@ -1303,7 +1405,8 @@ NSString *NSRecursiveLockException = @"NSRecursiveLockException";
|
||||||
if (result == -1)
|
if (result == -1)
|
||||||
{
|
{
|
||||||
if (tryCount%10==0)
|
if (tryCount%10==0)
|
||||||
NSLog(@"Try lock for %d micro-secondes",100*tryCount);
|
NSLog(@"Try lock for %d ms. lock current owner=%p this thread=%p",
|
||||||
|
10*tryCount,(void*)_mutex->owner,(void*)objc_thread_id());
|
||||||
locked=NO;
|
locked=NO;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1315,7 +1418,7 @@ NSString *NSRecursiveLockException = @"NSRecursiveLockException";
|
||||||
// NSDebugMLLog(@"low",@"locked=%d",(int)locked);
|
// NSDebugMLLog(@"low",@"locked=%d",(int)locked);
|
||||||
if (locked)
|
if (locked)
|
||||||
{
|
{
|
||||||
//NSDebugMLLog(@"low",@"AFT _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id());
|
//NSDebugMLLog(@"low",@"AFT _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1350,7 +1453,7 @@ NSString *NSRecursiveLockException = @"NSRecursiveLockException";
|
||||||
int tryCount=0;
|
int tryCount=0;
|
||||||
int result=0;
|
int result=0;
|
||||||
// LOGObjectFnStart();
|
// LOGObjectFnStart();
|
||||||
// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id());
|
// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id());
|
||||||
if (!_mutex->owner || _mutex->owner==objc_thread_id())
|
if (!_mutex->owner || _mutex->owner==objc_thread_id())
|
||||||
{
|
{
|
||||||
tryCount++;
|
tryCount++;
|
||||||
|
@ -1360,7 +1463,8 @@ NSString *NSRecursiveLockException = @"NSRecursiveLockException";
|
||||||
if (result == -1)
|
if (result == -1)
|
||||||
{
|
{
|
||||||
if (tryCount%10==0)
|
if (tryCount%10==0)
|
||||||
NSLog(@"Try lock for %d micro-secondes",100*tryCount);
|
NSLog(@"Try lock for %d ms. lock current owner=%p this thread=%p",
|
||||||
|
10*tryCount,(void*)_mutex->owner,(void*)objc_thread_id());
|
||||||
locked=NO;
|
locked=NO;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1373,8 +1477,8 @@ NSString *NSRecursiveLockException = @"NSRecursiveLockException";
|
||||||
{
|
{
|
||||||
tryCount++;
|
tryCount++;
|
||||||
//NSDebugMLLog(@"low",@"tmplockBeforeDate wait");
|
//NSDebugMLLog(@"low",@"tmplockBeforeDate wait");
|
||||||
usleep(100);
|
NSTimeIntervalSleep(0.010);
|
||||||
//NSDebugMLLog(@"low",@"BEF _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id());
|
//NSDebugMLLog(@"low",@"BEF _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id());
|
||||||
if (!_mutex->owner || _mutex->owner==objc_thread_id())
|
if (!_mutex->owner || _mutex->owner==objc_thread_id())
|
||||||
{
|
{
|
||||||
notOwner=NO;
|
notOwner=NO;
|
||||||
|
@ -1383,7 +1487,8 @@ NSString *NSRecursiveLockException = @"NSRecursiveLockException";
|
||||||
if (result == -1)
|
if (result == -1)
|
||||||
{
|
{
|
||||||
if (tryCount%10==0)
|
if (tryCount%10==0)
|
||||||
NSLog(@"Try lock for %d micro-secondes",100*tryCount);
|
NSLog(@"Try lock for %d ms. lock current owner=%p this thread=%p",
|
||||||
|
10*tryCount,(void*)_mutex->owner,(void*)objc_thread_id());
|
||||||
locked=NO;
|
locked=NO;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1395,7 +1500,7 @@ NSString *NSRecursiveLockException = @"NSRecursiveLockException";
|
||||||
// NSDebugMLLog(@"low",@"locked=%d",(int)locked);
|
// NSDebugMLLog(@"low",@"locked=%d",(int)locked);
|
||||||
if (locked)
|
if (locked)
|
||||||
{
|
{
|
||||||
//NSDebugMLLog(@"low",@"AFT _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id());
|
//NSDebugMLLog(@"low",@"AFT _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1432,7 +1537,7 @@ NSString *NSRecursiveLockException = @"NSRecursiveLockException";
|
||||||
{
|
{
|
||||||
int result=0;
|
int result=0;
|
||||||
// LOGObjectFnStart();
|
// LOGObjectFnStart();
|
||||||
// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id());
|
// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id());
|
||||||
if (_mutex->owner!=objc_thread_id())
|
if (_mutex->owner!=objc_thread_id())
|
||||||
{
|
{
|
||||||
LOGException(@"NSLockException unlock: failed to unlock mutex (not owner). Called from %s in %s %d",
|
LOGException(@"NSLockException unlock: failed to unlock mutex (not owner). Called from %s in %s %d",
|
||||||
|
@ -1448,7 +1553,7 @@ NSString *NSRecursiveLockException = @"NSRecursiveLockException";
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result=objc_mutex_unlock(_mutex);
|
result=objc_mutex_unlock(_mutex);
|
||||||
//NSDebugMLLog(@"low",@"AFT _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id());
|
//NSDebugMLLog(@"low",@"AFT _mutex->owner=%p _mutex->depth=%d objc_thread_id()=%p",(void*)_mutex->owner,(int)_mutex->depth,(void*)objc_thread_id());
|
||||||
//NSDebugMLLog(@"low",@"result=%d",result);
|
//NSDebugMLLog(@"low",@"result=%d",result);
|
||||||
if (result == -1)
|
if (result == -1)
|
||||||
{
|
{
|
||||||
|
@ -2152,7 +2257,7 @@ NSString* GSWGetDefaultDocRoot()
|
||||||
case NSNumFmtType__Unknown:
|
case NSNumFmtType__Unknown:
|
||||||
default:
|
default:
|
||||||
LOGSeriousError(@"Unknown type %d to convert %@ to string",
|
LOGSeriousError(@"Unknown type %d to convert %@ to string",
|
||||||
(int)type,
|
(int)_type,
|
||||||
anObject);
|
anObject);
|
||||||
string=@"***";
|
string=@"***";
|
||||||
break;
|
break;
|
||||||
|
@ -2164,7 +2269,7 @@ NSString* GSWGetDefaultDocRoot()
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
-(BOOL)getObjectValue:(id*)anObject
|
-(BOOL)getObjectValue:(id*)anObject
|
||||||
forString:(NSString*)string
|
forString:(NSString*)string
|
||||||
errorDescription:(NSString**)error
|
errorDescription:(NSString**)error
|
||||||
{
|
{
|
||||||
BOOL ok=NO;
|
BOOL ok=NO;
|
||||||
NSAssert(anObject,@"No value* to return");
|
NSAssert(anObject,@"No value* to return");
|
||||||
|
@ -2194,3 +2299,107 @@ NSString* GSWGetDefaultDocRoot()
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
#include <Foundation/GSMime.h>
|
||||||
|
|
||||||
|
@implementation NSData (Base64)
|
||||||
|
|
||||||
|
- (NSString*) base64Representation
|
||||||
|
{
|
||||||
|
return [[[NSString alloc]initWithData:[GSMimeDocument encodeBase64:self]
|
||||||
|
encoding:NSASCIIStringEncoding] autorelease];
|
||||||
|
};
|
||||||
|
|
||||||
|
- (id) initWithBase64Representation: (NSString*)string
|
||||||
|
{
|
||||||
|
return [self initWithData:[GSMimeDocument decodeBase64:[string dataUsingEncoding: NSASCIIStringEncoding]]];
|
||||||
|
};
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation NSData (Search)
|
||||||
|
- (NSRange) rangeOfData: (NSData *)data
|
||||||
|
range: (NSRange)aRange
|
||||||
|
{
|
||||||
|
NSRange range=NSMakeRange(0,0);
|
||||||
|
if (data == nil)
|
||||||
|
[NSException raise: NSInvalidArgumentException format: @"range of nil"];
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int selfLength=[self length];
|
||||||
|
int searchedLength=[data length];
|
||||||
|
if (aRange.location<0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else if (aRange.location+aRange.length>selfLength)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else if (selfLength>0 && searchedLength>0)
|
||||||
|
{
|
||||||
|
const unsigned char* bytes=(const unsigned char*)[self bytes];
|
||||||
|
const unsigned char* searchedBytes=(const unsigned char*)[data bytes];
|
||||||
|
|
||||||
|
int searchIndex=0;
|
||||||
|
for(searchIndex=aRange.location;
|
||||||
|
searchIndex<(selfLength-searchedLength) && range.length==0;
|
||||||
|
searchIndex++)
|
||||||
|
{
|
||||||
|
int i=0;
|
||||||
|
if (bytes[searchIndex]==searchedBytes[0])
|
||||||
|
{
|
||||||
|
for(i=1;i<searchedLength && bytes[searchIndex+i]==searchedBytes[i];i++);
|
||||||
|
if (i==searchedLength)
|
||||||
|
range=NSMakeRange(searchIndex,searchedLength);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
return range;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation NSMutableData (Replace)
|
||||||
|
- (unsigned int) replaceOccurrencesOfData: (NSData*)replace
|
||||||
|
withData: (NSData*)by
|
||||||
|
range: (NSRange)searchRange
|
||||||
|
{
|
||||||
|
NSRange range;
|
||||||
|
unsigned int count = 0;
|
||||||
|
|
||||||
|
if (replace == nil)
|
||||||
|
{
|
||||||
|
[NSException raise: NSInvalidArgumentException
|
||||||
|
format: @"%@ nil search string", NSStringFromSelector(_cmd)];
|
||||||
|
}
|
||||||
|
if (by == nil)
|
||||||
|
{
|
||||||
|
[NSException raise: NSInvalidArgumentException
|
||||||
|
format: @"%@ nil replace string", NSStringFromSelector(_cmd)];
|
||||||
|
}
|
||||||
|
range = [self rangeOfData: replace
|
||||||
|
range: searchRange];
|
||||||
|
|
||||||
|
if (range.length > 0)
|
||||||
|
{
|
||||||
|
unsigned byLen = [by length];
|
||||||
|
const void* byBytes=[by bytes];
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
unsigned int newEnd;
|
||||||
|
count++;
|
||||||
|
[self replaceBytesInRange:range
|
||||||
|
withBytes:byBytes
|
||||||
|
length:byLen];
|
||||||
|
|
||||||
|
newEnd = NSMaxRange(searchRange) + byLen - range.length;
|
||||||
|
searchRange.location = range.location + byLen;
|
||||||
|
searchRange.length = newEnd - searchRange.location;
|
||||||
|
|
||||||
|
range = [self rangeOfData: replace
|
||||||
|
range: searchRange];
|
||||||
|
}
|
||||||
|
while (range.length > 0);
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
Loading…
Reference in a new issue