Forum Navigation
D oriented System library
Posted: 03/08/07 12:06:24There are some things, I don't like, when D/Tango just wraps the libc.
First is the memory, as D is garbage collected, C is not, you must be very careful when interacting with both. The getcwd memory leak showed this, as getcwd allocated memory, you must free.
Second are zero terminated strings... horrible thing, when you want to pass a slice of your favourite string to the kernel, as you cannot put a \0 after the end (as it's a slice, there might be something useful) and at least the linux kernel does not depend on zero terminated strings in IO, as you always pass the length of your buffer as a parameter (which has to be calculated via strlen() by the libc, although your D program exactly knows the length...)
What I'd like to see, is a D-optimized kernel interface.
I already started a litte C library, but glibc-code is nearly unreadable ;-) But for example, implementing linux syscalls is very easy!
As one of the most important things of D is, that it's C-compatible, this system library must be written in C and must do all those things, the POSIX people want it to do (at least!). But the design would be completely different, as it's D oriented, so it defers the zero-terminated-string stuff to the C part and let's D access the kernel as fast as possible.
Another idea is to make the complete memory management (also of the C part) garbage collected. (If we're already rewriting everything, why not this way <g> ) Or make it at least modular enough to test both variants.
Maybe this should not be discussed here, but as the average D programmer just uses Tango and is not interested, how it's done inside, a D oriented system library is most interesting for the Tango team.
Any ideas, recommendations?