On Mon, Feb 4, 2013 at 4:12 AM, Sturla Molden <stu...@molden.no> wrote: > On 02.02.2013 01:23, Greg Ewing wrote: > >> If you're suggesting that 'def object foo' should give Python >> reference semantics and 'cdef object foo' raw C pointer >> semantics, > > > No I was not. > > I was suggesting that static declarations of Python and C variables should > have different keywords. > > Because they behave differently e.g. with respect to reference counting, it > can be confusing to new users. For example I was replying to a Cython user > who thought anything declared 'cdef' was reference counted. It might not be > obvious to a new Cython user what can be put in a Python list and what can > be put in an STL vector.
I find the distinction obvious: if Python understands it, it can be put in a Python list. If C++ understands it, it can be put in a STL container. Of course I'm the antithesis of a "new user." We should at least be producing obvious errors. > "cdef" refers to storage in the generated C, not to the semantics of Cython. > But how and where variables are stored in the generated C is an > implementation detail. Semantically the difference is between static and > dynamic variables. I think reference counting is much more of an implementation detail than how and where the variables are stored. When using Cython I hardly ever think about reference counts, it just does the right thing everywhere for me. From a performance perspective, aside from being able to manipulate raw C numeric types, one of the most important features is that functions and variables (both Python and C types) can be statically rather than dynamically bound, and specifying where it should be so. In any case, whether "cdef A a" is reference counted or not depends A in a straightforward manner (it's refcounted if and only if it can be, i.e. A is a subclass of object). Forcing the user to choose between two different forms of "cdef" based on the type of A would be entirely redundant. - Robert _______________________________________________ cython-devel mailing list cython-devel@python.org http://mail.python.org/mailman/listinfo/cython-devel