Re: [Cython] Bug(?): chained assignments and tuple unpacking

2013-04-12 Thread Stefan Behnel
Alok Singhal, 10.04.2013 22:36:
> The following code (also attached as a .pyx file) fails in the current
> Cython :
> 
> cdef class test:
> pass
> 
> def main():
> cdef test a, b, c, d
> (a, b) = (c, d) = (None, None)
> 
> When run, I get the following traceback:
> 
> In [1]: import assign_test
> In [2]: assign_test.main()
> Traceback (most recent call last):
>   File "", line 1, in 
> assign_test.main()
>   File "assign_test.pyx", line 6, in assign_test.main (assign_test.c:669)
> (a, b) = (c, d) = (None, None)
> TypeError: Cannot convert NoneType to assign_test.test
> 
> I am using the latest Cython development version (from github).  Also
> tested with Cython 0.18.
> 
> $ git rev-parse HEAD
> e8bd1789905a58d8224e4be5019be401f360aa54
> 
> I don't get an error when I change the assignments to either:
> 
> (a, b) = (None, None)
> 
> or
> 
> a = b = None
> 
> Is this a bug in Cython?  I tried doing a git bisect and it seems like
> commit ea6a71acb5c79afb080855be1cb6ca30d283ec25 is when the above code
> started failing (It works with the previous commit).

Thanks for the report and the excellent analysis. Here is a fix:

https://github.com/cython/cython/commit/eb1e7173133a5dcc266203e8928c60b2e3b8446a

Plus, the generated code was horribly redundant. I cleaned it up.

https://github.com/cython/cython/commit/2592064271ea1c1b9ad1844232c5890e06861eb3

Stefan

___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


[Cython] Cython 0.19 beta 2 released

2013-04-12 Thread Stefan Behnel
Hi,

I uploaded a second (and hopefully last) beta release for Cython 0.19.
Please give it a try with your code.

http://cython.org/release/Cython-0.19b2.tar.gz

http://cython.org/release/Cython-0.19b2.zip


Cython 0.19 features many enhancements and changes regarding performance,
usability and Python compatibility, including some very long standing bugs
and issues. The changelog is on github:

https://github.com/cython/cython/blob/58131b68dc033fc7ca269d875a2aab2b4e9646a2/CHANGES.rst


The latest documentation is here:

https://sage.math.washington.edu:8091/hudson/job/cython-docs/doclinks/1/


Have fun,

Stefan
___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] [PATCH] Refcount error when transposing memoryview attribute of an extension class

2013-04-12 Thread Matěj Laitl
On 8. 4. 2013 Matěj Laitl wrote:
> Hi cython-devel and Mark,
> I was getting
> 
> > Fatal Python error: Acquisition count is 0 (line XYZ)
> 
> when I was doing
> 
> > cdef class MemViewContainer:
> > cdef double[:, :] A
> > 
> > cdef a_method(self):
> > self.A = np.eye(2)
> > some_function(self.A.T)
> > some_function(self.A.T)
> 
> I have found out that it is caused by the self.A.T expression - Cython emits
> __PYX_XDEC_MEMVIEW() after the call, but no __PYX_INC_MEMVIEW() before the
> call. This doesn't happen if the memoryview is a function-local variable.
> 
> Proper test case is in the pull request [1] along with an ad-hoc patch that
> fixes the problem here, but needs review whether it is actually correct. I'd
> be very grateful if a fix for this problem could get it into Cython 0.19.
> 
> Cython version: 0.19b1 3a6b9856187d7e490e08
> 
> [1] https://github.com/cython/cython/pull/201

Bump. Anything else I can provide to help with getting this fixed in 0.19?

Ragards,
Matěj
___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


[Cython] Generated C++ code incompatible with Clang

2013-04-12 Thread Hannes Röst
Dear mailing list

In the process of developing a rather large Cython project where we wrap the
scientific OpenMS library (http://sourceforge.net/projects/open-ms/) using
Cython, we have come across an issue with the C++ code that is generated by
Cython. The issue is that Cython generates C++ that is not compatible with the
Clang compiler.

I hope this is the correct mailing list to report this issue since it seems to
be a bug in Cython and not in Clang (after some discussion we have concluded
that Clang is most likely correct in rejecting the generated code). Since we do
not have access to the issue tracker, we hoped posting our issue here would
clear up matters.

The issue occurs with the following minimal testcase:

from libcpp.vector cimport vector as libcpp_vector
from cython.operator cimport dereference as deref, preincrement as inc

cdef class TestClass:

cdef libcpp_vector[float] inst

def __iter__(self):
it = self.inst.begin()
while it != self.inst.end():
yield deref(it)
inc(it)

When compiled with Cython to C++, it generates C++ that cannot be compiled with
Clang (however it seems that gcc and MSVS accept the code). It seems that the
same issue with Clang was already discussed here:
https://bugzilla.mozilla.org/show_bug.cgi?id=623303 and the conclusion was that
Clang is correct in reporting the code as erroneous.

In the above case, the invalid C++ code that gets generated is:

  p->__pyx_v_it.std::vector::iterator::~iterator();

The correct code for the above case would probably be (this is just a
suggestion, it compiles with gcc and clang on our machines and our tests run
through with it):

  typedef std::vector::iterator _it;
  p->__pyx_v_it.~_it();


We have tested it with the 0.18 release as well as the newest 0.19b2 build from
github (58131b68dc033fc7ca269d875a2aab2b4e9646a2) and the results were the
same.

Thanks,

Hannes Röst




-- 
Hannes Röst
Institute of Molecular Systems Biology
ETH Zürich Hönggerberg HPT C75
Wolfgang-Pauli Strasse 16
CH-8093 Zürich (Switzerland)

phone: 0041 44 633 3945
fax: 0041 44 633 10 51
e-mail: ro...@imsb.biol.ethz.ch
___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] [PATCH] Refcount error when transposing memoryview attribute of an extension class

2013-04-12 Thread mark florisson
On 12 April 2013 13:20, Matěj Laitl  wrote:

> On 8. 4. 2013 Matěj Laitl wrote:
> > Hi cython-devel and Mark,
> > I was getting
> >
> > > Fatal Python error: Acquisition count is 0 (line XYZ)
> >
> > when I was doing
> >
> > > cdef class MemViewContainer:
> > > cdef double[:, :] A
> > >
> > > cdef a_method(self):
> > > self.A = np.eye(2)
> > > some_function(self.A.T)
> > > some_function(self.A.T)
> >
> > I have found out that it is caused by the self.A.T expression - Cython
> emits
> > __PYX_XDEC_MEMVIEW() after the call, but no __PYX_INC_MEMVIEW() before
> the
> > call. This doesn't happen if the memoryview is a function-local variable.
> >
> > Proper test case is in the pull request [1] along with an ad-hoc patch
> that
> > fixes the problem here, but needs review whether it is actually correct.
> I'd
> > be very grateful if a fix for this problem could get it into Cython 0.19.
> >
> > Cython version: 0.19b1 3a6b9856187d7e490e08
> >
> > [1] https://github.com/cython/cython/pull/201
>
> Bump. Anything else I can provide to help with getting this fixed in 0.19?
>
> Ragards,
> Matěj
>

Thanks for the bump, I merged it.

Stefan, do you want to wait with 0.19 for the strides fix? We don't know
when 0.20 would be, I'd like to give it a go this weekend.
___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] [PATCH] Refcount error when transposing memoryview attribute of an extension class

2013-04-12 Thread Stefan Behnel
mark florisson, 12.04.2013 18:37:
> Stefan, do you want to wait with 0.19 for the strides fix? We don't know
> when 0.20 would be, I'd like to give it a go this weekend.

No problem, I can wait. Let's plan the RC for early next week, if you can
get a fix ready by then.

Stefan

___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


[Cython] Cython mishandles None in slices

2013-04-12 Thread Bryan O'Sullivan
Here are two lines of valid Python:

>>> 'abc'[None:2]
'ab'
>>> 'abc'[1:None]
'bc'

If I try this in code that I compile with Cython, it throws an exception:

TypeError: 'NoneType' object cannot be interpreted as an index
___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] Cython mishandles None in slices

2013-04-12 Thread Stefan Behnel
Bryan O'Sullivan, 13.04.2013 05:02:
> Here are two lines of valid Python:
> 
> >>> 'abc'[None:2]
> 'ab'
> >>> 'abc'[1:None]
> 'bc'
> 
> If I try this in code that I compile with Cython, it throws an exception:
> 
> TypeError: 'NoneType' object cannot be interpreted as an index

Have you tried it with the latest beta?

http://cython.org/release/Cython-0.19b2.tar.gz

Stefan

___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel