You could look into memoryviews, new in the upcoming Cython release:
https://sage.math.washington.edu:8091/hudson/job/cython-docs/doclinks/1/src/userguide/memoryviews.html
Hm, what made you jump to that conclusion? Memoryviews work just fine
in python2.4 and 2.5. They do however always request writable buffers,
as they can't know about all the contexts they will be used in. Maybe
in the future, if we ever get support for const, we could allow a
declaration like 'cdef const unsigned char[:] myarray'.
> Here's my test case:
>
> --- 8< ---
> cdef extern from "foo.h":
> int sum(unsigned char *p, int len)
>
> def add_bytes(o):
> cdef unsigned char[::1] p = o
> return sum(&p[0], len(p))
> --- >8 ----
>
> Also, in order to avoid having to write "&p[0]", it would be nice if
> type "unsigned char[::1]" could be assigned to "unsigned char *".
Hm, no I don't think that would be nice, as they are really different
types. They should not coerce implicitly.
> Anyway, looks like great work. I'm looking forward to the next
> version of Cython!
>
>
> In the meantime, I might try to write a custom C function that creates
> a read-only memoryview if the version is >= 2.6 (using the Cython-
> generated code as a starting point!) and the old buffer protocol (and
> maybe special-casing NumPy) otherwise.
I really wouldn't buffer with the old buffer protocol. You can flag
buffers as readonly just as well with the new buffer interface, it's
just that memoryviews will only want writable buffers. You can
implement the new buffer interface much more easily anyway, by
implementing __getbuffer__/__releasebuffer__ on your extension type.