[issue30527] PyMemoryView_FromBuffer memory leak

2017-05-31 Thread Christoph Reiter
Christoph Reiter added the comment: In case someone ends up here with a similar problem, here is my solution using a proxy object: https://github.com/pygobject/pycairo/blob/4ab80df68dd99a8e4bfb0c6a88dc5b2a9b0f3f10/cairo/bufferproxy.c -- ___ Python t

[issue30527] PyMemoryView_FromBuffer memory leak

2017-05-31 Thread Stefan Krah
Stefan Krah added the comment: Sorry, actually I wasn't totally clear: The exporting object just needs a getbufferproc() that can respond to buffer requests and keeps track of how many views are exported. "View in the object" is misleading and not necessary; it can be used for some advanced

[issue30527] PyMemoryView_FromBuffer memory leak

2017-05-31 Thread Christoph Reiter
Christoph Reiter added the comment: Ah, so if I understand correctly, exposing always requires something implementing the buffer interface in some way. I might require multiple different memoryviews for this object, so maybe some proxy object implementing it might work. Thanks Stefan for your

[issue30527] PyMemoryView_FromBuffer memory leak

2017-05-31 Thread Stefan Krah
Stefan Krah added the comment: "Py_buffer view" needs to go into the exporting object. That object needs a getbufferproc(). That getbufferproc() can use PyBuffer_FillInfo() to fill in the view that is now kept alive because it's in the object. The object then supports the buffer protocol a

[issue30527] PyMemoryView_FromBuffer memory leak

2017-05-31 Thread Christoph Reiter
Christoph Reiter added the comment: hm, ok. Any idea how I can create a memoryview that is usable from Python then? -- ___ Python tracker ___ ___

[issue30527] PyMemoryView_FromBuffer memory leak

2017-05-31 Thread Stefan Krah
Stefan Krah added the comment: "Py_buffer view" is stack allocated. One can use memoryviews based on such buffers *inside* a function, but not return them. -- nosy: +skrah ___ Python tracker __

[issue30527] PyMemoryView_FromBuffer memory leak

2017-05-31 Thread Christoph Reiter
New submission from Christoph Reiter: I'm using the following code PyObject * get_memoryview (PyObject *self) { Py_buffer view; ... // this takes a ref on self if (PyBuffer_FillInfo (&view, self, buffer, length, 0, 0) < 0) return NULL; // this returns a object