From a9bba6fb9921056370ca0d98f13c727229bc1acb Mon Sep 17 00:00:00 2001 From: Marc Worrell Date: Mon, 2 Jun 2014 11:52:04 +0200 Subject: [PATCH] Replace dict() type depending on Erlang release. Issue #15 --- include/webmachine_logger.hrl | 2 +- include/wm_reqdata.hrl | 11 +++++++++-- rebar.config | 5 ++++- src/webmachine_decision_core.erl | 2 +- src/webmachine_logger.erl | 5 ++++- src/webmachine_mochiweb.erl | 2 +- src/webmachine_perf_logger.erl | 3 +++ src/webmachine_request.erl | 4 ++-- src/webmachine_sup.erl | 1 + src/webzmachine.erl | 1 - 10 files changed, 26 insertions(+), 10 deletions(-) diff --git a/include/webmachine_logger.hrl b/include/webmachine_logger.hrl index 204160d..75c7152 100644 --- a/include/webmachine_logger.hrl +++ b/include/webmachine_logger.hrl @@ -13,5 +13,5 @@ response_length, end_time :: tuple(), finish_time :: tuple(), - metadata :: dict()}). + metadata :: wm_dict()}). diff --git a/include/wm_reqdata.hrl b/include/wm_reqdata.hrl index 76f13b2..21fb3d4 100644 --- a/include/wm_reqdata.hrl +++ b/include/wm_reqdata.hrl @@ -1,7 +1,14 @@ + +-ifdef(namespaced_dicts). +-type wm_dict() :: dict:dict(). +-else. +-type wm_dict() :: dict(). +-endif. + -record(wm_reqdata, { % Reqstate socket=undefined, - metadata=dict:new(), + metadata=dict:new() :: wm_dict(), range=undefined, peer=undefined :: inet:ip_address(), bodyfetch=undefined, @@ -14,7 +21,7 @@ disp_path, path :: string(), raw_path :: string(), - path_info :: dict(), + path_info :: wm_dict(), path_tokens :: [string()], app_root :: string(), response_code :: pos_integer(), diff --git a/rebar.config b/rebar.config index f026d6c..98a9d18 100644 --- a/rebar.config +++ b/rebar.config @@ -1,5 +1,8 @@ %%-*- mode: erlang -*- -{erl_opts, [warnings_as_errors]}. +{erl_opts, [ + warnings_as_errors, + {platform_define, "^[0-9]+", namespaced_dicts} +]}. {cover_enabled, true}. {edoc_opts, [{preprocess, true}]}. diff --git a/src/webmachine_decision_core.erl b/src/webmachine_decision_core.erl index b7497d4..87e9176 100644 --- a/src/webmachine_decision_core.erl +++ b/src/webmachine_decision_core.erl @@ -23,8 +23,8 @@ -author('Bryan Fink '). -export([handle_request/2]). -export([do_log/1]). --include("webmachine_logger.hrl"). -include("wm_reqdata.hrl"). +-include("webmachine_logger.hrl"). handle_request(Resource, ReqData) -> try diff --git a/src/webmachine_logger.erl b/src/webmachine_logger.erl index b34c50e..e2791e4 100644 --- a/src/webmachine_logger.erl +++ b/src/webmachine_logger.erl @@ -22,7 +22,10 @@ -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -export([log_access/1, refresh/0, get_metadata/2]). --include("webmachine_logger.hrl"). + +-include_lib("wm_reqdata.hrl"). +-include_lib("webmachine_logger.hrl"). + -record(state, {hourstamp, filename, handle}). alog_path(BaseDir) -> diff --git a/src/webmachine_mochiweb.erl b/src/webmachine_mochiweb.erl index 36004e7..df8680a 100644 --- a/src/webmachine_mochiweb.erl +++ b/src/webmachine_mochiweb.erl @@ -20,8 +20,8 @@ -author('Andy Gross '). -export([start/1, start/2, stop/0, stop/1, loop/2]). --include("webmachine_logger.hrl"). -include_lib("wm_reqdata.hrl"). +-include_lib("webmachine_logger.hrl"). start(Options) -> {PName, Options1} = case get_option(name, Options) of diff --git a/src/webmachine_perf_logger.erl b/src/webmachine_perf_logger.erl index f166694..cababbb 100644 --- a/src/webmachine_perf_logger.erl +++ b/src/webmachine_perf_logger.erl @@ -22,7 +22,10 @@ -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). -export([log/1, refresh/0]). + +-include_lib("wm_reqdata.hrl"). -include("webmachine_logger.hrl"). + -record(state, {hourstamp, filename, handle}). alog_path(BaseDir) -> diff --git a/src/webmachine_request.erl b/src/webmachine_request.erl index b5ad252..ba018a8 100644 --- a/src/webmachine_request.erl +++ b/src/webmachine_request.erl @@ -76,8 +76,8 @@ use_sendfile/0 ]). --include("webmachine_logger.hrl"). --include("wm_reqdata.hrl"). +-include_lib("wm_reqdata.hrl"). +-include_lib("webmachine_logger.hrl"). -define(IDLE_TIMEOUT, infinity). -define(FILE_CHUNK_LENGTH, 65536). diff --git a/src/webmachine_sup.erl b/src/webmachine_sup.erl index 31f6a87..3d93f36 100644 --- a/src/webmachine_sup.erl +++ b/src/webmachine_sup.erl @@ -26,6 +26,7 @@ %% supervisor callbacks -export([init/1]). +-include_lib("wm_reqdata.hrl"). -include_lib("webmachine_logger.hrl"). %% @spec start_link() -> ServerRet diff --git a/src/webzmachine.erl b/src/webzmachine.erl index 8589eea..f4e16e6 100644 --- a/src/webzmachine.erl +++ b/src/webzmachine.erl @@ -20,7 +20,6 @@ -export([start/0, stop/0]). -export_type([reqdata/0, context/0, reply/0]). --include("webmachine_logger.hrl"). -include_lib("include/wm_reqdata.hrl"). -opaque reqdata() :: #wm_reqdata{}.