Refactoring and style cleanup with C++
Rangi42 opened this issue · 3 comments
Rangi42 commented
- Don't use redundant
struct
keyword in types.
This regex will fix the single-lines ones:perl -pe 's/\bstruct (\w+)\b(?! \{)(?=.+[;{)]$)/\1/g'
; just double-check for wrappedfor (...;
lines. - Use
nullptr
instead ofNULL
. - Use
()
instead of(void)
. - Use references instead of
NONNULL
pointers (C++ doesn't support[static 1]
) - Use
std::variant
instead ofunion
- Replace functions with methods:
foo_Bar(struct Foo *foo, ...)
intoFoo::bar(...)
- Get rid of
((m|c|re)alloc|strdup)
- Define constructors with default field values (and optimize some
push
es toemplace
ment) - Get rid of
new (std::nothrow)
in favor of automatic allocation with RAII- This will require the rgbasm parser to use variants and complete symbols like the linker script one does
- Re-enable ASan for rgbasm if this succeeds
src/asm/lexer.cpp:2206: lexerState->captureBuf = new (std::nothrow) std::vector<char>(); src/asm/symbol.cpp:503: std::string_view *macro = new (std::nothrow) std::string_view(body, size);
ISSOtm commented
We should look into updating NONNULL
to use [[gnu::nonnull]]
instead.
(Also, in general, replacing __attribute__((ATTR))
with [[gnu::ATTR]]
instead. This would make less code platform-specific!)
Rangi42 commented
Most if not all of the NONNULL
s should be references, as should many other functions which take pointers assumed not to be null.
Rangi42 commented
After the last few weeks of refactoring, RAII, smart pointers, etc, I'm declaring this done. There are two new (std::nothrow)
s left, both involved with how the lexer's files/mmaps/EQUs/interpolations/macro args can "leak as a feature", and fixing that (and re-enabling ASan) is a matter for #709.