Skip to content

fix an error message and a comment in _testcapimodule.c #392

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 1 commit into from
Mar 2, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ getargs_K(PyObject *self, PyObject *args)
}

/* This function not only tests the 'k' getargs code, but also the
PyLong_AsUnsignedLongMask() and PyLong_AsUnsignedLongMask() functions. */
PyLong_AsUnsignedLongMask() function. */
static PyObject *
test_k_code(PyObject *self)
{
Expand Down Expand Up @@ -1205,7 +1205,8 @@ test_k_code(PyObject *self)
value = PyLong_AsUnsignedLongMask(num);
if (value != (unsigned long)-0x42)
return raiseTestError("test_k_code",
"PyLong_AsUnsignedLongMask() returned wrong value for long 0xFFF...FFF");
"PyLong_AsUnsignedLongMask() returned wrong "
"value for long -0xFFF..000042");
Copy link
Member

Choose a reason for hiding this comment

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

0xFFF...000042 looks strange. Is this really the right value? (And what does the ... mean here?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

first we have:
num = PyLong_FromString("-FFFFFFFF000000000000000042", NULL, 16);
and then the check is whether PyLong_AsUnsignedLongMask returned -0x42,
i.e. truncated num as expected.
so yes, IMHO -0xFFF..000042 is the right value.

and I guess the .. means a big enough amount of zeros, such that the
truncation would indeed result in -0x42.
ISTM the original author felt this would be more elegant than writing
-0xFFFFFFFF000000000000000042 again...

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough. Given that it's just an error message, and that that error message is at least unique enough to identify exactly what's failing, it's probably good enough. Sorry for the bikeshedding.


PyTuple_SET_ITEM(tuple, 0, num);

Expand Down