[pypy-dev] Bug hunting in rctime becomes wtf

Lawrence Oluyede l.oluyede at gmail.com
Tue Jul 11 18:00:12 CEST 2006

I had a nasty bug like this one in the compilation process of the rctime module:

[translation:ERROR] Error:
[translation:ERROR]  TyperError: non-constant tuple index
[translation:ERROR] .. block at 34 with 1 exits
[translation:ERROR] .. v0 = getitem(tup_0, ___i_0)

You can reproduce it decommenting asctime function from interp_time.py
and in the __init__.py file of the rctime module.

After some digging I've found the source of the problem in the code
Armin and I have checked-in at the sprint to add the support for
"*args" arguments (see visit_args_w in pypy.objspace.cpy.function). I
tried patching it but I'm not very into cpy objspace and the compiler
mechanism under the hood.

The "wtf" thing came out when I tried to use the file with this
"stupid" patch applied:

rhymes at groove:~/scc/pypy/pypy/objspace/cpy $ svn diff
Index: function.py
--- function.py (revision 29953)
+++ function.py (working copy)
@@ -61,7 +61,7 @@
         tramp.inputargs.append('*' + basename)
         tramp.wrappings.append('%s = []' % (argname,))
         tramp.wrappings.append('for ___i in range(len(%s)):' % (basename,))
-        tramp.wrappings.append('    %s.append(___W_Object(%s[___i]))' % (
+        tramp.wrappings.append('    %s.append(___W_Object(%s[0]))' % (
             argname, basename))

The thing surprised me is the compilation after the patch goes fine
and (!!) the module works correctly. asctime() does it's dirty job.

So, why does it work?


More information about the Pypy-dev mailing list