knz / go-binsize-viz

Size visualization of Go executables using D3
GNU Affero General Public License v3.0
470 stars 30 forks source link

simplify.py: TypeError with golang.org/x/net/publicsuffix #3

Closed stapelberg closed 1 year ago

stapelberg commented 5 years ago

Great work, thanks for sharing!

When trying to use the tools for my own programs, I’m getting the following error:

% python3 simplify.py ~/out.py
loading...
transforming...
Traceback (most recent call last):
  File "simplify.py", line 32, in <module>
    _, values = transform(values)
  File "simplify.py", line 18, in transform
    ename, v = transform(v)
  File "simplify.py", line 18, in transform
    ename, v = transform(v)
  File "simplify.py", line 18, in transform
    ename, v = transform(v)
  [Previous line repeated 9 more times]
  File "simplify.py", line 23, in transform
    c = flatten(d['children'])
  File "simplify.py", line 11, in flatten
    v['name'] = k
TypeError: 'int' object does not support item assignment

I tracked it down to the following symtab line:

  a25e60       2148 D golang.org/x/net/publicsuffix.children
dreamerlzl commented 1 year ago

same problem here

tmm1 commented 1 year ago
diff --git a/simplify.py b/simplify.py
index b8e7357..1653d24 100644
--- a/simplify.py
+++ b/simplify.py
@@ -24,8 +24,9 @@ values['name'] = '>'
 def flatten(d):
     vals = []
     for k, v in d.items():
-        v['name'] = k
-        vals.append(v)
+        if isinstance(v, dict):
+            v['name'] = k
+            vals.append(v)
     return vals

 def transform(d):