File tree 2 files changed +41
-19
lines changed
2 files changed +41
-19
lines changed Original file line number Diff line number Diff line change @@ -192,3 +192,37 @@ jobs:
192
192
for target in $(cargo fuzz list ${{ matrix.features }}) ; do
193
193
RUST_BACKTRACE=1 cargo fuzz run ${{ matrix.features }} $target -- -max_total_time=10
194
194
done
195
+
196
+ link-c-dynamic-library :
197
+ name : dynamic library
198
+ strategy :
199
+ matrix :
200
+ include :
201
+ - target : x86_64-unknown-linux-gnu
202
+ features :
203
+ - ' '
204
+ runs-on : ubuntu-latest
205
+ steps :
206
+ - name : Checkout sources
207
+ uses : actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
208
+ with :
209
+ persist-credentials : false
210
+ - name : Install rust toolchain
211
+ uses : dtolnay/rust-toolchain@be73d7920c329f220ce78e0234b8f96b7ae60248
212
+ with :
213
+ toolchain : stable
214
+ targets : ${{matrix.target}}
215
+ - name : Rust cache
216
+ uses : Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8
217
+ with :
218
+ shared-key : " stable-${{matrix.target}}"
219
+ - name : get zpipe.c
220
+ run : wget https://www.zlib.net/zpipe.c
221
+ - name : cargo build
222
+ run : cargo build --target ${{matrix.target}} -p libz-rs-sys --release
223
+ - name : cc
224
+ run : cc -o zpipe zpipe.c target/${{matrix.target}}/release/deps/liblibz_rs_sys.so
225
+ - name : execute
226
+ run : cat Cargo.toml | ./zpipe | ./zpipe -d > out.txt
227
+ - name : compare
228
+ run : cmp -s Cargo.toml out.txt
Original file line number Diff line number Diff line change @@ -650,36 +650,24 @@ pub unsafe extern "C" fn deflateTune(
650
650
}
651
651
}
652
652
653
- const LIBZ_RS_SYS_VERSION : & str = env ! ( "CARGO_PKG_VERSION" ) ;
653
+ // the first part of this version specifies the zlib that we're compatible with (in terms of
654
+ // supported functions). In practice in most cases only the major version is checked, unless
655
+ // specific functions that were added later are used.
656
+ const LIBZ_RS_SYS_VERSION : & str = concat ! ( "1.3.0-zlib-rs-" , env!( "CARGO_PKG_VERSION" ) , "\0 " ) ;
654
657
655
658
unsafe fn is_version_compatible ( version : * const c_char , stream_size : i32 ) -> bool {
656
659
if version. is_null ( ) {
657
660
return false ;
658
661
}
659
662
660
- let cstr = core:: ffi:: CStr :: from_ptr ( version) ;
661
-
662
- if LIBZ_RS_SYS_VERSION . as_bytes ( ) [ 0 ] != cstr. to_bytes ( ) [ 0 ] {
663
+ let expected_major_version = core:: ptr:: read ( version) ;
664
+ if expected_major_version as u8 != LIBZ_RS_SYS_VERSION . as_bytes ( ) [ 0 ] {
663
665
return false ;
664
666
}
665
667
666
668
core:: mem:: size_of :: < z_stream > ( ) as i32 == stream_size
667
669
}
668
670
669
671
pub const extern "C" fn zlibVersion ( ) -> * const c_char {
670
- const BUF : [ u8 ; 16 ] = {
671
- let mut buf = [ 0 ; 16 ] ;
672
-
673
- let mut i = 0 ;
674
- while i < LIBZ_RS_SYS_VERSION . len ( ) {
675
- buf[ i] = LIBZ_RS_SYS_VERSION . as_bytes ( ) [ i] ;
676
- i += 1 ;
677
- }
678
-
679
- assert ! ( matches!( buf. last( ) , Some ( 0 ) ) ) ;
680
-
681
- buf
682
- } ;
683
-
684
- BUF . as_ptr ( ) as * const c_char
672
+ LIBZ_RS_SYS_VERSION . as_ptr ( ) as * const c_char
685
673
}
You can’t perform that action at this time.
0 commit comments