Skip to content

Commit

Permalink
Refine macros for get_stacktrace deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
zmstone committed Jul 23, 2018
1 parent d5a15c5 commit cc1fd91
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 74 deletions.
19 changes: 12 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,22 @@ notifications:
email: false

otp_release:
- 20.0
- 21.0
- 20.3
- 19.3
- 18.1
- 17.4

script:
- make elvis-rock
- make
- make eunit
- make edoc
- make xref
- if [ "$(erl -noshell -eval 'io:format(erlang:system_info(otp_release)), halt(0)')" -gt 18 ]; then make dialyzer; fi
- make cover
- make eunit
- |
OTP_RELEASE=`erl -noshell -eval 'io:format(erlang:system_info(otp_release)), halt(0)'`
if [ $OTP_RELEASE -eq 21 ]; then
make dialyzer
make cover
make coveralls
else
make cover
fi
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ hex-publish: clean
cover:
$(REBAR) cover -v

.PHONY: coveralls
coveralls:
$(REBAR) coveralls send
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Current version implements Apache Avro 1.8.1 specification.

License: Apache License 2.0

[![Build Status](https://travis-ci.org/klarna/erlavro.svg?branch=master)](https://travis-ci.org/klarna/erlavro)
[![Build Status](https://travis-ci.org/klarna/erlavro.svg?branch=master)](https://travis-ci.org/klarna/erlavro) [![Coverage Status](https://coveralls.io/repos/github/klarna/erlavro/badge.svg?branch=master)](https://coveralls.io/github/klarna/erlavro?branch=master)

# Avro Type and Erlang Spec Mapping

Expand Down
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@
- Upgrade jsone from 1.4.3 to 1.4.6 (for OTP-21)
* 2.6.4
- Do not conditionally export functions
* 2.6.5
- Refine macros for `get_stacktrace` deprecation
2 changes: 1 addition & 1 deletion include/avro_stacktrace.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
%% This file provides macros to support source code compaibility with old and
%% new ways of doing things.

-ifdef('FUN_STACKTRACE').
-ifndef(OTP_RELEASE).
-define(CAPTURE_STACKTRACE, ).
-define(GET_STACKTRACE, erlang:get_stacktrace()).
-else.
Expand Down
7 changes: 4 additions & 3 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
{erl_opts, [ debug_info
, warnings_as_errors
, {d,'NOTEST'}
, {platform_define, "^(R|1|20)", 'FUN_STACKTRACE'}
]}.
{eunit_opts, [verbose]}.
{cover_enabled, true}.
{cover_opts, [verbose]}.
{xref_checks, [ undefined_function_calls
, deprecated_function_calls
]}.
{edoc_opts, [{preprocess, true}]}.
{deps,
[ {jsone, "1.4.6"}
]}.

{cover_opts, [verbose]}.
{cover_enabled, true}.
{cover_export_enabled, true}.
13 changes: 12 additions & 1 deletion rebar.config.script
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
IsRebar3 = erlang:function_exported(rebar3, main, 1),

CONFIG0 = case os:getenv("TRAVIS") of
"true" ->
JobId = os:getenv("TRAVIS_JOB_ID"),
[{coveralls_service_job_id, JobId},
{plugins, [coveralls]},
{coveralls_coverdata, "_build/test/cover/eunit.coverdata"},
{coveralls_service_name , "travis-ci"} | CONFIG];
_ ->
CONFIG
end.

case IsRebar3 of
true ->
CONFIG;
CONFIG0;
false ->
Rebar3Deps = proplists:get_value(deps, CONFIG),
Rebar2Deps = [
Expand Down
1 change: 1 addition & 0 deletions src/avro.erl
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
| boolean()
| integer()
| float()
| binary()
| iolist()
| [avro:in()]
| [{name_raw(), avro:in()}].
Expand Down
22 changes: 5 additions & 17 deletions src/avro_binary_encoder.erl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%% coding: latin-1
%%%-----------------------------------------------------------------------------
%%%
%%% Copyright (c) 2016-2018 Klarna AB
%%% Copyright (c) 2016-2018 Klarna Bank AB (publ)
%%%
%%% This file is provided to you under the Apache License,
%%% Version 2.0 (the "License"); you may not use this file
Expand Down Expand Up @@ -84,8 +84,9 @@ encode(Sc, Type, Input) ->

%%%_* Internal functions =======================================================


%% @private
%% Tested in OTP-21, dialyzer had trouble understanding the 3 arg
%% for the call to enc/3.
-dialyzer({nowarn_function, [do_encode/3]}).
-spec do_encode(lkup_fun(), type_or_name(), avro_value() | avro:in()) ->
iodata().
do_encode(Lkup, Type, #avro_value{type = T} = V) ->
Expand All @@ -98,7 +99,6 @@ do_encode(Lkup, TypeName, Value) when ?IS_NAME_RAW(TypeName) ->
do_encode(Lkup, Type, Value) ->
enc(Lkup, Type, Value).

%% @private
-spec enc(schema_store() | lkup_fun(), type_or_name(),
avro_value() | avro:in()) -> iodata().
enc(_Lkup, Type, Value) when ?IS_PRIMITIVE_TYPE(Type) ->
Expand Down Expand Up @@ -128,7 +128,6 @@ enc(Lkup, Type, Union) when ?IS_UNION_TYPE(Type) ->
[long(Index), encode(Lkup, MemberT, Value)]
end).

%% @private
-spec encode_prim(avro_type(), avro:in()) -> iodata().
encode_prim(T, _) when ?IS_NULL_TYPE(T) -> null();
encode_prim(T, V) when ?IS_BOOLEAN_TYPE(T) -> bool(V);
Expand All @@ -139,7 +138,7 @@ encode_prim(T, V) when ?IS_DOUBLE_TYPE(T) -> double(V);
encode_prim(T, V) when ?IS_BYTES_TYPE(T) -> bytes(V);
encode_prim(T, V) when ?IS_STRING_TYPE(T) -> string(V).

%% @private Encode blocks, for arrays and maps
%% Encode blocks, for arrays and maps
%% 1. Blocks start with a 'long' type count
%% 2. If count is negative (abs value for real count), it should be followed by
%% a 'long' type data size
Expand All @@ -160,7 +159,6 @@ encode_prim(T, V) when ?IS_STRING_TYPE(T) -> string(V).
%% because it requires everyting in memory already).
%% This is however benifical when concatinating large lists which have chunks
%% encoded in different processes etc.
%% @end
-spec block(index(), iodata()) -> iodata().
block(0, []) -> [0];
block(Count, Payload) when is_binary(Payload) ->
Expand All @@ -169,44 +167,36 @@ block(Count, Payload) when is_binary(Payload) ->
block(Count, Payload) ->
block(Count, iolist_to_binary(Payload)).

%% @private
-spec null() -> binary().
null() -> <<>>.

%% @private
-spec bool(boolean()) -> <<_:8>>.
bool(false) -> <<0>>;
bool(true) -> <<1>>.

%% @private
-spec int(integer()) -> iodata().
int(Int) ->
ZzInt = zigzag(int, Int),
varint(ZzInt).

%% @private
-spec long(integer()) -> iodata().
long(Long) ->
ZzLong = zigzag(long, Long),
varint(ZzLong).

%% @private
-compile({no_auto_import, [float/1]}).
-spec float(float()) -> binary().
float(Float) when is_float(Float) ->
<<Float:32/little-float>>.

%% @private
-spec double(float()) -> binary().
double(Double) when is_float(Double) ->
<<Double:64/little-float>>.

%% @private
-spec bytes(binary()) -> iodata().
bytes(Data) when is_binary(Data) ->
[long(byte_size(Data)), Data].

%% @private
-spec string(atom() | iodata()) -> iodata().
string(Atom) when is_atom(Atom) ->
string(atom_to_binary(Atom, utf8));
Expand All @@ -217,15 +207,13 @@ string(String) when is_list(String) ->
string(String) when is_binary(String) ->
[long(size(String)), String].

%% @private
%% ZigZag encode/decode
%% https://developers.google.com/protocol-buffers/docs/encoding?&csw=1#types
%% @end
-spec zigzag(int | long, integer()) -> integer().
zigzag(int, Int) -> (Int bsl 1) bxor (Int bsr 31);
zigzag(long, Int) -> (Int bsl 1) bxor (Int bsr 63).

%% @private
%% Variable-length format
%% http://lucene.apache.org/core/3_5_0/fileformats.html#VInt
%% @end
Expand Down

0 comments on commit cc1fd91

Please sign in to comment.