Skip to content

bpo-35384: The repr of ctypes.CArgObject no longer fail for non-ascii character. #10863

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

Merged

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Dec 3, 2018

@@ -514,8 +522,8 @@ PyCArg_repr(PyCArgObject *self)
break;

default:
sprintf(buffer, "<cparam '%c' at %p>",
self->tag, self);
sprintf(buffer, "<cparam %02x' at %p>",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks as if this change accidentally removed the opening apostrophe.

Suggested change
sprintf(buffer, "<cparam %02x' at %p>",
sprintf(buffer, "<cparam '%02x' at %p>",

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the opposite. I have forgot to remove the closing apostrophe.

self->tag, self->value.c);
break;
if ((unsigned char)self->value.c < 128
&& _PyUnicode_IsPrintable(self->value.c)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is printability the right test here? Tab, newline, carriage return, vertical tab, form feed are all printable but probably don't make sense in this context.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'\t'.isprintable() returns False.

break;
if ((unsigned char)self->value.c < 128
&& _PyUnicode_IsPrintable(self->value.c)
&& self->value.c != '\'')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the goal here to make the output look like a syntactically valid Python string? If so, you should also exclude backslash.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Yes, the goal here to make the output look like a syntactically valid Python or C.

@serhiy-storchaka serhiy-storchaka merged commit 3ffa8b9 into python:master Dec 6, 2018
@miss-islington
Copy link
Contributor

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7.
🐍🍒⛏🤖

@serhiy-storchaka serhiy-storchaka deleted the CArgObject-repr-char branch December 6, 2018 09:16
@bedevere-bot
Copy link

GH-10983 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Dec 6, 2018
…i character. (pythonGH-10863)

(cherry picked from commit 3ffa8b9)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-bot
Copy link

GH-10984 is a backport of this pull request to the 3.6 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Dec 6, 2018
…i character. (pythonGH-10863)

(cherry picked from commit 3ffa8b9)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@miss-islington
Copy link
Contributor

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-10985 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Dec 6, 2018
…i character. (pythonGH-10863)

(cherry picked from commit 3ffa8b9)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
miss-islington added a commit that referenced this pull request Dec 6, 2018
…i character. (GH-10863)

(cherry picked from commit 3ffa8b9)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
miss-islington added a commit that referenced this pull request Dec 6, 2018
…i character. (GH-10863)

(cherry picked from commit 3ffa8b9)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip news type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants