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

“unmatched paren” for space before parenthesis in Py_BuildValue #84489

Closed
Wrzlprmft mannequin opened this issue Apr 17, 2020 · 2 comments
Closed

“unmatched paren” for space before parenthesis in Py_BuildValue #84489

Wrzlprmft mannequin opened this issue Apr 17, 2020 · 2 comments
Labels
3.13 new features, bugs and security fixes topic-C-API

Comments

@Wrzlprmft
Copy link
Mannequin

Wrzlprmft mannequin commented Apr 17, 2020

BPO 40309
Nosy @Wrzlprmft, @ZackerySpytz
PRs
  • gh-84489: Properly handle trailing spaces in Py_BuildValue() format strings #21158
  • Files
  • foo.c: Minimal Python C Extension showing the bug
  • 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 = None
    created_at = <Date 2020-04-17.08:54:27.483>
    labels = ['expert-C-API', '3.7', '3.8']
    title = '\xe2\x80\x9cunmatched paren\xe2\x80\x9d for space before parenthesis in Py_BuildValue'
    updated_at = <Date 2020-06-25.15:53:09.748>
    user = 'https://github.com/Wrzlprmft'

    bugs.python.org fields:

    activity = <Date 2020-06-25.15:53:09.748>
    actor = 'ZackerySpytz'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['C API']
    creation = <Date 2020-04-17.08:54:27.483>
    creator = 'Wrzlprmft'
    dependencies = []
    files = ['49069']
    hgrepos = []
    issue_num = 40309
    keywords = ['patch']
    message_count = 1.0
    messages = ['366647']
    nosy_count = 2.0
    nosy_names = ['Wrzlprmft', 'ZackerySpytz']
    pr_nums = ['21158']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue40309'
    versions = ['Python 3.7', 'Python 3.8']

    Linked PRs

    @Wrzlprmft
    Copy link
    Mannequin Author

    Wrzlprmft mannequin commented Apr 17, 2020

    According to the C-API documentation¹ for Py_BuildValue:

    The characters space, tab, colon and comma are ignored in format strings (but not within format units such as s#). This can be used to make long format strings a tad more readable.

    However format strings such as "(d )" cause the error:

    Unmatched paren in format

    By contrast "( d)" and "(d d)" cause no problems. I therefore assume that tuples are not considered “format units” in the sense of the above quote and this is a bug. Alternatively, the documentation needs clarification.

    I could reproduce this problem with Python 3.7 and 3.8. I did not try other versions.

    Appended is a minimal C extension exhibiting the problem. I compile and run with:

    gcc -fPIC -I/usr/include/python3.8 -c foo.c -o foo.o
    gcc -shared foo.o -o foo.so
    python3.8 -c "import foo; foo.bar()"

    ----

    ¹ https://docs.python.org/3/c-api/arg.html

    @Wrzlprmft Wrzlprmft mannequin added 3.7 (EOL) end of life 3.8 only security fixes topic-C-API labels Apr 17, 2020
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @iritkatriel iritkatriel added 3.11 only security fixes 3.10 only security fixes 3.12 bugs and security fixes and removed 3.8 only security fixes 3.7 (EOL) end of life labels Apr 3, 2023
    @iritkatriel iritkatriel added 3.13 new features, bugs and security fixes and removed 3.10 only security fixes labels May 13, 2023
    serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Oct 10, 2023
    serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Oct 10, 2023
    miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 11, 2023
    (cherry picked from commit 5c6e854)
    
    Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
    serhiy-storchaka added a commit that referenced this issue Oct 11, 2023
    …-110680)
    
    (cherry picked from commit 5c6e854)
    
    Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
    serhiy-storchaka added a commit that referenced this issue Oct 11, 2023
    …trings (GH-21158)
    
    The docs state that the space, tab, colon, and comma characters are
    ignored in Py_BuildValue() format strings.
    
    Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
    @serhiy-storchaka serhiy-storchaka removed 3.11 only security fixes 3.12 bugs and security fixes labels Oct 11, 2023
    @serhiy-storchaka
    Copy link
    Member

    I decided to not backport this change. It is impossible to backport tests to 3.11, because of completely different structure of C API tests. Backporting it without tests is not very good. But if we finally decide to backport C API tests from 3.12 to 3.11, the difference between 3.11 and 3.12 can cause many troubles.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.13 new features, bugs and security fixes topic-C-API
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants