From f6c72ac030380b859172ca072b7e4ec910bd4675 Mon Sep 17 00:00:00 2001 From: Reid Draper Date: Thu, 16 Jan 2014 15:41:36 -0600 Subject: [PATCH 1/6] Use tools.mk Makefile --- Makefile | 11 ++++++++--- tools.mk | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 tools.mk diff --git a/Makefile b/Makefile index 4b9c868..8d9de21 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,11 @@ +.PHONY: compile test -all: - ./rebar compile eunit +all: compile test + +compile: + @./rebar compile clean: - ./rebar clean \ No newline at end of file + ./rebar clean + +include tools.mk diff --git a/tools.mk b/tools.mk new file mode 100644 index 0000000..630ddfb --- /dev/null +++ b/tools.mk @@ -0,0 +1,45 @@ +test: compile + ./rebar eunit skip_deps=true + +docs: + ./rebar doc skip_deps=true + +PLT ?= $(HOME)/.riak_combo_dialyzer_plt +LOCAL_PLT = .local_dialyzer_plt +DIALYZER_FLAGS ?= -Wunmatched_returns + +${PLT}: compile +ifneq (,$(wildcard $(PLT))) + dialyzer --check_plt --plt $(PLT) --apps $(DIALYZER_APPS) && \ + dialyzer --add_to_plt --plt $(PLT) --output_plt $(PLT) --apps $(DIALYZER_APPS) ; test $$? -ne 1 +else + dialyzer --build_plt --output_plt $(PLT) --apps $(DIALYZER_APPS); test $$? -ne 1 +endif + +${LOCAL_PLT}: compile +ifneq (,$(wildcard deps/*)) +ifneq (,$(wildcard $(LOCAL_PLT))) + dialyzer --check_plt --plt $(LOCAL_PLT) deps/*/ebin && \ + dialyzer --add_to_plt --plt $(LOCAL_PLT) --output_plt $(LOCAL_PLT) deps/*/ebin ; test $$? -ne 1 +else + dialyzer --build_plt --output_plt $(LOCAL_PLT) deps/*/ebin ; test $$? -ne 1 +endif +endif + +dialyzer: ${PLT} ${LOCAL_PLT} + @echo "==> $(shell basename $(shell pwd)) (dialyzer)" +ifeq (,$(wildcard $(LOCAL_PLT))) + dialyzer $(DIALYZER_FLAGS) --plts $(PLT) -c ebin +else + dialyzer $(DIALYZER_FLAGS) --plts $(PLT) $(LOCAL_PLT) -c ebin +endif + +cleanplt: + @echo + @echo "Are you sure? It takes several minutes to re-build." + @echo Deleting $(PLT) and $(LOCAL_PLT) in 5 seconds. + @echo + sleep 5 + rm $(PLT) + rm $(LOCAL_PLT) + From 7146b8f5aab4d93ce49af114df7e2dfe6fbe866f Mon Sep 17 00:00:00 2001 From: Reid Draper Date: Thu, 16 Jan 2014 17:06:02 -0600 Subject: [PATCH 2/6] Update tools.mk --- tools.mk | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools.mk b/tools.mk index 630ddfb..82a0669 100644 --- a/tools.mk +++ b/tools.mk @@ -28,11 +28,11 @@ endif dialyzer: ${PLT} ${LOCAL_PLT} @echo "==> $(shell basename $(shell pwd)) (dialyzer)" -ifeq (,$(wildcard $(LOCAL_PLT))) - dialyzer $(DIALYZER_FLAGS) --plts $(PLT) -c ebin -else - dialyzer $(DIALYZER_FLAGS) --plts $(PLT) $(LOCAL_PLT) -c ebin -endif + @if [ -f $(LOCAL_PLT) ]; then \ + dialyzer $(DIALYZER_FLAGS) --plts $(PLT) $(LOCAL_PLT) -c ebin; \ + else \ + dialyzer $(DIALYZER_FLAGS) --plts $(PLT) -c ebin; \ + fi cleanplt: @echo From 0b615927ecc04b3de0e4e35389431aed64498acb Mon Sep 17 00:00:00 2001 From: Jared Morrow Date: Fri, 11 Apr 2014 15:12:10 -0600 Subject: [PATCH 3/6] Roll ebloom version 2.0 --- ebin/ebloom.app | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ebin/ebloom.app b/ebin/ebloom.app index f6702b8..e1d3d78 100644 --- a/ebin/ebloom.app +++ b/ebin/ebloom.app @@ -1,7 +1,7 @@ {application, ebloom, [ {description, ""}, - {vsn, "1.1.2"}, + {vsn, "2.0.0"}, {modules, [ ebloom ]}, From 802ea68e45b952429218820efe945a9b94ee6a69 Mon Sep 17 00:00:00 2001 From: Christopher Meiklejohn Date: Wed, 14 Oct 2015 13:11:24 -0700 Subject: [PATCH 4/6] No longer export from case. Reduce compile errors by removing case export. --- rebar.config | 2 ++ src/ebloom.erl | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/rebar.config b/rebar.config index 625c713..df0f1c2 100644 --- a/rebar.config +++ b/rebar.config @@ -4,3 +4,5 @@ {"(linux|solaris|freebsd|netbsd|openbsd|dragonfly|darwin)", "LDFLAGS", "$LDFLAGS -lstdc++"} ]}. + +{erl_opts, [debug_info, warnings_as_errors]}. diff --git a/src/ebloom.erl b/src/ebloom.erl index 2044b71..45c3df2 100644 --- a/src/ebloom.erl +++ b/src/ebloom.erl @@ -54,16 +54,16 @@ -spec deserialize(binary()) -> {ok, reference()}. init() -> - case code:priv_dir(ebloom) of + SoName = case code:priv_dir(ebloom) of {error, bad_name} -> case code:which(?MODULE) of Filename when is_list(Filename) -> - SoName = filename:join([filename:dirname(Filename),"../priv", "ebloom_nifs"]); + filename:join([filename:dirname(Filename),"../priv", "ebloom_nifs"]); _ -> - SoName = filename:join("../priv", "ebloom_nifs") + filename:join("../priv", "ebloom_nifs") end; Dir -> - SoName = filename:join(Dir, "ebloom_nifs") + filename:join(Dir, "ebloom_nifs") end, erlang:load_nif(SoName, 0). From 9e4c3d4fcada276083271ce67aaace0e4d3a6bf9 Mon Sep 17 00:00:00 2001 From: Magnus Kessler Date: Sat, 17 Sep 2016 08:15:09 +0100 Subject: [PATCH 5/6] Use erlang:nif_error/1 in nif wrapper According to Scott Fritchie, the use of random:uniform/0 to occasionally call some native Erlang code "was a really old style hack around a Dialyzer limitation" and should be replaced with erlang:nif_error/1. The random module was deprecated in OTP-19 and the compilation of the ebloom module fails with warnings_as_errors. --- src/ebloom.erl | 63 ++++++++++---------------------------------------- 1 file changed, 12 insertions(+), 51 deletions(-) diff --git a/src/ebloom.erl b/src/ebloom.erl index 45c3df2..c7ab637 100644 --- a/src/ebloom.erl +++ b/src/ebloom.erl @@ -68,79 +68,40 @@ init() -> erlang:load_nif(SoName, 0). new(_Count, _FalseProb, _Seed) -> - case random:uniform(999999999999) of - 666 -> {ok, make_ref()}; - _ -> exit("NIF library not loaded") - end. + erlang:nif_error({error, not_loaded}). insert(_Ref, _Bin) -> - case random:uniform(999999999999) of - 666 -> ok; - _ -> exit("NIF library not loaded") - end. + erlang:nif_error({error, not_loaded}). contains(_Ref, _Bin) -> - case random:uniform(999999999999) of - 666 -> true; - 667 -> false; - _ -> exit("NIF library not loaded") - end. + erlang:nif_error({error, not_loaded}). clear(_Ref) -> - case random:uniform(999999999999) of - 666 -> ok; - _ -> exit("NIF library not loaded") - end. + erlang:nif_error({error, not_loaded}). size(_Ref) -> - case random:uniform(999999999999) of - 666 -> random:uniform(4242); - 667 -> 0; - _ -> exit("NIF library not loaded") - end. + erlang:nif_error({error, not_loaded}). elements(_Ref) -> - case random:uniform(999999999999) of - 666 -> random:uniform(4242); - 667 -> 0; - _ -> exit("NIF library not loaded") - end. + erlang:nif_error({error, not_loaded}). effective_fpp(_Ref) -> - case random:uniform(999999999999) of - 666 -> random:uniform(4242) / 42.42; - _ -> exit("NIF library not loaded") - end. + erlang:nif_error({error, not_loaded}). intersect(_Ref, _OtherRef) -> - case random:uniform(999999999999) of - 666 -> ok; - _ -> exit("NIF library not loaded") - end. + erlang:nif_error({error, not_loaded}). union(_Ref, _OtherRef) -> - case random:uniform(999999999999) of - 666 -> ok; - _ -> exit("NIF library not loaded") - end. + erlang:nif_error({error, not_loaded}). difference(_Ref, _OtherRef) -> - case random:uniform(999999999999) of - 666 -> ok; - _ -> exit("NIF library not loaded") - end. + erlang:nif_error({error, not_loaded}). serialize(_Ref) -> - case random:uniform(999999999999) of - 666 -> list_to_binary(lists:duplicate(random:uniform(255), random:uniform(4242))); - _ -> exit("NIF library not loaded") - end. + erlang:nif_error({error, not_loaded}). deserialize(_Bin) -> - case random:uniform(999999999999) of - 666 -> {ok, make_ref()}; - _ -> exit("NIF library not loaded") - end. + erlang:nif_error({error, not_loaded}). %% =================================================================== %% EUnit tests From 0b103b23fa06fe4cc6d8ba7980f0f5d684f47543 Mon Sep 17 00:00:00 2001 From: Thomas O'Dowd Date: Mon, 16 Jan 2017 16:45:38 +0900 Subject: [PATCH 6/6] Add a plugin to trigger the port compiler when compiling using rebar3 - rebar3 uses a plugin for the port compiler and needs extra config. --- rebar.config | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/rebar.config b/rebar.config index df0f1c2..bb8d3c0 100644 --- a/rebar.config +++ b/rebar.config @@ -1,3 +1,17 @@ +%% port compiler plugin for rebar3 +{plugins, [pc]}. + +{provider_hooks, + [ + {pre, + [ + {compile, {pc, compile}}, + {clean, {pc, clean}} + ] + } + ] +}. + {port_specs, [{"priv/ebloom_nifs.so", ["c_src/*.cpp"]}]}. {port_env, [ %% Make sure to link -lstdc++