[dmd-internals] Asserts

Don Clugston dclugston at gmail.com
Fri Nov 9 01:14:17 PST 2012


On 9 November 2012 08:40, David Held <dmd at wyntrmute.com> wrote:
> My personal policy is to assert early and assert often.  I see many
> functions taking pointer args and dereferencing them without checking for
> NULL first.  I know Walter likes to claim that dmd doesn't have any NPEs
> because he is a careful coder; but the fact is, he is not the only coder,
> and most functions don't explicitly document which arguments are allowed to
> be NULL and/or when.  Of course, it would be better for non-null arguments
> to just pass by reference, but fixing that would be quite disruptive in most
> cases (and outright infeasible in others, like void*).
>
> However, I also know that asserting in every function is a religious issue
> for some, so I thought I would ask the dev community about thoughts on this
> topic.
>
> Dave

I don't think it buys much -- as Walter says, you get hardware asserts
anyway. Historically, there have never been many DMD segfaults in
Bugzilla , and they are the easiest type of bug to fix. More
importantly, a significant fraction of the DMD segfaults I've seen
were _not_ null pointers. Instead, the nasty ones are always caused by
an incorrect cast, resulting in a wrong vtable.
There are a *huge* number of casts in the code, it would be great to
reduce the number. The changes to the Array struct were a huge
improvement. I'm sure we can do more.


More information about the dmd-internals mailing list