This class is for testing the timing of the PyCapsule destructor invoked when numpy release its reference to the shared data as part of the numpy array interface protocol. If the PyCapsule destructor is called early the shared data is freed and invalid memory accesse
| 135 | def test_cstruct(get_module): |
| 136 | |
| 137 | class data_source: |
| 138 | """ |
| 139 | This class is for testing the timing of the PyCapsule destructor |
| 140 | invoked when numpy release its reference to the shared data as part of |
| 141 | the numpy array interface protocol. If the PyCapsule destructor is |
| 142 | called early the shared data is freed and invalid memory accesses will |
| 143 | occur. |
| 144 | """ |
| 145 | |
| 146 | def __init__(self, size, value): |
| 147 | self.size = size |
| 148 | self.value = value |
| 149 | |
| 150 | @property |
| 151 | def __array_struct__(self): |
| 152 | return get_module.new_array_struct(self.size, self.value) |
| 153 | |
| 154 | # write to the same stream as the C code |
| 155 | stderr = sys.__stderr__ |