Thanks, Tuncer. I've applied this to skerl.

D.

On Fri, Sep 24, 2010 at 2:55 AM, Tuncer Ayaz <[email protected]> wrote:
> # HG changeset patch
> # User Tuncer Ayaz <[email protected]>
> # Date 1285318146 -7200
> # Node ID 2a512594f4eb50d69aaf9443ec58d68480d62544
> # Parent  2cbd7361b5c946d6b5bb2ab0be4cbc28d7867f2a
> Adapt to R14 changes with compat macros
>
> Pull in erl_nif_compat.h as found in ebloom.
>
> diff -r 2cbd7361b5c9 -r 2a512594f4eb c_src/erl_nif_compat.h
> --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
> +++ b/c_src/erl_nif_compat.h    Fri Sep 24 10:49:06 2010 +0200
> @@ -0,0 +1,48 @@
> +#ifndef ERL_NIF_COMPAT_H_
> +#define ERL_NIF_COMPAT_H_
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif /* __cplusplus */
> +
> +#include "erl_nif.h"
> +
> +#if ERL_NIF_MAJOR_VERSION == 1 && ERL_NIF_MINOR_VERSION == 0
> +
> +#define enif_open_resource_type_compat enif_open_resource_type
> +#define enif_alloc_resource_compat enif_alloc_resource
> +#define enif_release_resource_compat enif_release_resource
> +#define enif_alloc_binary_compat enif_alloc_binary
> +#define enif_alloc_compat enif_alloc
> +#define enif_free_compat enif_free
> +#endif /* R13B04 */
> +
> +#if ERL_NIF_MAJOR_VERSION == 2 && ERL_NIF_MINOR_VERSION == 0
> +
> +#define enif_open_resource_type_compat(E, N, D, F, T) \
> +    enif_open_resource_type(E, NULL, N, D, F, T)
> +
> +#define enif_alloc_resource_compat(E, T, S) \
> +    enif_alloc_resource(T, S)
> +
> +#define enif_release_resource_compat(E, H) \
> +    enif_release_resource(H)
> +
> +#define enif_alloc_binary_compat(E, S, B) \
> +    enif_alloc_binary(S, B)
> +
> +#define enif_alloc_compat(E, S) \
> +    enif_alloc(S)
> +
> +#define enif_free_compat(E, P) \
> +    enif_free(P)
> +
> +#endif /* R14 */
> +
> +
> +
> +#ifdef __cplusplus
> +}
> +#endif /* __cplusplus */
> +
> +#endif /* ERL_NIF_COMPAT_H_ */
> diff -r 2cbd7361b5c9 -r 2a512594f4eb c_src/skerl_nifs.c
> --- a/c_src/skerl_nifs.c        Tue Sep 21 15:46:20 2010 -0700
> +++ b/c_src/skerl_nifs.c        Fri Sep 24 10:49:06 2010 +0200
> @@ -1,5 +1,6 @@
>
>  #include "erl_nif.h"
> +#include "erl_nif_compat.h"
>  #include "skein_api.h"
>  #include <stdio.h>
>
> @@ -31,7 +32,7 @@
>
>  int load(ErlNifEnv* env, void ** priv_data, ERL_NIF_TERM load_info)
>  {
> -  skein_hashstate = enif_open_resource_type(env, "hashstate", NULL, 
> ERL_NIF_RT_CREATE, NULL);
> +  skein_hashstate = enif_open_resource_type_compat(env, "hashstate", NULL, 
> ERL_NIF_RT_CREATE, NULL);
>   return 0;
>  }
>
> @@ -42,14 +43,14 @@
>     if(!enif_get_int(env, argv[0], &bits))
>         return enif_make_badarg(env);
>
> -    hashState *state = (hashState*) enif_alloc_resource(env, 
> skein_hashstate, sizeof(hashState));
> +    hashState *state = (hashState*) enif_alloc_resource_compat(env, 
> skein_hashstate, sizeof(hashState));
>     HashReturn r = Init(state, bits);
>     if (r == SUCCESS) {
>         hash_state_term = enif_make_resource(env, state);
> -        enif_release_resource(env, state);
> +        enif_release_resource_compat(env, state);
>         return enif_make_tuple2(env, enif_make_atom(env, "ok"), 
> hash_state_term);
>     } else {
> -        enif_release_resource(env, state);
> +        enif_release_resource_compat(env, state);
>         return enif_make_tuple2(env, enif_make_atom(env, "error"), 
> enif_make_atom(env, "fail"));
>     }
>  }
> @@ -75,7 +76,7 @@
>     enif_get_resource(env, argv[0], skein_hashstate, (void**)&state);
>
>     ErlNifBinary out;
> -    enif_alloc_binary(env, (size_t)(state->statebits/8), &out);
> +    enif_alloc_binary_compat(env, (size_t)(state->statebits/8), &out);
>
>     HashReturn r = Final(state, (BitSequence *)out.data);
>     if (r == SUCCESS) {
> @@ -92,7 +93,7 @@
>
>     ErlNifBinary bin, out;
>     enif_inspect_binary(env, argv[1], &bin);
> -    enif_alloc_binary(env, (size_t)(bits/8), &out);
> +    enif_alloc_binary_compat(env, (size_t)(bits/8), &out);
>
>     HashReturn r = Hash(bits, (BitSequence *)(bin.data), bin.size * 8, 
> (BitSequence *)out.data);
>     if (r == SUCCESS) {
>
> _______________________________________________
> riak-users mailing list
> [email protected]
> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
>

_______________________________________________
riak-users mailing list
[email protected]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com

Reply via email to