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

Add more checks to testcapi #47893

Closed
vstinner opened this issue Aug 22, 2008 · 9 comments
Closed

Add more checks to testcapi #47893

vstinner opened this issue Aug 22, 2008 · 9 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@vstinner
Copy link
Member

BPO 3643
Nosy @birkenfeld, @pitrou, @vstinner, @devdanzin, @benjaminp
Files
  • testcapi_py26.patch: Fix _test_thread_state() and raise_exception() and _testcapi module
  • testcapi_py30.patch: Fix exception_print() of _testcapi module
  • 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 = 'https://github.com/benjaminp'
    closed_at = <Date 2008-08-23.20:33:11.508>
    created_at = <Date 2008-08-22.01:41:22.063>
    labels = ['type-feature', 'library']
    title = 'Add more checks to testcapi'
    updated_at = <Date 2008-08-23.20:33:11.393>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2008-08-23.20:33:11.393>
    actor = 'benjamin.peterson'
    assignee = 'benjamin.peterson'
    closed = True
    closed_date = <Date 2008-08-23.20:33:11.508>
    closer = 'benjamin.peterson'
    components = ['Library (Lib)']
    creation = <Date 2008-08-22.01:41:22.063>
    creator = 'vstinner'
    dependencies = []
    files = ['11204', '11205']
    hgrepos = []
    issue_num = 3643
    keywords = ['patch']
    message_count = 9.0
    messages = ['71714', '71715', '71716', '71730', '71735', '71770', '71808', '71810', '71814']
    nosy_count = 5.0
    nosy_names = ['georg.brandl', 'pitrou', 'vstinner', 'ajaksu2', 'benjamin.peterson']
    pr_nums = []
    priority = 'high'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue3643'
    versions = ['Python 2.6', 'Python 3.0']

    @vstinner
    Copy link
    Member Author

    test_thread_state() doesn't check that the argument is a function and
    doesn't check function call result and so the exception is catched
    later:

    Non callable argument:
    import _testcapi
    _testcapi._test_thread_state(10)
    # no exception raise here
    import gc
    # exception raised too late!
    => TypeError: 'int' object is not callable

    Callback error:
    import _testcapi
    def err():
    raise ValueError("xxx")
    _testcapi._test_thread_state(err)
    # no exception raise here
    import gc
    # exception raised too late!
    => ValueError: xxx

    So I wrote a patch which fixes that but also raise_exception() which
    have to check that the argument is an exception class.

    @vstinner vstinner added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Aug 22, 2008
    @vstinner
    Copy link
    Member Author

    Python 3.0 has an new function which requires an extra patch:
    exception_print() have to check that the argument is an exception
    instance:

       >>> import _testcapi
       >>> _testcapi.exception_print(10)
       Erreur de segmentation (core dumped)

    @benjaminp
    Copy link
    Contributor

    Your patches are pretty harmless, but this module is just for testing
    purposes.

    @vstinner
    Copy link
    Member Author

    @benjamin.peterson: I know but the module (installed in CPython
    default installation) is for testing purpose only, but invalid uses of
    its method would lead to inconsistent CPython internal state and
    that's bad :-) If you tried to say that such issue is not critical:
    yes, it's just a suggestion to improve CPython ;-)

    @pitrou
    Copy link
    Member

    pitrou commented Aug 22, 2008

    Unless someone thinks it's somehow release-critical, I'm retargetting
    this to 2.7/3.1.

    @benjaminp
    Copy link
    Contributor

    Ok. I'll apply your patches when we get to 2.7. Do ping me if a forget,
    though.

    @benjaminp benjaminp self-assigned this Aug 22, 2008
    @vstinner
    Copy link
    Member Author

    @pitrou: This issue is not critical. It's not a bug, it's an
    enhancement since _testcapi :-)

    @birkenfeld
    Copy link
    Member

    Still, _testcapi is built even for non-debug builds, so it is a
    gratuitous way for bad code to crash or internally invalidate a Python
    interpreter, so this should be treated like a bugfix.

    @benjaminp
    Copy link
    Contributor

    Fair enough. Fixed in r66000 (trunk) and r66001 (py3k).

    @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
    stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants