foxwhale icon indicating copy to clipboard operation
foxwhale copied to clipboard

Proposal: Typed containers

Open malcolmstill opened this issue 4 years ago • 1 comments

Problem

At the moment an Object has a container field of type usize that stores a pointer to one of the compositor's structures. We use @intToPtr to get a pointer to said structure. Obviously this lacks type safety.

Proposal

Using the comptime features of zig, we could at compile time, parameterise the Object with parameter T. We set container to be of type T or a pointer to type T then anywhere in the code that references Object would instead reference Object(Container) if we defined Container to be a tagged union of pointers to different types of containers.

Benefits

  • Type safety

Thoughts

  • If the wl directory is ever spun out as a library, this would become a source-only library (no dynamic linking). I'm totally fine with that, I'd rather it not be dynamically linked.

malcolmstill avatar May 08 '20 11:05 malcolmstill

Also, we should really store the index / handle of the container rather than a pointer as pointers are potentially invalidated on realloc (though we're not realloc'ing a the moment). See https://github.com/malcolmstill/foxwhale/issues/44

malcolmstill avatar Sep 14 '20 02:09 malcolmstill