I have these 2 wrappers for the C++ vector class and I wrap both in CFFI the same way, and call them the same way but I'm getting unhandled memory fault errors when using my wrapper for the carraytovectorm, The only difference being, using the carraytovectorp as an example of all my other carraytovector type c wrappers that are written the same way, is that when I initialize the Point class to pass to the carraytovectorp I can do it like this:
Point* m, n, o; vector_Point* v = std_carrayTovectorp(m, 3);
and it works but when I attempt to do the same thing with carrayvectorm like so:
Mat* m, n, o; vector_Mat* v = std_carrayTovectorm(m, 3);
I get a segmentation fault error in C
This works in both though.
Point m, n, o; vector_Point* v = std_carrayTovectorp(&m, 3);
If you think this might be a bug too..I can forward any other info needed to debug..I just tried to keep this post light so it wouldn't seem daunting:)
vector_Mat* std_carrayTovectorm(Mat* a, size_t len) { vector<Mat>* v = new vector<Mat>; for(size_t i = 0; i < len; i++) v->push_back(a[i]); return v; } vector_Point* std_carrayTovectorp(Point* a, size_t len) { vector<Point>* v = new vector<Point>; for(size_t i = 0; i < len; i++) v->push_back(a[i]); return v; }
Joeish W joeish80829@yahoo.com writes:
I have these 2 wrappers for the C++ vector class and I wrap both in CFFI the same way, and call them the same way but I'm getting unhandled memory fault errors when using my wrapper for the carraytovectorm, The only difference being, using the carraytovectorp as an example of all my other carraytovector type c wrappers that are written the same way, is that when I initialize the Point class to pass to the carraytovectorp I can do it like this:
Point* m, n, o; vector_Point* v = std_carrayTovectorp(m, 3);
This is very odd, you define 3 variables, m, n and o. But they are of different type:
m - pointer to point n and o - are point
Secondly, you assume that they form a c-array of 3 elements. However you only defined 3 separate variables, not a c-array.
So the fact that it does not crash is luck. You ran out of luck in your second version.
Wim Oudshoorn.