Stefan Behnel wrote: > [bump] > > Stefan Behnel, 10.01.2010 18:23: > >> [...] 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*"). >> > > What do the others think about this? > > Note that this does not relate to the "stolen reference" case, for which > Robert already proposed a "steal()" function (and which I expect to be a > rare use case anyway). It only deals with borrowed references, where e.g. > PyTuple_GET_ITEM() would be declared as > > cdef object* PyTuple_GET_ITEM(object t, Py_ssize_t index) > > and Cython would automatically do the right thing when you write > > cdef object x = PyTuple_GET_ITEM(t, 0) > > or > > cdef object* x = PyTuple_GET_ITEM(t, 0) > > respectively. The only drawback I see with this syntax is that you can't write > > cdef object x = PyTuple_GET_ITEM(t, 0)[0] > > which you'd normally do with a pointer... >
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. How about a set of explicit functions like cdef object x = skip_incref(PyTuple_GET_ITEM(t, 0)) ? I don't care that much though, so I'm +0 at any rate. Dag Sverre _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
