DIP 1021--Argument Ownership and Function Calls--Community Review Round 1

Walter Bright newshound2 at digitalmars.com
Fri Jul 19 07:59:14 UTC 2019


On 7/18/2019 6:32 PM, Walter Bright wrote:
> On 7/18/2019 4:54 PM, Exil wrote:
>> You are not limited to one example. Showing an implementation using a common 
>> RAII pattern to illustrate why it isn't sufficient and why it requires a new 
>> feature to replace/complement it.
> 
> One example is all that's necessary. Adding a bunch of irrelevant code to it 
> adds nothing.

But what the heck. Open the file:

https://github.com/dlang/dmd/blob/master/src/dmd/root/outbuffer.d

Look at line 408, peekSlice(). It returns a slice of data[].

Now look at line 132, writeByte(). It calls reserve(1). Line 50 reallocates 
data[], invalidating the pointer returned by peekSlice().

Write a function that passes both the OutBuffer reference, and the result of 
peekSlice(). In that function, call writeByte(). Boom.

The example in the DIP is the same thing, minus the 470 lines of other stuff.


More information about the Digitalmars-d mailing list