-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make code more explicit and safe #13
base: master
Are you sure you want to change the base?
Conversation
These are a lot of changes. Could you please break them down by group and run the tests (at the very least on a recent version of Linux)? There’s a good chance we’ll need to do “mop-up” later fixing things on other platforms, but I’d like to review your changes quickly/efficiently and is sensible batches. The less changes, the more efficiently I can review, then merge them. |
aa50e8a
to
8bdf746
Compare
Lines 797 to 807 in 4b39412
In this case, should it throw an exception: Lines 153 to 165 in 4b39412
Other tests pass without any problem. |
Fixed the test for now. Please notify me if there is any problem with this fix. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can only guess why @jmmv wrote it this way, but in K&R C (which predates C++), the ()
form vs the (void)
form can be problematic: https://stackoverflow.com/a/7412301 . I honestly think it's best to be explicit -- it gets programmers into a habit of being explicit, which (given ATF) is important as it can introduce bugs in C.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove redundant qualifiers
I personally believe removing namespace qualifiers like this can prove itself more problematic in the long run, much like star imports in python. It makes it difficult to understand where code lives and can result in accidental namespace collisions.
Using better to be explicit and keep the namespace qualifiers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove redundant static definition
Again, I can only guess @jmmv 's original intentions, but using static
in C code at least can result in more optimal code with -O0
and can avoid namespace collisions and function/variable shadowing.
It's better to leave static
in IMHO to be explicit and to avoid these kinds of issues, for the reasoning I provided in my last comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace <cstring> with <string>
NAK: std::strcmp
(which is used in this source file) is exposed via cstring
, not string
: https://en.cppreference.com/w/cpp/string/byte/strcmp .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not include unused headers
NAK:
- lua.hpp is used for definitions like
lua_State
. It's best to be explicit, not implicit. - lutok/state.ipp: unsure if this is actually used.
- cstring: this appears to be unused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use std::move()
NAK:
This code seems like it would be less performant now with -O0
since it's passing by value instead of by reference. Also, depending on how it's called it could result in more data copies on input.
I think the former form is better: it's more explicit and less "by side-effect" than the new form.
@ngie-eign I tried to build on macOS 15, but I get this error while running
Is this a bug? |
Did you run |
Signed-off-by: Minsoo Choo <[email protected]>
This avoids unintentional implicit conversions.
Const-qualification of parameters only has an effect in function definitions.
Repeating the return type from the declaration should be avoided.
This helps avoiding duplicating the type name.
Static definition in anonymous namspace is redundant
Sorry my bad. I didn't install lua which was the issue. Build success on macOS 15. |
I'm trying to test on FreeBSD, but pkgconf and lua54 are installed.
|
NULL
withnullptr
void
in function declaration/definitionconst
throw()
andauto_ptr
static_cast<>
for type conversion