I’m trying to pass an array of strings from a DPI function into SystemVerilog in Questa. I have created a simple testcase to experiment with. I can successfully assign string literals to the pointers returned by svGetArrElemPtr1, but if I try to strcpy to them, I get segfaults (see commented lines in the C code). Any suggestions on the correct way to do this?
C++ Code:
#include <iostream>
#include <svdpi.h>
#include <string>
using namespace std;
extern "C" void strtest(
svOpenArrayHandle a // String Array Output
) {
*(char **)svGetArrElemPtr1(a,0) = "Hello";
*(char **)svGetArrElemPtr1(a,1) = "out";
*(char **)svGetArrElemPtr1(a,2) = "there";
// const char *mystr = "there";
// strcpy(*(char **)svGetArrElemPtr1(a,count), mystr);
}
SystemVerilog Code:
module strtest_tb;
import "DPI-C" function void strtest(
output string outbuf[]
);
string str_out[5];
initial begin
strtest(str_out);
for (int i=0; i<3; i++) begin
$display("OUTPUT STRING[%d]:%s", i,str_out[i]);
end
$stop;
end
endmodule