Cgocall entersyscall panics SIGSEGV on c function return with ** struct

whats the issue here? don’t know how to get into more detail

when I execute priceEffect (see c header below) in go
var cOut **C.PriceEffect
cOut = C.newPriceEffect()

go sigsegvs. when I remove cOut frm header and go call, it works fine. In my code I don’t even change cOut at all. I only create a new one in C, pass pointer to c/rust and then I ideally want to modify it (which I dont do in this thread for simplicity) in c/rust. so I assume go has some problems with the parameter type. how can I fix this?

this is the c header:
typedef struct {
int status;
double mean;
double d_mean;
double median;
double d_median;
double std_dev;
double d_std_dev;
double variance;
double d_variance;
double *effects;
unsigned int effects_len;
} PriceEffect;
int priceEffect(char *query, char *conn_str, int tls, int time_scope, int precise, PriceEffect **outs);
PriceEffect **newPriceEffect();
void destroyPriceEffect(PriceEffect **effect);

err (occurs when the function returns)

bot_1 | fatal error: unexpected signal during runtime execution
bot_1 | [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7fbc6fc294f4]
bot_1 |
bot_1 | runtime stack:
bot_1 | runtime.throw(0xbf1403, 0x2a)
bot_1 | /usr/lib/go/src/runtime/panic.go:605 +0x95
bot_1 | runtime.sigpanic()
bot_1 | /usr/lib/go/src/runtime/signal_unix.go:351 +0x2b8
bot_1 |
bot_1 | goroutine 71 [syscall, locked to thread]:
bot_1 | runtime.cgocall(0xa3e0f0, 0xc4202d9ba8, 0xc4201a0100)
bot_1 | /usr/lib/go/src/runtime/cgocall.go:132 +0xe4 fp=0xc4202d9b60 sp=0xc4202d9b20 pc=0x4038a4
bot_1 | bot/api._Cfunc_priceEffect(0x7fbc60000a20, 0x7fbc60000ad0, 0x500000000, 0x0, 0x7fbc600008c0, 0x0)

can close this. its some esoteric rust/c/go ■■■■, I don’t know who’s the culprit. htink its too complicated to think about.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.