Dag Sverre Seljebotn wrote: > Dag Sverre Seljebotn wrote: >> Stefan Behnel wrote: >>> Dag Sverre Seljebotn, 25.01.2010 10:17: >>> >>>> Stefan Behnel wrote: >>>> >>>>>> [...] why not just represent a borrowed reference as a pointer? >>>>>> So you could write >>>>>> >>>>>> cdef list some_list = [] >>>>>> cdef list* borrowed_ref = some_list >>>>>> >>>>>> and borrowed_ref would be a non-refcounted pointer to a Python >>>>>> list. Assignments back to a normal reference would be allowed: >>>>>> >>>>>> cdef list my_list = borrowed_ref # increfs the pointer >>>>>> >>>>>> After all, a non-refcounted reference to a Python object is not >>>>>> more than a bare pointer to a well-defined Python >>>>>> builtin/extension type (including "object*"). >>>>>> >>>> Well, there's the drawback of making the language more complicated, >>>> and also I think the notation is confusing -- plain "object" is not >>>> by value, and "object*" is not a pointer to an "object", so to speak. >>>> >>> >>> I was trying to let the syntax emphasise that it *is* a pointer, not a >>> reference. A reference is special in Cython in that it handles >>> ref-counting >>> for it. A pointer just behaves like any other pointer in the language. >>> >>> I agree that it's not flawless, but I think it makes sense and is >>> unambiguous. >>> >> Let me put it this way: To me, "object*" somehow indicates >> PyObject**, since "object" is PyObject*. I find it confusing that >> "object" and "object*" are at the same "indirection level", so to speak. >> >> Also, would >> >> cdef object* x = ... >> print x[0] >> >> do a getitem on x, or returned a reference-counted copy of x? Not >> easy to guess from the syntax alone. >> >> Assuming a getitem (as that's a useful operation and the other is >> already served by <object>x), one is then inconsistent with >> everywhere else the *-notation is used. >> >> I'd be fine with almost any kind of syntax which is a superset of the >> current syntax -- "cdef nonmanaged object x", you name it. The >> problem with "object*" is that it is not immediately obvious to a >> reader with a brief knowledge of Cython that it is fundamentally >> different from "int*". > > Another example: Reading the docs up front, just reading someone elses > code, I'd expect this to work:
I meant ***without*** reading the docs up front... > > cdef object x > cdef object* px > px = &x > px[0] = "hello" > print x # should print "hello" > > > Dag Sverre > _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
