ariovistus / pyd

Interoperability between Python and D
MIT License
158 stars 32 forks source link

RangeWrapper causing segfault on raspberry pi #73

Closed WebFreak001 closed 6 years ago

WebFreak001 commented 6 years ago
void main()
{
    writeln("A");
    py_init();
    writeln("B");
    module_init();
    writeln("C");

    PyEval_InitThreads();
}

when commenting out the init_rangewrapper function it seems to work, otherwise it segfaults:

[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1".
A

Program received signal SIGSEGV, Segmentation fault.
strlen () at ../sysdeps/arm/armv6/strlen.S:26
26  ../sysdeps/arm/armv6/strlen.S: No such file or directory.
(gdb) bt
#0  strlen () at ../sysdeps/arm/armv6/strlen.S:26
#1  0x76d71e28 in PyString_FromString () from /usr/lib/arm-linux-gnueabihf/libpython2.7.so.1.0
#2  0x76d02d44 in PyDict_GetItemString () from /usr/lib/arm-linux-gnueabihf/libpython2.7.so.1.0
#3  0x76d37dec in PyType_Ready () from /usr/lib/arm-linux-gnueabihf/libpython2.7.so.1.0
#4  0x0005bdc0 in pyd.class_wrap._wrap_class!(pyd.make_object.RangeWrapper, "RangeWrapper", "", "pyd", pyd.class_wrap.Def!(pyd.make_object.RangeWrapper.iter(), pyd.def.PyName!("__iter__").PyName).Def, pyd.class_wrap.Def!(pyd.make_object.RangeWrapper.next()).Def).wrap_class() () at /home/pi/.dub/packages/pyd-0.9.9/pyd/infrastructure/pyd/class_wrap.d:1565
#5  0x000523b4 in pyd.class_wrap.wrap_class!(pyd.make_object.RangeWrapper, pyd.def.ModuleName!("pyd").ModuleName, pyd.class_wrap.Def!(pyd.make_object.RangeWrapper.iter(), pyd.def.PyName!("__iter__").PyName).Def, pyd.class_wrap.Def!(pyd.make_object.RangeWrapper.next()).Def).wrap_class() () at /home/pi/.dub/packages/pyd-0.9.9/pyd/infrastructure/pyd/class_wrap.d:1476
#6  0x00052388 in pyd.make_object.init_rangewrapper().__lambda2() () at /home/pi/.dub/packages/pyd-0.9.9/pyd/infrastructure/pyd/make_object.d:77
#7  0x0005b7cc in pyd.def.doActions(pyd.def.PyInitOrdering) (which=pyd.def.PyInitOrdering.After) at /home/pi/.dub/packages/pyd-0.9.9/pyd/infrastructure/pyd/def.d:395
#8  0x0005b6d8 in pyd.def.py_init() () at /home/pi/.dub/packages/pyd-0.9.9/pyd/infrastructure/pyd/def.d:287
#9  0x0005e398 in D main () at /home/pi/components/simple-python/source/app.d:127

it crashes on py_init();

ariovistus commented 6 years ago

I have never tried using pyd on a pi. What compiler are you using?

WebFreak001 commented 6 years ago

ldc 1.6.0 (the arm release there)

I tried the ldc 1.1.1 deb package before which also had the same issue

ariovistus commented 6 years ago

which os?

WebFreak001 commented 6 years ago

Raspbian Stretch Lite from raspberry pi site on rpi 3 model B

ariovistus commented 6 years ago

don't call module_init. that's for python extensions (shared libraries)

WebFreak001 commented 6 years ago

nvm that comment, but well that still doesn't fix it

ariovistus commented 6 years ago

initial diagnosis: d thinks PyTypeObject.tp_flags' offset is 88, and c thinks it is 84. both agree on the previous field, tp_as_buffer, offset=80. d thinks tp_as_buffer's size is 4. A naive attempt at a reduced case didn't capture above behavior, which makes me suspect compiler bug. But it could be some linker configuration.

WebFreak001 commented 6 years ago

I noticed that on rpi 64 bit compilation still uses 32 bit size_t

ariovistus commented 6 years ago

filed ldc-developers/ldc#2456

ariovistus commented 6 years ago

@WebFreak001 try the raspibug branch. I have more environments to validate before it goes into master, but it should work for raspi.

WebFreak001 commented 6 years ago

yep that fixed it now, thanks

WebFreak001 commented 6 years ago

can you merge your change (I made a PR for you to easily do that) and release a new version?