mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Fix deallocation of placeholder strings at exit.
This commit is contained in:
parent
4185b687f2
commit
43484b2c34
2 changed files with 34 additions and 11 deletions
|
@ -878,7 +878,23 @@ register_printf_atsign ()
|
|||
|
||||
+ (void) atExit
|
||||
{
|
||||
DESTROY(placeholderMap);
|
||||
/* Deallocate all the placeholders in the map before destroying it.
|
||||
*/
|
||||
GS_MUTEX_LOCK(placeholderLock);
|
||||
if (placeholderMap)
|
||||
{
|
||||
NSMapEnumerator mEnum = NSEnumerateMapTable(placeholderMap);
|
||||
Class c;
|
||||
id o;
|
||||
|
||||
while (NSNextMapEnumeratorPair(&mEnum, (void *)&c, (void *)&o))
|
||||
{
|
||||
NSDeallocateObject(o);
|
||||
}
|
||||
NSEndMapTableEnumeration(&mEnum);
|
||||
DESTROY(placeholderMap);
|
||||
}
|
||||
GS_MUTEX_UNLOCK(placeholderLock);
|
||||
DESTROY(nonBase);
|
||||
DESTROY(rPathSeps);
|
||||
DESTROY(uPathSeps);
|
||||
|
@ -956,7 +972,7 @@ register_printf_atsign ()
|
|||
*/
|
||||
GS_MUTEX_LOCK(placeholderLock);
|
||||
obj = (id)NSMapGet(placeholderMap, (void*)z);
|
||||
if (obj == nil)
|
||||
if (obj == nil && NO == [NSObject isExiting])
|
||||
{
|
||||
/*
|
||||
* There is no placeholder object for this zone, so we
|
||||
|
|
|
@ -24,7 +24,8 @@ int main()
|
|||
int i = 256;
|
||||
char buf[32];
|
||||
NSString *s;
|
||||
NSString *testObj = [NSString stringWithCString: "Hello\n"];
|
||||
NSData *d;
|
||||
NSString *testObj = [NSString stringWithCString: "Hello\n"];
|
||||
|
||||
while (i-- > 0)
|
||||
{
|
||||
|
@ -49,21 +50,25 @@ int main()
|
|||
isKindOfClass: [NSString class]]
|
||||
&& ![s isKindOfClass: [NSMutableString class]],
|
||||
"[NSString initWithCharacters:length:] creates immutable string for ascii");
|
||||
DESTROY(s);
|
||||
|
||||
PASS([(s = [[NSMutableString alloc] initWithCharacters: &u0 length: 1])
|
||||
isKindOfClass: [NSString class]]
|
||||
&& [s isKindOfClass: [NSMutableString class]],
|
||||
"[NSMutableString initWithCharacters:length:] creates mutable string for ascii");
|
||||
DESTROY(s);
|
||||
|
||||
PASS([(s = [[NSString alloc] initWithCharacters: &u1 length: 1])
|
||||
isKindOfClass: [NSString class]]
|
||||
&& ![s isKindOfClass: [NSMutableString class]],
|
||||
"[NSString initWithCharacters:length:] creates immutable string for unicode");
|
||||
DESTROY(s);
|
||||
|
||||
PASS([(s = [[NSMutableString alloc] initWithCharacters: &u1 length: 1])
|
||||
isKindOfClass: [NSString class]]
|
||||
&& [s isKindOfClass: [NSMutableString class]],
|
||||
"[NSMutableString initWithCharacters:length:] creates mutable string for unicode");
|
||||
DESTROY(s);
|
||||
|
||||
PASS_EXCEPTION([[NSString alloc] initWithString: nil];,
|
||||
NSInvalidArgumentException,
|
||||
|
@ -81,6 +86,7 @@ int main()
|
|||
isKindOfClass: [NSString class]]
|
||||
&& [s length] == 256,
|
||||
"can create latin1 string with 256 values");
|
||||
DESTROY(s);
|
||||
|
||||
PASS([(s = [[NSString alloc] initWithBytes: bytes
|
||||
length: 128
|
||||
|
@ -88,6 +94,7 @@ int main()
|
|||
isKindOfClass: [NSString class]]
|
||||
&& [s length] == 128,
|
||||
"can create ascii string with 128 values");
|
||||
DESTROY(s);
|
||||
|
||||
PASS(nil == [[NSString alloc] initWithBytes: bytes
|
||||
length: 256
|
||||
|
@ -97,18 +104,18 @@ int main()
|
|||
s = [[NSString alloc] initWithBytes: bytes
|
||||
length: 256
|
||||
encoding: NSISOLatin1StringEncoding];
|
||||
s = [[NSString alloc]
|
||||
initWithData: [s dataUsingEncoding: NSNonLossyASCIIStringEncoding]
|
||||
encoding: NSASCIIStringEncoding];
|
||||
d = [s dataUsingEncoding: NSNonLossyASCIIStringEncoding];
|
||||
DESTROY(s);
|
||||
s = [[NSString alloc] initWithData: d encoding: NSASCIIStringEncoding];
|
||||
PASS_EQUAL(s, @"\\000\\001\\002\\003\\004\\005\\006\\007\\010\t\n\\013\\014\r\\016\\017\\020\\021\\022\\023\\024\\025\\026\\027\\030\\031\\032\\033\\034\\035\\036\\037 !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\\177\\200\\201\\202\\203\\204\\205\\206\\207\\210\\211\\212\\213\\214\\215\\216\\217\\220\\221\\222\\223\\224\\225\\226\\227\\230\\231\\232\\233\\234\\235\\236\\237\\240\\241\\242\\243\\244\\245\\246\\247\\250\\251\\252\\253\\254\\255\\256\\257\\260\\261\\262\\263\\264\\265\\266\\267\\270\\271\\272\\273\\274\\275\\276\\277\\300\\301\\302\\303\\304\\305\\306\\307\\310\\311\\312\\313\\314\\315\\316\\317\\320\\321\\322\\323\\324\\325\\326\\327\\330\\331\\332\\333\\334\\335\\336\\337\\340\\341\\342\\343\\344\\345\\346\\347\\350\\351\\352\\353\\354\\355\\356\\357\\360\\361\\362\\363\\364\\365\\366\\367\\370\\371\\372\\373\\374\\375\\376\\377", "latin1 in lossy encoding");
|
||||
NSLog(@"%lu '%s'", [s length], [s UTF8String]);
|
||||
RELEASE(s);
|
||||
DESTROY(s);
|
||||
|
||||
s = [[NSString alloc]
|
||||
initWithData: [@"€" dataUsingEncoding: NSNonLossyASCIIStringEncoding]
|
||||
encoding: NSASCIIStringEncoding];
|
||||
PASS_EQUAL(s, @"\\u20ac", "euro in lossy encoding");
|
||||
RELEASE(s);
|
||||
DESTROY(s);
|
||||
|
||||
s = [[NSString alloc] initWithBytes: "\\"
|
||||
length: 1
|
||||
|
@ -124,19 +131,19 @@ int main()
|
|||
length: 2
|
||||
encoding: NSNonLossyASCIIStringEncoding];
|
||||
PASS_EQUAL(s, @"\\", "lossy backslash-backslash is backslash");
|
||||
RELEASE(s);
|
||||
DESTROY(s);
|
||||
|
||||
s = [[NSString alloc] initWithBytes: "\\101"
|
||||
length: 4
|
||||
encoding: NSNonLossyASCIIStringEncoding];
|
||||
PASS_EQUAL(s, @"A", "lossy backslassh-101 is A");
|
||||
RELEASE(s);
|
||||
DESTROY(s);
|
||||
|
||||
s = [[NSString alloc] initWithBytes: "\\u20ac"
|
||||
length: 6
|
||||
encoding: NSNonLossyASCIIStringEncoding];
|
||||
PASS_EQUAL(s, @"€", "lossy backslassh-u20ac is a euro");
|
||||
RELEASE(s);
|
||||
DESTROY(s);
|
||||
|
||||
s = makeFormattedString(@"%d.%d%s", 10, 20, "hello");
|
||||
PASS_EQUAL(s, @"10.20hello", "simple intWithFormat: works");
|
||||
|
|
Loading…
Reference in a new issue