mnba / shedskin

Automatically exported from code.google.com/p/shedskin
0 stars 0 forks source link

Shed Skin compiler abort - KeyError in compiler while generating C++ code #109

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Bring in attached files.
2. shedskin stringio.py 

What is the expected output? What do you see instead?

$ shedskin stringio.py
*** SHED SKIN Python-to-C++ Compiler 0.6 ***
Copyright 2005-2010 Mark Dufour; License GNU GPL version 3 (See LICENSE)

[iterative type analysis..]
********************************100%
[generating c++ code..]
Traceback (most recent call last):
  File "/home/nagle/shedskin/shedskin-0.6/shedskin/__init__.py", line 87, in <module>
    main()
  File "/home/nagle/shedskin/shedskin-0.6/shedskin/__init__.py", line 84, in main
    cpp.generate_code()
  File "/home/nagle/shedskin/shedskin-0.6/shedskin/cpp.py", line 2953, in generate_code
    walk(module.ast, gv)
  File "/usr/lib/python2.6/compiler/visitor.py", line 106, in walk
    walker.preorder(tree, visitor)
  File "/usr/lib/python2.6/compiler/visitor.py", line 63, in preorder
    self.dispatch(tree, *args) # XXX *args make sense?
  File "/usr/lib/python2.6/compiler/visitor.py", line 57, in dispatch
    return meth(node, *args)
  File "/home/nagle/shedskin/shedskin-0.6/shedskin/cpp.py", line 405, in visitModule
    self.module_cpp(node)
  File "/home/nagle/shedskin/shedskin-0.6/shedskin/cpp.py", line 322, in module_cpp
    self.class_cpp(child)
  File "/home/nagle/shedskin/shedskin-0.6/shedskin/cpp.py", line 566, in class_cpp
    self.visitFunction(func.node, cl, declare)
  File "/home/nagle/shedskin/shedskin-0.6/shedskin/cpp.py", line 1177, in visitFunction
    self.visit(node.code, func)
  File "/usr/lib/python2.6/compiler/visitor.py", line 57, in dispatch
    return meth(node, *args)
  File "/home/nagle/shedskin/shedskin-0.6/shedskin/cpp.py", line 1304, in visitStmt
    self.visit(b, func)
  File "/usr/lib/python2.6/compiler/visitor.py", line 57, in dispatch
    return meth(node, *args)
  File "/home/nagle/shedskin/shedskin-0.6/shedskin/cpp.py", line 1271, in visitIf
    self.visit(test[1], func)
  File "/usr/lib/python2.6/compiler/visitor.py", line 57, in dispatch
    return meth(node, *args)
  File "/home/nagle/shedskin/shedskin-0.6/shedskin/cpp.py", line 1304, in visitStmt
    self.visit(b, func)
  File "/usr/lib/python2.6/compiler/visitor.py", line 57, in dispatch
    return meth(node, *args)
  File "/usr/lib/python2.6/compiler/visitor.py", line 40, in default
    self.dispatch(child, *args)
  File "/usr/lib/python2.6/compiler/visitor.py", line 57, in dispatch
    return meth(node, *args)
  File "/home/nagle/shedskin/shedskin-0.6/shedskin/cpp.py", line 2390, in visitAssAttr
    cl, module = lookup_class_module(node.expr, inode(node).mv, func)
  File "/home/nagle/shedskin/shedskin-0.6/shedskin/shared.py", line 354, in inode
    return getgx().cnode[node,0,0]
KeyError: (AssAttr(Name('self'), 'buf', 'OP_DELETE'), 0, 0)

What version of the product are you using? On what operating system?

Shed Skin 0.6 on Cygwin on Windows 7.

Please provide any additional information below.

Trying to compile a modified version of "StringIO.py"
Attached a version of "errno.py" needed for above.

Original issue reported on code.google.com by na...@animats.com on 8 Nov 2010 at 6:00

Attachments:

GoogleCodeExporter commented 9 years ago
auwf, I hate it when this happens.. :-) I put this on my list of things to look 
into quickly, thanks!

btw, it's a good idea to try some unsupported modules to locate bugs, but 
please don't expect string processing libs to become faster with shedskin! 
strings in C++ are probably actually slower than in CPython..

Original comment by mark.duf...@gmail.com on 8 Nov 2010 at 8:56

GoogleCodeExporter commented 9 years ago
I realize that string processing speed isn't going to improve that much yet.  
I'm trying to make StringIO work because so many modules import it. 

(Incidentally, it would really help if Shed Skin error messages like the one 
for an import within a conditional or an undefined type came with module names 
and line numbers.  Thanks.)

Original comment by na...@animats.com on 8 Nov 2010 at 9:05

GoogleCodeExporter commented 9 years ago
This turns out to be related to the line

del self.buf, self.pos

in StringIO.close.

It's "del self.buf" that's causing a crash. Replacing that with 

   self.buf = ""

is a successful workaround.

Attached is a somewhat hacked up version of StringIO which will pass its unit 
test compiled with ShedSkin.  Other problems that had to be dealt with involved 
removing Unicode support, avoiding "isinstance(s, str)", and eliminating mixing 
of None and int types. 

Original comment by na...@animats.com on 9 Nov 2010 at 5:29

Attachments:

GoogleCodeExporter commented 9 years ago
thanks for looking further into this. deleting an attribute is not supported by 
shedskin (too dynamic to translate to C++), so we should probably add a 
warning/error message for this case. 

I'm hoping to look into all the issues you reported on wednesday.

Original comment by mark.duf...@gmail.com on 9 Nov 2010 at 8:56

GoogleCodeExporter commented 9 years ago
btw, "del self.buf, self.pos" seems to be a no-op: it creates a tuple, then 
deletes just the tuple!? 

Original comment by mark.duf...@gmail.com on 14 Nov 2010 at 9:38

GoogleCodeExporter commented 9 years ago
oh, sorry, it does seem to work actually.. bah.

Original comment by mark.duf...@gmail.com on 14 Nov 2010 at 9:46

GoogleCodeExporter commented 9 years ago
okay, I fixed the crash, and added a warning instead. thanks again for 
reporting!

btw, I could fix the other two issues today, but instead I added them to the 
'easy tasks' wiki page.. I hope you don't mind. it seems like a good idea to 
have some easy tasks around to try and lure people into shedskin development.. 
:-)

Original comment by mark.duf...@gmail.com on 14 Nov 2010 at 10:50