Merge pull request #186 from gedaiu/patch-1
Add a way to enforce that the GC is not running
This commit is contained in:
commit
8792e315a4
|
@ -39,3 +39,25 @@ void disposeGCSafe(T, Allocator)(Allocator allocator, T obj)
|
||||||
GC.removeRange(cast(void*)obj);
|
GC.removeRange(cast(void*)obj);
|
||||||
allocator.dispose(obj);
|
allocator.dispose(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ensureNotInGC(T)(string info = null) nothrow
|
||||||
|
{
|
||||||
|
import core.exception : InvalidMemoryOperationError;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
import core.memory : GC;
|
||||||
|
cast(void) GC.malloc(1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
catch(InvalidMemoryOperationError e)
|
||||||
|
{
|
||||||
|
import core.stdc.stdio : fprintf, stderr;
|
||||||
|
import core.stdc.stdlib : exit;
|
||||||
|
fprintf(stderr,
|
||||||
|
"Error: clean-up of %s incorrectly depends on destructors called by the GC.\n",
|
||||||
|
T.stringof.ptr);
|
||||||
|
if (info)
|
||||||
|
fprintf(stderr, "Info: %s\n", info.ptr);
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue