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-38631: Replace compiler fatal errors with exceptions #24369

Merged
merged 3 commits into from
Jan 30, 2021
Merged

bpo-38631: Replace compiler fatal errors with exceptions #24369

merged 3 commits into from
Jan 30, 2021

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Jan 29, 2021

  • Replace Py_FatalError() calls with regular SystemError exceptions.
  • compiler_exit_scope() calls _PyErr_WriteUnraisableMsg() to log the
    PySequence_DelItem() failure.
  • compiler_unit_check() uses _PyMem_IsPtrFreed()
  • compiler_make_closure(): remove "(reftype == FREE)" comment since
    reftype can also be LOCAL or GLOBAL_EXPLICIT.

https://bugs.python.org/issue38631

* Replace Py_FatalError() calls with regular SystemError exceptions.
* compiler_exit_scope() calls _PyErr_WriteUnraisableMsg() to log the
  PySequence_DelItem() failure.
* compiler_unit_check() uses _PyMem_IsPtrFreed()
* compiler_make_closure(): remove "(reftype == FREE)" comment since
  reftype can also be LOCAL or GLOBAL_EXPLICIT.
@vstinner
Copy link
Member Author

cc @isidentical @lysnikolaou @pablogsal

I injected bugs to check if the SystemError error message is formatted properly.

Error 1:

SystemError: PyST_GetScope(name='self') failed: unknown scope in unit update_sources_depends (31747488); symbols: {'self': 10260, 'moddirlist': 10242, 'os': 6160, 'headers': 2066, 'sysconfig': 6160, 'glob': 6160, 'escape': 6160, 'ext': 2066}; locals: {'self': 0}; globals: {'os': 0, 'path': 1, 'join': 2, 'srcdir': 3}

Error 2:

SystemError: compiler_lookup_arg(name='self') with reftype=5 failed in update_sources_depends; freevars of code '<listcomp>': ('self',)

Error 3:

SystemError: compiler stack_effect(opcode=116, arg=0) failed

It seems like if PySequence_DelItem() fails in compiler_exit_scope(), the compiler can crash. But I prefer to log the exception rather than exiting the whole process immediately. As written in the comment, since c_stack is a list, the function "shouldn't fail":

    /* we are deleting from a list so this really shouldn't fail */

arg = compiler_lookup_arg(c->u->u_cellvars, name);
else /* (reftype == FREE) */
}
else {
Copy link
Member

Choose a reason for hiding this comment

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

Please, preserve the comment for the else branch: /* (reftype == FREE) */

Copy link
Member Author

Choose a reason for hiding this comment

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

Please, preserve the comment for the else branch: /* (reftype == FREE) */

See the commit message: the comment is wrong. Try to convert the comment into an assertion.

vstinner and others added 2 commits January 30, 2021 01:03
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
@vstinner vstinner merged commit ba7a99d into python:master Jan 30, 2021
@vstinner vstinner deleted the compiler_fatal branch January 30, 2021 00:46
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 13, 2021
)

* Replace Py_FatalError() calls with regular SystemError exceptions.
* compiler_exit_scope() calls _PyErr_WriteUnraisableMsg() to log the
  PySequence_DelItem() failure.
* compiler_unit_check() uses _PyMem_IsPtrFreed().
* compiler_make_closure(): remove "(reftype == FREE)" comment since
  reftype can also be LOCAL or GLOBAL_EXPLICIT.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants