Skip to content

Commit

Permalink
Getong erlang 20 fix (mochi#192)
Browse files Browse the repository at this point in the history
* add 20 compile module option: nowarn_export_all

* crypto:rand_uniform/2 is deprecated and will be removed in a future release; use rand:uniform/1

* add 20

* otp20 cleanup

* remove nowarn_export_all

* correct off by one error in rand_uniform/2
  • Loading branch information
etrepum authored Aug 12, 2017
1 parent aacb8f2 commit ae9c076
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 7 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ language: erlang
notifications:
email: false
otp_release:
- 20.0
- 19.0
- 18.3
- 17.5
Expand Down
1 change: 1 addition & 0 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{platform_define, "^R15", 'gen_tcp_r15b_workaround'},
{platform_define, "^(R14|R15|R16B-)", 'crypto_compatibility'},
{platform_define, "^(R14|R15|R16B|17)", 'rand_mod_unavailable'},
{platform_define, "^(R14|R15|R16B|17)", 'sni_unavailable'},
{platform_define, "^(R14|R15|R16)", 'map_unavailable'}]}.
{cover_enabled, true}.
{eunit_opts, [verbose, {report,{eunit_surefire,[{dir,"."}]}}]}.
Expand Down
2 changes: 1 addition & 1 deletion src/mochitemp.erl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ rngchars(N) ->
[rngchar() | rngchars(N - 1)].

rngchar() ->
rngchar(crypto:rand_uniform(0, tuple_size(?SAFE_CHARS))).
rngchar(mochiweb_util:rand_uniform(0, tuple_size(?SAFE_CHARS))).

rngchar(C) ->
element(1 + C, ?SAFE_CHARS).
Expand Down
1 change: 0 additions & 1 deletion src/mochiweb_html.erl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
-module(mochiweb_html).
-export([tokens/1, parse/1, parse_tokens/1, to_tokens/1, escape/1,
escape_attr/1, to_html/1]).
-compile([export_all]).
-ifdef(TEST).
-export([destack/1, destack/2, is_singleton/1]).
-endif.
Expand Down
2 changes: 1 addition & 1 deletion src/mochiweb_multipart.erl
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ with_socket_server(Transport, ServerFun, ClientFun) ->
plain ->
gen_tcp:connect("127.0.0.1", Port, ClientOpts);
ssl ->
ClientOpts1 = [{ssl_imp, new} | ClientOpts],
ClientOpts1 = mochiweb_test_util:ssl_client_opts(ClientOpts),
{ok, SslSocket} = ssl:connect("127.0.0.1", Port, ClientOpts1),
{ok, {ssl, SslSocket}}
end,
Expand Down
4 changes: 2 additions & 2 deletions src/mochiweb_socket_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ parse_options([{recbuf, RecBuf} | Rest], State) when is_integer(RecBuf) orelse
%% and this doubled value is returned by getsockopt(2).
%%
%% See: man 7 socket | grep SO_RCVBUF
%%
%%
%% In case undefined is passed instead of the default buffer
%% size ?RECBUF_SIZE, no size is set and the OS can control it dynamically
parse_options(Rest, State#mochiweb_socket_server{recbuf=RecBuf});
Expand Down Expand Up @@ -200,7 +200,7 @@ init(State=#mochiweb_socket_server{ip=Ip, port=Port, backlog=Backlog,
{_, _, _, _, _, _, _, _} -> % IPv6
[inet6, {ip, Ip} | BaseOpts]
end,
OptsBuf=case RecBuf of
OptsBuf=case RecBuf of
undefined ->
Opts;
_ ->
Expand Down
9 changes: 9 additions & 0 deletions src/mochiweb_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
-export([parse_qvalues/1, pick_accepted_encodings/3]).
-export([make_io/1]).
-export([normalize_path/1]).
-export([rand_uniform/2]).

-define(PERCENT, 37). % $\%
-define(FULLSTOP, 46). % $\.
Expand Down Expand Up @@ -601,6 +602,14 @@ normalize_path("/" ++ Path, "/" ++ _ = Acc) ->
normalize_path([C|Path], Acc) ->
normalize_path(Path, [C|Acc]).

-ifdef(rand_mod_unavailable).
rand_uniform(Start, End) ->
crypto:rand_uniform(Start, End).
-else.
rand_uniform(Start, End) ->
Start + rand:uniform(End - Start) - 1.
-endif.

%%
%% Tests
%%
Expand Down
12 changes: 10 additions & 2 deletions test/mochiweb_test_util.erl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-module(mochiweb_test_util).
-export([with_server/3, client_request/4, sock_fun/2,
read_server_headers/1, drain_reply/3]).
read_server_headers/1, drain_reply/3, ssl_client_opts/1]).
-include("mochiweb_test_util.hrl").
-include_lib("eunit/include/eunit.hrl").

Expand All @@ -25,6 +25,14 @@ with_server(Transport, ServerFun, ClientFun) ->
mochiweb_http:stop(Server),
Res.

-ifdef(sni_unavailable).
ssl_client_opts(Opts) ->
[{ssl_imp, new} | Opts].
-else.
ssl_client_opts(Opts) ->
[{server_name_indication, disable} | Opts].
-endif.

sock_fun(Transport, Port) ->
Opts = [binary, {active, false}, {packet, http}],
case Transport of
Expand All @@ -42,7 +50,7 @@ sock_fun(Transport, Port) ->
Socket
end;
ssl ->
{ok, Socket} = ssl:connect("127.0.0.1", Port, [{ssl_imp, new} | Opts]),
{ok, Socket} = ssl:connect("127.0.0.1", Port, ssl_client_opts(Opts)),
fun (recv) ->
ssl:recv(Socket, 0);
({recv, Length}) ->
Expand Down

0 comments on commit ae9c076

Please sign in to comment.