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

bpo-16637: libpython: interpret string as integer literal #15232

Merged
merged 1 commit into from
Sep 24, 2019

Conversation

marc1006
Copy link
Contributor

@marc1006 marc1006 commented Aug 12, 2019

This fixes the exception ValueError: invalid literal for int() with base 10
if str(gdbval) returns a hexadecimal value (e.g. '0xa0').

See https://docs.python.org/3/library/functions.html#int for more information.

https://bugs.python.org/issue16637

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for your contribution, we look forward to reviewing it!

@@ -1392,7 +1392,7 @@ def write_repr(self, out, visited):


def int_from_int(gdbval):
return int(str(gdbval))
return int(str(gdbval), 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can one not simply call int on integer-type GDB values?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean something like

Suggested change
return int(str(gdbval), 0)
return int(gdbval.cast(gdb.lookup_type('long')))

?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but do you have to do the cast?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think so - but to be sure I have to verify it. Will update my branch if it works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated my branch. Seems a simple int call is enough - thanks (I assume this only holds if the gdbvalue has the right type).

This fixes the exception '`ValueError: invalid literal for int() with base 10`
if `str(gdbval)` returns a hexadecimal value (e.g. '0xa0'). This is the case if
the output-radix is set to 16 in gdb. See
https://sourceware.org/gdb/onlinedocs/gdb/Numbers.html for more information.
@miss-islington
Copy link
Contributor

Thanks @marc1006 for the PR, and @benjaminp for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-16345 is a backport of this pull request to the 3.8 branch.

miss-islington added a commit that referenced this pull request Sep 24, 2019
…dbvalue (GH-15232)

This fixes the exception '`ValueError: invalid literal for int() with base 10`
if `str(gdbval)` returns a hexadecimal value (e.g. '0xa0'). This is the case if
the output-radix is set to 16 in gdb. See
https://sourceware.org/gdb/onlinedocs/gdb/Numbers.html for more information.
(cherry picked from commit 6f53d34)

Co-authored-by: Marc Hartmayer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants