14 Dec 2010 11:51
Re: " __builtin__.str has the wrong size, try recompiling" with Python 2.7
Stefan Behnel <stefan_ml <at> behnel.de>
2010-12-14 10:51:13 GMT
2010-12-14 10:51:13 GMT
Saúl Ibarra Corretgé, 14.12.2010 11:16: >> Depends on what you do with it. In Py2, 'str' (as 'bytes' in Py3) is a >> dynamically sized type (PyVarObject). As such, it cannot currently be >> subtyped in Cython, and other things may or may not work with it. > > It's a Py2 application and str is not subtyped. > >> Could you provide some details about your use case? > > We wrap a C library and have several cdef classes around it. Generally > it's used to hold attributes (cdef str something) and also for > readonly attributes (cdef readonly str something). Ah, ok, then just drop that declaration completely. Cython knows about the builtin Python types. However, 'bytes' may still be what you want to use here, unless you want to store text, in which case you may(!) want to consider using 'unicode' instead. 'str' is a somewhat underoptimised type in Cython due to its bytes/unicode duality when compiling for Python 3. For bytes and (especially) unicode, Cython can safely do various smart C-level optimisations internally. https://sage.math.washington.edu:8091/hudson/job/cython-docs/doclinks/1/src/tutorial/strings.html I should note that Cython 0.13 brings a another bunch of improvements here, as does 0.14 (which is close to release). Since you're migrating anyway, you should consider switching to 0.14 directly. >>> Is this a bug on Cython 0.12.1? Thinking about this some more, it's not even impossible that this *is* a(Continue reading)
RSS Feed