[issue17544] regex code re-raises exceptions on success

2020-05-31 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

When function sets an exception, it should return NULL. Otherwise the behavior 
of the interpreter is undefined, it can crash in debug build or developing mode.

See for example 
https://docs.python.org/3/extending/extending.html#intermezzo-errors-and-exceptions

--
nosy: +serhiy.storchaka
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17544] regex code re-raises exceptions on success

2013-03-26 Thread Zdeněk Pavlas

Zdeněk Pavlas added the comment:

Yes, found that *certain* IO operations re-raise the error, too.  However, if 
the Python runtime expects extension writers to keep tstate-curexc_type clear, 
it should be documented in

http://docs.python.org/2/c-api/exceptions.html

There's not a single use case of PyErr_Clear() mentioned.

--
assignee:  - docs@python
components: +Documentation -Regular Expressions
nosy: +docs@python

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17544
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17544] regex code re-raises exceptions on success

2013-03-25 Thread Zdeněk Pavlas

New submission from Zdeněk Pavlas:

documentation
There is a global indicator (per thread) of the last error that occurred. Most 
functions do not clear this on success, but will set it to indicate the cause 
of the error on failure. Most functions also return an error indicator, usually 
NULL if they are supposed to return a pointer, or -1 if they return an integer.
/documentation

AIUI, the last error global variable should be ignored, unless function fails.  
This is not the case.  To reproduce:

1. call a C function that sets TypeError, but does not return NULL.
2. run a lot of python code, do some I/O.. everything runs fine.
3. run a regexp match, or import the re module.  TypeError is raised.

--
components: Regular Expressions
messages: 185205
nosy: Zdeněk.Pavlas, ezio.melotti, mrabarnett
priority: normal
severity: normal
status: open
title: regex code re-raises exceptions on success
versions: Python 2.7

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17544
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17544] regex code re-raises exceptions on success

2013-03-25 Thread Ezio Melotti

Ezio Melotti added the comment:

Can you provide an actual example to reproduce the error?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17544
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17544] regex code re-raises exceptions on success

2013-03-25 Thread Zdeněk Pavlas

Zdeněk Pavlas added the comment:

static PyObject*
foo(PyObject *, PyObject *arg)
{
void *buf;
Py_ssize_t size;
if (PyObject_AsReadBuffer(arg, buf, size))
size = -1;
return PyInt_FromLong(size);
}

 import tst, re
 re.search(a, a)
_sre.SRE_Match object at 0xb76d0950
 tst.foo(abc)
3
 re.search(a, a)
_sre.SRE_Match object at 0xb76d0950
 tst.foo(None)
-1
 re.search(a, a)
TypeError: expected a readable buffer object


--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17544
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17544] regex code re-raises exceptions on success

2013-03-25 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc added the comment:

The returned value and the global indicator are not independent.  C functions 
should not set an error while returning a valid value.

The same behavior will occur in random places -- for example, for x in 
range(2): pass also triggers the issue, this is not specific to the re module.

If you compile python in debug mode (--with-pydebug) an additional (and 
expensive) check is done and will print XXX undetected error.

One of the reasons is that accessing the global indicator is an expensive 
operation, compared to checking the returned value.
But there are cases when this cannot be done. For example, PyIter_Next() 
returns NULL at the end of the loop, and one must call PyErr_Occurred() to 
check for errors.

In the _sre.c case though, it looks more like laziness: intermediate returned 
values are not checked, and PyErr_Occurred() is called at the end.  Bad.

--
nosy: +amaury.forgeotdarc

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17544
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com