sheldonrobinson / shedskin

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

__wrap causes core dump instead of 'index out of range' on empty list #204

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Not restricted to a cygwin-32 installation on Win7/64, but that's my setup with 
shedskin-0.9.4.exe.
To work around compilation issues just
$ touch execinfo.h
You will loose debugging possibilities but get it to work.

$ cat > wrap_check.py << __EOF__
l = []
print l[-1]
__EOF__
$ shedskin wrap_check.py
$ make
$ ./wrap_check
Segmentation fault (core dumped)

This is expected:
$ ./wrap_check.exe
IndexError: index out of range

The bug is easy to fix in site-packages/shedskin/lib/builtin.hpp:__wrap
 template<class T> static inline int __wrap(T a, int i) {
 #ifndef __SS_NOWRAP
-    if(i<0) return len(a)+i;
+    if(i<0) i += len(a);
 #endif
 #ifndef __SS_NOBOUNDS
         if(i<0 || i>= len(a))
             __throw_index_out_of_range();
 #endif
     return i;
 }

This way the bounds checking is still done.

Original issue reported on code.google.com by jsv...@gmail.com on 3 Sep 2014 at 8:35

GoogleCodeExporter commented 9 years ago
good catch, thanks a lot :) 

please let me know under which name to commit your patch. 

Original comment by mark.duf...@gmail.com on 4 Sep 2014 at 1:52

GoogleCodeExporter commented 9 years ago
You're welcome.
Please use 'Joerg Stippa <j.stippa@freenet.de>'.

And if I can be of any help for getting shedskin to work under cygwin let me 
know.
It just doesn't work out of the box :)

Original comment by jsv...@gmail.com on 4 Sep 2014 at 5:28

GoogleCodeExporter commented 9 years ago
okay committed. thanks again! I hope to do another (very minor) release in a 
few weeks.

please note that in issue 193, another user is working on running shedskin 
under cygwin. if you'd be interested perhaps you could join forces..?

Original comment by mark.duf...@gmail.com on 6 Sep 2014 at 7:20