Skip to content
Permalink
Browse files
Getong erlang 20 fix (#192)
* 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 committed Aug 12, 2017
1 parent aacb8f2 commit ae9c0766b25af436265a2f88357de2cb96c9e99f
Showing 8 changed files with 25 additions and 7 deletions.
@@ -3,6 +3,7 @@ language: erlang
notifications:
email: false
otp_release:
- 20.0
- 19.0
- 18.3
- 17.5
@@ -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,"."}]}}]}.
@@ -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).
@@ -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.
@@ -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,
@@ -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});
@@ -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;
_ ->
@@ -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). % $\.
@@ -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
%%
@@ -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").

@@ -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
@@ -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}) ->

0 comments on commit ae9c076

Please sign in to comment.