Skip to content

Fix compiler warnings in _zoneinfo.c #20342

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

Merged
merged 3 commits into from
May 27, 2020
Merged

Conversation

pablogsal
Copy link
Member

@pablogsal pablogsal commented May 24, 2020

D:\a\cpython\cpython\Modules\_zoneinfo.c(903,52): warning C4267: '=': conversion from 'size_t' to 'unsigned int', possible loss of data [D:\a\cpython\cpython\PCbuild\_zoneinfo.vcxproj]
D:\a\cpython\cpython\Modules\_zoneinfo.c(904,44): warning C4267: '=': conversion from 'size_t' to 'unsigned int', possible loss of data [D:\a\cpython\cpython\PCbuild\_zoneinfo.vcxproj]
D:\a\cpython\cpython\Modules\_zoneinfo.c(1772,31): warning C4244: '=': conversion from 'ssize_t' to 'uint8_t', possible loss of data [D:\a\cpython\cpython\PCbuild\_zoneinfo.vcxproj]

@pablogsal pablogsal force-pushed the zoneinfo branch 2 times, most recently from 913b482 to 9faef06 Compare May 24, 2020 03:58
@pablogsal
Copy link
Member Author

Changed also all ssize_t to Py_ssize_t

@pablogsal
Copy link
Member Author

pablogsal commented May 24, 2020

Hummm, there are still some places where there may be loss of data:

D:\a\cpython\cpython\Modules\_zoneinfo.c(1790,35): warning C4244: 'function': conversion from 'Py_ssize_t' to 'uint8_t', possible loss of data [D:\a\cpython\cpython\PCbuild\_zoneinfo.vcxproj]
D:\a\cpython\cpython\Modules\_zoneinfo.c(1790,41): warning C4244: 'function': conversion from 'Py_ssize_t' to 'uint8_t', possible loss of data [D:\a\cpython\cpython\PCbuild\_zoneinfo.vcxproj]
D:\a\cpython\cpython\Modules\_zoneinfo.c(1790,46): warning C4244: 'function': conversion from 'Py_ssize_t' to 'uint8_t', possible loss of data [D:\a\cpython\cpython\PCbuild\_zoneinfo.vcxproj]

but these require possible changes in CalendarRule values.... Why are these uint8_t?

@pganssle
Copy link
Member

I am really not a fan of this. These are blighted unsigned values, there is no reason to use signed data types for this.

@pablogsal
Copy link
Member Author

Yeah, I can see that. How do you want to proceed? There is still some mismatch with the precision of some of these types. I lack context on many of these so maybe is better to scope this PR on the ssize_t -> Py_ssize_t and you could fix the others in a separate one?

@pganssle
Copy link
Member

@pablogsal Yeah, I'm comfortable with changing ssize_t -> Py_ssize_t. We can also change num_* to size_t rather than ssize_t.

We can look at the uint8_t stuff later, but I think those are logically uint8_t, so I'd rather use assertions and/or error handling to enforce that rather than mess with the types.

@pablogsal
Copy link
Member Author

@pganssle Ok, if I not mistaken this PR should contain what you proposed. Could you please check if everything is ok with you?

@pganssle
Copy link
Member

@pablogsal So I created this equivalent PR on the backport, which in some ways addresses the "loss of precision" issues. I'm not sure, can we disable the error on the uint8_t? I believe it's basically a false alarm; the function that's called returns the result of subtracting two char values, so the maximum range should be [255,255]. The current error checking logic uses tmp < 0, so the result is guaranteed to fit into a uint8_t.

That said, we can change the error check to also raise with tmp >= 256, like I've done in the other PR, but that did not fix the compiler warning.

@pablogsal
Copy link
Member Author

I'm not sure, can we disable the error on the uint8_t? I believe it's basically a false alarm; the function that's called returns the result of subtracting two char values, so the maximum range should be [255,255]. The current error checking logic uses tmp < 0, so the result is guaranteed to fit into a uint8_t.

That said, we can change the error check to also raise with tmp >= 256, like I've done in the other PR, but that did not fix the compiler warning.

I would prefer to discuss that in a different PR as potentially involves reorganising some of the code (although the most likely outcome is suppressing the error).

@pganssle
Copy link
Member

I would prefer to discuss that in a different PR as potentially involves reorganising some of the code (although the most likely outcome is suppressing the error).

OK, do you want to comment on the backport PR? I'm planning to fix both at once in the backport.

@pganssle
Copy link
Member

I believe this solves https://bugs.python.org/issue40686, correct?

@pablogsal
Copy link
Member Author

I believe this solves https://bugs.python.org/issue40686, correct?

Yeah it should.

Btw I would like to have the same code for the fix as the backport so we can keep those in sync. I will update this PR shortly

@pablogsal
Copy link
Member Author

@pganssle I have updated the PR with the latest changes in your backport

@miss-islington
Copy link
Contributor

@pablogsal: Status check is done, and it's a success ✅ .

@miss-islington miss-islington merged commit e4799b9 into python:master May 27, 2020
@miss-islington
Copy link
Contributor

Thanks @pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.9.
🐍🍒⛏🤖

@bedevere-bot bedevere-bot removed the needs backport to 3.9 only security fixes label May 27, 2020
@bedevere-bot
Copy link

GH-20467 is a backport of this pull request to the 3.9 branch.

miss-islington added a commit that referenced this pull request May 27, 2020
```
D:\a\cpython\cpython\Modules\_zoneinfo.c(903,52): warning C4267: '=': conversion from 'size_t' to 'unsigned int', possible loss of data [D:\a\cpython\cpython\PCbuild\_zoneinfo.vcxproj]
D:\a\cpython\cpython\Modules\_zoneinfo.c(904,44): warning C4267: '=': conversion from 'size_t' to 'unsigned int', possible loss of data [D:\a\cpython\cpython\PCbuild\_zoneinfo.vcxproj]
D:\a\cpython\cpython\Modules\_zoneinfo.c(1772,31): warning C4244: '=': conversion from 'ssize_t' to 'uint8_t', possible loss of data [D:\a\cpython\cpython\PCbuild\_zoneinfo.vcxproj]
```
(cherry picked from commit e4799b9)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
@pablogsal pablogsal deleted the zoneinfo branch May 19, 2021 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants