Skip to content

gh-130317: fix PyFloat_Pack/Unpack[24] for NaN's with payload #130452

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 26 commits into from
Apr 28, 2025
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
971fd98
gh-130317: fix PyFloat_Pack2/Unpack2 for NaN's with payload
skirpichev Feb 22, 2025
b05720a
Merge branch 'master' into fix-nan-packing/130317
skirpichev Feb 25, 2025
f513b14
more tests in test_capi, fix also Pack/Unpack4
skirpichev Feb 25, 2025
218f6b3
+ different fix for Pack/Unpack2 (works as for floats)
skirpichev Feb 25, 2025
a7f5ed9
blacklist on win32
skirpichev Feb 25, 2025
c7c08ff
cleanup and comments
skirpichev Feb 25, 2025
de7b6aa
+ enable test_pack_unpack_roundtrip_nans on win32 for qNaN's
skirpichev Feb 25, 2025
e6c1c12
+1
skirpichev Feb 25, 2025
ac7bdcb
address review: warning on Windows
skirpichev Feb 25, 2025
b461b81
XXX try to revert win32 WA
skirpichev Feb 25, 2025
cbfbf05
Revert "XXX try to revert win32 WA"
skirpichev Feb 26, 2025
6a5dc1a
Merge branch 'master' into fix-nan-packing/130317
skirpichev Feb 26, 2025
86ab7c3
Merge branch 'main' into fix-nan-packing/130317
skirpichev Apr 27, 2025
32bdeed
revert redundant test
skirpichev Apr 27, 2025
773f51e
rename test
skirpichev Apr 27, 2025
b27c916
XXX revert win32 wa
skirpichev Apr 27, 2025
4dc5697
+1
skirpichev Apr 27, 2025
6f71e34
+1
skirpichev Apr 27, 2025
3e5a211
revert
skirpichev Apr 27, 2025
092d729
fixup value on win32
skirpichev Apr 27, 2025
6137c75
cleanup & comments
skirpichev Apr 27, 2025
00dfd66
address review: redo helper
skirpichev Apr 27, 2025
b7f727c
Apply suggestions from code review
skirpichev Apr 28, 2025
13e8310
restore comment
skirpichev Apr 28, 2025
bcf54f6
address review: ensure code works with strict aliasing
skirpichev Apr 28, 2025
9d20633
Apply suggestions from code review
skirpichev Apr 28, 2025
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
Prev Previous commit
Next Next commit
cleanup and comments
  • Loading branch information
skirpichev committed Feb 25, 2025
commit c7c08ff62fdcc53d2b9e0325b4b49dedf33b51b0
14 changes: 8 additions & 6 deletions Objects/floatobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2054,7 +2054,7 @@
uint64_t v;

memcpy(&v, &x, sizeof(v));
bits = ((v & 0xffc0000000000ULL)>>42); /* NaN's payload */
bits = (v & 0xffc0000000000ULL) >> 42; /* NaN's payload */

Check warning on line 2057 in Objects/floatobject.c

View workflow job for this annotation

GitHub Actions / Windows / build (arm64)

'=': conversion from 'uint64_t' to 'unsigned short', possible loss of data [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 2057 in Objects/floatobject.c

View workflow job for this annotation

GitHub Actions / Windows / build (arm64)

'=': conversion from 'uint64_t' to 'unsigned short', possible loss of data [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 2057 in Objects/floatobject.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build (arm64)

'=': conversion from 'uint64_t' to 'unsigned short', possible loss of data [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 2057 in Objects/floatobject.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build (arm64)

'=': conversion from 'uint64_t' to 'unsigned short', possible loss of data [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 2057 in Objects/floatobject.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

'=': conversion from 'uint64_t' to 'unsigned short', possible loss of data [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 2057 in Objects/floatobject.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

'=': conversion from 'uint64_t' to 'unsigned short', possible loss of data [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 2057 in Objects/floatobject.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (x64)

'=': conversion from 'uint64_t' to 'unsigned short', possible loss of data [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 2057 in Objects/floatobject.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (x64)

'=': conversion from 'uint64_t' to 'unsigned short', possible loss of data [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]
}
else {
sign = (x < 0.0);
Expand Down Expand Up @@ -2218,14 +2218,15 @@
if (isinf(y) && !isinf(x))
goto Overflow;

/* correct y if x was a sNaN, transformed to qNaN by assignment */
if (isnan(x)) {
uint64_t v;

memcpy(&v, &x, 8);
if ((v & (1ULL<<51)) == 0) {
if ((v & (1ULL << 51)) == 0) {
uint32_t *py = (uint32_t *)&y;

*py -= (1<<22);
*py -= 1 << 22; /* make sNaN */
}
}

Expand Down Expand Up @@ -2413,7 +2414,7 @@
/* NaN */
uint64_t v = sign ? 0xfff0000000000000ULL : 0x7ff0000000000000ULL;

v += ((uint64_t)f << 42); /* add NaN's payload */
v += (uint64_t)f << 42; /* add NaN's payload */
memcpy(&x, &v, sizeof(v));
return x;
}
Expand Down Expand Up @@ -2511,15 +2512,16 @@
memcpy(&x, p, 4);
}

/* return sNaN double if x was sNaN float */
if (isnan(x)) {
uint32_t v;

memcpy(&v, &x, 4);
if ((v & (1<<22)) == 0) {
double y = x;
double y = x; /* will make qNaN double */
uint64_t *py = (uint64_t *)&y;

*py -= (1ULL<<51);
*py -= (1ULL<<51); /* make sNaN */
return y;
}
}
Expand Down
Loading