@@ -66,6 +66,11 @@ pub enum DeterministicCacheError {
6666 MaxCorePerPackage ( CheckedAssignError ) ,
6767}
6868
69+ /// We always use this brand string.
70+ pub const DEFAULT_BRAND_STRING : & [ u8 ; BRAND_STRING_LENGTH ] =
71+ b"Intel(R) Xeon(R) Processor\0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 " ;
72+ pub const DEFAULT_BRAND_STRING_BASE : & [ u8 ; 28 ] = b"Intel(R) Xeon(R) Processor @" ;
73+
6974// We use this 2nd implementation so we can conveniently define functions only used within
7075// `normalize`.
7176#[ allow( clippy:: multiple_inherent_impl) ]
@@ -231,13 +236,12 @@ impl super::IntelCpuid {
231236 Ok ( ( ) )
232237 }
233238
234- /// Update brand string entry
235239 fn update_brand_string_entry ( & mut self ) -> Result < ( ) , NormalizeCpuidError > {
236240 // Get host brand string.
237241 let host_brand_string: [ u8 ; BRAND_STRING_LENGTH ] = host_brand_string ( ) ;
238242
239243 let default_brand_string =
240- default_brand_string ( host_brand_string) . map_err ( NormalizeCpuidError :: GetBrandString ) ? ;
244+ default_brand_string ( host_brand_string) . unwrap_or ( * DEFAULT_BRAND_STRING ) ;
241245
242246 self . apply_brand_string ( & default_brand_string)
243247 . map_err ( NormalizeCpuidError :: ApplyBrandString ) ?;
@@ -281,12 +285,10 @@ pub enum DefaultBrandStringError {
281285#[ inline]
282286fn default_brand_string (
283287 // Host brand string.
284- // This should look like b"Intel(R) Xeon(R) Platinum 8275CL CPU @ 3.00GHz".
288+ // This could look like "Intel(R) Xeon(R) Platinum 8275CL CPU @ 3.00GHz".
289+ // or this could look like "Intel(R) Xeon(R) Platinum 8275CL CPU\0\0\0\0\0\0\0\0\0\0".
285290 host_brand_string : [ u8 ; BRAND_STRING_LENGTH ] ,
286291) -> Result < [ u8 ; BRAND_STRING_LENGTH ] , DefaultBrandStringError > {
287- /// We always use this brand string.
288- const DEFAULT_BRAND_STRING_BASE : & [ u8 ] = b"Intel(R) Xeon(R) Processor @" ;
289-
290292 // The slice of the host string before the frequency suffix
291293 // e.g. b"Intel(R) Xeon(R) Processor Platinum 8275CL CPU @ 3.00" and b"GHz"
292294 let ( before, after) = ' outer: {
@@ -363,69 +365,26 @@ mod tests {
363365 ) ]
364366
365367 use super :: * ;
366-
367368 #[ test]
368369 fn default_brand_string_test ( ) {
369370 let brand_string = b"Intel(R) Xeon(R) Platinum 8275CL CPU @ 3.00GHz\0 \0 " ;
370371 let ok_result = default_brand_string ( * brand_string) ;
371372 let expected = Ok ( * b"Intel(R) Xeon(R) Processor @ 3.00GHz\0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 " ) ;
372- assert_eq ! (
373- ok_result,
374- expected,
375- "{:?} != {:?}" ,
376- ok_result. as_ref( ) . map( |s| unsafe {
377- std:: ffi:: CStr :: from_ptr( ( s as * const u8 ) . cast( ) )
378- . to_str( )
379- . unwrap( )
380- } ) ,
381- expected. as_ref( ) . map( |s| unsafe {
382- std:: ffi:: CStr :: from_ptr( ( s as * const u8 ) . cast( ) )
383- . to_str( )
384- . unwrap( )
385- } )
386- ) ;
373+ assert_eq ! ( ok_result, expected) ;
387374 }
388375 #[ test]
389376 fn default_brand_string_test_missing_frequency ( ) {
390377 let brand_string = b"Intel(R) Xeon(R) Platinum 8275CL CPU @ \0 \0 \0 \0 \0 \0 \0 \0 \0 " ;
391378 let result = default_brand_string ( * brand_string) ;
392379 let expected = Err ( DefaultBrandStringError :: MissingFrequency ( * brand_string) ) ;
393- assert_eq ! (
394- result,
395- expected,
396- "{:?} != {:?}" ,
397- result. as_ref( ) . map( |s| unsafe {
398- std:: ffi:: CStr :: from_ptr( ( s as * const u8 ) . cast( ) )
399- . to_str( )
400- . unwrap( )
401- } ) ,
402- unsafe {
403- std:: ffi:: CStr :: from_ptr( ( brand_string as * const u8 ) . cast( ) )
404- . to_str( )
405- . unwrap( )
406- }
407- ) ;
380+ assert_eq ! ( result, expected) ;
408381 }
409382 #[ test]
410383 fn default_brand_string_test_missing_space ( ) {
411384 let brand_string = b"Intel(R) Xeon(R) Platinum 8275CL CPU @3.00GHz\0 \0 \0 " ;
412385 let result = default_brand_string ( * brand_string) ;
413386 let expected = Err ( DefaultBrandStringError :: MissingSpace ( * brand_string) ) ;
414- assert_eq ! (
415- result,
416- expected,
417- "{:?} != {:?}" ,
418- result. as_ref( ) . map( |s| unsafe {
419- std:: ffi:: CStr :: from_ptr( ( s as * const u8 ) . cast( ) )
420- . to_str( )
421- . unwrap( )
422- } ) ,
423- unsafe {
424- std:: ffi:: CStr :: from_ptr( ( brand_string as * const u8 ) . cast( ) )
425- . to_str( )
426- . unwrap( )
427- }
428- ) ;
387+ assert_eq ! ( result, expected) ;
429388 }
430389 #[ test]
431390 fn default_brand_string_test_overflow ( ) {
0 commit comments