Skip to content
  • David Gobbi's avatar
    Add a python function to check buffer equivalence. · 8320da24
    David Gobbi authored
    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.
    8320da24