Define OTP_VSN/OTP_RELEASE/HAS_CALLBACKS macro#348
Define OTP_VSN/OTP_RELEASE/HAS_CALLBACKS macro#348iilyak wants to merge 1 commit intoapache:masterfrom
Conversation
|
Good idea, but patch doesn't applied on current master. |
|
I'll do rebase. |
We define HAS_CALLBACKS feature macro in order to make dialyzer
happy. OTP releases prior to 15 require defining behaviour_info instead
of callback attribute. New macro could be used to make conditional
compilation as follows:
-ifdef(HAS_CALLBACKS).
-callback app() -> atom().
-else.
-export([behaviour_info/1]).
behaviour_info(callbacks) ->
[
{app, 0}
];
behaviour_info(_) ->
undefined.
-endif.
23e271d to
85ce144
Compare
|
rebased |
|
Thanks! LGFM. On second thought, we plan to drop R14 support after 2.0 release. And since we don't support R15 even now, do we need this callback workaround in mid/long term? cc @rnewson |
There was a problem hiding this comment.
this could be presented more simply;
OtpVersion = erlang:system_info(compat_rel),
OtpRelease = erlang:system_info(otp_release),
HasCallbacks = OTP_VSN > 14,
Defines = [
{d, 'OTP_VSN', OtpVersion},
{d, 'OTP_RELEASE', OtpRelease},
{d, 'HAS_CALLBACKS', HasCallbacks}
],
There was a problem hiding this comment.
I guess @iilyak tried to have more generic solution, but yours simpler and clearer to read. Nice!
There was a problem hiding this comment.
hm, the HAS_CALLBACKS one needs more complexity as you say, it needs to not be defined at all in the 'false' case.
There was a problem hiding this comment.
further hm, how would we use ?OTP_RELEASE in code? We couldn't use a macro conditional on its value in couch_crypto as far as I can see.
There was a problem hiding this comment.
In guards?
md5(Data) when ?OTP_RELEASE >= "17"; ?OTP_RELEASE >= "R15B02" ->
crypto:hash(md5, Data);
md5(Data) ->
crypto:md5(Data).
Updated version checks (forgot when crypto deprecation were added).
There was a problem hiding this comment.
In conclusion, I think we need more feature flags (HAS_CRYPTO_HASH) and the version ones aren't useful for conditional compilation.
There was a problem hiding this comment.
Idea with guards will emit another warning about unreachable clause. So it seems the only way is indeed to stay with feature flags.
There was a problem hiding this comment.
I would call it HAS_CRYPTO_V2
There was a problem hiding this comment.
The reason I didn't hardcoded defines as [{d, Key, Value}] is to be able to define some macro from the content of config.erl. But I didn't do a second step to actually use config.erl. I'll update the PR with @rnewson's solution.
There was a problem hiding this comment.
Given we're supporting R16|17|18 and all the features we might test for are always present, do we need to do any of this right now?
|
I'd like to to see this simplified, it's a good idea and I'd like to simplify couch_crypto when it lands. |
|
Good! +1 then when it get simplified. |
|
Should I add |
|
Since we decided to make R16B03 our minimum, there's no need for HAS_CRYPTO_HASH or HAS_CALLBACKS, we know the features exist. |
|
Closing since we don't need it at the moment. |
Improve clustered purge documentation
…e-impr Improve clustered purge documentation
We define HAS_CALLBACKS feature macro in order to make
dialyzerhappy. OTP releases prior to 15 require defining
behaviour_infoinsteadof a
callbackattribute. New macro could be used to make conditionalcompilation as follows:
The same approach could be used to eliminate the cost of
erlang:function_exportedincouch_crypto.erl.