Commit d534bd67 authored by Dean Moldovan's avatar Dean Moldovan Committed by Wenzel Jakob
Browse files

Fix handling of Python exceptions during module initialization (#657)

Fixes #656.

Before this commit, the problematic sequence was:

1. `catch (const std::exception &e)` gets a Python exception,
   i.e. `error_already_set`.
2. `PyErr_SetString(PyExc_ImportError, e.what())` sets an `ImportError`.
3. `~error_already_set()` now runs, but `gil_scoped_acquire` fails due
   to an unhandled `ImportError` (which was just set in step 2).

This commit adds a separate catch block for Python exceptions which just
clears the Python error state a little earlier and replaces it with an
`ImportError`, thus making sure that there is only a single Python
exception in flight at a time. (After step 2 in the sequence above,
there were effectively two Python expections set.)
parent 1eaacd19
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment