Skip to content

Commit

Permalink
Merge pull request #15 from maximelenoir/master
Browse files Browse the repository at this point in the history
Make Encoder and Decoder Send
  • Loading branch information
bozaro committed Aug 18, 2016
2 parents 756d4b4 + 00b7b1e commit ef46781
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/decoder.rs
Expand Up @@ -96,7 +96,7 @@ impl<R: Read> Read for Decoder<R> {

impl DecoderContext {
fn new() -> Result<DecoderContext> {
let mut context: LZ4FDecompressionContext = ptr::null_mut();
let mut context = LZ4FDecompressionContext(ptr::null_mut());
try!(check_error(unsafe { LZ4F_createDecompressionContext(&mut context, LZ4F_VERSION) }));
Ok(DecoderContext { c: context })
}
Expand Down Expand Up @@ -277,4 +277,11 @@ mod test {
fn random_stream<R: Rng>(rng: &mut R, size: usize) -> Vec<u8> {
rand::sample(rng, 0x00..0xFF, size)
}

#[test]
fn test_decoder_send() {
fn check_send<S: Send>(_: &S) {}
let dec = Decoder::new(Cursor::new(Vec::new())).unwrap();
check_send(&dec);
}
}
9 changes: 8 additions & 1 deletion src/encoder.rs
Expand Up @@ -170,7 +170,7 @@ impl<W: Write> Write for Encoder<W> {

impl EncoderContext {
fn new() -> Result<EncoderContext> {
let mut context: LZ4FCompressionContext = ptr::null_mut();
let mut context = LZ4FCompressionContext(ptr::null_mut());
try!(check_error(unsafe { LZ4F_createCompressionContext(&mut context, LZ4F_VERSION) }));
Ok(EncoderContext { c: context })
}
Expand Down Expand Up @@ -209,4 +209,11 @@ mod test {
let (_, result) = encoder.finish();
result.unwrap();
}

#[test]
fn test_encoder_send() {
fn check_send<S: Send>(_: &S) {}
let enc = EncoderBuilder::new().build(Vec::new());
check_send(&enc);
}
}
10 changes: 8 additions & 2 deletions src/liblz4.rs
Expand Up @@ -7,9 +7,15 @@ use std::ffi::CStr;

use libc::{c_void, c_char, c_uint, size_t};

pub type LZ4FCompressionContext = *mut c_void;
#[derive(Clone, Copy)]
#[repr(C)]
pub struct LZ4FCompressionContext(pub *mut c_void);
unsafe impl Send for LZ4FCompressionContext {}

pub type LZ4FDecompressionContext = *mut c_void;
#[derive(Clone, Copy)]
#[repr(C)]
pub struct LZ4FDecompressionContext(pub *mut c_void);
unsafe impl Send for LZ4FDecompressionContext {}

pub type LZ4FErrorCode = size_t;

Expand Down

0 comments on commit ef46781

Please sign in to comment.