I am having some trouble writing a cython interface to a library. It does 
something pretty simple: creates a malloc'ed array of values, passes it to 
a external function in the library, and gets a malloc'ed array back.

In the past i made something similar to this work:



#clib homotopyPath


cdef extern from "stdlib.h":
    void free(void* ptr)


cdef extern from "homotopyPath.h":
    double* homotopyPath (int degree, double *_coef, double _y0R, double 
_y0I)


def contpath(deg,values,y0r,y0i):
    cdef double* rop
    c_values = <double*>sage_malloc(sizeof(double)*len(values))
    #cdef int clen = <int> len(values)
    for i,v in enumerate(values):
        c_values[i] = values[i]
    cdef double y0R = y0r
    cdef double y0I = y0i
    rop = homotopyPath (int(deg), c_values, y0R, y0I)
    n=int(rop[0])
    l=[0 for i in range(n)]
    for i in range(n):
        l[i]=(rop[3*i+1],rop[3*i+2],rop[3*i+3])
    free(rop)
    free(c_values)
    return l

But when i try to load it i get the error:

Compiling ./my_library.pyx...
Error compiling cython file:
Error compiling ./my_library.pyx:
running build
running build_ext
building '_home_mmarco_integrado_my_library_pyx_16' extension
gcc -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/home/
mmarco/sage/local/include/csage -I/home/mmarco/sage/local/include -I/home/
mmarco/sage/local/include/python2.7 -I/home/mmarco/sage/local/lib/python/
site-packages/numpy/core/include -I/home/mmarco/sage/src/sage/ext -I/home/
mmarco/sage/src -I/home/mmarco/sage/src/sage/gsl -I. -I/home/mmarco/sage/
local/include/python2.7 -c _home_mmarco_integrado_my_library_pyx_16.c -o 
build/temp.linux-x86_64-2.7/_home_mmarco_integrado_my_library_pyx_16.o -w -
O2


_home_mmarco_integrado_my_library_pyx_16.c:1183:28: error: redefinition of 
'sage_malloc'
 static CYTHON_INLINE void *sage_malloc(size_t __pyx_v_n) {
                            ^
In file included from /home/mmarco/sage/local/include/csage/stdsage.h:36:0,
                 from _home_mmarco_integrado_my_library_pyx_16.c:230:
/home/mmarco/sage/local/include/csage/memory.h:29:21: note: previous 
definition of 'sage_malloc' was here
 static inline void* sage_malloc(size_t n)
                     ^
_home_mmarco_integrado_my_library_pyx_16.c:1245:28: error: redefinition of 
'sage_realloc'
 static CYTHON_INLINE void *sage_realloc(void *__pyx_v_ptr, size_t 
__pyx_v_size) {
                            ^
In file included from /home/mmarco/sage/local/include/csage/stdsage.h:36:0,
                 from _home_mmarco_integrado_my_library_pyx_16.c:230:
/home/mmarco/sage/local/include/csage/memory.h:49:21: note: previous 
definition of 'sage_realloc' was here
 static inline void* sage_realloc(void *ptr, size_t size)
                     ^
_home_mmarco_integrado_my_library_pyx_16.c:1307:28: error: redefinition of 
'sage_calloc'
 static CYTHON_INLINE void *sage_calloc(size_t __pyx_v_nmemb, size_t 
__pyx_v_size) {
                            ^
In file included from /home/mmarco/sage/local/include/csage/stdsage.h:36:0,
                 from _home_mmarco_integrado_my_library_pyx_16.c:230:
/home/mmarco/sage/local/include/csage/memory.h:36:21: note: previous 
definition of 'sage_calloc' was here
 static inline void* sage_calloc(size_t nmemb, size_t size)
                     ^
_home_mmarco_integrado_my_library_pyx_16.c:1369:27: error: redefinition of 
'sage_free'
 static CYTHON_INLINE void sage_free(void *__pyx_v_ptr) {
                           ^
In file included from /home/mmarco/sage/local/include/csage/stdsage.h:36:0,
                 from _home_mmarco_integrado_my_library_pyx_16.c:230:
/home/mmarco/sage/local/include/csage/memory.h:43:20: note: previous 
definition of 'sage_free' was here
 static inline void sage_free(void* ptr)
                    ^
error: command 'gcc' failed with exit status 1


I have no idea why it complains about sage_malloc being redefined. Any clue?

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to