Neat project: add pointer capability to std.bitmanip.bitfields

Vladimir Panteleev via Digitalmars-d digitalmars-d at puremagic.com
Thu Dec 3 01:11:12 PST 2015


On Thursday, 3 December 2015 at 01:31:05 UTC, rsw0x wrote:
> On Wednesday, 2 December 2015 at 19:54:26 UTC, Vladimir 
> Panteleev wrote:
>> On Wednesday, 2 December 2015 at 19:39:47 UTC, Andrei 
>> Alexandrescu wrote:
>>> Once done, this is a fantastic example of (a) the power of 
>>> generative programming, and (b) the advantages of using 
>>> library facilities instead of built-in features.
>>>
>>> https://issues.dlang.org/show_bug.cgi?id=15397
>>>
>>> Who would want to take it?
>>
>> Warning, this is very unsafe and incompatible with the GC. 
>> Bit-twiddling GC pointers can lead to memory corruption and 
>> very hard-to-track bugs. Such a feature must be opt-in in a 
>> very explicit way.
>
> Iirc I'm the one that originally brought this up. There's no 
> reason for lsb smuggling in pointers to be unsafe

True, assuming that:

1. The pointers are still aligned at machine word boundaries
2. The underlying storage type is one that the GC will scan for 
pointers (e.g. void or void*, not size_t/ubyte)
3. The setters enforce that the discarded pointer bits were zero
4. No more than 4 bits are reused (as the smallest GC object size 
is 16 bytes)

Point 4 actually relies on the GC's current implementation, which 
could be an issue (it ties what is allowed to compile in code 
using the standard library with an implementation detail).



More information about the Digitalmars-d mailing list