New submission from 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.

----------
components: Interpreter Core
files: check_error_occurred.patch
keywords: patch
messages: 263540
nosy: haypo, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Determining the failure of C API call is ambiguous
Added file: http://bugs.python.org/file42478/check_error_occurred.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue26776>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to