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

Document that ctypes.xFUNCTYPE are decorators. #48510

Closed
lambertdw mannequin opened this issue Nov 5, 2008 · 8 comments
Closed

Document that ctypes.xFUNCTYPE are decorators. #48510

lambertdw mannequin opened this issue Nov 5, 2008 · 8 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes docs Documentation in the Doc dir easy type-feature A feature request or enhancement

Comments

@lambertdw
Copy link
Mannequin

lambertdw mannequin commented Nov 5, 2008

BPO 4260
Nosy @theller, @birkenfeld, @amauryfa, @abalkin, @meadori, @berkerpeksag, @andresdelfino, @miss-islington
PRs
  • bpo-4260: Document that ctypes.xFUNCTYPE are decorators #7924
  • [3.7] bpo-4260: Document that ctypes.xFUNCTYPE are decorators (GH-7924) #8272
  • [3.6] bpo-4260: Document that ctypes.xFUNCTYPE are decorators (GH-7924) #8273
  • 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 2018-07-13.14:05:29.865>
    created_at = <Date 2008-11-05.05:51:02.885>
    labels = ['easy', '3.8', 'type-feature', '3.7', 'docs']
    title = 'Document that ctypes.xFUNCTYPE are decorators.'
    updated_at = <Date 2018-07-13.14:05:29.864>
    user = 'https://bugs.python.org/LambertDW'

    bugs.python.org fields:

    activity = <Date 2018-07-13.14:05:29.864>
    actor = 'berker.peksag'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2018-07-13.14:05:29.865>
    closer = 'berker.peksag'
    components = ['Documentation']
    creation = <Date 2008-11-05.05:51:02.885>
    creator = 'LambertDW'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 4260
    keywords = ['patch', 'easy']
    message_count = 8.0
    messages = ['75515', '75535', '75577', '320464', '321601', '321610', '321612', '321614']
    nosy_count = 10.0
    nosy_names = ['theller', 'georg.brandl', 'amaury.forgeotdarc', 'belopolsky', 'kevinwatters', 'LambertDW', 'meador.inge', 'berker.peksag', 'adelfino', 'miss-islington']
    pr_nums = ['7924', '8272', '8273']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue4260'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8']

    @lambertdw
    Copy link
    Mannequin Author

    lambertdw mannequin commented Nov 5, 2008

    http://docs.python.org/dev/3.0/library/ctypes.html#callback-functions

    ctypes.xFUNCTYPE are another opportunity to advertise decorators.
    Please consider inserting yet another qsort example written as a
    decorator, perhaps as follows. Or---it could be that I'm slow and the
    average pythonista will figure this out on first read.

    @CFUNCTYPE(c_int, POINTER(c_int), POINTER(c_int))
    def py_cmp_func(*args):
        (a,b,) = (t[0] for t in args)
        print("py_cmp_func", a, b)
        return a-b

    qsort(ia,len(ia),sizeof(c_int),py_cmp_func)

    @lambertdw lambertdw mannequin assigned birkenfeld Nov 5, 2008
    @lambertdw lambertdw mannequin added docs Documentation in the Doc dir type-feature A feature request or enhancement labels Nov 5, 2008
    @kevinwatters
    Copy link
    Mannequin

    kevinwatters mannequin commented Nov 5, 2008

    As far as I know, the above code will fail randomly in release mode if
    you have multiple threads running Python, because when ctypes calls out
    to CFUNCTYPE functions, it releases the GIL.

    For decorating a python function to give to qsort, maybe you can use
    PYFUNCTYPE?

    @theller
    Copy link

    theller commented Nov 6, 2008

    [David Lambert]

    > @CFUNCTYPE(c_int, POINTER(c_int), POINTER(c_int))
    > def py_cmp_func(*args):
    > (a,b,) = (t[0] for t in args)
    > print("py_cmp_func", a, b)
    > return a-b
    >
    > qsort(ia,len(ia),sizeof(c_int),py_cmp_func)

    [Kevin Watters]

    > As far as I know, the above code will fail randomly in release mode if
    > you have multiple threads running Python, because when ctypes calls out
    > to CFUNCTYPE functions, it releases the GIL.
    >
    > For decorating a python function to give to qsort, maybe you can use
    > PYFUNCTYPE?

    Kevin is wrong - the code is perfect! Sure does calling a CFUNCTYPE instance
    release the GIL, but ctypes aquires the GIL again before executing the python
    code in the wrapped py_cmp_func above.

    I guess that using PYFUNCTYPE instead would possibly crash because the call to
    'qsort' releases the GIL, and the PYFUNCTYPE instance assumes the GIL but does not
    acquire it.

    But I have no time to work on the docs, sorry.

    @admin admin mannequin assigned docspython and unassigned birkenfeld Oct 29, 2010
    @pppery pppery mannequin changed the title ctypes.xFUNCTYPE are decorators. Document that ctypes.xFUNCTYPE are decorators. May 7, 2016
    @csabella csabella added 3.7 (EOL) end of life 3.8 only security fixes labels Feb 25, 2018
    @andresdelfino
    Copy link
    Contributor

    I suspect we'll be working on this PR a little, but a least it's a start to get this moving.

    @berkerpeksag
    Copy link
    Member

    New changeset 379e9d6 by Berker Peksag (Andrés Delfino) in branch 'master':
    bpo-4260: Document that ctypes.xFUNCTYPE are decorators (GH-7924)
    379e9d6

    @miss-islington
    Copy link
    Contributor

    New changeset 08c1da7 by Miss Islington (bot) in branch '3.7':
    bpo-4260: Document that ctypes.xFUNCTYPE are decorators (GH-7924)
    08c1da7

    @miss-islington
    Copy link
    Contributor

    New changeset 083a836 by Miss Islington (bot) in branch '3.6':
    bpo-4260: Document that ctypes.xFUNCTYPE are decorators (GH-7924)
    083a836

    @berkerpeksag
    Copy link
    Member

    I think we can now close this one. Thanks for the report, David, and thanks for the PR Andreas.

    (And thanks for creating and maintaining this awesome module for years, Thomas :))

    @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
    3.7 (EOL) end of life 3.8 only security fixes docs Documentation in the Doc dir easy type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    6 participants