Message107194
A segmentation error happens in Embedding Python.
condition
When I called four times of Py_Main in one process.
and When I used ctypes in the script.
A happening
segmentation error(core dumped)
[user@localhost debug]$
[user@localhost debug]$ ls -l
total 24
-rwxrwxrwx 1 user user 333 May 30 03:17 build.sh
-rwxrwxrwx 1 user user 385 Jun 6 23:27 ctypes_segmfault.c
-rwxrwxrwx 1 user user 14 Jun 6 23:25 import_ctypes.py
[user@localhost debug]$
[user@localhost debug]$
[user@localhost debug]$ ./build.sh
/usr/local/lib/libpython2.6.a(posixmodule.o): In function `posix_tmpnam':
/work/Python-2.6.5/./Modules/posixmodule.c:7207: warning: the use of `tmpnam_r' is dangerous, better use `mkstemp'
/usr/local/lib/libpython2.6.a(posixmodule.o): In function `posix_tempnam':
/work/Python-2.6.5/./Modules/posixmodule.c:7162: warning: the use of `tempnam' is dangerous, better use `mkstemp'
[user@localhost debug]$
[user@localhost debug]$
[user@localhost debug]$ ls -l
total 4212
-rwxrwxrwx 1 user user 333 May 30 03:17 build.sh
-rwxrwxr-x 1 user user 4256056 Jun 6 23:30 ctypes_segmfault
-rwxrwxrwx 1 user user 385 Jun 6 23:27 ctypes_segmfault.c
-rw-rw-r-- 1 user user 4664 Jun 6 23:30 ctypes_segmfault.o
-rwxrwxrwx 1 user user 14 Jun 6 23:25 import_ctypes.py
[user@localhost debug]$
[user@localhost debug]$
[user@localhost debug]$ ./ctypes_segmfault
----- 0 -----
----- 1 -----
----- 2 -----
----- 3 -----
Segmentation fault (core dumped)
[user@localhost debug]$
[user@localhost debug]$
[user@localhost debug]$ ls -l
total 5960
-rwxrwxrwx 1 user user 333 May 30 03:17 build.sh
-rw------- 1 user user 1933312 Jun 6 23:31 core.2981
-rwxrwxr-x 1 user user 4256056 Jun 6 23:30 ctypes_segmfault
-rwxrwxrwx 1 user user 385 Jun 6 23:27 ctypes_segmfault.c
-rw-rw-r-- 1 user user 4664 Jun 6 23:30 ctypes_segmfault.o
-rwxrwxrwx 1 user user 14 Jun 6 23:25 import_ctypes.py
[user@localhost debug]$
so I watched core with gdb.
[user@localhost debug]$ gdb ctypes_segmfault core.2981
GNU gdb (GDB) Red Hat Enterprise Linux (7.0.1-23.el5_5.1)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/user/debug/ctypes_segmfault...done.
warning: core file may not match specified executable file.
Reading symbols from /lib/libpthread.so.0...(no debugging symbols found)...done.
Loaded symbols for /lib/libpthread.so.0
Reading symbols from /lib/libdl.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib/libdl.so.2
Reading symbols from /lib/libutil.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib/libutil.so.1
Reading symbols from /lib/libm.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib/libm.so.6
Reading symbols from /lib/libc.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib/ld-linux.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib/ld-linux.so.2
Reading symbols from /usr/local/lib/python2.6/lib-dynload/_ctypes.so...done.
Loaded symbols for /usr/local/lib/python2.6/lib-dynload/_ctypes.so
Reading symbols from /usr/local/lib/python2.6/lib-dynload/_struct.so...done.
Loaded symbols for /usr/local/lib/python2.6/lib-dynload/_struct.so
Core was generated by `./ctypes_segmfault'.
Program terminated with signal 11, Segmentation fault.
#0 0x080a103a in type_dealloc (type=0x9f3180) at Objects/typeobject.c:2610
2610 _PyObject_GC_UNTRACK(type);
(gdb) bt
#0 0x080a103a in type_dealloc (type=0x9f3180) at Objects/typeobject.c:2610
#1 0x080888ef in dict_dealloc (mp=0xb7ef313c) at Objects/dictobject.c:911
#2 0x080888ef in dict_dealloc (mp=0xb7f4c02c) at Objects/dictobject.c:911
#3 0x080e7599 in _PyImport_Fini () at Python/import.c:240
#4 0x080f47cc in Py_Finalize () at Python/pythonrun.c:460
#5 0x08058183 in Py_Main (argc=1, argv=0xbfe5c6c8) at Modules/main.c:596
#6 0x080579d3 in main () at ./ctypes_segmfault.c:16
(gdb) quit
[user@localhost debug]$
fumm... I don't know about inside of Python Interpreter.
[user@localhost debug]$ cat ctypes_segmfault.c
#include <stdio.h>
#include <Python.h>
/* ulimit -c unlimited */
int main(void) {
char *argpy[] = { "python", "import_ctypes.py" };
printf("----- 0 -----\n");
Py_Main(2, argpy);
printf("----- 1 -----\n");
Py_Main(2, argpy);
printf("----- 2 -----\n");
Py_Main(2, argpy);
printf("----- 3 -----\n");
Py_Main(2, argpy);
printf("----- 4 -----\n");
return 0;
}
[user@localhost debug]$
[user@localhost debug]$ cat build.sh
#!/bin/sh
gcc -pthread -c -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 \
-Wall -Wstrict-prototypes -I/usr/local/include/python2.6/ \
-DPy_BUILD_CORE -o ctypes_segmfault.o ./ctypes_segmfault.c
gcc -pthread -Xlinker -export-dynamic -o ctypes_segmfault \
ctypes_segmfault.o \
-lpython2.6 -lpthread -ldl -lutil -lm
[user@localhost debug]$
[user@localhost debug]$ cat import_ctypes.py
import ctypes
[user@localhost debug]$ |
|
Date |
User |
Action |
Args |
2010-06-06 14:47:43 | tanaga | set | recipients:
+ tanaga, theller |
2010-06-06 14:47:43 | tanaga | set | messageid: <1275835663.33.0.520214000656.issue8917@psf.upfronthosting.co.za> |
2010-06-06 14:47:40 | tanaga | link | issue8917 messages |
2010-06-06 14:47:38 | tanaga | create | |
|