ss3681755
NIFs Segmentation Fault without creating erl_crash.dump however code is working fine when ran normallly without NIFs.
I am working on integrating a Third Party C++ api in Elixir using NIFs. Here is the code sample that is shared and is working fine when I run it like a binary.
class Client: public AbstractThirdPartyClient {
public:
int ConnectionSuccess(int status) {
return status;
}
};
Client *client = new Client;
ThirdPartyControl *control;
int main () {
control = new ThirdPartyControl(client, "fully/qualified/path/to/some/config/file");
return 0;
}
But when I am trying to introduce NIFs converting to a dynamic lib (.so) file, NIF loading fails with seg fault and since ThirdPartyControl class implementation is hidden from me, I am having a hard time figuring out why this is failing.
typedef struct {
Client *client;
ThirdPartyControl *control;
} node;
ERL_NIF_TERM setup(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
return enif_make_atom(env, "ok");
}
static ErlNifFunc nif_funcs[] = {{"setup", 0, setup}};
int load(ErlNifEnv* caller_env, void** priv_data, ERL_NIF_TERM load_info) {
try {
node *r = (node *)malloc(sizeof(node));
r->client = new Client;
/* this line causes seg fault don't know why */
r->control = new ThirdPartyControl(r->client, (char *)NULL, (char *)"fully/qualified/path/to/some/config/file");
*priv_data = r;
} catch (exception e) {
return 1;
}
return 0;
}
int upgrade(ErlNifEnv* caller_env, void** priv_data, void **old_priv_data, ERL_NIF_TERM load_info) {
return 0;
}
ERL_NIF_INIT(Elixir.Vendor.Middleware, nif_funcs, load, NULL, upgrade, NULL);
Popular in Questions
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
Hi there,
I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
Hey guys.
I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
What is most correct way to open, read and parse JSON file with poison?
For example if we have example.json file in root of some projec...
New
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
Other popular topics
Hello, I get Persian date from my client and convert it to normal calendar like this:
def jalali_string_to_miladi_english_number(persi...
New
Credo is smart enough to check for (something like) this:
assert length(the_list) == 0
with this response:
Checking if an enum is empt...
New
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set?
Thanks.
New
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
I would like to know what is the best IDE for elixir development?
New
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch.
This project took far...
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Hi,
I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New







