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

Incorrect use of c_char_p in example code #81752

Closed
rrt mannequin opened this issue Jul 12, 2019 · 9 comments
Closed

Incorrect use of c_char_p in example code #81752

rrt mannequin opened this issue Jul 12, 2019 · 9 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes docs Documentation in the Doc dir topic-ctypes

Comments

@rrt
Copy link
Mannequin

rrt mannequin commented Jul 12, 2019

BPO 37571
Nosy @amauryfa, @abalkin, @meadori, @zooba, @miss-islington, @tirkarthi
PRs
  • bpo-37571: Add 'b' to prevent the TypeError exception. #14721
  • [3.8] bpo-37571: Add 'b' to prevent the TypeError exception. (GH-14721) #14762
  • [3.7] bpo-37571: Add 'b' to prevent the TypeError exception. (GH-14721) #14763
  • bpo-37571: Remove extra space in ctypes docs #14764
  • [3.8] bpo-37571: Remove extra space in ctypes docs (GH-14764) #14766
  • [3.7] bpo-37571: Remove extra space in ctypes docs (GH-14764) #14767
  • 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 2019-07-14.08:14:38.349>
    created_at = <Date 2019-07-12.07:40:49.474>
    labels = ['ctypes', '3.7', '3.8', '3.9', 'docs']
    title = 'Incorrect use of c_char_p in example code'
    updated_at = <Date 2019-07-14.08:24:38.449>
    user = 'https://bugs.python.org/rrt'

    bugs.python.org fields:

    activity = <Date 2019-07-14.08:24:38.449>
    actor = 'miss-islington'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2019-07-14.08:14:38.349>
    closer = 'steve.dower'
    components = ['Documentation', 'ctypes']
    creation = <Date 2019-07-12.07:40:49.474>
    creator = 'rrt'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 37571
    keywords = ['patch']
    message_count = 9.0
    messages = ['347725', '347727', '347873', '347875', '347876', '347878', '347879', '347882', '347884']
    nosy_count = 8.0
    nosy_names = ['amaury.forgeotdarc', 'belopolsky', 'meador.inge', 'docs@python', 'steve.dower', 'rrt', 'miss-islington', 'xtreak']
    pr_nums = ['14721', '14762', '14763', '14764', '14766', '14767']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue37571'
    versions = ['Python 3.7', 'Python 3.8', 'Python 3.9']

    @rrt
    Copy link
    Mannequin Author

    rrt mannequin commented Jul 12, 2019

    The CTypes documentation has this example:

    >>> s = c_char_p()
    >>> s.value = "abc def ghi"
    >>> s.value
    'abc def ghi'
    >>> s.value is s.value
    False
    >>>

    It appears not to have been updated since Python 2: in Python 3, you can't assign a str to a c_char_p. If one tries the example code above, one gets:

    >>> s = c_char_p()
    >>> s.value = "abc def ghi"
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: bytes or integer address expected instead of str instance

    Using a bytes works:

    >>> s = c_char_p()
    >>> s.value = b"abc def ghi"
    >>> s.value
    b'abc def ghi'
    >>> s.value is s.value
    False
    >>>

    Hence adding the two "b"s is an obvious fix.

    Note that the similar example with c_wchar_p does work fine with str.

    @rrt rrt mannequin added the 3.9 only security fixes label Jul 12, 2019
    @rrt rrt mannequin assigned docspython Jul 12, 2019
    @rrt rrt mannequin added the docs Documentation in the Doc dir label Jul 12, 2019
    @tirkarthi
    Copy link
    Member

    Thanks for the report. Looks like a valid issue to me. Would you like to create a PR?

    @tirkarthi tirkarthi added topic-ctypes 3.7 (EOL) end of life 3.8 only security fixes labels Jul 12, 2019
    @zooba
    Copy link
    Member

    zooba commented Jul 14, 2019

    New changeset 6b92958 by Steve Dower (Michele Angrisano) in branch 'master':
    bpo-37571: Add 'b' to prevent the TypeError exception. (GH-14721)
    6b92958

    @miss-islington
    Copy link
    Contributor

    New changeset e7c114d by Miss Islington (bot) in branch '3.8':
    bpo-37571: Add 'b' to prevent the TypeError exception. (GH-14721)
    e7c114d

    @miss-islington
    Copy link
    Contributor

    New changeset d7caf75 by Miss Islington (bot) in branch '3.7':
    bpo-37571: Add 'b' to prevent the TypeError exception. (GH-14721)
    d7caf75

    @zooba
    Copy link
    Member

    zooba commented Jul 14, 2019

    New changeset 68c74d0 by Steve Dower in branch 'master':
    bpo-37571: Remove extra space in ctypes docs (GH14764)
    68c74d0

    @zooba
    Copy link
    Member

    zooba commented Jul 14, 2019

    Thanks for the patch!

    @zooba zooba closed this as completed Jul 14, 2019
    @miss-islington
    Copy link
    Contributor

    New changeset 4f733f4 by Miss Islington (bot) in branch '3.8':
    bpo-37571: Remove extra space in ctypes docs (GH14764)
    4f733f4

    @miss-islington
    Copy link
    Contributor

    New changeset 13c89f3 by Miss Islington (bot) in branch '3.7':
    bpo-37571: Remove extra space in ctypes docs (GH14764)
    13c89f3

    @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 3.9 only security fixes docs Documentation in the Doc dir topic-ctypes
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants