Skip to content
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

Removing long (part 7): Various miscellaneous changes #31550

Merged
merged 19 commits into from
Jun 18, 2019

Conversation

jbytheway
Copy link
Contributor

@jbytheway jbytheway commented Jun 17, 2019

Summary

SUMMARY: Infrastructure "Remove most uses of long and unsigned long from the code"

Purpose of change

My ongoing campaign to remove uses of long.

Describe the solution

Many assorted small changes. Mostly they just come down to changing long or unsigned long to either int, size_t, uint32_t, or int64_t as seems appropriate, or suppressing the warnings if long is the right choice. Some other things:

  • Use explicit conversion to bool on item_location.
  • Removed a random unnecessary old-style cast.
  • Updated a comment.

See the individual commit comments for details.

Additional context

I think this is essentially all the remaining uses of long caught and dealt with, but there are probably a couple more lurking (there are some uses that my clang-tidy check can't find, for example in code that isn't compiled in this configuration).

@ZhilkinSerg ZhilkinSerg added [C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style labels Jun 17, 2019
@kevingranade
Copy link
Member

MINGW and XCode are both unhappy:

line_test.cpp: In function 'void line_to_comparison(int)':
line_test.cpp:341:39: error: format '%ld' expects argument of type 'long int', but argument 3 has type 'int64_t {aka long long int}' [-Werror=format=]
                     iterations, diff1 );
                                       ^
line_test.cpp:343:39: error: format '%ld' expects argument of type 'long int', but argument 3 has type 'int64_t {aka long long int}' [-Werror=format=]
                     iterations, diff2 );
                                       ^

@ZhilkinSerg ZhilkinSerg self-assigned this Jun 17, 2019
@ZhilkinSerg
Copy link
Contributor

When building under MSYS2:

line_test.cpp: In function 'void line_to_comparison(int)':
line_test.cpp:341:21: error: ISO C++11 does not support the 'I' printf flag [-Werror=format=]
             printf( "line_to() executed %d times in %" PRId64 " microseconds.\n",
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
line_test.cpp:341:21: error: format '%d' expects argument of type 'int', but argument 3 has type 'int64_t' {aka 'long long int'} [-Werror=format=]
line_test.cpp:343:21: error: ISO C++11 does not support the 'I' printf flag [-Werror=format=]
             printf( "canonical_line_to() executed %d times in %" PRId64 " microseconds.\n",
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
line_test.cpp:343:21: error: format '%d' expects argument of type 'int', but argument 3 has type 'int64_t' {aka 'long long int'} [-Werror=format=]
cc1plus.exe: all warnings being treated as errors
make[1]: *** [Makefile:45: objwin/tiles/line_test.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: Leaving directory '/c/Projects/Cataclysm-DDA/tests'
make: *** [Makefile:1043: tests] Error 2

jbytheway added 18 commits June 18, 2019 07:43
item_location had a hacky workaround to suppress implicit conversion to
int (give that it had a conversion to bool).

This probably dates to an old compiler or something like that.  Removed
the workaround and simply made the conversion to bool explicit.
When overloading different integer types, it's necessary to explicitly
use long, because otherwise you can't get exact coverage of the various
integer types.
mission::value (which is what this function returns) had already been
converted to int.
I'm not sure this function is even actually used, but in any case it
needn't process longs.
SDL_GetTicks returns a Uint32, so this seems a good fit.
TTF_FontFaces returns a long, so it's a reasonable choice for this use
case.
Lots of unnecessary longs here, like the number of tiles travelled.
This is only ever equal to 1 or 7, as far as I can see.
Amongst other things, switch mod_manager_ui selection from long to
size_t

This was written as if it might be negative, but none of the callers
could ever make it so, and the code is just much simpler if it's a
size_t.
@@ -102,7 +102,8 @@ TEST_CASE( "lru_cache_perf", "[.]" )
}
}
const auto end1 = std::chrono::high_resolution_clock::now();
const long diff1 = std::chrono::duration_cast<std::chrono::microseconds>( end1 - start1 ).count();
const int64_t diff1 = std::chrono::duration_cast<std::chrono::microseconds>
( end1 - start1 ).count();
printf( "completed %d insertions in %ld microseconds.\n", max_size, diff1 );
Copy link
Contributor

@ZhilkinSerg ZhilkinSerg Jun 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
printf( "completed %d insertions in %ld microseconds.\n", max_size, diff1 );
printf( "completed %d insertions in %lld microseconds.\n", max_size, diff1 );

Can't find any format specifier that works portably for int64_t (PRId64
is problematic on MSYS) so just use long longs instead.
@jbytheway
Copy link
Contributor Author

Jenkins rebuild

@kevingranade kevingranade merged commit dfcb4d2 into CleverRaven:master Jun 18, 2019
@ZhilkinSerg ZhilkinSerg removed their assignment Jun 19, 2019
@jbytheway jbytheway deleted the remove_long_misc branch June 19, 2019 06:39
@jbytheway jbytheway mentioned this pull request Jun 19, 2019
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants