A possible bug related to parsing

23 views
Skip to first unread message

RCU

unread,
Jun 3, 2013, 10:38:59 PM6/3/13
to shedskin...@googlegroups.com
Hello,
I would like to report a bug I got while running ShedSkin.
I am not sure it's really Shedskin - it looks to me actually the problem comes from
the compiler module.
You can reproduce the error by running the attached Python script.

The problem is the following: although ShedSkin treats well global vars declared and
used inside functions, if a global var is used as iterator in a for statement, then
ShedSkin is considering that variable to be local to the function. Therefore, the
local-considered variable will obstruct the global, which will lead to different behavior
in the function with the for statement in C++ as oposed to Python.
You can see that by running:
- the Python script directly
- the resulting C++ code from ShedSkin for the Python script.
Note that the boing() Python function has:
global day
while the C++ translation of boing is:
__ss_int boing(__ss_int c, double d) {
__ss_int __0, __1, day, sum;

The reason this happens is that day is reported as a (local) variable of function
boing() by func.vars.items() in module cpp.py, method local_defs(self, func) .
I looked a bit in Python/Lib/compiler (module ast.py), but I couldn't figure out
where the result of func.vars.items() is really created.

Could you please take a look and see if I am missing something?

Note that I run ShedSkin on Python 2.7.2, which comes with Ubuntu 11.10. I've tested
also a bit on Python 2.5.4 and 2.6.6.

Best regards,
Alex

1.py

Mark Dufour

unread,
Jun 4, 2013, 5:36:21 AM6/4/13
to shedskin-discuss
hi alex,

good catch! :D it's a shedskin bug, and just in time for 0.9.4. I will see if I can fix the problem tomorrow. or if you like, I could try to give you some pointers so you might be able to fix the problem yourself..?

thanks again!
mark.




--
You received this message because you are subscribed to the Google Groups "shedskin-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shedskin-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to shedskin-discuss@googlegroups.com.
Visit this group at http://groups.google.com/group/shedskin-discuss?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.





--
http://www.youtube.com/watch?v=E6LsfnBmdnk

srepmub

unread,
Jun 6, 2013, 8:52:26 AM6/6/13
to shedskin...@googlegroups.com
hi alex,

sorry I'm always a bit impatient :P the problem is now fixed in git!

thanks again for reporting!
mark.

RCU

unread,
Jun 23, 2013, 4:00:16 PM6/23/13
to shedskin...@googlegroups.com
Hi.
Sorry for the late reply.

Glad to know you solved it.
I looked in git for the latest code - is the changed you performed to fix this bug
found in cpp.py, def local_defs(self, func) ?

Best regards,
Alex


On 6/4/2013 12:36 PM, Mark Dufour wrote:
> hi alex,
>
> good catch! :D it's a shedskin bug, and just in time for 0.9.4. I will see if I can fix

Interesting. It looked to me that ShedSkin is not really the culprit.


> the problem tomorrow. or if you like, I could try to give you some pointers so you might
> be able to fix the problem yourself..?
>
> thanks again!
> mark.


> http://www.youtube.com/watch?v=E6LsfnBmdnk <http://www.youtube.com/watch?v=E6LsfnBmdnk>
>
> --
> You received this message because you are subscribed to the Google Groups
> "shedskin-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> shedskin-discu...@googlegroups.com.
> To post to this group, send email to shedskin...@googlegroups.com.

Mark Dufour

unread,
Jun 26, 2013, 5:52:44 AM6/26/13
to shedskin-discuss
hi alex,

git show a9fa2ac

[..]

+    def default_var(self, name, func):
+        if isinstance(func, Function) and name in func.globals:
+            return default_var(self.gx, name, None, mv=getmv())
+        else:
+            return default_var(self.gx, name, func, mv=getmv())
+

this check was not done consistently before. so it missed in some cases that a variable was declared global.

thanks!
mark.


--
You received this message because you are subscribed to the Google Groups "shedskin-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shedskin-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to shedskin-discuss@googlegroups.com.
Visit this group at http://groups.google.com/group/shedskin-discuss.

For more options, visit https://groups.google.com/groups/opt_out.


Reply all
Reply to author
Forward
0 new messages