-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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
bpo-27961: Replace PY_LONG_LONG with long long #15386
Conversation
@@ -3005,7 +3005,7 @@ def parse_arg(self, argname, argnum): | |||
goto exit; | |||
}}}} | |||
{paramname} = PyLong_AsLongLong({argname}); | |||
if ({paramname} == (PY_LONG_LONG)-1 && PyErr_Occurred()) {{{{ | |||
if ({paramname} == -1 && PyErr_Occurred()) {{{{ |
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 decided to remove this cast as it's unneeded.
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 decided to remove this cast as it's unneeded.
Any idea as to why this cast was previously needed?
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.
@serhiy-storchaka you committed this code in 32d96a2. Does it make sense to you to remove this cast?
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.
It was copied from Python/getargs.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.
I would prefer to keep the explicit cast, since long long is an uncommon type and I prefer to avoid bad surprises on some platforms.
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.
@vstinner I don't really see a problem here, because implicit conversion of integers of the same signedness is well defined and always lossless. If it's so important it can be rewritten as:
if ({paramname} == -1LL && PyErr_Occurred()) {{{{
In that case there are no casts at all.
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.
Ok.
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 don't really see a problem here, because implicit conversion of integers of the same signedness is well defined and always lossless
@vstinner @serhiy-storchaka So is this okay universally across the C-API or is it different in other areas? Of course it wouldn't be worth a PR on it's own since it's more of a conventional/styling decision, I just want to know in case I see a similar implicit integer conversion (signed -> signed or unsigned -> unsigned) without the cast in another PR or if the issue comes up again.
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 have no idea. The C language remains partially a mystery to me.
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 have no idea. The C language remains partially a mystery to me.
If the C language is partially a mystery even to you, what hope do the rest of us mere mortals have? ;)
c11ffef
to
65e6196
Compare
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 you know why the build is failing on azure pipelines?
65e6196
to
4351678
Compare
Not sure why it's failed, but seems OK now. |
@@ -1269,7 +1269,7 @@ test_long_long_converter(PyObject *module, PyObject *const *args, Py_ssize_t nar | |||
goto exit; | |||
} | |||
a = PyLong_AsLongLong(args[0]); | |||
if (a == (PY_LONG_LONG)-1 && PyErr_Occurred()) { |
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 would prefer to keep the explicit cast.
Thanks @sir-sigurd for the cleanup :-) |
https://bugs.python.org/issue27961