Quick question.  If I want to return a char * from Cython to Python as a
string, should I be freeing the original char * or not?  In other words,
when Cython does the implicit conversion from char * ---> string, does it
create a Python object and strcpy the char * into its data, or does it copy
the pointer?

Here's some code to make this clearer:

cdef class MyStringHolder:

  cdef char *my_str

  ...

  cpdef add_to_set(object set):
    // Is this necessary or is this a memory leak?
    cdef char * str_cpy = <char*>malloc(strlen(my_str) + 1)
    strcpy(str_cpy, my_str)

    // Should this just be set.add(my_str)?
    set.add(str_cpy)


Thanks!
jack
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to