@@ -880,7 +880,7 @@ pub unsafe extern "C" fn ZDICT_trainFromBuffer_cover(
880880 dictionarySize
881881}
882882
883- pub ( super ) unsafe fn COVER_checkTotalCompressedSize (
883+ pub ( super ) fn COVER_checkTotalCompressedSize (
884884 parameters : ZDICT_cover_params_t ,
885885 samplesSizes : & [ size_t ] ,
886886 samples : & [ u8 ] ,
@@ -911,12 +911,14 @@ pub(super) unsafe fn COVER_checkTotalCompressedSize(
911911 }
912912 dstCapacity = ZSTD_compressBound ( maxSampleSize) ;
913913 let mut dst: Box < [ MaybeUninit < u8 > ] > = Box :: new_uninit_slice ( dstCapacity) ;
914- cctx = ZSTD_createCCtx ( ) ;
915- cdict = ZSTD_createCDict (
916- dict as * const core:: ffi:: c_void ,
917- dictBufferCapacity,
918- parameters. zParams . compressionLevel ,
919- ) ;
914+ cctx = unsafe { ZSTD_createCCtx ( ) } ;
915+ cdict = unsafe {
916+ ZSTD_createCDict (
917+ dict as * const core:: ffi:: c_void ,
918+ dictBufferCapacity,
919+ parameters. zParams . compressionLevel ,
920+ )
921+ } ;
920922 if !( cctx. is_null ( ) || cdict. is_null ( ) ) {
921923 totalCompressedSize = dictBufferCapacity;
922924 i = if parameters. splitPoint < 1.0f64 {
@@ -925,14 +927,16 @@ pub(super) unsafe fn COVER_checkTotalCompressedSize(
925927 0
926928 } ;
927929 while i < nbSamples {
928- let size = ZSTD_compress_usingCDict (
929- cctx,
930- dst. as_mut_ptr ( ) . cast :: < core:: ffi:: c_void > ( ) ,
931- dstCapacity,
932- samples[ offsets[ i] ..] . as_ptr ( ) as * const core:: ffi:: c_void ,
933- samplesSizes[ i] ,
934- cdict,
935- ) ;
930+ let size = unsafe {
931+ ZSTD_compress_usingCDict (
932+ cctx,
933+ dst. as_mut_ptr ( ) . cast :: < core:: ffi:: c_void > ( ) ,
934+ dstCapacity,
935+ samples[ offsets[ i] ..] . as_ptr ( ) as * const core:: ffi:: c_void ,
936+ samplesSizes[ i] ,
937+ cdict,
938+ )
939+ } ;
936940 if ERR_isError ( size) {
937941 totalCompressedSize = size;
938942 break ;
@@ -942,8 +946,8 @@ pub(super) unsafe fn COVER_checkTotalCompressedSize(
942946 }
943947 }
944948 }
945- ZSTD_freeCCtx ( cctx) ;
946- ZSTD_freeCDict ( cdict) ;
949+ unsafe { ZSTD_freeCCtx ( cctx) } ;
950+ unsafe { ZSTD_freeCDict ( cdict) } ;
947951 drop ( dst) ;
948952 totalCompressedSize
949953}
@@ -1022,7 +1026,7 @@ pub(super) unsafe fn COVER_dictSelectionFree(selection: COVER_dictSelection_t) {
10221026 drop ( selection)
10231027}
10241028
1025- pub ( super ) unsafe fn COVER_selectDict (
1029+ pub ( super ) fn COVER_selectDict (
10261030 customDictContent : & [ u8 ] ,
10271031 dictBufferCapacity : size_t ,
10281032 mut dictContentSize : size_t ,
@@ -1042,16 +1046,18 @@ pub(super) unsafe fn COVER_selectDict(
10421046 let regressionTolerance =
10431047 params. shrinkDictMaxRegression as core:: ffi:: c_double / 100.0f64 + 1.00f64 ;
10441048 largestDictbuffer[ ..customDictContent. len ( ) ] . copy_from_slice ( customDictContent) ;
1045- dictContentSize = ZDICT_finalizeDictionary (
1046- largestDictbuffer. as_mut_ptr ( ) as * mut core:: ffi:: c_void ,
1047- dictBufferCapacity,
1048- customDictContent. as_ptr ( ) as * const core:: ffi:: c_void ,
1049- dictContentSize,
1050- samplesBuffer. as_ptr ( ) as * const core:: ffi:: c_void ,
1051- samplesSizes. as_ptr ( ) ,
1052- nbFinalizeSamples,
1053- params. zParams ,
1054- ) ;
1049+ dictContentSize = unsafe {
1050+ ZDICT_finalizeDictionary (
1051+ largestDictbuffer. as_mut_ptr ( ) as * mut core:: ffi:: c_void ,
1052+ dictBufferCapacity,
1053+ customDictContent. as_ptr ( ) as * const core:: ffi:: c_void ,
1054+ dictContentSize,
1055+ samplesBuffer. as_ptr ( ) as * const core:: ffi:: c_void ,
1056+ samplesSizes. as_ptr ( ) ,
1057+ nbFinalizeSamples,
1058+ params. zParams ,
1059+ )
1060+ } ;
10551061 if ZDICT_isError ( dictContentSize) != 0 {
10561062 drop ( largestDictbuffer) ;
10571063 drop ( candidateDictBuffer) ;
@@ -1081,18 +1087,20 @@ pub(super) unsafe fn COVER_selectDict(
10811087 dictContentSize = ZDICT_DICTSIZE_MIN as size_t ;
10821088 while dictContentSize < largestDict {
10831089 candidateDictBuffer[ ..largestDict] . copy_from_slice ( & largestDictbuffer[ ..largestDict] ) ;
1084- dictContentSize = ZDICT_finalizeDictionary (
1085- candidateDictBuffer. as_mut_ptr ( ) as * mut core:: ffi:: c_void ,
1086- dictBufferCapacity,
1087- customDictContent[ customDictContent. len ( ) - dictContentSize..]
1088- . as_ptr ( )
1089- . cast ( ) ,
1090- dictContentSize,
1091- samplesBuffer. as_ptr ( ) as * const core:: ffi:: c_void ,
1092- samplesSizes. as_ptr ( ) ,
1093- nbFinalizeSamples,
1094- params. zParams ,
1095- ) ;
1090+ dictContentSize = unsafe {
1091+ ZDICT_finalizeDictionary (
1092+ candidateDictBuffer. as_mut_ptr ( ) as * mut core:: ffi:: c_void ,
1093+ dictBufferCapacity,
1094+ customDictContent[ customDictContent. len ( ) - dictContentSize..]
1095+ . as_ptr ( )
1096+ . cast ( ) ,
1097+ dictContentSize,
1098+ samplesBuffer. as_ptr ( ) as * const core:: ffi:: c_void ,
1099+ samplesSizes. as_ptr ( ) ,
1100+ nbFinalizeSamples,
1101+ params. zParams ,
1102+ )
1103+ } ;
10961104 if ZDICT_isError ( dictContentSize) != 0 {
10971105 drop ( largestDictbuffer) ;
10981106 drop ( candidateDictBuffer) ;
0 commit comments