Skip to content
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

Py_GetVersion() is broken when using mqueue and a long patch name #65512

Closed
ericsnowcurrently opened this issue Apr 19, 2014 · 6 comments
Closed
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@ericsnowcurrently
Copy link
Member

BPO 21313
Nosy @ericsnowcurrently, @vadmium
Files
  • parse-version.patch
  • 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:

    assignee = None
    closed_at = <Date 2016-06-08.12:16:20.554>
    created_at = <Date 2014-04-19.22:17:18.809>
    labels = ['interpreter-core', 'type-bug']
    title = 'Py_GetVersion() is broken when using mqueue and a long patch name'
    updated_at = <Date 2016-06-08.12:16:20.552>
    user = 'https://github.com/ericsnowcurrently'

    bugs.python.org fields:

    activity = <Date 2016-06-08.12:16:20.552>
    actor = 'martin.panter'
    assignee = 'none'
    closed = True
    closed_date = <Date 2016-06-08.12:16:20.554>
    closer = 'martin.panter'
    components = ['Interpreter Core']
    creation = <Date 2014-04-19.22:17:18.809>
    creator = 'eric.snow'
    dependencies = []
    files = ['42836']
    hgrepos = []
    issue_num = 21313
    keywords = ['patch']
    message_count = 6.0
    messages = ['216883', '238905', '265443', '265444', '267827', '267842']
    nosy_count = 3.0
    nosy_names = ['python-dev', 'eric.snow', 'martin.panter']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue21313'
    versions = ['Python 2.7', 'Python 3.5', 'Python 3.6']

    @ericsnowcurrently
    Copy link
    Member Author

    Py_GetVersion() (in Python/getversion.c) builds the version string returned by sys.version:

    PyOS_snprintf(version, sizeof(version), "%.80s (%.80s) %.80s",
    PY_VERSION, Py_GetBuildInfo(), Py_GetCompiler());

    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);

    @ericsnowcurrently ericsnowcurrently added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Apr 19, 2014
    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Mar 22, 2015

    Any comments on the proposal to restrict the length of the returned string from Py_GetBuildInfo() to 80 characters?

    @vadmium
    Copy link
    Member

    vadmium commented May 13, 2016

    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 :)

    @vadmium
    Copy link
    Member

    vadmium commented May 13, 2016

    >>> 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]'

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jun 8, 2016

    New changeset b86e259271b3 by Martin Panter in branch '2.7':
    Issue bpo-21313: Tolerate truncated buildinfo in sys.version
    https://hg.python.org/cpython/rev/b86e259271b3

    New changeset 4deec876db0d by Martin Panter in branch '3.5':
    Issue bpo-21313: Tolerate truncated buildinfo in sys.version
    https://hg.python.org/cpython/rev/4deec876db0d

    New changeset aec5a3fc4890 by Martin Panter in branch 'default':
    Issue bpo-21313: Merge version parsing from 3.5
    https://hg.python.org/cpython/rev/aec5a3fc4890

    @vadmium
    Copy link
    Member

    vadmium commented Jun 8, 2016

    Closing now that platform._sys_version() can tolerate the truncated version info.

    @vadmium vadmium closed this as completed Jun 8, 2016
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants