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

SystemError when printing symbol table entry #109207

Closed
yunline opened this issue Sep 10, 2023 · 1 comment · Fixed by #109225 or #109227
Closed

SystemError when printing symbol table entry #109207

yunline opened this issue Sep 10, 2023 · 1 comment · Fixed by #109225 or #109227
Labels
3.11 only security fixes 3.12 bugs and security fixes 3.13 bugs and security fixes easy OS-windows type-bug An unexpected behavior, bug, or error

Comments

@yunline
Copy link
Contributor

yunline commented Sep 10, 2023

Bug report

Bug description:

Platform: Windows10
Tested version: 3.10, 3.11, 3.12rc2

import symtable

script = "a=0"

symt = symtable.symtable(script, "test.py", "exec")
print(symt._table)
<symtable entry top(-1), line 0>OverflowError: Python int too large to convert to C long

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "x:\python\oneliner\__develop\symt.py", line 8, in <module>
    print(symt._table)
SystemError: <built-in method write of _io.TextIOWrapper object at 0x000001508B5559A0> returned a result with an exception set

CPython versions tested on:

3.12

Operating systems tested on:

Windows

Linked PRs

@yunline yunline added the type-bug An unexpected behavior, bug, or error label Sep 10, 2023
@serhiy-storchaka serhiy-storchaka added 3.11 only security fixes easy 3.12 bugs and security fixes 3.13 bugs and security fixes OS-windows labels Sep 10, 2023
@serhiy-storchaka
Copy link
Member

I can see what the problem can be.

The repr first converts the table id to C long using PyLong_AS_LONG(). But the table id is just the id() of the corresponding AST node, and in Python it is an integer representation of pointer. Pointers are 64-bit on 64-bit platform, but C long is 32-bit on Windows. So we get an exception on 64-bit Windows.

Marking this as easy issue, as what you only need is simply remove PyLong_AS_LONG(), replace the %ld format code with %S or %R, and add a test and a NEWS entry. Welcome!

yunline added a commit to yunline/cpython that referenced this issue Sep 10, 2023
yunline added a commit to yunline/cpython that referenced this issue Sep 10, 2023
yunline added a commit to yunline/cpython that referenced this issue Sep 10, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Sep 10, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Sep 10, 2023
serhiy-storchaka pushed a commit that referenced this issue Sep 10, 2023
Yhg1s pushed a commit that referenced this issue Oct 2, 2023
GH-109225) (#109227)

gh-109207: Fix SystemError when printing symtable entry object. (GH-109225)
(cherry picked from commit 4297499)

Co-authored-by: 云line <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 only security fixes 3.12 bugs and security fixes 3.13 bugs and security fixes easy OS-windows type-bug An unexpected behavior, bug, or error
Projects
None yet
2 participants