GeezerVison is showing github.com — gh-94808: Cover `%p` in `PyUnicode_FromFormat` by sobolevn · Pull Request #96677 · python/cpython
Conversation
sobolevn
commented
Sep 8, 2022
•
edited by bedevere-bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Source:
|
case 'p': |
|
{ |
|
char number[MAX_LONG_LONG_CHARS]; |
|
|
|
len = sprintf(number, "%p", va_arg(*vargs, void*)); |
|
assert(len >= 0); |
|
|
|
/* %p is ill-defined: ensure leading 0x. */ |
|
if (number[1] == 'X') |
|
number[1] = 'x'; |
|
else if (number[1] != 'x') { |
|
memmove(number + 2, number, |
|
strlen(number) + 1); |
|
number[0] = '0'; |
|
number[1] = 'x'; |
|
len += 2; |
|
} |
|
|
|
if (_PyUnicodeWriter_WriteASCIIString(writer, number, len) < 0) |
|
return NULL; |
|
break; |
|
} |
Internet says that some systems can return representation with 0x, some with 0X, and some with none. It is reflected in the implementation, but cannot be reflected in tests.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
sobolevn
commented
Sep 8, 2022
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
And we got a failure: MacOS passes locally and on CI, but other platforms do not.
Windows:
======================================================================
FAIL: test_from_format (test.test_unicode.CAPITest.test_from_format)
----------------------------------------------------------------------
Traceback (most recent call last):
File "D:\a\cpython\cpython\Lib\test\test_unicode.py", line 2817, in test_from_format
self.assertEqual(len(p_format1), 11)
AssertionError: 10 != 11
Ubuntu:
======================================================================
FAIL: test_from_format (test.test_unicode.CAPITest.test_from_format)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/work/cpython/cpython-ro-srcdir/Lib/test/test_unicode.py", line 2817, in test_from_format
self.assertEqual(len(p_format1), 11)
AssertionError: 14 != 11
I think it is better to remove len assumptions.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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 think a regex test would be better here.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
self.assertIsInstance(p_format1, str)
|
|
|
self.assertRegex(p_format1, p_format_regex)
|
|
|
|
|
|
p_format2 = PyUnicode_FromFormat(b'repr=%p', '123456', None, b'xyz')
|
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.
What does this case test? I don't see what it adds over the previous case.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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 has:
- Multiple arguments (while
p_format1 only has one arg)
- All arguments have different types
- New types are tested:
bytes and None
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Aren't the additional arguments ignored though, because there is only one %p in the format string?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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 agree, tests can be better :)
Can you please take a look at the updated version?
It now has both:
- Extra types
- Ignored arguments
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Interesting! I think that comes from libc since I can't find code in CPython that would do this.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
From https://pubs.opengroup.org/onlinepubs/009695399/functions/fprintf.html
p
The argument shall be a pointer to void. The value of the pointer is converted to a sequence of printable characters, in an implementation-defined manner.
I think it is better to just leave None out of this test case.
And possibly create a new discussion about this: aren't NULL and None confused here?
Related discussions:
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
I think ctypes translates None into NULL, which is reasonable.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
Thanks @sobolevn for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11.
🐍🍒⛏🤖
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Sorry @sobolevn and @JelleZijlstra, I had trouble checking out the 3.11 backport branch.
Please backport using cherry_picker on command line.
cherry_picker 72c166add89a0cd992d66f75ce94eee5eb675a99 3.11
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Thanks @sobolevn for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️
Hi! The buildbot s390x SLES 3.x has failed when building commit 72c166a.
What do you need to do:
- Don't panic.
- Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
- Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/540/builds/3747) and take a look at the build logs.
- Check if the failure is related to this commit (72c166a) or if it is a false positive.
- If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.
You can take a look at the buildbot page here:
https://buildbot.python.org/all/#builders/540/builds/3747
Failed tests:
Failed subtests:
- test_from_format - test.test_unicode.CAPITest.test_from_format
Summary of the results of the build (if available):
== Tests result: FAILURE then FAILURE ==
420 tests OK.
10 slowest tests:
- test_concurrent_futures: 2 min 51 sec
- test_tools: 2 min 34 sec
- test_multiprocessing_spawn: 1 min 51 sec
- test_asyncio: 1 min 17 sec
- test_multiprocessing_forkserver: 1 min 14 sec
- test_signal: 1 min 10 sec
- test_multiprocessing_fork: 1 min 8 sec
- test_nntplib: 1 min 5 sec
- test_capi: 52.3 sec
- test_tokenize: 48.6 sec
1 test failed:
test_unicode
16 tests skipped:
test_devpoll test_ioctl test_kqueue test_launcher test_msilib
test_nis test_perf_profiler test_startfile test_tix test_tkinter
test_ttk test_winconsoleio test_winreg test_winsound test_wmi
test_zipfile64
1 re-run test:
test_unicode
Total duration: 5 min 53 sec
Click to see traceback logs
Traceback (most recent call last):
File "/home/dje/cpython-buildarea/3.x.edelsohn-sles-z/build/Lib/test/test_unicode.py", line 2817, in test_from_format
self.assertRegex(p_format1, p_format_regex)
AssertionError: Regex didn't match: '^0x[a-zA-Z0-9]{8,}$' not found in '0x153b8c0'
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
I guess the pointers are shorter on s390. I'll adjust the regex.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️
Hi! The buildbot AMD64 FreeBSD Non-Debug 3.x has failed when building commit 72c166a.
What do you need to do:
- Don't panic.
- Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
- Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/172/builds/2913) and take a look at the build logs.
- Check if the failure is related to this commit (72c166a) or if it is a false positive.
- If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.
You can take a look at the buildbot page here:
https://buildbot.python.org/all/#builders/172/builds/2913
Failed tests:
Failed subtests:
- test_from_format - test.test_unicode.CAPITest.test_from_format
Summary of the results of the build (if available):
== Tests result: FAILURE then FAILURE ==
415 tests OK.
10 slowest tests:
- test_multiprocessing_spawn: 4 min 3 sec
- test_tokenize: 3 min 40 sec
- test_asyncio: 3 min 18 sec
- test_concurrent_futures: 3 min 9 sec
- test_multiprocessing_forkserver: 2 min 19 sec
- test_unparse: 2 min 10 sec
- test_lib2to3: 2 min 3 sec
- test_unicodedata: 1 min 48 sec
- test_subprocess: 1 min 37 sec
- test_multiprocessing_fork: 1 min 36 sec
1 test failed:
test_unicode
21 tests skipped:
test_dbm_gnu test_devpoll test_epoll test_idle test_ioctl
test_launcher test_msilib test_perf_profiler test_spwd
test_startfile test_tcl test_tix test_tkinter test_ttk
test_ttk_textonly test_turtle test_winconsoleio test_winreg
test_winsound test_wmi test_zipfile64
1 re-run test:
test_unicode
Total duration: 17 min
Click to see traceback logs
Traceback (most recent call last):
File "/usr/home/buildbot/python/3.x.koobs-freebsd-9e36.nondebug/build/Lib/test/test_unicode.py", line 2817, in test_from_format
self.assertRegex(p_format1, p_format_regex)
AssertionError: Regex didn't match: '^0x[a-zA-Z0-9]{8,}$' not found in '0x612bd0'
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️
Hi! The buildbot x86 Gentoo Installed with X 3.x has failed when building commit 72c166a.
What do you need to do:
- Don't panic.
- Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
- Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/464/builds/3172) and take a look at the build logs.
- Check if the failure is related to this commit (72c166a) or if it is a false positive.
- If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.
You can take a look at the buildbot page here:
https://buildbot.python.org/all/#builders/464/builds/3172
Failed tests:
Failed subtests:
- test_from_format - test.test_unicode.CAPITest.test_from_format
Summary of the results of the build (if available):
== Tests result: FAILURE then FAILURE ==
417 tests OK.
1 test failed:
test_unicode
17 tests skipped:
test_asdl_parser test_check_c_globals test_clinic test_dbm_ndbm
test_devpoll test_gdb test_ioctl test_kqueue test_launcher
test_msilib test_perf_profiler test_startfile test_winconsoleio
test_winreg test_winsound test_wmi test_zipfile64
1 re-run test:
test_unicode
Total duration: 53 min 22 sec
Click to see traceback logs
Traceback (most recent call last):
File "/buildbot/buildarea/cpython/3.x.ware-gentoo-x86.installed/build/target/lib/python3.12/test/test_unicode.py", line 2817, in test_from_format
self.assertRegex(p_format1, p_format_regex)
AssertionError: Regex didn't match: '^0x[a-zA-Z0-9]{8,}$' not found in '0x8bd9f0'
Traceback (most recent call last):
File "/buildbot/buildarea/cpython/3.x.ware-gentoo-x86.installed/build/target/lib/python3.12/test/test_unicode.py", line 2817, in test_from_format
self.assertRegex(p_format1, p_format_regex)
AssertionError: Regex didn't match: '^0x[a-zA-Z0-9]{8,}$' not found in '0x9809f0'
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
mpage
pushed a commit
to mpage/cpython
that referenced
this pull request
Oct 11, 2022
Uh oh!
There was an error while loading. Please reload this page.
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|