[erlang-patches] Bit string generators, unsized binaries, modules and the REPL

Björn Gustavsson bgustavsson@REDACTED
Thu May 2 17:42:54 CEST 2013


On Sun, Mar 31, 2013 at 4:22 PM, Anthony Ramine <n.oxyde@REDACTED> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-patches/attachments/20130502/615124fa/attachment.htm>


More information about the erlang-patches mailing list