Commits

tuncer committed 2a51259

Adapt to R14 changes with compat macros

Pull in erl_nif_compat.h as found in ebloom.

Comments (0)

Files changed (2)

c_src/erl_nif_compat.h

+#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_ */

c_src/skerl_nifs.c

 
 #include "erl_nif.h"
+#include "erl_nif_compat.h"
 #include "skein_api.h"
 #include <stdio.h>
 
 
 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;
 }
 
     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"));
     }
 }
     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) {
     
     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) {