platform/upstream/python-cython.git
11 years agoimplement 'raise ... from None' in Py3.3
Stefan Behnel [Tue, 12 Feb 2013 19:23:56 +0000 (20:23 +0100)]
implement 'raise ... from None' in Py3.3

--HG--
extra : rebase_source : 9ad9c4ea052a3eae0888f02a07ba4c40d62ddddf

11 years agochangelog
Stefan Behnel [Sun, 10 Feb 2013 09:10:40 +0000 (10:10 +0100)]
changelog

--HG--
extra : rebase_source : ca6bbd2378e2e67004b236da8a67e6b607aa0ae2

11 years agoFix docs about non-extern variables in pxd files.
Robert Bradshaw [Sat, 9 Feb 2013 21:21:46 +0000 (13:21 -0800)]
Fix docs about non-extern variables in pxd files.

11 years agofix build
Stefan Behnel [Sat, 9 Feb 2013 18:46:54 +0000 (19:46 +0100)]
fix build

11 years agoexternalise some utility code functions
Stefan Behnel [Sat, 9 Feb 2013 16:23:21 +0000 (17:23 +0100)]
externalise some utility code functions

11 years agoexternalise some utility code functions
Stefan Behnel [Sat, 9 Feb 2013 16:16:56 +0000 (17:16 +0100)]
externalise some utility code functions

11 years agomake a couple of parser errors non-fatal to keep parsing
Stefan Behnel [Sat, 9 Feb 2013 14:41:41 +0000 (15:41 +0100)]
make a couple of parser errors non-fatal to keep parsing

11 years agoclean up exec test file
Stefan Behnel [Sat, 9 Feb 2013 14:15:51 +0000 (15:15 +0100)]
clean up exec test file

11 years agoextended test case
Stefan Behnel [Sat, 9 Feb 2013 14:09:16 +0000 (15:09 +0100)]
extended test case

11 years agoimplement tuple compatibility form of Py2 exec statement
Stefan Behnel [Sat, 9 Feb 2013 14:07:26 +0000 (15:07 +0100)]
implement tuple compatibility form of Py2 exec statement

11 years agoclean up exec() code a little
Stefan Behnel [Sat, 9 Feb 2013 10:50:39 +0000 (11:50 +0100)]
clean up exec() code a little

11 years agoimprove error message on failing exec()
Stefan Behnel [Sat, 9 Feb 2013 10:34:36 +0000 (11:34 +0100)]
improve error message on failing exec()

11 years agosafety fix
Stefan Behnel [Sat, 9 Feb 2013 06:44:18 +0000 (07:44 +0100)]
safety fix

11 years agopatch inspect.isfunction() in pyregr tests to include CyFunction
Stefan Behnel [Fri, 8 Feb 2013 14:38:34 +0000 (15:38 +0100)]
patch inspect.isfunction() in pyregr tests to include CyFunction

11 years agoadd disabled test case
Stefan Behnel [Fri, 8 Feb 2013 07:44:37 +0000 (08:44 +0100)]
add disabled test case

11 years agosupport keyword arguments for C function pointers
Stefan Behnel [Fri, 8 Feb 2013 07:26:22 +0000 (08:26 +0100)]
support keyword arguments for C function pointers

11 years agofix kwargs mapping in Py2.[45]
Stefan Behnel [Thu, 7 Feb 2013 23:45:23 +0000 (00:45 +0100)]
fix kwargs mapping in Py2.[45]

11 years agoprovide fallback for cpdef functions that were previously called with full Python...
Stefan Behnel [Thu, 7 Feb 2013 23:07:20 +0000 (00:07 +0100)]
provide fallback for cpdef functions that were previously called with full Python semantics

11 years agofix one more test fixing after changing declared C function argument names
Stefan Behnel [Thu, 7 Feb 2013 23:04:17 +0000 (00:04 +0100)]
fix one more test fixing after changing declared C function argument names

11 years agoadd test for keyword arguments passed into cdef functions with optional arguments...
Stefan Behnel [Thu, 7 Feb 2013 22:52:52 +0000 (23:52 +0100)]
add test for keyword arguments passed into cdef functions with optional arguments, fix parameter names in test

11 years agofix illegal Python names in C lower cased declarations
Stefan Behnel [Thu, 7 Feb 2013 22:49:45 +0000 (23:49 +0100)]
fix illegal Python names in C lower cased declarations

11 years agorename test
Stefan Behnel [Thu, 7 Feb 2013 22:33:29 +0000 (23:33 +0100)]
rename test

--HG--
rename : tests/run/simplify_calls.pyx => tests/run/cdef_function_kwargs.pyx

11 years agoconvert function argument names in libc declarations to lower case to make their...
Stefan Behnel [Thu, 7 Feb 2013 22:25:38 +0000 (23:25 +0100)]
convert function argument names in libc declarations to lower case to make their use as keyword arguments more natural

11 years agoextend cdef function kwargs tests to include functions from the libc standard declara...
Stefan Behnel [Thu, 7 Feb 2013 21:58:07 +0000 (22:58 +0100)]
extend cdef function kwargs tests to include functions from the libc standard declarations

11 years agochangelog
Stefan Behnel [Thu, 7 Feb 2013 21:35:33 +0000 (22:35 +0100)]
changelog

11 years agofix ticket 801: wrong declarations in math.pxd for frexp() and ldexp()
Stefan Behnel [Thu, 7 Feb 2013 21:33:14 +0000 (22:33 +0100)]
fix ticket 801: wrong declarations in math.pxd for frexp() and ldexp()

11 years agoimprove error reporting on mapped keyword arguments for C functions, implement out...
Stefan Behnel [Thu, 7 Feb 2013 21:31:49 +0000 (22:31 +0100)]
improve error reporting on mapped keyword arguments for C functions, implement out-of-order keywords and C method mapping

11 years agoMerge pull request #183 from jrray/master
scoder [Thu, 7 Feb 2013 18:16:35 +0000 (10:16 -0800)]
Merge pull request #183 from jrray/master

Fix runtime crash as described on cython-devel.

11 years agoFully initialize allocated memory.
J Robert Ray [Thu, 7 Feb 2013 18:03:48 +0000 (10:03 -0800)]
Fully initialize allocated memory.

__pyx_CyFunctionObject.defaults must be fully zeroed or a segfault or
memory corruption may occur if the object is visited by the garbage
collector before defaults is later populated. Uninitialized memory is
cast to PyObject* with undefined results:

  static int __Pyx_CyFunction_traverse(__pyx_CyFunctionObject *m, visitproc visit, void *arg)
  {
      ...
      if (m->defaults) {
          PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m);
          int i;
          for (i = 0; i < m->defaults_pyobjects; i++)
              Py_VISIT(pydefaults[i]);
                       ^^^^^^^^^^^^^

11 years agoreimplement SimplifyCalls transform in-place in GeneralCallNode.analyse_types()
Stefan Behnel [Thu, 7 Feb 2013 17:59:43 +0000 (18:59 +0100)]
reimplement SimplifyCalls transform in-place in GeneralCallNode.analyse_types()

11 years agorefactor analyse_types() and friends to work more like a transform by returning the...
Stefan Behnel [Thu, 7 Feb 2013 07:16:27 +0000 (08:16 +0100)]
refactor analyse_types() and friends to work more like a transform by returning the node or a replacement

11 years agomatch simple keyword arguments that are passed into cdef function calls out-of-order
Stefan Behnel [Wed, 6 Feb 2013 18:41:24 +0000 (19:41 +0100)]
match simple keyword arguments that are passed into cdef function calls out-of-order

11 years agofix safety coercion after call node optimisation
Stefan Behnel [Wed, 6 Feb 2013 09:47:23 +0000 (10:47 +0100)]
fix safety coercion after call node optimisation

11 years agomove major part of SimplifyCalls transform into type analysis in GeneralCallNode
Stefan Behnel [Wed, 6 Feb 2013 07:34:40 +0000 (08:34 +0100)]
move major part of SimplifyCalls transform into type analysis in GeneralCallNode

11 years agofix error test after enabling keyword arguments in simple C functions
Stefan Behnel [Wed, 6 Feb 2013 06:18:53 +0000 (07:18 +0100)]
fix error test after enabling keyword arguments in simple C functions

11 years agofix compiler crash
Stefan Behnel [Wed, 6 Feb 2013 06:17:44 +0000 (07:17 +0100)]
fix compiler crash

11 years agofix error test after enabling keyword arguments in simple C functions
Stefan Behnel [Wed, 6 Feb 2013 06:16:49 +0000 (07:16 +0100)]
fix error test after enabling keyword arguments in simple C functions

11 years agosimple optimisation that statically maps keyword arguments to positional arguments...
Stefan Behnel [Tue, 5 Feb 2013 20:38:23 +0000 (21:38 +0100)]
simple optimisation that statically maps keyword arguments to positional arguments when called signature is known

11 years agoadd some more typing in FlowControl.py
Stefan Behnel [Mon, 4 Feb 2013 21:43:26 +0000 (22:43 +0100)]
add some more typing in FlowControl.py

11 years agodisable incorrect optimisation for set.discard()
Stefan Behnel [Mon, 4 Feb 2013 21:22:03 +0000 (22:22 +0100)]
disable incorrect optimisation for set.discard()

11 years agominor tweak
Stefan Behnel [Mon, 4 Feb 2013 18:34:05 +0000 (19:34 +0100)]
minor tweak

11 years agodeclare some classes in FlowControl.py final to speed up internal method calls
Stefan Behnel [Mon, 4 Feb 2013 17:54:37 +0000 (18:54 +0100)]
declare some classes in FlowControl.py final to speed up internal method calls

11 years agoclean up and improve static type declarations in FlowControl.py a bit
Stefan Behnel [Mon, 4 Feb 2013 17:42:58 +0000 (18:42 +0100)]
clean up and improve static type declarations in FlowControl.py a bit

11 years agoslight code simplification
Stefan Behnel [Mon, 4 Feb 2013 17:04:31 +0000 (18:04 +0100)]
slight code simplification

11 years agoextend test case
Stefan Behnel [Sat, 2 Feb 2013 10:26:01 +0000 (11:26 +0100)]
extend test case

11 years agorst fix
Stefan Behnel [Fri, 1 Feb 2013 22:10:24 +0000 (23:10 +0100)]
rst fix

11 years agoclean up the C library wrapping tutorial a bit and add a section on callbacks
Stefan Behnel [Fri, 1 Feb 2013 22:02:23 +0000 (23:02 +0100)]
clean up the C library wrapping tutorial a bit and add a section on callbacks

11 years agoclarify comment in example
Stefan Behnel [Fri, 1 Feb 2013 21:23:42 +0000 (22:23 +0100)]
clarify comment in example

11 years agoOops, we do handle raise MemoryError() gracefully.
Robert Bradshaw [Fri, 1 Feb 2013 17:46:57 +0000 (09:46 -0800)]
Oops, we do handle raise MemoryError() gracefully.

11 years agoUndo a couple of documentation fixes (where the old style was intentional).
Robert Bradshaw [Fri, 1 Feb 2013 17:43:14 +0000 (09:43 -0800)]
Undo a couple of documentation fixes (where the old style was intentional).

11 years agoFix one instance of code highlighting
Yury V. Zaytsev [Fri, 1 Feb 2013 14:26:18 +0000 (15:26 +0100)]
Fix one instance of code highlighting

11 years agoFix various typos in the documentation
Yury V. Zaytsev [Fri, 1 Feb 2013 14:25:25 +0000 (15:25 +0100)]
Fix various typos in the documentation

11 years agoUpdate code samples to use newer Cython / Python syntax
Yury V. Zaytsev [Fri, 1 Feb 2013 14:22:02 +0000 (15:22 +0100)]
Update code samples to use newer Cython / Python syntax

11 years agoFix broken code samples (indent, spaces, failing doctest)
Yury V. Zaytsev [Fri, 1 Feb 2013 14:20:20 +0000 (15:20 +0100)]
Fix broken code samples (indent, spaces, failing doctest)

11 years agoPrefer the use of C++ style pointer declarations (char *c -> char* c)
Yury V. Zaytsev [Fri, 1 Feb 2013 14:16:28 +0000 (15:16 +0100)]
Prefer the use of C++ style pointer declarations (char *c -> char* c)

11 years agoRemove extra commas before colons (,:: -> ::)
Yury V. Zaytsev [Fri, 1 Feb 2013 14:13:45 +0000 (15:13 +0100)]
Remove extra commas before colons (,:: -> ::)

11 years agoIntroduce more consistent capitalization of Python, Cython and NumPy
Yury V. Zaytsev [Fri, 1 Feb 2013 14:09:48 +0000 (15:09 +0100)]
Introduce more consistent capitalization of Python, Cython and NumPy

11 years agoFix some internal and external links in the documentation
Yury V. Zaytsev [Fri, 1 Feb 2013 14:04:07 +0000 (15:04 +0100)]
Fix some internal and external links in the documentation

11 years agomerge 0.18.x branch into master
Stefan Behnel [Wed, 30 Jan 2013 07:04:45 +0000 (08:04 +0100)]
merge 0.18.x branch into master

11 years agoremove warning about missing 'const' support from docs and fix advice on declaring...
Stefan Behnel [Wed, 30 Jan 2013 07:04:10 +0000 (08:04 +0100)]
remove warning about missing 'const' support from docs and fix advice on declaring macros as 'enum' (which works only for ints)

11 years agoexclude test in Py2.4
Stefan Behnel [Tue, 29 Jan 2013 06:40:03 +0000 (07:40 +0100)]
exclude test in Py2.4

11 years agoAdded tag 0.18 for changeset 76f33728e853
Stefan Behnel [Mon, 28 Jan 2013 21:46:51 +0000 (22:46 +0100)]
Added tag 0.18 for changeset 76f33728e853

11 years agoincrease master version to 0.19-dev
Stefan Behnel [Mon, 28 Jan 2013 21:45:32 +0000 (22:45 +0100)]
increase master version to 0.19-dev

11 years agomerge 0.18.x branch into master
Stefan Behnel [Mon, 28 Jan 2013 21:44:28 +0000 (22:44 +0100)]
merge 0.18.x branch into master

11 years agoprepare release of 0.18 0.18
Stefan Behnel [Mon, 28 Jan 2013 21:27:24 +0000 (22:27 +0100)]
prepare release of 0.18

11 years agofix a corner case where float(x) would not call x.__float__() for a float subtype
Stefan Behnel [Mon, 28 Jan 2013 21:04:04 +0000 (22:04 +0100)]
fix a corner case where float(x) would not call x.__float__() for a float subtype

11 years agoAdded tag 0.18rc1 for changeset 9a11631e0edb
Stefan Behnel [Mon, 28 Jan 2013 07:00:48 +0000 (08:00 +0100)]
Added tag 0.18rc1 for changeset 9a11631e0edb

11 years agomerge 0.18.x branch into master
Stefan Behnel [Mon, 28 Jan 2013 07:00:11 +0000 (08:00 +0100)]
merge 0.18.x branch into master

11 years agoMerge pull request #179 from cgohlke/patch-3
scoder [Mon, 28 Jan 2013 06:52:41 +0000 (22:52 -0800)]
Merge pull request #179 from cgohlke/patch-3

Fix overflow_check CompileError with msvc

11 years agoFix overflow_check CompileError with msvc
Christoph Gohlke [Sun, 27 Jan 2013 18:07:01 +0000 (10:07 -0800)]
Fix overflow_check CompileError with msvc

--HG--
extra : transplant_source : %3FH%B6t%1FFL%D8%2BF%7CV%7D%10T9%EA%CB%A0%00

11 years agoFix overflow_check CompileError with msvc
Christoph Gohlke [Sun, 27 Jan 2013 18:07:01 +0000 (10:07 -0800)]
Fix overflow_check CompileError with msvc

11 years agofix doctest dependency on dict order
Stefan Behnel [Sun, 27 Jan 2013 14:12:02 +0000 (15:12 +0100)]
fix doctest dependency on dict order

11 years agoset version to 0.18rc1 0.18rc1
Stefan Behnel [Sun, 27 Jan 2013 12:18:05 +0000 (13:18 +0100)]
set version to 0.18rc1

11 years agoenable control flow analysis for stack allocated structured variables (struct, union...
Stefan Behnel [Sun, 27 Jan 2013 10:22:21 +0000 (11:22 +0100)]
enable control flow analysis for stack allocated structured variables (struct, union, array, C++ class)

11 years agosimplify code a bit
Stefan Behnel [Sun, 27 Jan 2013 05:47:44 +0000 (06:47 +0100)]
simplify code a bit

11 years agouse interned Python string constant instead of calling through __Pyx_GetAttrString()
Stefan Behnel [Sun, 27 Jan 2013 05:45:58 +0000 (06:45 +0100)]
use interned Python string constant instead of calling through __Pyx_GetAttrString()

11 years agomerge 0.18.x branch into master
Stefan Behnel [Sun, 27 Jan 2013 05:16:47 +0000 (06:16 +0100)]
merge 0.18.x branch into master

11 years agofix C compiler warnings about missing PyModuleDef field initialisers in Py3.[01]
Stefan Behnel [Sun, 27 Jan 2013 05:16:30 +0000 (06:16 +0100)]
fix C compiler warnings about missing PyModuleDef field initialisers in Py3.[01]

11 years agomerge 0.18.x branch into master
Stefan Behnel [Sun, 27 Jan 2013 04:56:27 +0000 (05:56 +0100)]
merge 0.18.x branch into master

11 years agofix new test in Py2.[45]
Stefan Behnel [Sun, 27 Jan 2013 04:56:12 +0000 (05:56 +0100)]
fix new test in Py2.[45]

11 years agorewrite except-as semantics using try-finally - seems to be the easiest way to get...
Stefan Behnel [Sat, 26 Jan 2013 21:24:46 +0000 (22:24 +0100)]
rewrite except-as semantics using try-finally - seems to be the easiest way to get flow control analysis working for all cases

11 years agomerge 0.18.x branch into master
Stefan Behnel [Sat, 26 Jan 2013 18:20:35 +0000 (19:20 +0100)]
merge 0.18.x branch into master

11 years agoMerge pull request #164 from strohel/master
scoder [Sat, 26 Jan 2013 18:19:07 +0000 (10:19 -0800)]
Merge pull request #164 from strohel/master

Add test for memoryview of extension type

11 years agomerge 0.18.x branch into master
Stefan Behnel [Sat, 26 Jan 2013 18:15:39 +0000 (19:15 +0100)]
merge 0.18.x branch into master

11 years agoMerge pull request #178 from strohel/cpp-catch-in-nogil
scoder [Sat, 26 Jan 2013 18:11:48 +0000 (10:11 -0800)]
Merge pull request #178 from strohel/cpp-catch-in-nogil

Fix calling an "except +" cpp function in a nogil function

11 years agoenable except-as target deletion only when language level is 3
Stefan Behnel [Sat, 26 Jan 2013 13:53:30 +0000 (14:53 +0100)]
enable except-as target deletion only when language level is 3

11 years agodisable broken optimisation for except-as special case
Stefan Behnel [Sat, 26 Jan 2013 13:23:47 +0000 (14:23 +0100)]
disable broken optimisation for except-as special case

11 years agoremove some code redundancy
Stefan Behnel [Sat, 26 Jan 2013 12:55:16 +0000 (13:55 +0100)]
remove some code redundancy

11 years agoextend except-as test case
Stefan Behnel [Sat, 26 Jan 2013 12:15:04 +0000 (13:15 +0100)]
extend except-as test case

11 years agomake except-as delete the target after the except clause
Stefan Behnel [Sat, 26 Jan 2013 12:06:57 +0000 (13:06 +0100)]
make except-as delete the target after the except clause

11 years agomerge 0.18.x branch into master
Stefan Behnel [Sat, 26 Jan 2013 10:06:46 +0000 (11:06 +0100)]
merge 0.18.x branch into master

11 years agofix test when using NumPy 1.7
Stefan Behnel [Sat, 26 Jan 2013 10:06:26 +0000 (11:06 +0100)]
fix test when using NumPy 1.7

11 years agomerge 0.18.x branch into master
Stefan Behnel [Sat, 26 Jan 2013 09:57:20 +0000 (10:57 +0100)]
merge 0.18.x branch into master

11 years agofix new memory view error test in Py2.4
Stefan Behnel [Sat, 26 Jan 2013 09:54:04 +0000 (10:54 +0100)]
fix new memory view error test in Py2.4

--HG--
extra : transplant_source : %8A%F1%17%5C%A7%CA%1C%B1%17%A1%C5t%06O%5BI%F2%19Vq

11 years agofix new memory view error test in Py2.4
Stefan Behnel [Sat, 26 Jan 2013 09:54:04 +0000 (10:54 +0100)]
fix new memory view error test in Py2.4

11 years agoFix calling an "except +" cpp function in a nogil function
Matěj Laitl [Fri, 25 Jan 2013 10:27:49 +0000 (11:27 +0100)]
Fix calling an "except +" cpp function in a nogil function

For a source:
|cdef extern from "<foo>":
|    cdef void foo_cpp() nogil except +
|
|cdef call_foo() nogil:
|    foo_cpp()

We used to generate something like this to actually call foo_cpp() in call_foo():
|try{foo_cpp();}
|catch(...) {
|  Py_BLOCK_THREADS; __Pyx_CppExn2PyErr(); Py_UNBLOCK_THREADS
|  `code.error_goto(self.pos))`
|}

where Py_BLOCK_THREADS expands to "PyEval_RestoreThread(_save);".
__Pyx_CppExn2PyErr() (and alternatives, see SimpleCallNode) calls CPython A API
methods so it needs to be guarded in a nogil environment.

One problem is that "PyThreadState *_save" is only declared by "with nogil:"
block, so a .cpp file that doesn't compile is generated for the above code.

However, I think the real issue is that Py_(UN)BLOCK_THREADS is inappropriate
here, as it isn't allowed to be called recursively and is valid only directly
in a Py_BEGIN_ALLOW_THREADS ... Py_END_ALLOW_THREADS. IMO PyGILState_Ensure()
and PyGILState_Release() (through `code.put_ensure_gil()` and a friend) is the
correct thing to call here as it is allowed to be called recursively and
actually ensures the current thread can call CPython C API.

This patch does exactly this (and it breaks the generated code to multiple
lines as it would be way too long otherwise), plus it extends the
cpp_exceptions_nogil.pyx test with above example that doesn't compile with this
fix not applied.

Note that we explicitly pass declare_gilstate=True to put_ensure_gil(), as
PyGILState_Ensure() docs state that recursive calls to it must not share the
PyGILState_STATE. C++-style declaring a variable inside a block should be
no-problem here, as try{} .. catch() is obviously valid only in a C++ code.

--HG--
extra : transplant_source : %AA%F3%BDk%FE%F9%01%7F%8C%A4n%5E%DA4%97%A5%D9%AF%D60

11 years agochangelog
Stefan Behnel [Sat, 26 Jan 2013 18:15:09 +0000 (19:15 +0100)]
changelog

11 years agoFix calling an "except +" cpp function in a nogil function
Matěj Laitl [Fri, 25 Jan 2013 10:27:49 +0000 (11:27 +0100)]
Fix calling an "except +" cpp function in a nogil function

For a source:
|cdef extern from "<foo>":
|    cdef void foo_cpp() nogil except +
|
|cdef call_foo() nogil:
|    foo_cpp()

We used to generate something like this to actually call foo_cpp() in call_foo():
|try{foo_cpp();}
|catch(...) {
|  Py_BLOCK_THREADS; __Pyx_CppExn2PyErr(); Py_UNBLOCK_THREADS
|  `code.error_goto(self.pos))`
|}

where Py_BLOCK_THREADS expands to "PyEval_RestoreThread(_save);".
__Pyx_CppExn2PyErr() (and alternatives, see SimpleCallNode) calls CPython A API
methods so it needs to be guarded in a nogil environment.

One problem is that "PyThreadState *_save" is only declared by "with nogil:"
block, so a .cpp file that doesn't compile is generated for the above code.

However, I think the real issue is that Py_(UN)BLOCK_THREADS is inappropriate
here, as it isn't allowed to be called recursively and is valid only directly
in a Py_BEGIN_ALLOW_THREADS ... Py_END_ALLOW_THREADS. IMO PyGILState_Ensure()
and PyGILState_Release() (through `code.put_ensure_gil()` and a friend) is the
correct thing to call here as it is allowed to be called recursively and
actually ensures the current thread can call CPython C API.

This patch does exactly this (and it breaks the generated code to multiple
lines as it would be way too long otherwise), plus it extends the
cpp_exceptions_nogil.pyx test with above example that doesn't compile with this
fix not applied.

Note that we explicitly pass declare_gilstate=True to put_ensure_gil(), as
PyGILState_Ensure() docs state that recursive calls to it must not share the
PyGILState_STATE. C++-style declaring a variable inside a block should be
no-problem here, as try{} .. catch() is obviously valid only in a C++ code.

11 years agoMerge pull request #177 from strohel/propagate-error-memoryview
Robert Bradshaw [Fri, 25 Jan 2013 07:37:11 +0000 (23:37 -0800)]
Merge pull request #177 from strohel/propagate-error-memoryview

Fix error propagation from memoryview-returning functions

11 years agoFix error propagation from memoryview-returning functions
Matěj Laitl [Thu, 24 Jan 2013 10:59:23 +0000 (11:59 +0100)]
Fix error propagation from memoryview-returning functions

A code like
|cdef double[:] foo():
|    raise AttributeError('dummy')

generated C code like this:
|  __pyx_L1_error:;
|  (...)
|  __pyx_r.memview = NULL;
|  __Pyx_AddTraceback("view_return_errors.foo", __pyx_clineno, __pyx_lineno, __pyx_filename);
|  __pyx_L0:;
|  if (unlikely(!__pyx_r.memview)) {
|    PyErr_SetString(PyExc_TypeError,"Memoryview return value is not initialized");
|  }
|  __Pyx_RefNannyFinishContext();
|  return __pyx_r;
|}

Which is incorrect in error case, because we set __pyx_r.memview to NULL and
then we test it, so that the PyErr_SetString() is always called in the error
case, which swallows previously-set error. (it also swallowed the traceback,
which I don't understand)

A fix is to jump to return_from_error_cleanup label in case return type is
memoryview, as it is currently done for the case when buffers are present.

A testcase that fauils w/out this fix applied is included, too.

v2: fix test under Python 3 by not using StandardError

--HG--
extra : transplant_source : G%B5%99Og%D1%81%25k%8F%1F%7B%02V%3E%B9%A4y%FF%EA