Skip to content

Commit

Permalink
add leak detector
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane committed Apr 26, 2024
1 parent a57ded0 commit 8896f31
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
9 changes: 5 additions & 4 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ pub fn build(b: *std.Build) !void {

const config = optionsDefault(b, .{ .target = target, .optimize = optimize });
const bdwgc = buildLibGC(b, config);
const libgc = if (config.enable_throw_bad_alloc_library)
bdwgc.artifact("gctba") // libgc + libgctba
else
bdwgc.artifact("gc");
const libgc = bdwgc.artifact("gc");
const libgctba = if (config.enable_throw_bad_alloc_library) bdwgc.artifact("gctba") else null;
const libgccxx: ?*std.Build.Step.Compile = if (config.enable_cplusplus) bdwgc.artifact("gccpp") else null;

// generate di file (like, zig-translate-c from D-importC)
Expand Down Expand Up @@ -151,6 +149,9 @@ pub fn build(b: *std.Build) !void {
if (libgccxx) |cxx| {
b.installArtifact(cxx);
}
if (libgctba) |tba| {
b.installArtifact(tba);
}
}
}
fn buildD(b: *std.Build, options: abs.DCompileStep) !void {
Expand Down
2 changes: 1 addition & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.{
.name = "bdwgc-d",
.version = "0.2.0",
.version = "0.3.0",
.dependencies = .{
.abs = .{
.url = "git+https://github.com/kassane/anotherBuildStep#main",
Expand Down
6 changes: 3 additions & 3 deletions examples/example1.d
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ void main()

foreach (i; 0 .. max)
{
auto p = cast(int**) GC_malloc(size_t.sizeof);
auto q = cast(int*) GC_malloc(size_t.sizeof);
*p = cast(int*) GC_realloc(q, size_t.sizeof * 2);
auto p = cast(int**) GC_MALLOC_ATOMIC(size_t.sizeof);
auto q = cast(int*) GC_MALLOC(size_t.sizeof);
*p = cast(int*) GC_REALLOC(q, size_t.sizeof * 2);
if (i % 100_000 == 0)
{
const heap = GC_get_heap_size();
Expand Down
3 changes: 2 additions & 1 deletion examples/example3.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import core.thread;

void main()
{
GC_set_find_leak(1);
GC_init(); // Initialize GC
GC_enable_incremental();

GC_start_incremental_collection();

auto t = new Thread(() {
int* numbers = cast(int*) GC_malloc(100 * int.sizeof);
int* numbers = cast(int*) GC_MALLOC(100 * int.sizeof);

// Populate array
foreach (i; 0 .. 100)
Expand Down
2 changes: 1 addition & 1 deletion examples/example4.d
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ extern (C++)
extern (C)
void main()
{
GC_init();
GC_set_all_interior_pointers(1);
GC_init();

auto p1 = newPerson();
auto p2 = newPerson();
Expand Down

0 comments on commit 8896f31

Please sign in to comment.