The function signature is:
extern (C) void _d_cover_register2(string filename, size_t[] valid, uint[] data, ubyte minPercent)
'valid' should point to a boolean bit-array, where the bit-value indicates whether the coverage line count is valid for the corresponding source line number. The rest of the code assumes the slice type to be 'bit[]' (see the precondition of BitArray::opIndex()), i.e. the slice points to the start of the bit-array and the slice's length field is equal to the number of valid *bits* in the array. The current type size_t[] indicates otherwise: the slice pointing to the start of the bit-array and the length field being equal to the number of valid size_ts (= valid bits divided by sizeof(size_t)).
This means the _d_cover_register2 function cannot be called from D code without very ugly slice manipulation.
I see two possibilities of fixing this. I have no preference.
1) Add a new _d_cover_register3 function, with the signature:
extern (C) void _d_cover_register3(string filename, size_t* valid_ptr, size_t valid_len, uint[] data, ubyte minPercent). Deprecate _d_cover_register2.
2) Accept the current interface of _d_cover_register2, and fix calling code (e.g. DMD), and fix the precondition of BitArray::opIndex().
I can work on a PR to fix this, but need advice on what course to take.
Thanks,
Johan
Comment #1 by jbc.engelen — 2015-04-06T12:02:14Z
Created attachment 1509
Patch for fix proposal 1
A patch explaining what I mean with option 1.
Comment #2 by jbc.engelen — 2015-04-06T12:02:53Z
Created attachment 1510
Patch for fix proposal 2
Comment #3 by jbc.engelen — 2015-04-06T12:05:12Z
Note, the BitArray code can be made much simpler by changing to a fixed-size type like ubyte, instead of using size_t:
ubyte[] valid
ubyte* valid_ptr
size_t valid_len
Comment #4 by robert.schadek — 2024-12-07T13:35:10Z