diff options
author | Lukas Larsson <[email protected]> | 2011-06-30 14:33:28 +0200 |
---|---|---|
committer | Lukas Larsson <[email protected]> | 2011-06-30 14:33:28 +0200 |
commit | 256391d4f9b7425fd96b5b9f344b212751bdfda2 (patch) | |
tree | 854f354b294af4b3bc5cd646768291d0b1b3c431 /erts/emulator/beam/erl_nif.c | |
parent | 12ecb8c36fd00fff873f3bcaf8ffd53d5f2fb31f (diff) | |
download | otp-256391d4f9b7425fd96b5b9f344b212751bdfda2.tar.gz otp-256391d4f9b7425fd96b5b9f344b212751bdfda2.tar.bz2 otp-256391d4f9b7425fd96b5b9f344b212751bdfda2.zip |
Added enif_get_reverse_list to nif API
Diffstat (limited to 'erts/emulator/beam/erl_nif.c')
-rw-r--r-- | erts/emulator/beam/erl_nif.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/erts/emulator/beam/erl_nif.c b/erts/emulator/beam/erl_nif.c index 68421b4387..d1afeb4f03 100644 --- a/erts/emulator/beam/erl_nif.c +++ b/erts/emulator/beam/erl_nif.c @@ -1007,6 +1007,30 @@ void enif_system_info(ErlNifSysInfo *sip, size_t si_size) driver_system_info(sip, si_size); } +int enif_get_reverse_list(ErlNifEnv* env, ERL_NIF_TERM term, ERL_NIF_TERM *list) { + Eterm *listptr, *ret, *hp; + + if (is_nil(term)) { + *list = term; + return 1; + } + + ret = alloc_heap(env, 2); + *ret = NIL; + + while (is_not_nil(term)) { + if (is_not_list(term)) { + return 0; + } + hp = alloc_heap(env, 2); + listptr = list_val(term); + *ret = CONS(hp, CAR(listptr), *ret); + term = CDR(listptr); + } + *list = *ret; + return 1; +} + ErlNifMutex* enif_mutex_create(char *name) { return erl_drv_mutex_create(name); } void enif_mutex_destroy(ErlNifMutex *mtx) { erl_drv_mutex_destroy(mtx); } |