You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2016-04-16.08:02:38.488>labels= ['interpreter-core']
title='Determining the failure of C API call is ambiguous'updated_at=<Date2016-04-16.09:27:24.259>user='https://github.com/serhiy-storchaka'
C API functions returns a special value unambiguously signaling about a raised exception (NULL or -1). But in some cases this is ambiguous, because the special value is a legitimate value (e.g. -1 for PyLong_AsLong() or NULL for PyDict_GetItem()). Needed to use PyErr_Occurred() to distinguish between successful and failed call.
The problem is that if PyLong_AsLong() is called when the exception is set, successful call returned -1 is interpreted as failed. Since it is happen in very rare case, this bug is usually unnoticed.
Attached experimental patch makes some functions like PyLong_AsLong() always failing if called with an exception set. Some tests are failed with it applied: test_compile test_datetime test_io test_os test_symtable test_syntax test_xml_etree_c.
Ah yes. Some months (years?) ago, i started to add assertions to fail if
some functions are called with an exception set.
Checking if an exception is set at runtime adds a low overhead. Maybe it's
better to fail with a fatal error (like an assertion error) in debug mode
(and do nothing in release mode).
But I'm not sure that developers of C extensions are all able to get a
Python compiled in debug mode :-/ That's also why I added a check a
runtime: raise a SystemError if a function with an exception set. I also
added PYTHONMALLOC=debug to make some debug checks easily available on
release builds.
The bug also reminds me my PEP-490 to chain exceptions. It would be
yet another option...
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: