@@ -270,12 +270,13 @@ def is_optimized_out(self):
270270
271271 def safe_tp_name (self ):
272272 try :
273- return self .type ().field ('tp_name' ).string ()
274- except NullPyObjectPtr :
275- # NULL tp_name?
276- return 'unknown'
277- except RuntimeError :
278- # Can't even read the object at all?
273+ ob_type = self .type ()
274+ tp_name = ob_type .field ('tp_name' )
275+ return tp_name .string ()
276+ # NullPyObjectPtr: NULL tp_name?
277+ # RuntimeError: Can't even read the object at all?
278+ # UnicodeDecodeError: Failed to decode tp_name bytestring
279+ except (NullPyObjectPtr , RuntimeError , UnicodeDecodeError ):
279280 return 'unknown'
280281
281282 def proxyval (self , visited ):
@@ -349,7 +350,9 @@ def subclass_from_type(cls, t):
349350 try :
350351 tp_name = t .field ('tp_name' ).string ()
351352 tp_flags = int (t .field ('tp_flags' ))
352- except RuntimeError :
353+ # RuntimeError: NULL pointers
354+ # UnicodeDecodeError: string() fails to decode the bytestring
355+ except (RuntimeError , UnicodeDecodeError ):
353356 # Handle any kind of error e.g. NULL ptrs by simply using the base
354357 # class
355358 return cls
@@ -617,7 +620,10 @@ class PyCFunctionObjectPtr(PyObjectPtr):
617620
618621 def proxyval (self , visited ):
619622 m_ml = self .field ('m_ml' ) # m_ml is a (PyMethodDef*)
620- ml_name = m_ml ['ml_name' ].string ()
623+ try :
624+ ml_name = m_ml ['ml_name' ].string ()
625+ except UnicodeDecodeError :
626+ ml_name = '<ml_name:UnicodeDecodeError>'
621627
622628 pyop_m_self = self .pyop_field ('m_self' )
623629 if pyop_m_self .is_null ():
@@ -1340,13 +1346,13 @@ def safe_name(self):
13401346 try :
13411347 name = self .field ('descr' )['d_base' ]['name' ].string ()
13421348 return repr (name )
1343- except (NullPyObjectPtr , RuntimeError ):
1349+ except (NullPyObjectPtr , RuntimeError , UnicodeDecodeError ):
13441350 return '<unknown name>'
13451351
13461352 def safe_tp_name (self ):
13471353 try :
13481354 return self .field ('self' )['ob_type' ]['tp_name' ].string ()
1349- except (NullPyObjectPtr , RuntimeError ):
1355+ except (NullPyObjectPtr , RuntimeError , UnicodeDecodeError ):
13501356 return '<unknown tp_name>'
13511357
13521358 def safe_self_addresss (self ):
0 commit comments