Skip to content

Commit

Permalink
Disable native code if on_load is used
Browse files Browse the repository at this point in the history
The on_load functionality does not work yet (will cause a crash)
if a module has been native-compiled. Fix it by disabling
native-code compilation if a module has an on_load attribute.
  • Loading branch information
bjorng committed Mar 15, 2010
1 parent 97aa2da commit 3befa76
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/compiler/src/compile.erl
Expand Up @@ -1043,9 +1043,16 @@ beam_asm(#compile{ifile=File,code=Code0,abstract_code=Abst,options=Opts0}=St) ->
(Other) -> Other
end, Opts0),
Opts2 = [O || O <- Opts1, is_informative_option(O)],
case beam_asm:module(Code0, Abst, Source, Opts2) of
{ok,Code} -> {ok,St#compile{code=Code,abstract_code=[]}}
end.

%% Turn off native code generation if on_load is used.
{_Mod,_Exp,Attr,_Asm,_NumLabels} = Code0,
NewOpts = case proplists:get_value(on_load, Attr) of
undefined -> Opts0;
[{_,_}] -> Opts0 -- [native]
end,

{ok,Code} = beam_asm:module(Code0, Abst, Source, Opts2),
{ok,St#compile{code=Code,abstract_code=[],options=NewOpts}}.

test_native(#compile{options=Opts}) ->
%% This test is done late, in case some other option has turned off native.
Expand Down

0 comments on commit 3befa76

Please sign in to comment.