-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
Py_GetVersion() is broken when using mqueue and a long patch name #65512
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
Comments
Py_GetVersion() (in Python/getversion.c) builds the version string returned by sys.version: PyOS_snprintf(version, sizeof(version), "%.80s (%.80s) %.80s", In turn, Py_GetBuildInfo() (in Modules/getbuildinfo.c) returns the "build" portion of Python's version string. When available, the tag returned by "hg id -t" constitutes part of that build string. The problem is that when using mqueue the result of "hg id -t" can be pretty long. For example: bpo-21226-fix-PyImport_ExecCodeModuleObject.diff qbase qtip tip That's 74 characters for just part of a build string that may be well over 100 characters. However, Py_GetVersion() truncates it to 80 characters. The consequence is that this value of sys.version causes platform._sys_version() to fail since the version string does not match the expected pattern. So either Py_GetVersion() should relax (-1) or Py_GetBuildInfo() should restrict the length of the resulting build string (+1). Would it work to truncate just the hgid part so that the whole string returned by Py_GetBuildInfo() is no more than length 80? E.g. - PyOS_snprintf(buildinfo, sizeof(buildinfo),
- "%s%s%s, %.20s, %.9s", hgid, sep, revision, DATE, TIME);
+ PyOS_snprintf(buildinfo, 80,
+ "%.43s%.1s%.13s, %.20s, %.9s", hgid, sep, revision, DATE, TIME); |
Any comments on the proposal to restrict the length of the returned string from Py_GetBuildInfo() to 80 characters? |
Currently Py_GetBuildInfo() just returns a long untruncated string. Perhaps it would be safer to leave that as it is, and just make the parsing in the “platform” module more tolerant. What do you think? I never really cared about the details in Py_GetBuildInfo(), but it would be nice if the test suite would run :) |
>>> Py_GetBuildInfo = pythonapi.Py_GetBuildInfo
>>> Py_GetBuildInfo.restype = c_char_p
>>> Py_GetBuildInfo() # Not truncated
'qbase qtip subprocess-stderr_redirect_with_no_stdout_redirect-2.diff tip:0b641285389d+, May 13 2016, 02:10:26' Demo of my problem with the test suite: $ ./python -m test.regrtest
Traceback (most recent call last):
[. . .]
File "/media/disk/home/proj/python/cpython/Lib/test/test_support.py", line 1423, in check_impl_detail
return guards.get(platform.python_implementation().lower(), default)
File "/media/disk/home/proj/python/cpython/Lib/platform.py", line 1451, in python_implementation
return _sys_version()[0]
File "/media/disk/home/proj/python/cpython/Lib/platform.py", line 1416, in _sys_version
repr(sys_version))
ValueError: failed to parse CPython sys.version: '2.7.11+ (qbase qtip subprocess-stderr_redirect_with_no_stdout_redirect-2.diff tip:0b64128) \n[GCC 5.3.0]' |
New changeset b86e259271b3 by Martin Panter in branch '2.7': New changeset 4deec876db0d by Martin Panter in branch '3.5': New changeset aec5a3fc4890 by Martin Panter in branch 'default': |
Closing now that platform._sys_version() can tolerate the truncated version info. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: