2

Recently i have been working on programming python module with C extension. ( python2.7, gcc 4.1.2) Once done and testing. i found following bus error.

does anybody know why?

p.s before i got this error. i fixed 'return Py_False related error' described in

Application gives segmentation fault randomly in python extension functions in c++

Core was generated by python2.7 app.py --debug=False --multi_slaves=True

Program terminated with signal 7, Bus error.
#0 0x0000003d22272cf1 in _int_malloc () from /lib64/libc.so.6
(gdb) where
#0 0x0000003d22272cf1 in _int_malloc () from /lib64/libc.so.6
#1 0x0000003d22274e4e in malloc () from /lib64/libc.so.6
#2 0x00000000004d3069 in _PyObject_GC_Malloc (basicsize=<value optimized out>) at Modules/gcmodule.c:1445
#3 0x000000000046408c in PyType_GenericAlloc (type=0x768360, nitems=0) at Objects/typeobject.c:753
#4 0x00000000004477ec in dict_new (type=0x3d225539e0, args=, kwds=0x7fff8dcb4eb0) at Objects/dictobject.c:2301
#5 0x00000000004661c3 in type_call (type=0x3d225539e0, args=0x2b3e5a521050, kwds=0x2239bca0) at Objects/typeobject.c:721
#6 0x00000000004189cd in PyObject_Call (func=0x768360, arg=0x2b3e5a521050, kw=0x2239bca0) at Objects/abstract.c:2529

c extension code looks like this

static PyObject* analyze( PyObject *self, PyObject *args )
{
    int     ret;
    char*   in;

    // global variables : void* obj, char* outbuf, int outbuf_size;
    if (PyArg_ParseTuple(args, "s", &in)){
        ret = process(obj, in, outbuf, outbuf_size);
        if ( ret == SUCCESS ) {
            PyObject* py_out = PyString_FromString(outbuf);
            return py_out;
        } else {
            Py_INCREF(Py_False);
            return Py_False;
        }
    } else {
        Py_INCREF(Py_False);
        return Py_False;
    }
}

~

8
  • 1
    That very much looks like your module messes something up. Can you post the complete source code of a module that exhibits the problem? Commented Apr 17, 2013 at 7:41
  • c extension module, first initialize void* obj, and then call analyze(obj, in, ...). problem appears here. Commented Apr 17, 2013 at 9:10
  • Although the problem appears in analyze, the actual error is most likely somewhere completely different (say, a double free). Can you post complete code that still exhibits the problem? Also, the example code is obviously invalid - outbuf is never declared. Commented Apr 17, 2013 at 9:14
  • I would think the usual thing to do would be to compile with --debug=True and run your code through a debugger; that should at least give you the exact point where things crash. Commented Apr 17, 2013 at 9:18
  • @phihag outbuf is global variable. and process() is very long c code. so it's not proper to post here. sorry ^^;; Commented Apr 17, 2013 at 9:26

1 Answer 1

0

FWIW I was getting a Bus error from a python program. Turned out to be related to it allocating shared memory. I was running it in a docker container and had to set docker run ... --shm_size=1g as described in: https://goblincoding.com/2018/02/19/docker-bus-error-no-space-left-on-device/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.