Re: Pointers to shared functions

29 views
Skip to first unread message

Bradley Froehle

unread,
Aug 29, 2012, 6:10:59 PM8/29/12
to cython...@googlegroups.com
I believe that Cython already stores nearest_neighbor as a pointer when you cimport it from another module, so you are getting the bus error because of an extra &.  The following works for me:

## interpolation.pxd
def double nearest_neighbour(double val)

## interpolation.pyx
def double nearest_neighbour(double val):
    return val

## main.pyx
from interpolation cimport nearest_neighbour

def main():
    cdef double (*interp_func)(double)
    interp_func = nearest_neighbour
    print interp_func(4)

-Brad

On Wednesday, August 29, 2012 1:14:41 PM UTC-7, Johannes Schönberger wrote:
Hi,

pointers to functions declared in another Cython module don't seem to work:

    cdef inline double nearest_neighbour(double val):
        return val

    def main():

        cdef double (*interp_func)(double)

        interp_func = &nearest_neighbour

        print interp_func(10)

This works, whereas the following fails with a "Bus error: 10" (on OSX with Cython 0.16 and Python 2.7.3):

    from interpolation cimport nearest_neighbour


    def main():

        cdef double (*interp_func)(double)

        interp_func = &nearest_neighbour

        print interp_func(10)

Am I doing something wrong here or is there a workaround for this apart from declaring the function in the same module?

Thanks and regards,

Johannes
Reply all
Reply to author
Forward
0 new messages