igormarfin / shedskin

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

Name clash between Python object attributes and global functions #110

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. shedskin lentest.py
2. make 
3.

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

$ shedskin lentest.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..]

nagle@user-PC ~/work
$ make
g++  -O2 -msse2 -fomit-frame-pointer -pipe -Wno-deprecated  -I. 
-I/home/nagle/shedskin/shedskin-0.6/shedskin/lib /home/nagle/shedski
n/shedskin-0.6/shedskin/lib/builtin.cpp lentest.cpp 
/home/nagle/shedskin/shedskin-0.6/shedskin/lib/re.cpp -lgc -lpcre  -o lentest
lentest.cpp: In member function `__shedskin__::__ss_int 
__lentest__::Test1::getlen()':
lentest.cpp:20: error: `((__lentest__::Test1*)this)->__lentest__::Test1::len' 
cannot be used as a function
make: *** [lentest] Error 1

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

Shed Skin 0.6, Cygwin, Windows 7

Please provide any additional information below.

If a Python program has a data attribute called "len", then, in the generated C 
code, "len" standing alone refers to that data attribute.  This masks the 
global non-module function "len".  This may apply to other global functions.  

Discovered while trying to compile StringIO.py from the Python library. 
Workaround is to rename the field to "length". 

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

Attachments:

GoogleCodeExporter commented 8 years ago
good catch, thanks! I added lentest.py to the test set. I will think about the 
best way to solve this. very strange I never encountered this problem before.. 
:-)

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

GoogleCodeExporter commented 8 years ago
I started with this issue today, because it seemed nastiest.. and it was indeed 
somewhat nasty, but it's fixed now in GIT! (gitorious.org/shedskin) I fixed it 
by renaming every instance variable that clashes with some global (function, 
variable, import..), and of course using the new name in places where it is 
accessed.. this also led to some nice cleanups. thanks again for reporting! :D

Original comment by mark.duf...@gmail.com on 13 Nov 2010 at 11:47