From 41c0850f237934bef429560bf76dc22c368127bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn-Egil=20Dahlberg?= Date: Thu, 12 Jan 2012 19:25:18 +0100 Subject: [PATCH] erts: Add some erlang:process_flag/2 functionality --- erts/emulator/beam/bif.c | 51 ++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/erts/emulator/beam/bif.c b/erts/emulator/beam/bif.c index 4d8347a9094d..cff903512c3b 100644 --- a/erts/emulator/beam/bif.c +++ b/erts/emulator/beam/bif.c @@ -868,7 +868,7 @@ BIF_RETTYPE spawn_opt_1(BIF_ALIST_1) if (is_tuple(limit)) { tpl = tuple_val(limit); - if (*tp2 != make_arityval(2)) + if (*tpl != make_arityval(2)) goto error; /* reuse vars */ @@ -1636,6 +1636,9 @@ BIF_RETTYPE process_flag_2(BIF_ALIST_2) BIF_RET(old_value); } else if (BIF_ARG_1 == am_limits) { + /* lots here can be refactored with spawn_opt + * this should be broken out + */ if (is_tuple(BIF_ARG_2)) { Eterm *tp = tuple_val(BIF_ARG_2); if (arityval(tp[0]) == 2) { @@ -1644,16 +1647,50 @@ BIF_RETTYPE process_flag_2(BIF_ALIST_2) old_value = make_small(LIMIT_HEAP_SIZE(BIF_P)); LIMIT_HEAP_SIZE(BIF_P) = i; BIF_RET(old_value); - } else { - goto error; } } } else if (is_list(BIF_ARG_2)) { - /* will this be the real one? */ - goto error; - } else { - goto error; + + Eterm limits = BIF_ARG_2; + Eterm limit, arg, limitval; + Eterm *tpl; + + while (is_list(limits)) { + limit = CAR(list_val(limits)); + if (is_tuple(limit)) { + tpl = tuple_val(limit); + + if (*tpl != make_arityval(2)) + goto error; + + arg = tpl[1]; + limitval = tpl[2]; + + if (arg == am_heap_size && is_small(limitval)) { + Sint heap_size = signed_val(limitval); + + if (heap_size < 0) { + goto error; + } else { + old_value = make_small(LIMIT_HEAP_SIZE(BIF_P)); + LIMIT_HEAP_SIZE(BIF_P) = heap_size; + BIF_RET(old_value); + } + } else /* not heap_size */ + goto error; + } else /* not a is_tuple */ + goto error; + + limits = CDR(list_val(limits)); + } + + /* is proper list + if (is_not_nil(limits)) { + goto error; + } + */ } + goto error; } else if (BIF_ARG_1 == am_min_bin_vheap_size) { Sint i; if (!is_small(BIF_ARG_2)) {