add sp_bitmap_into_bitvec, sp_bitmap_from_bitvec
This commit is contained in:
		
							parent
							
								
									8a3e84b6fa
								
							
						
					
					
						commit
						c0f5b4d0da
					
				
					 2 changed files with 42 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
use crate::byte_slice::ByteSlice;
 | 
			
		||||
use crate::{heap_drop, heap_move, heap_move_nonnull};
 | 
			
		||||
use crate::{heap_drop, heap_move, heap_move_nonnull, SPBitVec};
 | 
			
		||||
use servicepoint::{Bitmap, DataRef, Grid};
 | 
			
		||||
use std::ptr::NonNull;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -68,6 +68,24 @@ pub unsafe extern "C" fn sp_bitmap_load(
 | 
			
		|||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Tries to convert the BitVec to a Bitmap.
 | 
			
		||||
///
 | 
			
		||||
/// The provided BitVec gets consumed.
 | 
			
		||||
///
 | 
			
		||||
/// Returns NULL in case of error.
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_bitmap_from_bitvec(
 | 
			
		||||
    width: usize,
 | 
			
		||||
    bitvec: NonNull<SPBitVec>,
 | 
			
		||||
) -> *mut Bitmap {
 | 
			
		||||
    let bitvec = unsafe { *Box::from_raw(bitvec.as_ptr()) };
 | 
			
		||||
    if let Ok(bitmap) = Bitmap::from_bitvec(width, bitvec.0) {
 | 
			
		||||
        heap_move(bitmap)
 | 
			
		||||
    } else {
 | 
			
		||||
        std::ptr::null_mut()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Clones a [Bitmap].
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_bitmap_clone(
 | 
			
		||||
| 
						 | 
				
			
			@ -172,3 +190,12 @@ pub unsafe extern "C" fn sp_bitmap_unsafe_data_ref(
 | 
			
		|||
) -> ByteSlice {
 | 
			
		||||
    unsafe { ByteSlice::from_slice(bitmap.as_mut().data_ref_mut()) }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Consumes the Bitmap and returns the contained BitVec
 | 
			
		||||
#[no_mangle]
 | 
			
		||||
pub unsafe extern "C" fn sp_bitmap_into_bitvec(
 | 
			
		||||
    bitmap: NonNull<Bitmap>,
 | 
			
		||||
) -> NonNull<SPBitVec> {
 | 
			
		||||
    let bitmap = unsafe { *Box::from_raw(bitmap.as_ptr()) };
 | 
			
		||||
    heap_move_nonnull(SPBitVec(bitmap.into()))
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue