def get_buffer_mask(self):
        if not self.free_stencil_bits:
            raise ImageException('No free stencil bits are available.')

        stencil_bit = self.free_stencil_bits.pop(0)
        x, y, width, height = self.get_viewport()
        buffer = BufferImageMask(x, y, width, height)
        buffer.stencil_bit = stencil_bit

        def release_buffer(ref, self=self):
            self.free_stencil_bits.insert(0, stencil_bit)
        self.refs.append(weakref.ref(buffer, release_buffer))

        return buffer
Base on test2 of https://github.com/numba/numba/issues/381
dataset/ETHPy150Open ardekantur/pyglet/pyglet/image/__init__.py/BufferManager.get_buffer_mask--crossover with--dataset/ETHPy150Open numba/numba/numba/tests/test_recarray_usecases.py/usecase3