Skip to content
Snippets Groups Projects
Commit 8320da24 authored by David Gobbi's avatar David Gobbi
Browse files

Add a python function to check buffer equivalence.

The python "buffer" and "memoryview" objects do not expose the pointer
to the underlying memory, they only expose the contents of the memory.
Likewise, if you check (buffer1 == buffer2) within python, then python
will iterate through both buffers to see if they have the same contents!
After all, for python, that's how equality is defined for sequence types.

This commit adds a method called buffer_shared(ob1, ob2) that checks to
see if two objects (e.g. arrays) expose the same block of memory via
their buffer interface.  It assumes that the "buf" pointer is the lowest
address of the buffer (i.e. the strides must be non-negative).

It also adds two changes to dataset_adapter.py:
1) The adapter now uses buffer_shared() instead of using "==" to compare
buffers, because as stated above "==" does the wrong thing.
2) It repairs an infinite recursion where __getattr__ called hasattr().
The infinite recursion was caught silently by hasattr() itself in python2,
but is exposed as a RuntimeError in python3.
parent d6f7466d
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment