types - Converting cstruct to python string -


here's summary of i'm trying accomplish:

  1. convert opaque cstruct python array
  2. pickle array

i'm having issues persuading cython let me convert c object python object.

here's simplified version of code that's giving me headaches. in file myothermodule.pyx

cdef char* struct_to_string(structtype ctarg):     cdef:         bspmat *bsptarg         list arrays = []         np.ndarray[np.float64_t, ndim=2] arr         char * string_data      in range(ctarg.numlevel):          bsptarg = ctarg.level[i]          arr = bspmat_to_array(bsptarg) #this works fine in other contexts          arrays.append(arr)      cdef bytes pystr = cpickle.dumps(arrays, protocol=2) #fastest protocol     string_data = <char *> pystr      return string_data 

this code in middle.pyx:

cdef push_data(mycythonstruct pv):     cdef:         cdef char * strdata         cdef myothermodule.structtype *ctarg     ctarg = pv.another_cython_struct     strdata = myothermodule.struct_to_string( ctarg ) 

this type of error results when trying compile:

middle.pyx:232:45: cannot convert 'structtype *' python object  error compiling cython file: ------------------------------------------------------------      [...]      ctarg = pv.another_cython_struct     strdata = myothermodule.struct_to_string( ctarg )                                     ^ ------------------------------------------------------------  middle.pyx:232:37: obtaining 'char *' temporary python value traceback (most recent call last):   file "setup.py", line 21, in <module>     ext_modules = cythonize(extensions)   file "/usr/local/lib/python2.7/dist-packages/cython-0.20.1-py2.7-linux-x86_64.egg/cython/build/dependencies.py", line 785, in cythonize     cythonize_one(*args[1:])   file "/usr/local/lib/python2.7/dist-packages/cython-0.20.1-py2.7-linux-x86_64.egg/cython/build/dependencies.py", line 902, in cythonize_one     raise compileerror(none, pyx_file) cython.compiler.errors.compileerror: middle.pyx 

any clues how persuade work appreciated!


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -