Skip to content

Commit

Permalink
Merge branch 'sverker/halfword-testcases/OTP-8884' into dev
Browse files Browse the repository at this point in the history
* sverker/halfword-testcases/OTP-8884:
  NIF 64-bit integer get/make bugfix for halfword emulator.
  Teach erl_alloc.c not to disable internal allocators for halfword
  • Loading branch information
sverker committed Nov 26, 2010
2 parents e643069 + cacb1e5 commit 47b934a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
7 changes: 7 additions & 0 deletions erts/emulator/beam/erl_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,13 @@ handle_args(int *argc, char **argv, erts_alc_hndl_args_init_t *init)
argv[j++] = argv[i];
}
*argc = j;
#if HALFWORD_HEAP
/* If halfword heap, silently ignore any disabling of internal
allocators */
for (i = 0; i < aui_sz; ++i)
aui[i]->enable = 1;
#endif


}

Expand Down
30 changes: 24 additions & 6 deletions erts/emulator/beam/erl_nif.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ static Eterm* alloc_heap_heavy(ErlNifEnv* env, unsigned need, Eterm* hp)
return hp;
}

#if SIZEOF_LONG != ERTS_SIZEOF_ETERM
static ERTS_INLINE void ensure_heap(ErlNifEnv* env, unsigned may_need)
{
if (env->hp + may_need > env->hp_end) {
alloc_heap_heavy(env, may_need, env->hp);
env->hp -= may_need;
}
}
#endif

void erts_pre_nif(ErlNifEnv* env, Process* p, struct erl_module_nif* mod_nif)
{
env->mod_nif = mod_nif;
Expand Down Expand Up @@ -730,9 +740,8 @@ int enif_get_long(ErlNifEnv* env, Eterm term, long* ip)
{
#if SIZEOF_LONG == ERTS_SIZEOF_ETERM
return term_to_Sint(term, ip);
#elif SIZEOF_INT == ERTS_SIZEOF_ETERM
Sint i;
return term_to_Sint(term, &i) ? (*ip = (long) i, 1) : 0;
#elif SIZEOF_LONG == 8
return term_to_Sint64(term, ip);
#else
# error Unknown long word size
#endif
Expand All @@ -742,9 +751,8 @@ int enif_get_ulong(ErlNifEnv* env, Eterm term, unsigned long* ip)
{
#if SIZEOF_LONG == ERTS_SIZEOF_ETERM
return term_to_Uint(term, ip);
#elif SIZEOF_INT == ERTS_SIZEOF_ETERM
Uint u;
return term_to_Uint(term, &u) ? (*ip = (unsigned long) u, 1) : 0;
#elif SIZEOF_LONG == 8
return term_to_Uint64(term, ip);
#else
# error Unknown long word size
#endif
Expand Down Expand Up @@ -821,12 +829,22 @@ ERL_NIF_TERM enif_make_uint(ErlNifEnv* env, unsigned i)

ERL_NIF_TERM enif_make_long(ErlNifEnv* env, long i)
{
#if SIZEOF_LONG == ERTS_SIZEOF_ETERM
return IS_SSMALL(i) ? make_small(i) : small_to_big(i, alloc_heap(env,2));
#elif SIZEOF_LONG == 8
ensure_heap(env,3);
return erts_sint64_to_big(i, &env->hp);
#endif
}

ERL_NIF_TERM enif_make_ulong(ErlNifEnv* env, unsigned long i)
{
#if SIZEOF_LONG == ERTS_SIZEOF_ETERM
return IS_USMALL(0,i) ? make_small(i) : uint_to_big(i,alloc_heap(env,2));
#elif SIZEOF_LONG == 8
ensure_heap(env,3);
return erts_uint64_to_big(i, &env->hp);
#endif
}

#if HAVE_INT64 && SIZEOF_LONG != 8
Expand Down

0 comments on commit 47b934a

Please sign in to comment.