0

When my exe exiting after python script finish,I got a error point to crt0dat.c enter image description here The call stack like this... enter image description here Are there some error in my c++ code or in the python code?

the c++ code like this:

void PythonCall::call(std::vector<double>& s,std::vector<double>& b,std::vector<double>& t,std::vector<double>& y)
{

    PyObject* args = PyTuple_New(2);
    PyObject* tPyList = convert2PythonList(t);
    PyObject* yPyList = convert2PythonList(y);
    PyTuple_SetItem(args,0,tPyList);
    PyTuple_SetItem(args,1,yPyList);

    PyObject* r = PyObject_CallObject(func,args);

    PyObject* item;


    PyObject* iter = PyObject_GetIter(r);
    /*{
    PyObject *errtype, *errvalue, *traceback;
    PyErr_Fetch(&errtype, &errvalue, &traceback);
    PyObject *s = PyObject_Str(errvalue);
    char *errstr = PyString_AsString(s);
    std::cout << "Python Error: " << errstr; 
    }*/


    item = PyIter_Next(iter);
    int i = 0;
    PyObject* iter2 = PyObject_GetIter(item);
    PyObject* item2;
    while (item2 = PyIter_Next(iter2))
    {
        s[i] = PyFloat_AsDouble(item2);
        Py_XDECREF(item2);
        i++;
    }
    Py_XDECREF(item);
    //Py_XDECREF(iter2);

    item = PyIter_Next(iter);
    i = 0;
    iter2 = PyObject_GetIter(item);
    while (item2 = PyIter_Next(iter2))
    {
        b[i] = PyFloat_AsDouble(item2);
        Py_XDECREF(item2);
        i++;
    }
    Py_XDECREF(item);
    //Py_XDECREF(iter2);

    //Py_XDECREF(iter);
    Py_XDECREF(args);
    Py_XDECREF(r);
    Py_XDECREF(item);
    Py_XDECREF(tPyList);
    Py_XDECREF(yPyList);
    //std::cout << "done" << std::endl;
}

and the python code:

def get_slope_baseLine(tl,xl):
    slopes = get_slope2(tl,xl)
    baselines = get_leakTime(tl,slopes)
    return slopes,baselines

sorry about my poor English...

8
  • 7
    Can you post any code? It's hard to debug code that is invisible. Commented May 3, 2012 at 3:21
  • 2
    How do you expect us to know that if you're not giving us your C++, nor your python code? Commented May 3, 2012 at 3:25
  • 1
    doexit() is likely being called because the program has terminated due to an access violation or some other termination condition. What that is, depends entirely on what either the C++ or Python code is doing. I second the first two comments - there's no way to know what is happening just by looking at the fact that the program terminated. Commented May 3, 2012 at 3:26
  • yes ,without any error it does not occur Commented May 3, 2012 at 4:00
  • Hello @wtm, welcome to StackOverflow. :) Hope you're not turned off by the downvotes and flippant responses, but although you may feel you've provided a good screenshot that indicates the problem...we'd really need a lot more to figure out what's going on. You can edit your question with the "edit" button to add more information about the context and code, without which we can't help you. If you're new to seeking help on the internet, many people share this link as a good way of "helping us help you" sscce.org Commented May 3, 2012 at 4:36

1 Answer 1

3

Apparently you're intending to iterate over two lists and decrement the ref counts of their elements, but you forget to reset iter so you're not iterating over the second list.

PyObject* iter = PyObject_GetIter(r);

item = PyIter_Next(iter);
int i = 0;
PyObject* iter2 = PyObject_GetIter(item);
PyObject* item2;
while (item2 = PyIter_Next(iter2))
{
    s[i] = PyFloat_AsDouble(item2);
    Py_XDECREF(item2);
    i++;
}
Py_XDECREF(item);

// ! Here you probably intended another call to PyObject_GetIter
item = PyIter_Next(iter);
i = 0;
iter2 = PyObject_GetIter(item);
while (item2 = PyIter_Next(iter2))
{
    b[i] = PyFloat_AsDouble(item2);
    Py_XDECREF(item2);
    i++;
}
Py_XDECREF(item);

The crash may however be due to other reasons (it depends on the documented behavior of the functions you're using).

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

3 Comments

Thanks a lot,I found the reason.I do this Py_XDECREF(item) three times....but I just have tow lists
@wtm If your problem is solved by the information someone gives you, make sure you "accept" the answer...that's the etiquette on StackOverflow...
@wtm Nice all depends on who you ask. Your question was poorly formed, but I antagonized Mr. Alf (who is quite experienced and from whose answers I regularly learn things) to introduce a balance I think needs to be maintained. Good cop, bad cop...? :)

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.