Repository navigation
size_t cast cleanup - #6982
size_t cast cleanup#6982
size_t cast cleanup#6982Conversation
|
Is this pr dead? |
|
personally, I'm a bit under the weather. appreciate your patience. |
aitap
left a comment
There was a problem hiding this comment.
Most changes are fine, but let's at least commit to use native-sized offsets in the new code and keep fixed-size integers for pre-mmap file sizes and MSVCRT compatibility kludges.
| static const char* strlim(const char *ch, int64_t limit) { | ||
| static char buf[1002]; | ||
| static int flip = 0; | ||
| char *ptr = buf + 501 * flip; | ||
| flip = 1 - flip; | ||
| char *ch2 = ptr; | ||
| if (limit>500) limit=500; | ||
| size_t width = 0; | ||
| limit = imin(limit, 500); | ||
| int64_t width = 0; |
There was a problem hiding this comment.
Could you please explain again why this these two types need to be changed from size_t to int64_t? Isn't it the size of space to be taken in the internal buffer, buf? On a 32-bit system it would be definitely wasteful.
There was a problem hiding this comment.
@badasahog please weigh in here; we can address in follow-up
| // own page (4k) of the final column, hence 1000 rows of the smallest type (4 byte int) is just | ||
| // under 4096 to leave space for R's header + malloc's header. | ||
| size_t chunkBytes = umax((size_t)(1000*meanLineLen), 1ULL/*MB*/ *1024*1024); | ||
| int64_t chunkBytes = umax((uint64_t)(1000*meanLineLen), 1ULL/*MB*/ *1024*1024); |
There was a problem hiding this comment.
This is used to construct offsets into the memory-mapped file. It should be a native-sized integer, not a fixed-size integer.
There was a problem hiding this comment.
@badasahog please weigh in here; we can address in follow-up
|
hi @badasahog there are still pending review comments for response from you |
| } else { | ||
| ch = (jump == nJumps-1) ? eof - (size_t)(0.5*jump0size) : // to almost-surely sample the last line | ||
| pos + (size_t)jump*((size_t)(eof-pos)/(size_t)(nJumps-1)); | ||
| ch = (jump == nJumps-1) ? eof - (ptrdiff_t)(0.5*jump0size) : // to almost-surely sample the last line |
There was a problem hiding this comment.
Thank you for the improvements! Would you recommend rewriting (ptrdiff_t)(0.5*jump0size) to jump0size/2 and avoiding the floating point operation and the cast altogether? They do get compiled differently, even at -O2.
There was a problem hiding this comment.
@badasahog please weigh in here; we can address in follow-up
There are a lot of casts to/from
size_tthat didn't need to exist.In addition,
size_twas often used as a shorthand forint64_twhich not only inappropriate, but potentially wasteful becausesize_tis unsigned, which means that overflow wrapping would slip through the sanitizer.There are probably other examples of this, which I've left out