wlav / cppyy

Other
387 stars 39 forks source link

Persistence issue with global vectors? #166

Open Alex-EEE opened 1 year ago

Alex-EEE commented 1 year ago

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;
Gabrielcarvfer commented 2 months ago

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

wlav commented 2 months ago

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