Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Cython malloc/new and templates

%cython
#clang c++
from libcpp.vector cimport vector as cvector
from libcpp.list cimport list as clist
from cython.operator cimport dereference as deref, preincrement as inc
cdef extern from "stdlib.h":
    void free(void* ptr)
    void* malloc(size_t size)
    void* realloc(void* ptr, size_t size)

cdef cvector[clist[int]] *v
cdef clist[int] *l

v = new cvector[clist[int]]()
l = new clist[int]()

#v= < cvector[clist[int]] * > malloc(1*sizeof(cvector[clist[int]]))
#l= < clist[int] * > malloc(1*sizeof(clist[int]))



Error compiling Cython file:
------------------------------------------------------------
...

cdef cvector[clist[int]] *v
cdef clist[int] *l

v = new cvector[clist[int]]()
       ^
------------------------------------------------------------

_[...]_sage52_spyx_0.pyx:17:8: Operation only allowed in c++

Using malloc instead of new:

Error compiling Cython file:
------------------------------------------------------------
...

#v = new cvector[clist[int]]()
#l = new clist[int]()

v= < cvector[clist[int]] * > malloc(1*sizeof(cvector[clist[int]]))
                        ^
------------------------------------------------------------

_[...]_sage54_spyx_0.pyx:20:25: Unknown type

Cython malloc/new and templates

%cython
#clang c++
from libcpp.vector cimport vector as cvector
from libcpp.list cimport list as clist
from cython.operator cimport dereference as deref, preincrement as inc
cdef extern from "stdlib.h":
    void free(void* ptr)
    void* malloc(size_t size)
    void* realloc(void* ptr, size_t size)

cdef cvector[clist[int]] *v
cdef clist[int] *l

v = new cvector[clist[int]]()
l = new clist[int]()

#v= < cvector[clist[int]] * > malloc(1*sizeof(cvector[clist[int]]))
#l= < clist[int] * > malloc(1*sizeof(clist[int]))



Error compiling Cython file:
------------------------------------------------------------
...

cdef cvector[clist[int]] *v
cdef clist[int] *l

v = new cvector[clist[int]]()
       ^
------------------------------------------------------------

_[...]_sage52_spyx_0.pyx:17:8: Operation only allowed in c++

Using malloc instead of new:

Error compiling Cython file:
------------------------------------------------------------
...

#v = new cvector[clist[int]]()
#l = new clist[int]()

v= < cvector[clist[int]] * > malloc(1*sizeof(cvector[clist[int]]))
                        ^
------------------------------------------------------------

_[...]_sage54_spyx_0.pyx:20:25: Unknown type

Cython malloc/new and templates

%cython
#clang c++
from libcpp.vector cimport vector as cvector
from libcpp.list cimport list as clist
from cython.operator cimport dereference as deref, preincrement as inc
cdef extern from "stdlib.h":
    void free(void* ptr)
    void* malloc(size_t size)
    void* realloc(void* ptr, size_t size)

cdef cvector[clist[int]] *v
cdef clist[int] *l

v = new cvector[clist[int]]()
l = new clist[int]()

#v= < cvector[clist[int]] * > malloc(1*sizeof(cvector[clist[int]]))
#l= < clist[int] * > malloc(1*sizeof(clist[int]))



Error compiling Cython file:
------------------------------------------------------------
...

cdef cvector[clist[int]] *v
cdef clist[int] *l

v = new cvector[clist[int]]()
       ^
------------------------------------------------------------

_[...]_sage52_spyx_0.pyx:17:8: Operation only allowed in c++

Using malloc instead of new:

Error compiling Cython file:
------------------------------------------------------------
...

#v = new cvector[clist[int]]()
#l = new clist[int]()

v= < cvector[clist[int]] * > malloc(1*sizeof(cvector[clist[int]]))
                        ^
------------------------------------------------------------

_[...]_sage54_spyx_0.pyx:20:25: Unknown type

Cython malloc/new and templates

%cython
#clang c++
from libcpp.vector cimport vector as cvector
from libcpp.list cimport list as clist
from cython.operator cimport dereference as deref, preincrement as inc
cdef extern from "stdlib.h":
    void free(void* ptr)
    void* malloc(size_t size)
    void* realloc(void* ptr, size_t size)

cdef cvector[clist[int]] *v
cdef clist[int] *l

v = new cvector[clist[int]]()
l = new clist[int]()

#v= < cvector[clist[int]] * > malloc(1*sizeof(cvector[clist[int]]))
#l= < clist[int] * > malloc(1*sizeof(clist[int]))



Error compiling Cython file:
------------------------------------------------------------
...

cdef cvector[clist[int]] *v
cdef clist[int] *l

v = new cvector[clist[int]]()
       ^
------------------------------------------------------------

_[...]_sage52_spyx_0.pyx:17:8: Operation only allowed in c++

EDIT: the problem below was addressed in the comments.

Using malloc instead of new:

Error compiling Cython file:
------------------------------------------------------------
...

#v = new cvector[clist[int]]()
#l = new clist[int]()

v= < cvector[clist[int]] * > malloc(1*sizeof(cvector[clist[int]]))
                        ^
------------------------------------------------------------

_[...]_sage54_spyx_0.pyx:20:25: Unknown type

Cython malloc/new and templates

%cython
#clang c++
from libcpp.vector cimport vector as cvector
from libcpp.list cimport list as clist
from cython.operator cimport dereference as deref, preincrement as inc
cdef extern from "stdlib.h":
    void free(void* ptr)
    void* malloc(size_t size)
    void* realloc(void* ptr, size_t size)

cdef cvector[clist[int]] *v
cdef clist[int] *l

v = new cvector[clist[int]]()
l = new clist[int]()

#v= < cvector[clist[int]] * > malloc(1*sizeof(cvector[clist[int]]))
#l= < clist[int] * > malloc(1*sizeof(clist[int]))



Error compiling Cython file:
------------------------------------------------------------
...

cdef cvector[clist[int]] *v
cdef clist[int] *l

v = new cvector[clist[int]]()
       ^
------------------------------------------------------------

_[...]_sage52_spyx_0.pyx:17:8: Operation only allowed in c++

EDIT: the problem below was addressed in the comments.comments. (The problem above still stands)

Using malloc instead of new:

Error compiling Cython file:
------------------------------------------------------------
...

#v = new cvector[clist[int]]()
#l = new clist[int]()

v= < cvector[clist[int]] * > malloc(1*sizeof(cvector[clist[int]]))
                        ^
------------------------------------------------------------

_[...]_sage54_spyx_0.pyx:20:25: Unknown type