mixxx icon indicating copy to clipboard operation
mixxx copied to clipboard

User more gsl::not_null

Open daschuer opened this issue 3 years ago • 0 comments

I couldn't resist to try to get rid of the party stopping runtime checks of gsl::not_null.

This is the case when the compiler sees null checks in our own code. So I went ahead creating a wrapper header that checks this by turning the runtime checks into link-time checks. It is a drop in replacement for #include <gsl/pointers> and re-defines the Expects(a) and Ensures(a) macros as link-time assertions. https://github.com/daschuer/mixxx/blob/not_null_link_assert/src/util/not_null_link_assert.h

With this in place, I found the changes presented in this PR, required to have no run-time null check in the constructor. Unfortunately without this wrapping header there is still a null check involved with each copy by a pedantic "Postcondition" that verifies that gsl::not_null template itself works.

Here you see the failing workflow without this PR: https://github.com/daschuer/mixxx/actions/runs/2807983581

And this is the workflow using not_null_link_assert.h and the changes from this PR: https://github.com/daschuer/mixxx/actions/runs/2807984837

I would like to include not_null_link_assert.h in a second PR to make sure all null checks are in place before creating a not_null pointer in future changes as well.

The changes of this PR should be non-controversial.

What do you think?

daschuer avatar Aug 06 '22 15:08 daschuer

Merged since this is small improvements that have been open for a while.

ferranpujolcamins avatar Aug 17 '22 20:08 ferranpujolcamins

Thank you.

daschuer avatar Aug 18 '22 09:08 daschuer