From 3de93a0ec93bab8c7bae8f1e34d61ae260a21583 Mon Sep 17 00:00:00 2001
From: Kostis Sagonas <kostis@it.uu.se>
Date: Wed, 13 Feb 2013 09:07:48 +0100
Subject: Change the return value of hipe_bifs:remove_refs_from/1

In order to avoid an ummatched return warning in erts and make the code
more sane, the return value of the bif was changed from [] to 'ok'.
(Probably more hipe_bifs need such changes but they will have to wait.)

While at it, the code of various functions in hipe_unified_loader was
shortened by using lists:foreach/1 instead of explicit recursion.
---
 lib/kernel/src/hipe_unified_loader.erl | 25 ++++++++-----------------
 1 file changed, 8 insertions(+), 17 deletions(-)

(limited to 'lib/kernel')

diff --git a/lib/kernel/src/hipe_unified_loader.erl b/lib/kernel/src/hipe_unified_loader.erl
index 06d404905d..e676ca997d 100644
--- a/lib/kernel/src/hipe_unified_loader.erl
+++ b/lib/kernel/src/hipe_unified_loader.erl
@@ -218,7 +218,7 @@ load_common(Mod, Bin, Beam, OldReferencesToPatch) ->
       {MFAs,Addresses} = exports(ExportMap, CodeAddress),
       %% Remove references to old versions of the module.
       ReferencesToPatch = get_refs_from(MFAs, []),
-      remove_refs_from(MFAs),
+      ok = remove_refs_from(MFAs),
       %% Patch all dynamic references in the code.
       %%  Function calls, Atoms, Constants, System calls
       patch(Refs, CodeAddress, ConstMap2, Addresses, TrampolineMap),
@@ -802,7 +802,7 @@ patch_to_emu_step1(Mod) ->
       %% Find all call sites that call these MFAs. As a side-effect,
       %% create native stubs for any MFAs that are referred.
       ReferencesToPatch = get_refs_from(MFAs, []),
-      remove_refs_from(MFAs),
+      ok = remove_refs_from(MFAs),
       ReferencesToPatch;
     false ->
       %% The first time we load the module, no redirection needs to be done.
@@ -846,11 +846,8 @@ get_refs_from(MFAs, []) ->
   mark_referred_from(MFAs),
   MFAs.
 
-mark_referred_from([MFA|MFAs]) ->
-  hipe_bifs:mark_referred_from(MFA),
-  mark_referred_from(MFAs);
-mark_referred_from([]) ->
-  [].
+mark_referred_from(MFAs) ->
+  lists:foreach(fun(MFA) -> hipe_bifs:mark_referred_from(MFA) end, MFAs).
 
 %%--------------------------------------------------------------------
 %% Given a list of MFAs with referred_from references, update their
@@ -858,11 +855,8 @@ mark_referred_from([]) ->
 %%
 %% The {MFA,Refs} list must come from get_refs_from/2.
 %%
-redirect([MFA|Rest]) ->
-  hipe_bifs:redirect_referred_from(MFA),
-  redirect(Rest);
-redirect([]) ->
-  ok.
+redirect(MFAs) ->
+  lists:foreach(fun(MFA) -> hipe_bifs:redirect_referred_from(MFA) end, MFAs).
 
 %%--------------------------------------------------------------------
 %% Given a list of MFAs, remove all referred_from references having
@@ -874,11 +868,8 @@ redirect([]) ->
 %% list. The refers_to list is used here to find the CalleeMFAs whose
 %% referred_from lists should be updated.
 %%
-remove_refs_from([CallerMFA|CallerMFAs]) ->
-  hipe_bifs:remove_refs_from(CallerMFA),
-  remove_refs_from(CallerMFAs);
-remove_refs_from([]) ->
-  [].
+remove_refs_from(MFAs) ->
+  lists:foreach(fun(MFA) -> hipe_bifs:remove_refs_from(MFA) end, MFAs).
 
 %%--------------------------------------------------------------------
 
-- 
cgit v1.2.3


From d3048b6e6fa36979720253dc202355de46acc805 Mon Sep 17 00:00:00 2001
From: Kostis Sagonas <kostis@it.uu.se>
Date: Tue, 19 Feb 2013 10:18:12 +0100
Subject: Fixed test to allow for lists:foreach/2 call

---
 lib/kernel/test/code_SUITE.erl | 4 ++++
 1 file changed, 4 insertions(+)

(limited to 'lib/kernel')

diff --git a/lib/kernel/test/code_SUITE.erl b/lib/kernel/test/code_SUITE.erl
index 4c040f0a0e..d8dac7d3a6 100644
--- a/lib/kernel/test/code_SUITE.erl
+++ b/lib/kernel/test/code_SUITE.erl
@@ -822,6 +822,10 @@ check_funs({'$M_EXPR','$F_EXPR',2},
 check_funs({'$M_EXPR','$F_EXPR',1},
 	   [{lists,foreach,2},
 	    {hipe_unified_loader,patch_consts,3} | _]) -> 0;
+check_funs({'$M_EXPR','$F_EXPR',1},
+	   [{lists,foreach,2},
+	    {hipe_unified_loader,mark_referred_from,1},
+	    {hipe_unified_loader,get_refs_from,2}| _]) -> 0;
 check_funs({'$M_EXPR',warning_msg,2},
 	   [{code_server,finish_on_load_report,2} | _]) -> 0;
 %% This is cheating! /raimo
-- 
cgit v1.2.3