|
1 | 1 | cimport croaring |
2 | | -from libc.stdint cimport uint32_t, uint64_t, int64_t |
| 2 | +from libc.stdint cimport uint32_t, uint64_t, uintptr_t, int64_t |
3 | 3 | from libcpp cimport bool |
4 | 4 | from libcpp.vector cimport vector |
5 | 5 | from libc.stdlib cimport free, malloc |
@@ -174,6 +174,26 @@ cdef class AbstractBitMap: |
174 | 174 | (<AbstractBitMap>bm)._c_bitmap = ptr |
175 | 175 | return bm |
176 | 176 |
|
| 177 | + @property |
| 178 | + def raw_pointer(self): |
| 179 | + """ |
| 180 | + The address of the underlying `roaring_bitmap_t`, as a Python int. |
| 181 | +
|
| 182 | + Intended for FFI interop, e.g. passing the bitmap to another |
| 183 | + native extension via CFFI or ctypes without a copy. |
| 184 | +
|
| 185 | + Caveats (the caller is responsible for all of these): |
| 186 | +
|
| 187 | + - The pointer is owned by this Python object. It is only valid |
| 188 | + while the object is alive; the caller must not pass it to |
| 189 | + `roaring_bitmap_free`. |
| 190 | +
|
| 191 | + - Mutating the bitmap through this pointer on a `FrozenBitMap` |
| 192 | + is undefined behaviour: it silently invalidates the cached |
| 193 | + hash and breaks set/dict semantics. |
| 194 | + """ |
| 195 | + return <uintptr_t>self._c_bitmap |
| 196 | + |
177 | 197 | @property |
178 | 198 | def copy_on_write(self): |
179 | 199 | """ |
@@ -884,6 +904,26 @@ cdef class AbstractBitMap64: |
884 | 904 | (<AbstractBitMap64>bm)._c_bitmap = ptr |
885 | 905 | return bm |
886 | 906 |
|
| 907 | + @property |
| 908 | + def raw_pointer(self): |
| 909 | + """ |
| 910 | + The address of the underlying `roaring_bitmap_t`, as a Python int. |
| 911 | +
|
| 912 | + Intended for FFI interop, e.g. passing the bitmap to another |
| 913 | + native extension via CFFI or ctypes without a copy. |
| 914 | +
|
| 915 | + Caveats (the caller is responsible for all of these): |
| 916 | +
|
| 917 | + - The pointer is owned by this Python object. It is only valid |
| 918 | + while the object is alive; the caller must not pass it to |
| 919 | + `roaring_bitmap_free`. |
| 920 | +
|
| 921 | + - Mutating the bitmap through this pointer on a `FrozenBitMap` |
| 922 | + is undefined behaviour: it silently invalidates the cached |
| 923 | + hash and breaks set/dict semantics. |
| 924 | + """ |
| 925 | + return <uintptr_t>self._c_bitmap |
| 926 | + |
887 | 927 | @property |
888 | 928 | def copy_on_write(self): |
889 | 929 | """ |
|
0 commit comments