On Wednesday, October 3, 2012 5:56:02 AM UTC+1, Robert Bradshaw wrote:
> On Tue, Oct 2, 2012 at 12:38 AM, peter aberline
> <peter.a...@gmail.com <javascript:>> wrote:
> > Hi all,
> > I'm new to Cython, it looks to be an incredible technology -
> congratulations
> > to all the devs.
> > Please excuse my basic question. I'm trying to pass a reference to a
> > std::vector to a function and I'm getting a cpp compilaton error. Here's
> a
> > minimum example of what I'm doing:
> > test.py:
> > import sys
> > def vectortest(a, idx):
> > print ('a[idx] is: ' + str(a[idx]))
> > a[idx] += 1
> > print ('a[idx] is: ' + str(a[idx]))
> > return a
> > def run():
> > lst = range(1, 5)
> > lstNew = vectortest(lst, 1)
> > print ('lstNew[1] is :' + str(lstNew[1]))
> > test.pxd
> > import cython
> > from libcpp.vector cimport vector
> > import sys
> > if sys.version_info < (3,):
> > range = xrange
> > cpdef vector[int] vectortest(vector[int] a, int idx) # <-- This works
> fine
> > ('a' is pass by value?)
> > #cpdef vector[int] vectortest(vector[int]& a, int idx) #<-- This
> generates
> > an 'uninitialised reference' cpp compilation error ('a' is pass by
> > reference?')
> > @cython.locals(lst = vector[int])
> > cpdef run()
> > Compilation error:
> > $/test.cpp: In function ‘PyObject* __pyx_pw_4perf_1vectortest(PyObject*,
> > PyObject*, PyObject*)’:
> > $/test.cpp:640:21: error: ‘__pyx_v_a’ declared as reference but not
> > initialized
> > Can anyone suggest what I'm going wrong?
> Looks like this was a bug introduced In 0.17.1 and already fixed in
> master.
> - Robert
Just got the latest source from git and that has indeed fixed it. Thanks