1/* Copyright (c) 2010-2011 Basho Technologies, Inc.
2 * With some minor modifications for Apache CouchDB.
3 *
4 * This file is provided to you under the Apache License,
5 * Version 2.0 (the "License"); you may not use this file
6 * except in compliance with the License.  You may obtain
7 * a copy of the License at
8 *
9 *   http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied.  See the License for the
15 * specific language governing permissions and limitations
16 * under the License.
17*/
18
19#ifndef ERL_NIF_COMPAT_H_
20#define ERL_NIF_COMPAT_H_
21
22#ifdef __cplusplus
23extern "C" {
24#endif /* __cplusplus */
25
26#include "erl_nif.h"
27
28
29#if ERL_NIF_MAJOR_VERSION == 0 && ERL_NIF_MINOR_VERSION == 1
30#define OTP_R13B03
31#elif ERL_NIF_MAJOR_VERSION == 1 && ERL_NIF_MINOR_VERSION == 0
32#define OTP_R13B04
33#elif ERL_NIF_MAJOR_VERSION == 2 && ERL_NIF_MINOR_VERSION == 0
34#define OTP_R14A
35#define OTP_R14B
36#define OTP_R14B01
37#elif ERL_NIF_MAJOR_VERSION == 2 && ERL_NIF_MINOR_VERSION == 1
38#define OTP_R14B02
39#endif
40
41
42#ifdef OTP_R13B03
43
44#define enif_open_resource_type_compat enif_open_resource_type
45#define enif_alloc_resource_compat enif_alloc_resource
46#define enif_release_resource_compat enif_release_resource
47#define enif_alloc_binary_compat enif_alloc_binary
48#define enif_alloc_compat enif_alloc
49#define enif_release_binary_compat enif_release_binary
50#define enif_free_compat enif_free
51#define enif_get_atom_compat enif_get_atom
52#define enif_priv_data_compat enif_get_data
53#define enif_make_uint_compat enif_make_ulong
54
55#define enif_make_string_compat(E, B, Enc) \
56    enif_make_string(E, B)
57
58#endif /* R13B03 */
59
60
61#ifdef OTP_R13B04
62
63#define enif_open_resource_type_compat enif_open_resource_type
64#define enif_alloc_resource_compat enif_alloc_resource
65#define enif_release_resource_compat enif_release_resource
66#define enif_alloc_binary_compat enif_alloc_binary
67#define enif_realloc_binary_compat enif_realloc_binary
68#define enif_release_binary_compat enif_release_binary
69#define enif_alloc_compat enif_alloc
70#define enif_free_compat enif_free
71#define enif_get_atom_compat enif_get_atom
72#define enif_priv_data_compat enif_priv_data
73#define enif_make_string_compat enif_make_string
74#define enif_make_uint_compat enif_make_uint
75
76#endif /* R13B04 */
77
78
79/* OTP R14 and future releases */
80#if !defined(OTP_R13B03) && !defined(OTP_R13B04)
81
82#define enif_open_resource_type_compat(E, N, D, F, T) \
83    enif_open_resource_type(E, NULL, N, D, F, T)
84
85#define enif_alloc_resource_compat(E, T, S) \
86    enif_alloc_resource(T, S)
87
88#define enif_release_resource_compat(E, H) \
89    enif_release_resource(H)
90
91#define enif_alloc_binary_compat(E, S, B) \
92    enif_alloc_binary(S, B)
93
94#define enif_realloc_binary_compat(E, S, B) \
95    enif_realloc_binary(S, B)
96
97#define enif_release_binary_compat(E, B) \
98    enif_release_binary(B)
99
100#define enif_alloc_compat(E, S) \
101    enif_alloc(S)
102
103#define enif_free_compat(E, P) \
104    enif_free(P)
105
106#define enif_get_atom_compat(E, T, B, S) \
107    enif_get_atom(E, T, B, S, ERL_NIF_LATIN1)
108
109#define enif_priv_data_compat enif_priv_data
110#define enif_make_string_compat enif_make_string
111#define enif_make_uint_compat enif_make_uint
112
113#endif  /* R14 and future releases */
114
115
116#ifdef __cplusplus
117}
118#endif /* __cplusplus */
119
120#endif /* ERL_NIF_COMPAT_H_ */
121