Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERL-345: Cannot compile NIFs for modules with dots in name #3195

Closed
OTP-Maintainer opened this issue Jan 27, 2017 · 6 comments
Closed

ERL-345: Cannot compile NIFs for modules with dots in name #3195

OTP-Maintainer opened this issue Jan 27, 2017 · 6 comments
Assignees
Labels
bug Issue is reported as a bug help wanted Issue not worked on by OTP; help wanted from the community priority:low team:VM Assigned to OTP team VM

Comments

@OTP-Maintainer
Copy link

Original reporter: ukasiu
Affected version: Not Specified
Component: Not Specified
Migrated from: https://bugs.erlang.org/browse/ERL-345


I'm trying to compile NIF with {{STATIC_ERLANG_NIF}} to use in Elixir. {{ERL_NIF_INIT}} looks like this {{ERL_NIF_INIT(Elixir.FastCompare, nif_funcs, NULL, NULL, NULL, NULL)}} -- {{MODNAME}} contains dot. I'm getting this when trying to compile:

{noformat}
In file included from fast_compare.c:2:0:
fast_compare.c:20:20: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
 ERL_NIF_INIT(Elixir.FastCompare, nif_funcs, NULL, NULL, NULL, NULL)
                    ^
.../erts-8.2.1/include/erl_nif.h:264:51: note: in definition of macro 'ERL_NIF_INIT_DECL'
 #  define ERL_NIF_INIT_DECL(MODNAME) ErlNifEntry* MODNAME ## _nif_init(ERL_NIF_INIT_ARGS)
                                                   ^
fast_compare.c:20:1: note: in expansion of macro 'ERL_NIF_INIT'
 ERL_NIF_INIT(Elixir.FastCompare, nif_funcs, NULL, NULL, NULL, NULL)
 ^
fast_compare.c:20:20: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
 ERL_NIF_INIT(Elixir.FastCompare, nif_funcs, NULL, NULL, NULL, NULL)
                    ^
.../erts-8.2.1/include/erl_nif.h:264:51: note: in definition of macro 'ERL_NIF_INIT_DECL'
 #  define ERL_NIF_INIT_DECL(MODNAME) ErlNifEntry* MODNAME ## _nif_init(ERL_NIF_INIT_ARGS)
                                                   ^
fast_compare.c:20:1: note: in expansion of macro 'ERL_NIF_INIT'
 ERL_NIF_INIT(Elixir.FastCompare, nif_funcs, NULL, NULL, NULL, NULL)
 ^
{noformat}

@OTP-Maintainer
Copy link
Author

sverker said:

It uses the module name to form a C identifier for the init function
and C identifiers cannot contain dots.

A dynamic NIF module with dot in the name should work I think.


@OTP-Maintainer
Copy link
Author

ukasiu said:

Yep, but dynamic NIFs don't work on Android/arm7 -- I'm getting SEGFAULTs (which is probably another bug) on erlang:load_nif irrespectively to presence of `.so` file.

@OTP-Maintainer
Copy link
Author

sverker said:

I think the easiest solution to this would be a new ERL_NIF_INIT_X macro
that separates module name and C identifier.

@OTP-Maintainer
Copy link
Author

josevalim said:

This code works as expected and it defines Elixir.Markdown, with a dot: https://github.com/devinus/markdown/blob/master/src/markdown.c#L125

What am I missing?

@OTP-Maintainer
Copy link
Author

ukasiu said:

You're missing {{#define STATIC_ERLANG_NIF}}

@OTP-Maintainer OTP-Maintainer added bug Issue is reported as a bug help wanted Issue not worked on by OTP; help wanted from the community team:VM Assigned to OTP team VM priority:low labels Feb 10, 2021
@sverker
Copy link
Contributor

sverker commented Feb 11, 2022

Fix #5477 merged to master for OTP 25.0.

@sverker sverker closed this as completed Feb 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is reported as a bug help wanted Issue not worked on by OTP; help wanted from the community priority:low team:VM Assigned to OTP team VM
Projects
None yet
Development

No branches or pull requests

2 participants