ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.85k stars 2.55k forks source link

Standard library allocators should support valgrind client requests #1837

Open daurnimator opened 5 years ago

daurnimator commented 5 years ago

To find memory leaks in zig programs, the standard library allocators should inform valgrind about allocations/frees.

This has a dependency on making valgrind client requests possible from zig code. valgrind/valgrind.h is a gnarly piece of code!

Valgrind docs: http://valgrind.org/docs/manual/mc-manual.html#mc-manual.clientreqs

Related to

andrewrk commented 5 years ago

This is a good idea. At least the general purpose allocator that we eventually have should support this, in debug mode. We'll need to balance it with the use case of comptime allocation (see #1291). (Maybe that can be solved with "use this special allocator" for comptime allocation).

Also related #896

andrewrk commented 5 years ago

And #480

andrewrk commented 5 years ago

@daurnimator your pull request was a great start to tackling this issue. It was the basis for solving #460 which is now integrated directly into the codegen of the compiler. I merged the std.valgrind module but I removed the integration with std.mem.Allocator for now. I want to work towards solving #1291 and this issue at the same time. For future reference, the integration with std.mem.Allocator code can be found here: https://github.com/ziglang/zig/commit/d633dcd07a053d76942217ca845ff2735a0ce6a2

This issue is still open, and I'm not sure yet how exactly the integration will work, whether it goes into the Allocator interface, or implementations, or something special. Whatever happens, thanks to @daurnimator's work, it's now possible for zig users' custom allocators to add valgrind integration, and example integration can be found in the above linked commit.