cppyy icon indicating copy to clipboard operation
cppyy copied to clipboard

Persistence issue with global vectors?

Open Alex-EEE opened this issue 2 years ago • 2 comments

I had an issue where reading from the array from a vector declared globally, but inside a namespace, triggered a seg fault when trying to read the pointer returned by zi.data(). However, replacing the vector with a float array removed the issue. (Moreover, compiling the code manually also had no seg fault). I'm wondering if these headers are being processed correctly by cling?

This seg faults, only in cppyy, not when compiled manually:

static const std::vector<float> sos = {
    0.000309f, 0.000617f, 0.000309f, 1.000000f, -0.743836f, 0.149371f,
// ...
 };

static const std::vector<float> zi = {
    0.002736f, -0.000146f, 0.021946f, -0.002831f, 0.135929f, -0.042818f, 0.635863f, -0.438359f,
    -0.796782f, 0.796782f, -0.000000f, 0.000000f, -0.000000f, 0.000000f, -0.000000f, 0.000000 };
}
}

float bp_and_scale(float* sig, size_t sig_len, float scale) {

    // sos band pass filter
    ei::signal::sosfilt bpf(fs50::bpf::sos.data(), fs50::bpf::zi.data(), 8);

Changing to this allows cppyy to function again:

static const float sos[] = {
    0.000309f, 0.000617f, 0.000309f, 1.000000f, -0.743836f, 0.149371f,
// ....
 };

static const float zi[] = {
    0.002736f, -0.000146f, 0.021946f, -0.002831f, 0.135929f, -0.042818f, 0.635863f, -0.438359f,
    -0.796782f, 0.796782f, -0.000000f, 0.000000f, -0.000000f, 0.000000f, -0.000000f, 0.000000 };
}
}

float bp_and_scale(float* sig, size_t sig_len, float scale) {
    // sos band pass filter
    ei::signal::sosfilt bpf(fs50::bpf::sos, fs50::bpf::zi, 8);
    return 0;

Alex-EEE avatar Jun 07 '23 21:06 Alex-EEE

This is the same I saw in https://github.com/wlav/cppyy/issues/226#issuecomment-2041499781

I'm pretty sure it is related to static initialization issues. Could be some crazy hidden template missing, like for the string bug in https://github.com/wlav/cppyy/issues/175#issuecomment-1811035639

Gabrielcarvfer avatar Apr 19 '24 09:04 Gabrielcarvfer

The above is one of those that works fine for me / can't reproduce. Maybe indeed very specific version combos of gcc / linux.

wlav avatar Apr 19 '24 16:04 wlav