On Friday, 12 April 2013 at 16:04:09 UTC, Manu wrote:
I didn't see anywhere where it was possible to example the
current
processed environment? I only saw the mechanism for feeding
additional env
vars to the system command.
Linear array of key/value pair struct would be fine.
There's the "environment" object. It generally acts like a
string[string], and has a toAA() method that constructs a real
string[string].
Beautiful! Actually, I think if you look a couple of pages
below, I think
you'll see something rather like that already there in the
windows code.
I see, it also uses appender, although appender's buffer will be
on the heap, and there is no need for an envz array.
Thought not sure why you use a size_t array which you just cast
to a char*
array?
I think you could also fold that into one pass, rather than 2.
And I'm not sure about this line: envz[n] +=
cast(size_t)buf.data.ptr;
The problem is that the pointer to the data may change once
appender reallocates the buffer when it reaches the current
buffer's capacity. For this reason, we can't store pointers to
the strings we store, since they can "move" around until the
point that we're done appending.
I think this is the most common gotcha when writing / working
with appenders, and it bit be once too. As you can see, the code
is not completely obvious ;)
But those helpers make the problem rather painless.
I wonder if there's opportunity for improvement by having
appender support
the ~ operator? Might be able to jig it to use natural concat
syntax rather
than put()...
Allowing put() take multiple arguments would be an improvement as
well - not just in usability, but performance as well, since it
would only need to check for overflow once for all arguments.
I have this in my own appender:
https://github.com/CyberShadow/ae/blob/master/utils/appender.d
Rob Jacques was working on a Phobos appender replacement which
also had this, I believe:
http://d.puremagic.com/issues/show_bug.cgi?id=5813
Too bad nothing came out of the latter.