Hi folks
I'm trying to wrap a git blob class with a simple readonly buffer. The buffer should wrap the blob contents, which is exposed as a `const void*`, preferably without copying it. The latter is hard because it seems like the `buf` member of the PyBuffer struct is declared as a `void*`, so it can't accept values which are declared const.
My attempt looks like this so far:
>
> cdef class Blob:
> cdef unique_ptr[cppgit2_blob] thisptr
>
> def __getbuffer__(self, Py_buffer *buffer, int flags):
>
> # const void *blob::raw_contents()
> contents = <char*>deref(self.thisptr).raw_contents()
> size = deref(self.thisptr).raw_size()
>
> buffer.buf = contents
> buffer.format = 'c'
> buffer.internal = NULL
> buffer.itemsize = 1
> buffer.len = size;
> buffer.ndim = 1
> buffer.obj = self
> buffer.readonly = 1
> buffer.shape = [size]
> buffer.strides = [1]
> buffer.suboffsets = NULL
>
> def __releasebuffer__(self, Py_buffer *buffer):
> pass
And results in this compile error:
libkart.cpp:6252:47: error: assigning to 'void *' from 'const void *' discards qualifiers
__pyx_v_contents = (*__pyx_v_self->thisptr).raw_contents();
~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
Is there any way to avoid this? Or perhaps is there a better way to achieve this, e.g. is it possible to achieve this using the Typed Memoryviews somehow?
Thanks
Craig