I can crash program (core.exception.InvalidMemoryOperationError) by using __FUNCTION__ in a class ctor
James Blachly
james.blachly at gmail.com
Fri Jan 18 16:37:58 UTC 2019
On Friday, 18 January 2019 at 15:42:55 UTC, Steven Schveighoffer
wrote:
> On 1/18/19 10:35 AM, Steven Schveighoffer wrote:
>
>>
>> https://github.com/blachlylab/dhtslib/blob/master/source/dhtslib/htslib/hts_log.d#L94
>>
>>
>> That is your problem. toStringz is going to attempt to
>> allocate using the GC. Allocating during a GC collection
>> causes an InvalidMemoryOperationError.
>>
>> Take that out of your destructor, and you should not cause
>> that error.
>>
>> Alternatively, fix the logger so it doesn't use the GC.
>
> If I had to guess why __FUNCTION__ causes it and others do not,
> then I would say it's because toStringz has particular cases
> where it DOESN'T allocate, and that depends completely on the
> length of the string.
>
> https://github.com/dlang/phobos/blob/master/std/string.d#L364-L365
>
> -Steve
Steve: Thanks for your quick reply. Why does manipulation of the
default constructor, which is never called, affect whether or not
the destructor throws the error?
James
More information about the Digitalmars-d
mailing list