Browse Source

safeRepr prints class name before calling repr on C++ objects

Darren Ranalli 17 years ago
parent
commit
36b6f93353
1 changed files with 14 additions and 2 deletions
  1. 14 2
      direct/src/showbase/PythonUtil.py

+ 14 - 2
direct/src/showbase/PythonUtil.py

@@ -2253,15 +2253,27 @@ def _getDtoolSuperBase():
     from pandac.PandaModules import PandaNode
     dtoolSuperBase = PandaNode('').__class__.__bases__[0].__bases__[0].__bases__[0]
 
+safeReprNotify = None
+
+def _getSafeReprNotify():
+    global safeReprNotify
+    from direct.directnotify.DirectNotifyGlobal import directNotify
+    safeReprNotify = directNotify.newCategory("safeRepr")
+
 def safeRepr(obj):
     global dtoolSuperBase
     if dtoolSuperBase is None:
         _getDtoolSuperBase()
 
+    global safeReprNotify
+    if safeReprNotify is None:
+        _getSafeReprNotify()
+
     if isinstance(obj, dtoolSuperBase):
         # repr of C++ object could crash, particularly if the object has been deleted
-        return '<%s.%s instance at %s>' % (
-            obj.__class__.__module__, obj.__class__.__name__, hex(id(obj)))
+        # log that we're calling repr
+        safeReprNotify.info('calling repr on instance of %s.%s' % (obj.__class__.__module__, obj.__class__.__name__))
+        sys.stdout.flush()
 
     try:
         return repr(obj)