segmentation fault when executing PyImport_ImportModule("sys")

  • Thread starter Dietrich Bollmann
  • Start date
D

Dietrich Bollmann

Hi,

Since some time I get the following segmentation fault in an
application which used to work fine until recently.

I made a backtrace but couldn't find the reason for the segmentaion
fault until now.

In the hope that somebody might have encountered a similar problem or
does understand the backtrace better than me and can explain it I posted
the backtrace here...

At the end of the backtrace I appended some more context concerning the
involved code.

Thanks for your help :)

Dietrich


Here comes the backtrace:

----
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb046ab90 (LWP 9854)]
threadstate_getframe (self=0xb7e8a889) at ../Python/pystate.c:154
154 ../Python/pystate.c: No such file or directory.
in ../Python/pystate.c
(gdb) bt full
#0 threadstate_getframe (self=0xb7e8a889) at ../Python/pystate.c:154
No locals.
#1 0xb7e8a897 in PyEval_GetGlobals () at ../Python/ceval.c:3340
current_frame = <value optimized out>
#2 0xb7eaeb67 in PyImport_Import (module_name=0xb7119480)
at ../Python/import.c:2400
globals = <value optimized out>
import = <value optimized out>
builtins = <value optimized out>
r = <value optimized out>
silly_list = (PyObject *) 0xb738fb0c
builtins_str = (PyObject *) 0xb7391c50
import_str = (PyObject *) 0xb7391fc0
#3 0xb7eaede5 in PyImport_ImportModule (name=0x901504b "sys")
at ../Python/import.c:1903
pname = (PyObject *) 0xb7119480
result = (PyObject *) 0x0
#4 0x08996c9f in py_stdouterr_buffer_new () at
source/blender/commandport/blender/src/py_stdouterr_buffer.c:75
buffer = (py_stdouterr_buffer) 0x94fd428
func_StringIO = (PyObject *) 0x9152a48
args_StringIO = (PyObject *) 0x0
#5 0x089967e1 in bcp_blender_handler_new () at
source/blender/commandport/blender/src/bcp_blender.c:130
handler = (bcp_blender_handler) 0x9810420
#6 0x08998db3 in bcp_handle_client (client_socket=8) at
source/blender/commandport/blender/src/bcp_handle_client.c:73
debug = 0
debug3 = 0
debug4 = 0
message_handler = (message_handler) 0x97eba10
blender_handler = (bcp_blender_handler) 0x0
command = 0x0
result = 0x9152a48 "%G�%@016\025\th%G��%@@\\%G�%@022v#\b
\"v#\b%G��%@v#\bRv#\bbv#\brv#\b\202v#\b\222v#\b%G�%@v#\b%G�%@v#\b`
\032%G�%@020\026%G���%@#\b%G�%@#\b\002w#\b\022w#
\b\"w#\b2w#\bBw#\bRw#\bbw#\brw#\b\202w#\b\222w#\b%G�%@w#\b%G�%@w#
\bp#p%G��%@#\b"
package_number = -1216545219
#7 0x08998d60 in bcp_client_thread (args=0x0) at
source/blender/commandport/blender/src/bcp_server.c:164
targs = (struct bcp_client_thread_args *) 0x0
client_socket = 8
client_thread = 2957421456
#8 0xb76b04fb in start_thread () from /lib/i686/cmov/libpthread.so.0
No symbol table info available.
#9 0xb77c2d7e in clone () from /lib/i686/cmov/libc.so.6
No symbol table info available.
(gdb) q
The program is running. Exit anyway? (y or n) y
---

and here some informations about its context:

Python-2.4.4/Python/ceval.c

line 3340: PyFrameObject *current_frame = PyEval_GetFrame();

context:
---
PyObject *
PyEval_GetGlobals(void)
{
PyFrameObject *current_frame = PyEval_GetFrame();
if (current_frame == NULL)
return NULL;
else
return current_frame->f_globals;
}
---

Python-2.4.4/Python/pystate.c

lign 154: {

context:
---
/* Default implementation for _PyThreadState_GetFrame */
static struct _frame *
threadstate_getframe(PyThreadState *self)
{
return self->frame;
}
---

Python-2.4.4/Python/import.c
lign 2400: globals = PyEval_GetGlobals();

context:
---
PyObject *
PyImport_Import(PyObject *module_name)
{
...
/* Get the builtins from current globals */
globals = PyEval_GetGlobals();
if (globals != NULL) {
Py_INCREF(globals);
builtins = PyObject_GetItem(globals, builtins_str);
if (builtins == NULL)
goto err;
}
...
}
---

Python-2.4.4/Python/import.c
lign 1903: result = PyImport_Import(pname);

context:
---
PyObject *
PyImport_ImportModule(char *name)
{
PyObject *pname;
PyObject *result;

pname = PyString_FromString(name);
if (pname == NULL)
return NULL;
result = PyImport_Import(pname);
Py_DECREF(pname);
return result;
}
---

source/blender/commandport/blender/src/py_stdouterr_buffer.c
lign 75: buffer->mod_sys = PyImport_ImportModule("sys");

context:
---
/**
Make a new python io buffer.
*/
py_stdouterr_buffer py_stdouterr_buffer_new()
{
py_stdouterr_buffer buffer;
buffer = (py_stdouterr_buffer)
malloc(sizeof(py_stdouterr_buffer_struct));

if (buffer == NULL) {
fprintf(stderr, "Couldn't allocate memory for new py_stdouterr_buffer!
\n");
exit(ERROR_MEMORY);
}

buffer->mod_sys = PyImport_ImportModule("sys");
buffer->mod_cStringIO = PyImport_ImportModule("cStringIO");

/* store stdout and stderr */
buffer->stdout_obj = PyObject_GetAttrString(buffer->mod_sys, "stdout");
buffer->stderr_obj = PyObject_GetAttrString(buffer->mod_sys, "stderr");

/* make new string buffer for stdout and stderr */
PyObject *func_StringIO, *args_StringIO;
func_StringIO = PyObject_GetAttrString(buffer->mod_cStringIO,
"StringIO");
args_StringIO = Py_BuildValue("()");
buffer->outbuf_obj = PyEval_CallObject(func_StringIO,
args_StringIO);
buffer->errbuf_obj = PyEval_CallObject(func_StringIO,
args_StringIO);
Py_DECREF(args_StringIO);
Py_DECREF(func_StringIO);

return buffer;
}
---
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top