Pitfalls of delegates inside ranges
Artur Skawina
art.08.09 at gmail.com
Mon Sep 2 11:50:13 PDT 2013
On 09/02/13 20:21, Joseph Rushton Wakeling wrote:
> On 02/09/13 19:31, Artur Skawina wrote:
>> "Fixing" type system bugs by adding library helpers is not really a good
>> idea. '.funcptr' returning incorrect type (and 'typeof(T.method)' etc)
>> needs to be fixed properly. Until that happens, the alternatives are:
>> a) convention - don't directly access these wrongly-typed pointers;
>> b) cast to (void*) (or the correct type) and back; ugly and still un at safe;
>> c) wrap the pointer, this way it's at least a little bit harder to
>> mistakenly use the bogus type.
>
> Do you want to take a quick look at the proposed patch to std.random and see if there's anything obviously risky about it? No pressure, but would be nice to have your comments.
> https://github.com/D-Programming-Language/phobos/pull/1533/files
I'm not qualified.
But it looks like it could work, just that I'd document the hack (the fact
that '_skip' is not a normal, working function pointer, but it's actually a
pointer to a method, is missing an argument and is incorrectly typed.
Otherwise someone reading that code later will a) miss this fact, then b)
notice what's going on, and c) wonder if it's really ok, which may not be
obvious when looking just at the code, and not the patch that introduced it.
Or even - a1) modify the code w/o realizing that calling `_skip` is not valid...
So it needs to be well documented. No idea however how phobos handles this;
I try to avoid D's std libs at all costs. (Dealing with the bugs is much
more expensive than just writing everything from scratch). So ignore me. :)
artur
More information about the Digitalmars-d-learn
mailing list