Skip to content

Loading…

Enable builds on R14 and R13 #2

Merged
2 commits merged into from

2 participants

@argv0

Add compatibility header and use compatibility macros to enable builds on both R13 and R14.

@beerriot
Owner

Merged, thanks!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 2, 2010
  1. @argv0
  2. @argv0

    Add changes to ustring.c.

    argv0 committed
Showing with 75 additions and 14 deletions.
  1. +61 −0 c_src/erl_nif_compat.h
  2. +14 −14 c_src/ustring.c
View
61 c_src/erl_nif_compat.h
@@ -0,0 +1,61 @@
+#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_realloc_binary_compat enif_realloc_binary
+#define enif_release_binary_compat enif_release_binary
+#define enif_alloc_compat enif_alloc
+#define enif_free_compat enif_free
+#define enif_get_atom_compat(E, T, B, S, C) \
+ enif_get_atom(E, T, B, S)
+
+#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_realloc_binary_compat(E, B, S) \
+ enif_realloc_binary(B, S)
+
+#define enif_release_binary_compat(E, B) \
+ enif_release_binary(B)
+
+#define enif_alloc_compat(E, S) \
+ enif_alloc(S)
+
+#define enif_free_compat(E, P) \
+ enif_free(P)
+
+#define enif_get_atom_compat enif_get_atom
+
+#endif /* R14 */
+
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* ERL_NIF_COMPAT_H_ */
View
28 c_src/ustring.c
@@ -27,7 +27,7 @@
* All binaries passed to these functions should be UTF16-encoded,
* in the native endian.
*/
-#include "erl_nif.h"
+#include "erl_nif_compat.h"
#include "unicode/utypes.h"
#include "unicode/ustring.h"
#include "unicode/unorm.h"
@@ -78,26 +78,26 @@ ERL_NIF_TERM ustring_new(ErlNifEnv* env, int argc,
size = in.size;
do {
- if(!enif_alloc_binary(env, size, &norm))
+ if(!enif_alloc_binary_compat(env, size, &norm))
return error_tuple(env, "failed to alloc normalized binary");
used = unorm_normalize((UChar*)in.data, in.size/2, UNORM_NFC, 0,
(UChar*)norm.data, norm.size/2, &ec);
if (ec == U_BUFFER_OVERFLOW_ERROR) {
/* enlarge buffer if it was too small */
- enif_release_binary(env, &norm);
+ enif_release_binary_compat(env, &norm);
size = used*2;
}
} while (ec == U_BUFFER_OVERFLOW_ERROR);
if (U_FAILURE(ec)) {
- enif_release_binary(env, &norm);
+ enif_release_binary_compat(env, &norm);
return error_tuple(env, u_errorName(ec));
}
if (used*2 != size) {
/* shrink binary if it was too large */
- enif_realloc_binary(env, &norm, used*2);
+ enif_realloc_binary_compat(env, &norm, used*2);
}
return enif_make_binary(env, &norm);
@@ -185,26 +185,26 @@ ERL_NIF_TERM ustring_toupper(ErlNifEnv* env, int argc,
size = in.size;
do {
- if (!enif_alloc_binary(env, size, &upper))
+ if (!enif_alloc_binary_compat(env, size, &upper))
return error_tuple(env, "failed to alloc upper binary");
used = u_strToUpper((UChar*)upper.data, upper.size/2,
(UChar*)in.data, in.size/2, NULL, &ec);
if (ec == U_BUFFER_OVERFLOW_ERROR) {
/* enlarge buffer if it was too small */
- enif_release_binary(env, &upper);
+ enif_release_binary_compat(env, &upper);
size = used*2;
}
} while (ec == U_BUFFER_OVERFLOW_ERROR);
if (U_FAILURE(ec)) {
- enif_release_binary(env, &upper);
+ enif_release_binary_compat(env, &upper);
return error_tuple(env, u_errorName(ec));
}
if (used*2 != size) {
/* shrink binary if it was too large */
- enif_realloc_binary(env, &upper, used*2);
+ enif_realloc_binary_compat(env, &upper, used*2);
}
return enif_make_binary(env, &upper);
@@ -230,26 +230,26 @@ ERL_NIF_TERM ustring_tolower(ErlNifEnv* env, int argc,
size = in.size;
do {
- if (!enif_alloc_binary(env, size, &lower))
+ if (!enif_alloc_binary_compat(env, size, &lower))
return error_tuple(env, "failed to alloc lower binary");
used = u_strToLower((UChar*)lower.data, lower.size/2,
(UChar*)in.data, in.size/2, NULL, &ec);
if (ec == U_BUFFER_OVERFLOW_ERROR) {
/* enlarge buffer if it was too small */
- enif_release_binary(env, &lower);
+ enif_release_binary_compat(env, &lower);
size = used*2;
}
} while (ec == U_BUFFER_OVERFLOW_ERROR);
if (U_FAILURE(ec)) {
- enif_release_binary(env, &lower);
+ enif_release_binary_compat(env, &lower);
return error_tuple(env, u_errorName(ec));
}
if (used*2 != size) {
/* shrink binary if it was too large */
- enif_realloc_binary(env, &lower, used*2);
+ enif_realloc_binary_compat(env, &lower, used*2);
}
return enif_make_binary(env, &lower);
@@ -277,7 +277,7 @@ ERL_NIF_TERM ustring_length(ErlNifEnv* env, int argc,
if(!enif_inspect_binary(env, argv[0], &bin))
return enif_make_badarg(env);
- if(!enif_get_atom(env, argv[1], type, 10))
+ if(!enif_get_atom_compat(env, argv[1], type, 10, ERL_NIF_LATIN1))
return enif_make_badarg(env);
switch(type[0]) {
Something went wrong with that request. Please try again.