0

I have successfully executed the cmake and make command to build target in dsent of gem5 But it comes a segmentation fault as below when I execute import dsent

Python ver: 3.10

Segfault happened at: 0x557878f5cc15<PyLong_AsLongLong+21>: testb $Ox1,0xab(%rax)PC(Ox557878f5cc15)ok
source "$ox1" ok
destination "Oxab(%rax)"(Oxffffo603090703aa)not located in a known vMA region(needed writable region)!

and this is my only function using PyLong_AsLongLong()

static PyObject* dsent_computeLinkPower(PyObject *self, PyObject *arg) {

    uint64_t frequency = PyLong_AsLongLong(arg);

    // Read the arguments sent from the python script
    if (frequency == -1) {
        Py_RETURN_NONE;
    }

    // DSENT outputs
    map<string, double> outputs;
    params["Frequency"] = String(frequency);

    // Run DSENT
    DSENT::run(params, ms_model, outputs);

    // Store outputs
    PyObject *r = PyTuple_New(outputs.size());
    int index = 0;

    // Prepare the output.  The assumption is that all the output
    for (const auto &it : outputs) {
        PyObject *s = PyTuple_New(2);
        PyTuple_SetItem(s, 0, PyUnicode_FromString(it.first.c_str()));
        PyTuple_SetItem(s, 1, PyFloat_FromDouble(it.second));

        PyTuple_SetItem(r, index, s);
        index++;
    }

    return r;
}

I've modified some py3.x deprecated c extension API to the newest version, such as PyModule_Create(), PyUnicode_AsUTF8()

WITHER
  • 1
  • 1
  • What is the exact behavior ([\[SO\]: How to create a Minimal, Reproducible Example (reprex (mcve))](https://stackoverflow.com/help/minimal-reproducible-example))? There's not enough information there. You should add some *printf*s (or debug) in order to get the line where the crash occurs (might be somewhere else). Generally non *Python* stuff is placed inside a *Py\_BEGIN\_ALLOW\_THREADS* / *Py\_END\_ALLOW\_THREADS* pair (https://docs.python.org/3/c-api/init.html#thread-state-and-the-global-interpreter-lock). Do the same with your *DSENT*. – CristiFati May 05 '23 at 05:44

0 Answers0