@@ -15,6 +15,7 @@ use crate::{
1515 suggestion:: offer_suggestions,
1616 types:: { Callable , Constructor , Initializer , Representable } ,
1717} ;
18+ use core:: fmt:: { self , Display , Formatter } ;
1819use crossbeam_utils:: atomic:: AtomicCell ;
1920use itertools:: Itertools ;
2021#[ cfg( feature = "host_env" ) ]
@@ -1188,20 +1189,62 @@ impl serde::Serialize for SerializeException<'_, '_> {
11881189 }
11891190}
11901191
1191- pub fn cstring_error ( vm : & VirtualMachine ) -> PyBaseExceptionRef {
1192+ #[ derive( Debug ) ]
1193+ pub struct NulError ;
1194+
1195+ impl Display for NulError {
1196+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
1197+ write ! ( f, "embedded null character" )
1198+ }
1199+ }
1200+
1201+ pub fn nul_char_error ( vm : & VirtualMachine ) -> PyBaseExceptionRef {
11921202 vm. new_value_error ( "embedded null character" )
11931203}
11941204
1205+ pub fn nul_char_type_error ( vm : & VirtualMachine ) -> PyBaseExceptionRef {
1206+ vm. new_type_error ( "embedded null character" )
1207+ }
1208+
1209+ pub fn nul_byte_error ( vm : & VirtualMachine ) -> PyBaseExceptionRef {
1210+ vm. new_value_error ( "embedded null byte" )
1211+ }
1212+
11951213impl ToPyException for alloc:: ffi:: NulError {
11961214 fn to_pyexception ( & self , vm : & VirtualMachine ) -> PyBaseExceptionRef {
1197- cstring_error ( vm)
1215+ nul_char_error ( vm)
1216+ }
1217+ }
1218+
1219+ impl ToPyException for alloc:: ffi:: FromVecWithNulError {
1220+ fn to_pyexception ( & self , vm : & VirtualMachine ) -> PyBaseExceptionRef {
1221+ nul_char_error ( vm)
1222+ }
1223+ }
1224+
1225+ impl ToPyException for core:: ffi:: FromBytesWithNulError {
1226+ fn to_pyexception ( & self , vm : & VirtualMachine ) -> PyBaseExceptionRef {
1227+ nul_char_error ( vm)
1228+ }
1229+ }
1230+
1231+ impl ToPyException for NulError {
1232+ fn to_pyexception ( & self , vm : & VirtualMachine ) -> PyBaseExceptionRef {
1233+ nul_char_error ( vm)
11981234 }
11991235}
12001236
12011237#[ cfg( windows) ]
12021238impl < C > ToPyException for widestring:: error:: ContainsNul < C > {
12031239 fn to_pyexception ( & self , vm : & VirtualMachine ) -> PyBaseExceptionRef {
1204- cstring_error ( vm)
1240+ nul_char_error ( vm)
1241+ }
1242+ }
1243+
1244+ #[ cfg( windows) ]
1245+ impl ToPyException for widestring:: error:: MissingNulTerminator {
1246+ fn to_pyexception ( & self , vm : & VirtualMachine ) -> PyBaseExceptionRef {
1247+ vm. new_value_error ( self . to_string ( ) )
12051248 }
12061249}
12071250
0 commit comments