[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Segfault from call through a function pointer in assert_int_equal()


Hi all,
I find I get a segfault in the following code:
    assert_int_equal(0, run_fft(dbl_data, cplx_result, sample_count));

Separating the function call from the macro resolves this. The following code works OK.
    int i=run_fft(dbl_data, cplx_result, sample_count);
    assert_int_equal(0, i);

run_fft is a function pointer and is defined as
int (*run_fft)(double* in, fftw_complex* out, int count) = production_run_fft;
in a C file so it has C linkage. The macro is in a C++ file but the declaration for run_fft is in an 'Extern "C"' block. I have also been careful to define the two functions assigned to run_fft with C linkage.

Also, before I made run_fft a function pointer it was a normal function with C linkage and the original code listed above (function in the macro) ran w/out problems. I'm using a mock for run_fft to support unit testing of run_fft.

It seems to me that changing from a function to calling through a pointer has caused the problem. C makes these appear the same but I suppose they are enough different to cause a problem. Is this something I should reasonable expect to work?

I can see two work arounds:

1)      Move the call thorough function pointer outside the macro as above (tested and seems to work.)

2)      Provide a local function that would then call through the function pointer. (Expected to work.)

Suggestions for a better strategy?

Thanks!
hank
________________________________
NOTICE OF CONFIDENTIALITY:
This message may contain information that is considered confidential and which may be prohibited from disclosure under applicable law or by contractual agreement. The information is intended solely for the use of the individual or entity named above. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or use of the information contained in or attached to this message is strictly prohibited. If you have received this email transmission in error, please notify the sender by replying to this email and then delete it from your system.

Follow-Ups:
Re: Segfault from call through a function pointer in assert_int_equal()Lukas Slebodnik <lslebodn@xxxxxxxxxx>