mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-10 00:00:50 +00:00
Rename method to better reflect what it actually does.
This commit is contained in:
parent
39e46d214c
commit
ef0569cd4a
3 changed files with 34 additions and 24 deletions
|
@ -219,16 +219,17 @@ extern "C" {
|
||||||
* set to YES).<br />
|
* set to YES).<br />
|
||||||
* Your class then has two options for performing clean-up when the process
|
* Your class then has two options for performing clean-up when the process
|
||||||
* ends:
|
* ends:
|
||||||
* <p>1. Use the +leak: at: method to register addresses whose contents are
|
* <p>1. Use the +keep:at: method to register static/global variables whose
|
||||||
* to be either ignored or released depending on the clean-up setting in
|
* contents are to be retained for the lifetime of the program (up to exit)
|
||||||
* force when the program exits.
|
* and either ignored or released depending on the clean-up setting in force
|
||||||
|
* when the program exits.<br />
|
||||||
* This mechanism is simple and should be sufficient for many classes.
|
* This mechanism is simple and should be sufficient for many classes.
|
||||||
* </p>
|
* </p>
|
||||||
* <p>2. Implement a +atExit method to be run when the process ends and,
|
* <p>2. Implement an +atExit method to be run when the process ends and,
|
||||||
* within your +initialize implementation, call +shouldCleanUp to determine
|
* within your +initialize implementation, +registerAtExit to have your
|
||||||
* whether clean-up should be done, and if it returns YES then call
|
* +atExit method called when the process exits. Within the +atExit method
|
||||||
* +registerAtExit to have your +atExit method called when the process
|
* you may call +shouldCleanUp to determine whether celan up has been
|
||||||
* terminates.
|
* requested.
|
||||||
* </p>
|
* </p>
|
||||||
* <p>The order in which 'leaked' objects are released and +atExit methods
|
* <p>The order in which 'leaked' objects are released and +atExit methods
|
||||||
* are called on process exist is the reverse of the order in which they
|
* are called on process exist is the reverse of the order in which they
|
||||||
|
@ -241,23 +242,23 @@ extern "C" {
|
||||||
*/
|
*/
|
||||||
+ (BOOL) isExiting;
|
+ (BOOL) isExiting;
|
||||||
|
|
||||||
/** This method stored anObject at anAddress (retaining it) and notes
|
/** This method stores anObject at anAddress (which should be a static or
|
||||||
* that the object should persist until the process exits. If clean-up
|
* global variable) and retains it. The code notes that the object should
|
||||||
* is enabled the object should be released (and the address content
|
* persist until the process exits. If clean-up is enabled the object will
|
||||||
* zeroed out) upon process exit.
|
* be released (and the address content zeroed out) upon process exit.
|
||||||
* If this method is called while the process is already exiting it
|
* If this method is called while the process is already exiting it
|
||||||
* simply zeros out the memory location then returns nil, otherwise
|
* simply zeros out the memory location then returns nil, otherwise
|
||||||
* it returns the object stored at the memory location.
|
* it returns the object stored at the memory location.
|
||||||
* Raises an exception if anObject is nil or anAddress is NULL (unless
|
* Raises an exception if anObject is nil or anAddress is NULL or the old
|
||||||
* the process is already exiting).
|
* value at anAddresss is not nil (unless the process is already exiting).
|
||||||
*/
|
*/
|
||||||
+ (id) leak: (id)anObject at: (id*)anAddress;
|
+ (id) NS_RETURNS_RETAINED keep: (id)anObject at: (id*)anAddress;
|
||||||
|
|
||||||
/** DEPRECATED ... use +leak: at: instead.
|
/** DEPRECATED ... use +keep:at: instead.
|
||||||
*/
|
*/
|
||||||
+ (id) NS_RETURNS_RETAINED leak: (id)anObject;
|
+ (id) NS_RETURNS_RETAINED leak: (id)anObject;
|
||||||
|
|
||||||
/** DEPRECATED ... use +leak: at: instead.
|
/** DEPRECATED ... use +keep:at: instead.
|
||||||
*/
|
*/
|
||||||
+ (id) NS_RETURNS_RETAINED leakAt: (id*)anAddress;
|
+ (id) NS_RETURNS_RETAINED leakAt: (id*)anAddress;
|
||||||
|
|
||||||
|
|
|
@ -197,7 +197,11 @@ handleExit()
|
||||||
Method method;
|
Method method;
|
||||||
IMP msg;
|
IMP msg;
|
||||||
|
|
||||||
fprintf(stderr, "*** +[%s %s]\n", class_getName(tmp->obj), sel_getName(tmp->sel));
|
if (shouldCleanUp)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "*** clean-up +[%s %s]\n",
|
||||||
|
class_getName(tmp->obj), sel_getName(tmp->sel));
|
||||||
|
}
|
||||||
method = class_getClassMethod(tmp->obj, tmp->sel);
|
method = class_getClassMethod(tmp->obj, tmp->sel);
|
||||||
msg = method_getImplementation(method);
|
msg = method_getImplementation(method);
|
||||||
if (0 != msg)
|
if (0 != msg)
|
||||||
|
@ -211,12 +215,16 @@ fprintf(stderr, "*** +[%s %s]\n", class_getName(tmp->obj), sel_getName(tmp->sel)
|
||||||
{
|
{
|
||||||
if (tmp->obj != *(tmp->at))
|
if (tmp->obj != *(tmp->at))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "*** leaked value %p at %p changed to %p\n", tmp->obj, (const void*)tmp->at, *(tmp->at));
|
fprintf(stderr,
|
||||||
|
"*** clean-up kept value %p at %p changed to %p\n",
|
||||||
|
tmp->obj, (const void*)tmp->at, *(tmp->at));
|
||||||
tmp->obj = *(tmp->at);
|
tmp->obj = *(tmp->at);
|
||||||
}
|
}
|
||||||
*(tmp->at) = nil;
|
*(tmp->at) = nil;
|
||||||
}
|
}
|
||||||
fprintf(stderr, "*** -[%s release] %p %p\n", class_getName(object_getClass(tmp->obj)), tmp->obj, (const void*)tmp->at);
|
fprintf(stderr, "*** clean-up -[%s release] %p %p\n",
|
||||||
|
class_getName(object_getClass(tmp->obj)),
|
||||||
|
tmp->obj, (const void*)tmp->at);
|
||||||
[tmp->obj release];
|
[tmp->obj release];
|
||||||
}
|
}
|
||||||
free(tmp);
|
free(tmp);
|
||||||
|
@ -237,7 +245,7 @@ fprintf(stderr, "*** -[%s release] %p %p\n", class_getName(object_getClass(tmp->
|
||||||
return isExiting;
|
return isExiting;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (id) leak: (id)anObject at: (id*)anAddress
|
+ (id) keep: (id)anObject at: (id*)anAddress
|
||||||
{
|
{
|
||||||
struct exitLink *l;
|
struct exitLink *l;
|
||||||
|
|
||||||
|
@ -253,6 +261,7 @@ fprintf(stderr, "*** -[%s release] %p %p\n", class_getName(object_getClass(tmp->
|
||||||
NSAssert([anObject isKindOfClass: [NSObject class]],
|
NSAssert([anObject isKindOfClass: [NSObject class]],
|
||||||
NSInvalidArgumentException);
|
NSInvalidArgumentException);
|
||||||
NSAssert(anAddress != NULL, NSInvalidArgumentException);
|
NSAssert(anAddress != NULL, NSInvalidArgumentException);
|
||||||
|
NSAssert(*anAddress == nil, NSInvalidArgumentException);
|
||||||
setup();
|
setup();
|
||||||
[exitLock lock];
|
[exitLock lock];
|
||||||
for (l = exited; l != NULL; l = l->next)
|
for (l = exited; l != NULL; l = l->next)
|
||||||
|
@ -520,9 +529,9 @@ fprintf(stderr, "*** -[%s release] %p %p\n", class_getName(object_getClass(tmp->
|
||||||
|
|
||||||
/* Dummy implementation
|
/* Dummy implementation
|
||||||
*/
|
*/
|
||||||
@implementation NSObject(GSCleanup)
|
@implementation NSObject(GSCleanUp)
|
||||||
|
|
||||||
+ (id) leak: (id)anObject at: (id*)anAddress
|
+ (id) keep: (id)anObject at: (id*)anAddress
|
||||||
{
|
{
|
||||||
ASSIGN(*anAddress, anObject);
|
ASSIGN(*anAddress, anObject);
|
||||||
return *anAddress;
|
return *anAddress;
|
||||||
|
|
|
@ -223,7 +223,7 @@ GSDomainFromDefaultLocale(void)
|
||||||
*/
|
*/
|
||||||
if (saved == nil)
|
if (saved == nil)
|
||||||
{
|
{
|
||||||
[NSObject leak: AUTORELEASE([dict copy]) at: &saved];
|
[NSObject keep: AUTORELEASE([dict copy]) at: &saved];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue