Skip to content

Commit

Permalink
View.py: Ignore any non-capsules and show a warning
Browse files Browse the repository at this point in the history
The ugly part is the the type object is fetched using ctypes...
The types module does not expose this type.

Fixes #13
  • Loading branch information
zhuyifei1999 committed Nov 9, 2019
1 parent 4d27d3f commit fe22e59
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions guppy/heapy/View.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ class _GLUECLAMP_:
'_parent.Use:idset',
'_parent.Use:iso',
'_parent.Use:Type',
'_root:ctypes',
'_root:gc',
'_root:types',
'_root.warnings:warn',
)

_chgable_ = ('is_rg_update_all', 'referrers_lock', '_is_clear_drg_enabled')
Expand Down Expand Up @@ -139,6 +141,10 @@ def clear_drg():
def _get_gchook_type(self):
return Gchook_type

def _get_capsule_type(self):
return self.ctypes.cast(
self.ctypes.pythonapi.PyCapsule_Type, self.ctypes.py_object).value

def _get_heapdef_modules(self):
# We touch self.heapyc to import it & its dependent guppy.sets;
# this is kinda specialcase-hacky but see Notes Apr 8 2005.
Expand All @@ -152,6 +158,10 @@ def _get_heapdefs(self):
hd = getattr(m, '_NyHeapDefs_')
except AttributeError:
continue
if not hd or not isinstance(hd, self.capsule_type):
self.warn('Ignoring non-capsule object '
'{}._NyHeapDefs_'.format(n))
continue
heapdefs.append(hd)
return tuple(heapdefs)

Expand Down

0 comments on commit fe22e59

Please sign in to comment.