BIF_RETTYPE bit_size_1(BIF_ALIST_1) { Uint low_bits; Uint bytesize; Uint high_bits; if (is_binary(BIF_ARG_1)) { bytesize = binary_size(BIF_ARG_1); high_bits = bytesize >> ((sizeof(Uint) * 8)-3); low_bits = (bytesize << 3) + binary_bitsize(BIF_ARG_1); if (high_bits == 0) { if (IS_USMALL(0,low_bits)) { BIF_RET(make_small(low_bits)); } else { Eterm* hp = HAlloc(BIF_P, BIG_UINT_HEAP_SIZE); BIF_RET(uint_to_big(low_bits, hp)); } } else { Uint sz = BIG_UINT_HEAP_SIZE+1; Eterm* hp = HAlloc(BIF_P, sz); hp[0] = make_pos_bignum_header(sz-1); BIG_DIGIT(hp,0) = low_bits; BIG_DIGIT(hp,1) = high_bits; BIF_RET(make_big(hp)); } } else {
BIF_RETTYPE is_binary_1(BIF_ALIST_1) { if (is_binary(BIF_ARG_1) && binary_bitsize(BIF_ARG_1) == 0) { BIF_RET(am_true); } BIF_RET(am_false); }
BIF_RETTYPE iolist_to_iovec_1(BIF_ALIST_1) { BIF_RETTYPE result; if (is_nil(BIF_ARG_1)) { BIF_RET(NIL); } else if (is_binary(BIF_ARG_1)) { if (binary_bitsize(BIF_ARG_1) != 0) { ASSERT(!(BIF_P->flags & F_DISABLE_GC)); BIF_ERROR(BIF_P, BADARG); } else if (binary_size(BIF_ARG_1) != 0) { Eterm *hp = HAlloc(BIF_P, 2); BIF_RET(CONS(hp, BIF_ARG_1, NIL)); } else { BIF_RET(NIL); } } else if (is_internal_magic_ref(BIF_ARG_1)) { iol2v_state_t *state; Binary *magic; magic = erts_magic_ref2bin(BIF_ARG_1); if (ERTS_MAGIC_BIN_DESTRUCTOR(magic) != &iol2v_state_destructor) { ASSERT(!(BIF_P->flags & F_DISABLE_GC)); BIF_ERROR(BIF_P, BADARG); } ASSERT(BIF_P->flags & F_DISABLE_GC); state = ERTS_MAGIC_BIN_UNALIGNED_DATA(magic); result = iol2v_continue(state); } else if (!is_list(BIF_ARG_1)) { ASSERT(!(BIF_P->flags & F_DISABLE_GC)); BIF_ERROR(BIF_P, BADARG); } else { iol2v_state_t state; iol2v_init(&state, BIF_P, BIF_ARG_1); erts_set_gc_state(BIF_P, 0); result = iol2v_continue(&state); } if (result != THE_NON_VALUE || BIF_P->freason != TRAP) { erts_set_gc_state(BIF_P, 1); } BIF_RET(result); }
int enif_is_binary(ErlNifEnv* env, ERL_NIF_TERM term) { return is_binary(term) && (binary_bitsize(term) % 8 == 0); }