diff options
author | Tuncer Ayaz <[email protected]> | 2010-05-07 18:18:26 +0200 |
---|---|---|
committer | Raimo Niskanen <[email protected]> | 2010-05-24 14:25:13 +0200 |
commit | dc47b560f0d0ba67fffd083eb79be8797f970012 (patch) | |
tree | 45b10bd82bae43078ccaca898d08a802dd1ccef7 /erts/emulator/beam/erl_nif.c | |
parent | 8c8663f32f0e9fc2b9483e2b99cee5f703640e88 (diff) | |
download | otp-dc47b560f0d0ba67fffd083eb79be8797f970012.tar.gz otp-dc47b560f0d0ba67fffd083eb79be8797f970012.tar.bz2 otp-dc47b560f0d0ba67fffd083eb79be8797f970012.zip |
erl_nif: add make_atom_len, make_existing_atom_len and make_string_len
Add new NIF API functions
- enif_make_atom_len
- enif_make_existing_atom_len
- enif_make_string_len
These are basically the same as enif_make_atom,
enif_make_existing_atom and enif_make_string except that the
new functions require a length parameter instead of a
null-terminated C-string.
Signed-off-by: Tuncer Ayaz <[email protected]>
Diffstat (limited to 'erts/emulator/beam/erl_nif.c')
-rw-r--r-- | erts/emulator/beam/erl_nif.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/erts/emulator/beam/erl_nif.c b/erts/emulator/beam/erl_nif.c index 4a3b0ad8ca..7095ae03e7 100644 --- a/erts/emulator/beam/erl_nif.c +++ b/erts/emulator/beam/erl_nif.c @@ -666,12 +666,23 @@ ERL_NIF_TERM enif_make_double(ErlNifEnv* env, double d) ERL_NIF_TERM enif_make_atom(ErlNifEnv* env, const char* name) { - return am_atom_put(name, sys_strlen(name)); + return enif_make_atom_len(env, name, sys_strlen(name)); +} + +ERL_NIF_TERM enif_make_atom_len(ErlNifEnv* env, const char* name, size_t len) +{ + return am_atom_put(name, len); } int enif_make_existing_atom(ErlNifEnv* env, const char* name, ERL_NIF_TERM* atom) { - return erts_atom_get(name, sys_strlen(name), atom); + return enif_make_existing_atom_len(env, name, sys_strlen(name), atom); +} + +int enif_make_existing_atom_len(ErlNifEnv* env, const char* name, size_t len, + ERL_NIF_TERM* atom) +{ + return erts_atom_get(name, len, atom); } ERL_NIF_TERM enif_make_tuple(ErlNifEnv* env, unsigned cnt, ...) @@ -750,11 +761,16 @@ ERL_NIF_TERM enif_make_list_from_array(ErlNifEnv* env, const ERL_NIF_TERM arr[], ERL_NIF_TERM enif_make_string(ErlNifEnv* env, const char* string, ErlNifCharEncoding encoding) -{ - Sint n = sys_strlen(string); - Eterm* hp = alloc_heap(env,n*2); +{ + return enif_make_string_len(env, string, sys_strlen(string), encoding); +} + +ERL_NIF_TERM enif_make_string_len(ErlNifEnv* env, const char* string, + size_t len, ErlNifCharEncoding encoding) +{ + Eterm* hp = alloc_heap(env,len*2); ASSERT(encoding == ERL_NIF_LATIN1); - return erts_bld_string_n(&hp,NULL,string,n); + return erts_bld_string_n(&hp,NULL,string,len); } ERL_NIF_TERM enif_make_ref(ErlNifEnv* env) |