Package: python-pyrex
Version: 0.9.9-1
Severity: normal

[crybaby /tmp/mdw]cat t.pyx
### -*-pyrex-*-

def test(x):
  try: return int(x)
  except TypeError: pass
  return 'failed'
[crybaby /tmp/mdw]cat u.py
### -*-python-*-

import t

def p(x):
  y = t.test(x)
  print '%r -> %r' % (x, y)
for i in [1, id, 3]:
  p(i)
[crybaby /tmp/mdw]pyrexc t.pyx && gcc -fPIC -Og -g -c -I/usr/include/python2.7 
t.c && ld -shared -otmodule.so t.o -lpython2.7
[crybaby /tmp/mdw]python u.py
1 -> 1
<built-in function id> -> 'failed'
3 -> 3
Traceback (most recent call last):
  File "u.py", line 8, in <module>
    for i in [1, id, 3]:
TypeError: int() argument must be a string or a number, not 
'builtin_function_or_method'

It's choking on `id', but shouldn't because the `test' function
shouldn't have let a `TypeError' escape.  Indeed, it sort of didn't: we
see that it returned `failed' just fine, continued hacking on the rest
of the list, and /then/ exploded at the end of the `for' loop.

I don't know CPython's internals well enough to say exactly why, but it
checks for pending exceptions after loops, and while Pyrex has performed
the appropriate evasive action following the `TypeError', it failed to
mark the error has handled (likely by calling `PyErr_Clear'), leaving a
time-bomb for later.

-- [mdw]

Reply via email to