I have a library written using cython that wraps a C library, and I expose a few lines of c in python code. These lines are large and static (cannot free them), so just making a python line from them (which makes a copy) is not an option - I get OOM errors.
I have code working for python 2.x currently using the old buffer API that looks something like this:
def get_foo(): return PyBuffer_FromMemory(c_foo_ptr,c_foo_len)
This just works (tm) for python 2.x, but the old buffer API is missing in 3.x, and I can't figure out how to get this with the new one.
I see that there PyMemoryView_FromBuffer and PyBuffer_FillInfo , which are supposed to do the same, but PyBuffer_FillInfo wants an object that does not exist for me (this is just a module level function), creating a dummy object and passing it just gives me segfault. so I guess this object should somehow support the buffer ... but where is it documented?
further from the experiments with memory, they do not look at all or act like strings (or bytes), so I will either have to rewrite all my Python code, or somehow recreate this functionality.
Am I missing something? is there an easy way to replace PyBuffer_FromMemory in py3k?
Note. I use cython, but this is the source material of c-api, so you can respond without participating in cython.
bdew
source share