On Fri, Jan 29, 2010 at 11:58 AM, Robert Bradshaw
<[email protected]> wrote:
> On Jan 29, 2010, at 2:25 AM, Stefan Behnel wrote:
>> One thing that strikes me: Is "new" a keyword now?
>
> "new" was chosen because of the symmetry between new and del (if one
> allocates, one needs to delete), and it would be easy for C++ people
> to understand. Calling the constructor directly returns an object by
> value, not a heap allocated one. (How to best handle objects returned
> by value is an open question...) Note that the lack of block-level
> scoping, and the c89/MSVC requirement of pre-declaring all variables
> at the top, makes stack allocated C classes a stickier problem,
> necessitating good support for new.

But could someone please clarify explicitly whether the following
(trivial, no fancy non-Python features) code will work in the C++
branch?

def new(x):
  return myobj(x)
foo = new(1)

? Note that this would fail to compile if the function were named "if"
or "cdef", etc., but with the name "new" it is currently legal.

> How would cython.new be used to invoke a constructor?
>
> cdef extern from "a.h":
>     cdef cppclass A:
>         A(int, int)
>
> cdef *A = cython.new(A(2,3)) #?

-1

> cdef *A = cython.new(A, 2, 3) #?

+0

>> Or is it only enabled when compiling C++
>> code? That would be bad enough, but would at least make it less
>> likely to
>> break code.
>
> I think this is an easy issue to work around--the original grammar
> would prohibit new as an identifier in this context anyway.

Can you give more details on what you mean here?

-- Nathaniel
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to