Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to enforce that the GC is not running #186

Merged
merged 1 commit into from
Dec 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions source/vibe/internal/allocator.d
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,25 @@ void disposeGCSafe(T, Allocator)(Allocator allocator, T obj)
GC.removeRange(cast(void*)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);
}
}