From 36b6f933531ed342d217c69e1f159fedf0f3f1f0 Mon Sep 17 00:00:00 2001 From: Darren Ranalli Date: Fri, 5 Sep 2008 20:44:26 +0000 Subject: [PATCH] safeRepr prints class name before calling repr on C++ objects --- direct/src/showbase/PythonUtil.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/direct/src/showbase/PythonUtil.py b/direct/src/showbase/PythonUtil.py index c72326cc63..66f46993e9 100644 --- a/direct/src/showbase/PythonUtil.py +++ b/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)