From a945dd39d70db21ef624f0612a44f1eca946472b Mon Sep 17 00:00:00 2001 From: Simon MacMullen Date: Wed, 11 Jun 2014 15:39:25 +0100 Subject: Don't fail if asked to truncate a reference. And go to having a catch-all case. --- src/truncate.erl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/truncate.erl b/src/truncate.erl index 3ead6f38..b959d21e 100644 --- a/src/truncate.erl +++ b/src/truncate.erl @@ -102,17 +102,17 @@ term_limit(Thing, Max) -> term_size(B, M, _W) when is_bitstring(B) -> lim(M, size(B)); term_size(A, M, W) when is_atom(A) -> lim(M, 2 * W); term_size(N, M, W) when is_number(N) -> lim(M, 2 * W); -term_size(F, M, W) when is_function(F) -> lim(M, erts_debug:flat_size(F) * W); -term_size(P, M, W) when is_pid(P) -> lim(M, erts_debug:flat_size(P) * W); term_size(T, M, W) when is_tuple(T) -> tuple_term_size( T, M, 1, tuple_size(T), W); -term_size([], M, _W) -> +term_size([], M, _W) -> M; term_size([H|T], M, W) -> case term_size(H, M, W) of limit_exceeded -> limit_exceeded; M2 -> lim(term_size(T, M2, W), 2 * W) - end. + end; +term_size(X, M, W) -> + lim(M, erts_debug:flat_size(X) * W); lim(S, T) when is_number(S) andalso S > T -> S - T; lim(_, _) -> limit_exceeded. @@ -156,6 +156,8 @@ test_short_examples_exactly() -> P = spawn(fun() -> receive die -> ok end end), F([0, 0.0, <<1:1>>, F, P], [0, 0.0, <<1:1>>, F, P]), P ! die, + R = make_ref(), + F([R], [R]), ok. test_term_limit() -> -- cgit v1.2.1