Re: Bit string generators, unsized binaries, modules and the REPL

Björn Gustavsson <[email protected]>
Newsgroups gmane.comp.lang.erlang.patches,gmane.comp.lang.erlang.bugs
Message-ID <CA+yh78TE3Yx+do_ynrJMBQQcwLUPjGvYv210P+bQpeVPNweicg@mail.gmail.com>
On Sun, Mar 31, 2013 at 4:22 PM, Anthony Ramine <[email protected]> wrote:

>
> This patch implements this new error and simplifies how v3_core works with
> forbidden unsized tail segments in patterns of bit string generators.
>
>         git fetch https://github.com/nox/otp illegal-bitstring-gen-pattern
>
>
> https://github.com/nox/otp/compare/erlang:maint...illegal-bitstring-gen-pattern
>
> https://github.com/nox/otp/compare/erlang:maint...illegal-bitstring-gen-pattern.patch


There is a major and a minor issue.

The major issue is that the test suites bs_bincomp_SUITE.erl
(compiler application) and erl_eval_SUITE.erl (stdlib application)
no longer compiles.

The minor issue is that erl_eval and eval_bits have assertions
to reject bad inputs in case the abstract code has not been
verified by erl_lint. The assertion can be written like this to
reject unsized tails in binary generators:

diff --git a/lib/stdlib/src/eval_bits.erl b/lib/stdlib/src/eval_bits.erl
index e49cbc1..56be5a6 100644
--- a/lib/stdlib/src/eval_bits.erl
+++ b/lib/stdlib/src/eval_bits.erl
@@ -193,6 +193,13 @@ bin_gen_field({bin_element,Line,VE,Size0,Options0},
     V = erl_eval:partial_eval(VE),
     NewV = coerce_to_float(V, Type),
     match_check_size(Mfun, Size1, BBs0),
+    case Size1 of
+       {atom,_,all} ->
+           %% An unsized field is forbidden in a generator.
+           throw(invalid);
+       _ ->
+           ok
+    end,
     {value, Size, _BBs} = Efun(Size1, BBs0),
     bin_gen_field1(Bin, Type, Size, Unit, Sign, Endian, NewV, Bs0, BBs0,
Mfun).


-- 
Björn Gustavsson, Erlang/OTP, Ericsson AB

_______________________________________________
erlang-patches mailing list
[email protected]
http://erlang.org/mailman/listinfo/erlang-patches
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.