@@ -1222,12 +1222,36 @@ pub unsafe extern "C" fn ZDICT_finalizeDictionary(
12221222 dictBuffer : * mut core:: ffi:: c_void ,
12231223 dictBufferCapacity : size_t ,
12241224 customDictContent : * const core:: ffi:: c_void ,
1225- mut dictContentSize : size_t ,
1225+ dictContentSize : size_t ,
12261226 samplesBuffer : * const core:: ffi:: c_void ,
12271227 samplesSizes : * const size_t ,
12281228 nbSamples : core:: ffi:: c_uint ,
12291229 params : ZDICT_params_t ,
12301230) -> size_t {
1231+ finalize_dictionary (
1232+ dictBuffer,
1233+ dictBufferCapacity,
1234+ customDictContent,
1235+ dictContentSize,
1236+ samplesBuffer,
1237+ samplesSizes,
1238+ nbSamples,
1239+ params,
1240+ )
1241+ . map_err ( |e| e. to_error_code ( ) )
1242+ . unwrap_or_else ( |e| e)
1243+ }
1244+
1245+ unsafe fn finalize_dictionary (
1246+ dictBuffer : * mut core:: ffi:: c_void ,
1247+ dictBufferCapacity : size_t ,
1248+ customDictContent : * const core:: ffi:: c_void ,
1249+ mut dictContentSize : size_t ,
1250+ samplesBuffer : * const core:: ffi:: c_void ,
1251+ samplesSizes : * const size_t ,
1252+ nbSamples : core:: ffi:: c_uint ,
1253+ params : ZDICT_params_t ,
1254+ ) -> Result < usize , Error > {
12311255 let mut hSize: size_t = 0 ;
12321256 let mut header: [ u8 ; 256 ] = [ 0 ; 256 ] ;
12331257 let compressionLevel = if params. compressionLevel == 0 {
@@ -1239,10 +1263,10 @@ pub unsafe extern "C" fn ZDICT_finalizeDictionary(
12391263 let minContentSize = * repStartValue. iter ( ) . max ( ) . unwrap ( ) as size_t ;
12401264 let mut paddingSize: size_t = 0 ;
12411265 if dictBufferCapacity < dictContentSize {
1242- return Error :: dstSize_tooSmall. to_error_code ( ) ;
1266+ return Err ( Error :: dstSize_tooSmall) ;
12431267 }
12441268 if dictBufferCapacity < ZDICT_DICTSIZE_MIN as size_t {
1245- return Error :: dstSize_tooSmall. to_error_code ( ) ;
1269+ return Err ( Error :: dstSize_tooSmall) ;
12461270 }
12471271 header[ ..4 ] . copy_from_slice ( & ZSTD_MAGIC_DICTIONARY . to_le_bytes ( ) ) ;
12481272 let randomID = ZSTD_XXH64 ( customDictContent, dictContentSize, 0 ) ;
@@ -1272,16 +1296,16 @@ pub unsafe extern "C" fn ZDICT_finalizeDictionary(
12721296 dictContentSize,
12731297 notificationLevel,
12741298 ) ;
1275- if ZDICT_isError ( eSize ) != 0 {
1276- return eSize ;
1299+ if let Some ( err ) = Error :: from_error_code ( eSize ) {
1300+ return Err ( err ) ;
12771301 }
12781302 hSize = hSize. wrapping_add ( eSize) ;
12791303 if hSize. wrapping_add ( dictContentSize) > dictBufferCapacity {
12801304 dictContentSize = dictBufferCapacity. wrapping_sub ( hSize) ;
12811305 }
12821306 if dictContentSize < minContentSize {
12831307 if hSize. wrapping_add ( minContentSize) > dictBufferCapacity {
1284- return Error :: dstSize_tooSmall. to_error_code ( ) ;
1308+ return Err ( Error :: dstSize_tooSmall) ;
12851309 }
12861310 paddingSize = minContentSize. wrapping_sub ( dictContentSize) ;
12871311 } else {
@@ -1300,7 +1324,7 @@ pub unsafe extern "C" fn ZDICT_finalizeDictionary(
13001324 ) ;
13011325 core:: ptr:: copy_nonoverlapping ( header. as_mut_ptr ( ) , outDictHeader, hSize) ;
13021326 core:: ptr:: write_bytes ( outDictPadding, 0 , paddingSize) ;
1303- dictSize
1327+ Ok ( dictSize)
13041328}
13051329
13061330const HBUFFSIZE : core:: ffi:: c_int = 256 ;
0 commit comments