bool test_equality_piece(cpiece expected, cpiece value, char *msg) { if ((get_x(expected) != get_x(value)) || (get_y(expected) != get_y(value)) || (is_horizontal(expected) != is_horizontal(value)) || (is_small(expected) != is_small(value))) { fprintf(stderr, "%s expected piece is not equal to value piece\n", msg); return false; } return true; }
bool Timer::trigger_time(uint64_t old_time, int hour, int minute) { ACE_Time_Value old_tv; old_tv.set_msec(old_time); ACE_Date_Time old_dt(old_tv); uint64_t new_time = now(); ACE_Time_Value new_tv; new_tv.set_msec(new_time); ACE_Date_Time new_dt(new_tv); if (new_time <= old_time) { return false; } if (new_time - old_time >= 86400000) { return true; } bool old_small = is_small(old_dt, hour, minute); bool new_small = is_small(new_dt, hour, minute); if (is_same_day(old_dt, new_dt)) { if (old_small && !new_small) { return true; } else { return false; } } else { if (!old_small && !new_small) { return true; } else if (old_small && new_small) { return true; } else { return false; } } return false; }
static Eterm math_call_1(Process* p, double (*func)(double), Eterm arg1) { FloatDef a1; Eterm res; Eterm* hp; ERTS_FP_CHECK_INIT(p); if (is_float(arg1)) { GET_DOUBLE(arg1, a1); } else if (is_small(arg1)) { a1.fd = signed_val(arg1); } else if (is_big(arg1)) { if (big_to_double(arg1, &a1.fd) < 0) { badarith: p->freason = BADARITH; return THE_NON_VALUE; } } else { p->freason = BADARG; return THE_NON_VALUE; } a1.fd = (*func)(a1.fd); ERTS_FP_ERROR_THOROUGH(p, a1.fd, goto badarith); hp = HAlloc(p, FLOAT_SIZE_OBJECT); res = make_float(hp); PUT_DOUBLE(a1, hp); return res; }
static void update_small_screen_settings (GnomeControlCenter *self) { CcSmallScreen small; update_monitor_number (self); small = is_small (self); if (small == SMALL_SCREEN_TRUE) { gtk_window_set_resizable (GTK_WINDOW (self->priv->window), TRUE); if (self->priv->small_screen != small) gtk_window_maximize (GTK_WINDOW (self->priv->window)); } else { if (self->priv->small_screen != small) gtk_window_unmaximize (GTK_WINDOW (self->priv->window)); gtk_window_set_resizable (GTK_WINDOW (self->priv->window), FALSE); } self->priv->small_screen = small; /* And update the minimum sizes */ notebook_page_notify_cb (GTK_NOTEBOOK (self->priv->notebook), NULL, self->priv); }
static void dump_element(int to, void *to_arg, Eterm x) { if (is_list(x)) { erts_print(to, to_arg, "H" WORD_FMT, list_val(x)); } else if (is_boxed(x)) { erts_print(to, to_arg, "H" WORD_FMT, boxed_val(x)); } else if (is_immed(x)) { if (is_atom(x)) { unsigned char* s = atom_tab(atom_val(x))->name; int len = atom_tab(atom_val(x))->len; int i; erts_print(to, to_arg, "A%X:", atom_tab(atom_val(x))->len); for (i = 0; i < len; i++) { erts_putc(to, to_arg, *s++); } } else if (is_small(x)) { erts_print(to, to_arg, "I%T", x); } else if (is_pid(x)) { erts_print(to, to_arg, "P%T", x); } else if (is_port(x)) { erts_print(to, to_arg, "p<%bpu.%bpu>", port_channel_no(x), port_number(x)); } else if (is_nil(x)) { erts_putc(to, to_arg, 'N'); } } }
size_t digit_array::size() const { if (is_small()) return element_n; else return (*vec)->size(); }
void digit_array::resize(size_t new_size) { if (new_size <= size()) return; if (new_size == 1) { element_n = 1; digit = 0; } else if (is_small()) { size_t temp = digit; vec = new shared_vector(new_size, 0); if (element_n == 1) (*vec)->at(0) = temp; element_n = new_size; } else { vec->detach(); (*vec)->resize(new_size); } }
BIF_RETTYPE float_1(BIF_ALIST_1) { Eterm res; Eterm* hp; FloatDef f; /* check args */ if (is_not_integer(BIF_ARG_1)) { if (is_float(BIF_ARG_1)) { BIF_RET(BIF_ARG_1); } else { badarg: BIF_ERROR(BIF_P, BADARG); } } if (is_small(BIF_ARG_1)) { Sint i = signed_val(BIF_ARG_1); f.fd = i; /* use "C"'s auto casting */ } else if (big_to_double(BIF_ARG_1, &f.fd) < 0) { goto badarg; } hp = HAlloc(BIF_P, FLOAT_SIZE_OBJECT); res = make_float(hp); PUT_DOUBLE(f, hp); BIF_RET(res); }
digit_array& digit_array::operator=(digit_array const& other) { if (&other == this) return *this; if (!is_small()) delete vec; element_n = other.element_n; if (is_small()) digit = other.digit; else vec = new shared_vector(*other.vec); return *this; }
digit_array::digit_array(digit_array const& other) : element_n(other.element_n) { if (is_small()) digit = other.digit; else vec = new shared_vector(*other.vec); }
digit_array::digit_array(size_t size, size_t init) : element_n(size) { if (is_small()) digit = init; else vec = new shared_vector(size, init); }
void digit_array::pop_back() { if (!is_small()) { vec->detach(); (*vec)->pop_back(); } else --element_n; }
static void newton(mpf_t x, double seed, fun_3term *fun, fun_3term *der, int n) { DECLARE_3VARS(ox,f,df); mpf_set_d(x, seed); do { mpf_set(ox, x); fun(f, n,x), der(df, n,x), mpf_div(f, f,df), mpf_sub(x, x,f); } while(!is_small(f,x)); fun( f, n,x), der(df, n,x), mpf_div(f, f,df), mpf_sub(x, x,f); }
void refine() { CGAL_POLYNOMIAL_NS::Interval_arithmetic_guard gd; assert(stack_.size()>1); while (stack_.size() >1 ){ if (! is_small(stack_.back())) { //std::cout << "Splitting " << stack_.back() << std::endl; Interval b= stack_.back(); stack_.pop_back(); Interval fh= Interval(b.inf(), mp(b.inf(),b.sup())); Interval sh(fh.sup(), b.sup()); stack_.push_back(sh); stack_.push_back(fh); } bool changed=false; do { changed=false; while(stack_.size() >1&&no_root(stack_.back()) ){ assert(!stack_.empty()); //std::cout << "Discarding " << stack_.back() << std::endl; stack_.pop_back(); changed =true; } while (stack_.size() >1 && is_small(stack_.back()) && !is_odd(stack_.back().inf(), stack_.back().sup())) { assert(!stack_.empty()); //std::cout << "Discarding " << stack_.back() << std::endl; stack_.pop_back(); changed =true; } } while (changed); if (is_small(stack_.back())) break; } if (!empty()) { Interval b= stack_.back(); assert(is_small(b)); assert(is_odd(b.inf(),b.sup())); } ok_=true; }
/// Reserve memory, may change buffer type(ref, small or large). void reserve(size_t capacity) { if (capacity > capacity_) { /// Make capacity % RESP_SMALL_BUFFER_SIZE == 0. capacity = capacity % RESP_SMALL_BUFFER_SIZE == 0 ? capacity : RESP_SMALL_BUFFER_SIZE * (capacity / RESP_SMALL_BUFFER_SIZE + 1); if (is_ref() || is_small()) { char const* ptr = data_; bool is_small_before = is_small(); if (capacity > RESP_SMALL_BUFFER_SIZE) { capacity_ = capacity; data_ = (char*)std::malloc(capacity_); if (data_ == 0) { throw std::bad_alloc(); } } else { capacity_ = RESP_SMALL_BUFFER_SIZE; data_ = small_; } if (!(is_small_before && is_small())) { std::memcpy(data_, ptr, size_); } } else { /// large capacity_ = capacity; data_ = (char*)std::realloc(data_, capacity_); } } }
Box pop_small_box(list<Box>& v){ list<Box>::iterator it; for(it=v.begin(); it!=v.end(); it++){ if(is_small(*it, v)){ Box b(*it); v.erase(it); return b; } } throw NotFound(); return Box(0,0,0); }
BIF_RETTYPE abs_1(BIF_ALIST_1) { Eterm res; Sint i0, i; Eterm* hp; /* integer arguments */ if (is_small(BIF_ARG_1)) { i0 = signed_val(BIF_ARG_1); i = ERTS_SMALL_ABS(i0); if (i0 == MIN_SMALL) { hp = HAlloc(BIF_P, BIG_UINT_HEAP_SIZE); BIF_RET(uint_to_big(i, hp)); } else { BIF_RET(make_small(i)); } } else if (is_big(BIF_ARG_1)) { if (!big_sign(BIF_ARG_1)) { BIF_RET(BIF_ARG_1); } else { int sz = big_arity(BIF_ARG_1) + 1; Uint* x; hp = HAlloc(BIF_P, sz); /* See note at beginning of file */ sz--; res = make_big(hp); x = big_val(BIF_ARG_1); *hp++ = make_pos_bignum_header(sz); x++; /* skip thing */ while(sz--) *hp++ = *x++; BIF_RET(res); } } else if (is_float(BIF_ARG_1)) { FloatDef f; GET_DOUBLE(BIF_ARG_1, f); if (f.fd < 0.0) { hp = HAlloc(BIF_P, FLOAT_SIZE_OBJECT); f.fd = fabs(f.fd); res = make_float(hp); PUT_DOUBLE(f, hp); BIF_RET(res); } else BIF_RET(BIF_ARG_1); } BIF_ERROR(BIF_P, BADARG); }
/// Assignment. buffer& operator=(buffer const& rhs) { if (this != &rhs) { if (rhs.is_ref()) { dealloc(); capacity_ = 0; data_ = rhs.data_; } else if (rhs.is_small()) { dealloc(); capacity_ = RESP_SMALL_BUFFER_SIZE; data_ = small_; } else { /// rhs is large if (rhs.capacity_ > capacity_) { if (is_ref() || is_small()) { data_ = 0; } data_ = (char*)std::realloc(data_, rhs.capacity_); if (data_ == 0) { throw std::bad_alloc(); } capacity_ = rhs.capacity_; } } size_ = rhs.size_; if (!is_ref()) { std::memcpy(data_, rhs.data_, size_); } } return *this; }
Eterm erl_is_function(Process* p, Eterm arg1, Eterm arg2) { Sint arity; /* * Verify argument 2 (arity); arity must be >= 0. */ if (is_small(arg2)) { arity = signed_val(arg2); if (arity < 0) { error: BIF_ERROR(p, BADARG); } } else if (is_big(arg2) && !bignum_header_is_neg(*big_val(arg2))) { /* A positive bignum is OK, but can't possibly match. */ arity = -1; } else { /* Everything else (including negative bignum) is an error. */ goto error; } if (is_fun(arg1)) { ErlFunThing* funp = (ErlFunThing *) fun_val(arg1); if (funp->arity == (Uint) arity) { BIF_RET(am_true); } } else if (is_export(arg1)) { Export* exp = (Export *) (export_val(arg1)[1]); if (exp->info.mfa.arity == (Uint) arity) { BIF_RET(am_true); } } BIF_RET(am_false); }
static BIF_RETTYPE iol2v_continue(iol2v_state_t *state) { Eterm iterator; DECLARE_ESTACK(s); ESTACK_CHANGE_ALLOCATOR(s, ERTS_ALC_T_SAVED_ESTACK); state->bytereds_available = ERTS_BIF_REDS_LEFT(state->process) * IOL2V_SMALL_BIN_LIMIT; state->bytereds_spent = 0; if (state->estack.start) { ESTACK_RESTORE(s, &state->estack); } iterator = state->input_list; for(;;) { if (state->bytereds_spent >= state->bytereds_available) { ESTACK_SAVE(s, &state->estack); state->input_list = iterator; return iol2v_yield(state); } while (is_list(iterator)) { Eterm *cell; Eterm head; cell = list_val(iterator); head = CAR(cell); if (is_binary(head)) { if (!iol2v_append_binary(state, head)) { goto l_badarg; } iterator = CDR(cell); } else if (is_small(head)) { Eterm seq_end; if (!iol2v_append_byte_seq(state, iterator, &seq_end)) { goto l_badarg; } iterator = seq_end; } else if (is_list(head) || is_nil(head)) { Eterm tail = CDR(cell); if (!is_nil(tail)) { ESTACK_PUSH(s, tail); } state->bytereds_spent += 1; iterator = head; } else { goto l_badarg; } if (state->bytereds_spent >= state->bytereds_available) { ESTACK_SAVE(s, &state->estack); state->input_list = iterator; return iol2v_yield(state); } } if (is_binary(iterator)) { if (!iol2v_append_binary(state, iterator)) { goto l_badarg; } } else if (!is_nil(iterator)) { goto l_badarg; } if(ESTACK_ISEMPTY(s)) { break; } iterator = ESTACK_POP(s); } if (state->acc_size != 0) { iol2v_enqueue_result(state, iol2v_promote_acc(state)); } BUMP_REDS(state->process, state->bytereds_spent / IOL2V_SMALL_BIN_LIMIT); CLEAR_SAVED_ESTACK(&state->estack); DESTROY_ESTACK(s); BIF_RET(state->result_head); l_badarg: CLEAR_SAVED_ESTACK(&state->estack); DESTROY_ESTACK(s); if (state->acc != NULL) { erts_bin_free(state->acc); state->acc = NULL; } BIF_ERROR(state->process, BADARG); }
digit_array::~digit_array() { if (!is_small()) delete vec; }
static Eterm reference_table_term(Uint **hpp, Uint *szp) { #undef MK_2TUP #undef MK_3TUP #undef MK_CONS #undef MK_UINT #define MK_2TUP(E1, E2) erts_bld_tuple(hpp, szp, 2, (E1), (E2)) #define MK_3TUP(E1, E2, E3) erts_bld_tuple(hpp, szp, 3, (E1), (E2), (E3)) #define MK_CONS(CAR, CDR) erts_bld_cons(hpp, szp, (CAR), (CDR)) #define MK_UINT(UI) erts_bld_uint(hpp, szp, (UI)) int i; Eterm tup; Eterm tup2; Eterm nl = NIL; Eterm dl = NIL; Eterm nrid; for(i = 0; i < no_referred_nodes; i++) { NodeReferrer *nrp; Eterm nril = NIL; for(nrp = referred_nodes[i].referrers; nrp; nrp = nrp->next) { Eterm nrl = NIL; /* NodeReferenceList = [{ReferenceType,References}] */ if(nrp->heap_ref) { tup = MK_2TUP(AM_heap, MK_UINT(nrp->heap_ref)); nrl = MK_CONS(tup, nrl); } if(nrp->link_ref) { tup = MK_2TUP(AM_link, MK_UINT(nrp->link_ref)); nrl = MK_CONS(tup, nrl); } if(nrp->monitor_ref) { tup = MK_2TUP(AM_monitor, MK_UINT(nrp->monitor_ref)); nrl = MK_CONS(tup, nrl); } if(nrp->ets_ref) { tup = MK_2TUP(AM_ets, MK_UINT(nrp->ets_ref)); nrl = MK_CONS(tup, nrl); } if(nrp->bin_ref) { tup = MK_2TUP(AM_binary, MK_UINT(nrp->bin_ref)); nrl = MK_CONS(tup, nrl); } if(nrp->timer_ref) { tup = MK_2TUP(AM_timer, MK_UINT(nrp->timer_ref)); nrl = MK_CONS(tup, nrl); } if(nrp->system_ref) { tup = MK_2TUP(AM_system, MK_UINT(nrp->system_ref)); nrl = MK_CONS(tup, nrl); } nrid = nrp->id; if (!IS_CONST(nrp->id)) { Uint nrid_sz = size_object(nrp->id); if (szp) *szp += nrid_sz; if (hpp) nrid = copy_struct(nrp->id, nrid_sz, hpp, NULL); } if (is_internal_pid(nrid) || nrid == am_error_logger) { ASSERT(!nrp->ets_ref && !nrp->bin_ref && !nrp->system_ref); tup = MK_2TUP(AM_process, nrid); } else if (is_tuple(nrid)) { Eterm *t; ASSERT(!nrp->ets_ref && !nrp->bin_ref); t = tuple_val(nrid); ASSERT(2 == arityval(t[0])); tup = MK_2TUP(t[1], t[2]); } else if(is_internal_port(nrid)) { ASSERT(!nrp->heap_ref && !nrp->ets_ref && !nrp->bin_ref && !nrp->timer_ref && !nrp->system_ref); tup = MK_2TUP(AM_port, nrid); } else if(nrp->ets_ref) { ASSERT(!nrp->heap_ref && !nrp->link_ref && !nrp->monitor_ref && !nrp->bin_ref && !nrp->timer_ref && !nrp->system_ref); tup = MK_2TUP(AM_ets, nrid); } else if(nrp->bin_ref) { ASSERT(is_small(nrid) || is_big(nrid)); ASSERT(!nrp->heap_ref && !nrp->ets_ref && !nrp->link_ref && !nrp->monitor_ref && !nrp->timer_ref && !nrp->system_ref); tup = MK_2TUP(AM_match_spec, nrid); } else { ASSERT(!nrp->heap_ref && !nrp->ets_ref && !nrp->bin_ref); ASSERT(is_atom(nrid)); tup = MK_2TUP(AM_dist, nrid); } tup = MK_2TUP(tup, nrl); /* NodeReferenceIdList = [{{ReferrerType, ID}, NodeReferenceList}] */ nril = MK_CONS(tup, nril); } /* NodeList = [{{Node, Creation}, Refc, NodeReferenceIdList}] */ tup = MK_2TUP(referred_nodes[i].node->sysname, MK_UINT(referred_nodes[i].node->creation)); tup = MK_3TUP(tup, MK_UINT(erts_refc_read(&referred_nodes[i].node->refc, 1)), nril); nl = MK_CONS(tup, nl); } for(i = 0; i < no_referred_dists; i++) { DistReferrer *drp; Eterm dril = NIL; for(drp = referred_dists[i].referrers; drp; drp = drp->next) { Eterm drl = NIL; /* DistReferenceList = [{ReferenceType,References}] */ if(drp->node_ref) { tup = MK_2TUP(AM_node, MK_UINT(drp->node_ref)); drl = MK_CONS(tup, drl); } if(drp->ctrl_ref) { tup = MK_2TUP(AM_control, MK_UINT(drp->ctrl_ref)); drl = MK_CONS(tup, drl); } if (is_internal_pid(drp->id)) { ASSERT(drp->ctrl_ref && !drp->node_ref); tup = MK_2TUP(AM_process, drp->id); } else if(is_internal_port(drp->id)) { ASSERT(drp->ctrl_ref && !drp->node_ref); tup = MK_2TUP(AM_port, drp->id); } else { ASSERT(!drp->ctrl_ref && drp->node_ref); ASSERT(is_atom(drp->id)); tup = MK_2TUP(drp->id, MK_UINT(drp->creation)); tup = MK_2TUP(AM_node, tup); } tup = MK_2TUP(tup, drl); /* DistReferenceIdList = [{{ReferrerType, ID}, DistReferenceList}] */ dril = MK_CONS(tup, dril); } /* DistList = [{Dist, Refc, ReferenceIdList}] */ tup = MK_3TUP(referred_dists[i].dist->sysname, MK_UINT(erts_refc_read(&referred_dists[i].dist->refc, 1)), dril); dl = MK_CONS(tup, dl); } /* {{node_references, NodeList}, {dist_references, DistList}} */ tup = MK_2TUP(AM_node_references, nl); tup2 = MK_2TUP(AM_dist_references, dl); tup = MK_2TUP(tup, tup2); return tup; #undef MK_2TUP #undef MK_3TUP #undef MK_CONS #undef MK_UINT }
//This function is equal to mspace_free //replacing PREACTION with 0 and POSTACTION with nothing static void mspace_free_lockless(mspace msp, void* mem) { if (mem != 0) { mchunkptr p = mem2chunk(mem); #if FOOTERS mstate fm = get_mstate_for(p); msp = msp; /* placate people compiling -Wunused */ #else /* FOOTERS */ mstate fm = (mstate)msp; #endif /* FOOTERS */ if (!ok_magic(fm)) { USAGE_ERROR_ACTION(fm, p); return; } if (!0){//PREACTION(fm)) { check_inuse_chunk(fm, p); if (RTCHECK(ok_address(fm, p) && ok_inuse(p))) { size_t psize = chunksize(p); mchunkptr next = chunk_plus_offset(p, psize); s_allocated_memory -= psize; if (!pinuse(p)) { size_t prevsize = p->prev_foot; if (is_mmapped(p)) { psize += prevsize + MMAP_FOOT_PAD; if (CALL_MUNMAP((char*)p - prevsize, psize) == 0) fm->footprint -= psize; goto postaction; } else { mchunkptr prev = chunk_minus_offset(p, prevsize); psize += prevsize; p = prev; if (RTCHECK(ok_address(fm, prev))) { /* consolidate backward */ if (p != fm->dv) { unlink_chunk(fm, p, prevsize); } else if ((next->head & INUSE_BITS) == INUSE_BITS) { fm->dvsize = psize; set_free_with_pinuse(p, psize, next); goto postaction; } } else goto erroraction; } } if (RTCHECK(ok_next(p, next) && ok_pinuse(next))) { if (!cinuse(next)) { /* consolidate forward */ if (next == fm->top) { size_t tsize = fm->topsize += psize; fm->top = p; p->head = tsize | PINUSE_BIT; if (p == fm->dv) { fm->dv = 0; fm->dvsize = 0; } if (should_trim(fm, tsize)) sys_trim(fm, 0); goto postaction; } else if (next == fm->dv) { size_t dsize = fm->dvsize += psize; fm->dv = p; set_size_and_pinuse_of_free_chunk(p, dsize); goto postaction; } else { size_t nsize = chunksize(next); psize += nsize; unlink_chunk(fm, next, nsize); set_size_and_pinuse_of_free_chunk(p, psize); if (p == fm->dv) { fm->dvsize = psize; goto postaction; } } } else set_free_with_pinuse(p, psize, next); if (is_small(psize)) { insert_small_chunk(fm, p, psize); check_free_chunk(fm, p); } else { tchunkptr tp = (tchunkptr)p; insert_large_chunk(fm, tp, psize); check_free_chunk(fm, p); if (--fm->release_checks == 0) release_unused_segments(fm); } goto postaction; } } erroraction: USAGE_ERROR_ACTION(fm, p); postaction: ;//POSTACTION(fm); } } }
BIF_RETTYPE erts_debug_disassemble_1(BIF_ALIST_1) { Process* p = BIF_P; Eterm addr = BIF_ARG_1; erts_dsprintf_buf_t *dsbufp; Eterm* hp; Eterm* tp; Eterm bin; Eterm mfa; ErtsCodeMFA *cmfa = NULL; BeamCodeHeader* code_hdr; BeamInstr *code_ptr; BeamInstr instr; BeamInstr uaddr; Uint hsz; int i; if (term_to_UWord(addr, &uaddr)) { code_ptr = (BeamInstr *) uaddr; if ((cmfa = find_function_from_pc(code_ptr)) == NULL) { BIF_RET(am_false); } } else if (is_tuple(addr)) { ErtsCodeIndex code_ix; Module* modp; Eterm mod; Eterm name; Export* ep; Sint arity; int n; tp = tuple_val(addr); if (tp[0] != make_arityval(3)) { error: BIF_ERROR(p, BADARG); } mod = tp[1]; name = tp[2]; if (!is_atom(mod) || !is_atom(name) || !is_small(tp[3])) { goto error; } arity = signed_val(tp[3]); code_ix = erts_active_code_ix(); modp = erts_get_module(mod, code_ix); /* * Try the export entry first to allow disassembly of special functions * such as erts_debug:apply/4. Then search for it in the module. */ if ((ep = erts_find_function(mod, name, arity, code_ix)) != NULL) { /* XXX: add "&& ep->address != ep->code" condition? * Consider a traced function. * Its ep will have ep->address == ep->code. * erts_find_function() will return the non-NULL ep. * Below we'll try to derive a code_ptr from ep->address. * But this code_ptr will point to the start of the Export, * not the function's func_info instruction. BOOM !? */ cmfa = erts_code_to_codemfa(ep->addressv[code_ix]); } else if (modp == NULL || (code_hdr = modp->curr.code_hdr) == NULL) { BIF_RET(am_undef); } else { n = code_hdr->num_functions; for (i = 0; i < n; i++) { cmfa = &code_hdr->functions[i]->mfa; if (cmfa->function == name && cmfa->arity == arity) { break; } } if (i == n) { BIF_RET(am_undef); } } code_ptr = (BeamInstr*)erts_code_to_codeinfo(erts_codemfa_to_code(cmfa)); } else { goto error; } dsbufp = erts_create_tmp_dsbuf(0); erts_print(ERTS_PRINT_DSBUF, (void *) dsbufp, HEXF ": ", code_ptr); instr = (BeamInstr) code_ptr[0]; for (i = 0; i < NUM_SPECIFIC_OPS; i++) { if (BeamIsOpCode(instr, i) && opc[i].name[0] != '\0') { code_ptr += print_op(ERTS_PRINT_DSBUF, (void *) dsbufp, i, opc[i].sz-1, code_ptr) + 1; break; } } if (i >= NUM_SPECIFIC_OPS) { erts_print(ERTS_PRINT_DSBUF, (void *) dsbufp, "unknown " HEXF "\n", instr); code_ptr++; } bin = new_binary(p, (byte *) dsbufp->str, dsbufp->str_len); erts_destroy_tmp_dsbuf(dsbufp); hsz = 4+4; (void) erts_bld_uword(NULL, &hsz, (BeamInstr) code_ptr); hp = HAlloc(p, hsz); addr = erts_bld_uword(&hp, NULL, (BeamInstr) code_ptr); ASSERT(is_atom(cmfa->module) || is_nil(cmfa->module)); ASSERT(is_atom(cmfa->function) || is_nil(cmfa->function)); mfa = TUPLE3(hp, cmfa->module, cmfa->function, make_small(cmfa->arity)); hp += 4; return TUPLE3(hp, addr, bin, mfa); }
BIF_RETTYPE erts_debug_breakpoint_2(BIF_ALIST_2) { Process* p = BIF_P; Eterm MFA = BIF_ARG_1; Eterm boolean = BIF_ARG_2; Eterm* tp; ErtsCodeMFA mfa; int i; int specified = 0; Eterm res; BpFunctions f; if (boolean != am_true && boolean != am_false) goto error; if (is_not_tuple(MFA)) { goto error; } tp = tuple_val(MFA); if (*tp != make_arityval(3)) { goto error; } if (!is_atom(tp[1]) || !is_atom(tp[2]) || (!is_small(tp[3]) && tp[3] != am_Underscore)) { goto error; } for (i = 0; i < 3 && tp[i+1] != am_Underscore; i++, specified++) { /* Empty loop body */ } for (i = specified; i < 3; i++) { if (tp[i+1] != am_Underscore) { goto error; } } mfa.module = tp[1]; mfa.function = tp[2]; if (is_small(tp[3])) { mfa.arity = signed_val(tp[3]); } if (!erts_try_seize_code_write_permission(BIF_P)) { ERTS_BIF_YIELD2(bif_export[BIF_erts_debug_breakpoint_2], BIF_P, BIF_ARG_1, BIF_ARG_2); } erts_proc_unlock(p, ERTS_PROC_LOCK_MAIN); erts_thr_progress_block(); erts_bp_match_functions(&f, &mfa, specified); if (boolean == am_true) { erts_set_debug_break(&f); erts_install_breakpoints(&f); erts_commit_staged_bp(); } else { erts_clear_debug_break(&f); erts_commit_staged_bp(); erts_uninstall_breakpoints(&f); } erts_consolidate_bp_data(&f, 1); res = make_small(f.matched); erts_bp_free_matched_functions(&f); erts_thr_progress_unblock(); erts_proc_lock(p, ERTS_PROC_LOCK_MAIN); erts_release_code_write_permission(); return res; error: BIF_ERROR(p, BADARG); }
static int iol2v_append_byte_seq(iol2v_state_t *state, Eterm seq_start, Eterm *seq_end) { Eterm lookahead, iterator; Uint observed_bits; SWord seq_length; char *acc_data; lookahead = seq_start; seq_length = 0; ASSERT(state->bytereds_available > state->bytereds_spent); while (is_list(lookahead)) { Eterm *cell = list_val(lookahead); if (!is_small(CAR(cell))) { break; } if (seq_length * 2 >= (state->bytereds_available - state->bytereds_spent)) { break; } lookahead = CDR(cell); seq_length += 1; } ASSERT(seq_length >= 1); iol2v_expand_acc(state, seq_length); /* Bump a few extra reductions to account for list traversal. */ state->bytereds_spent += seq_length; acc_data = &(state->acc)->orig_bytes[state->acc_size]; state->acc_size += seq_length; iterator = seq_start; observed_bits = 0; while (iterator != lookahead) { Eterm *cell; Uint byte; cell = list_val(iterator); iterator = CDR(cell); byte = unsigned_val(CAR(cell)); observed_bits |= byte; ASSERT(acc_data < &(state->acc)->orig_bytes[state->acc_size]); *(acc_data++) = byte; } if (observed_bits > UCHAR_MAX) { return 0; } ASSERT(acc_data == &(state->acc)->orig_bytes[state->acc_size]); *seq_end = iterator; return 1; }
static Eterm keyfind(int Bif, Process* p, Eterm Key, Eterm Pos, Eterm List) { int max_iter = 10 * CONTEXT_REDS; Sint pos; Eterm term; if (!is_small(Pos) || (pos = signed_val(Pos)) < 1) { BIF_ERROR(p, BADARG); } if (is_small(Key)) { double float_key = (double) signed_val(Key); while (is_list(List)) { if (--max_iter < 0) { BUMP_ALL_REDS(p); BIF_TRAP3(bif_export[Bif], p, Key, Pos, List); } term = CAR(list_val(List)); List = CDR(list_val(List)); if (is_tuple(term)) { Eterm *tuple_ptr = tuple_val(term); if (pos <= arityval(*tuple_ptr)) { Eterm element = tuple_ptr[pos]; if (Key == element) { return term; } else if (is_float(element)) { FloatDef f; GET_DOUBLE(element, f); if (f.fd == float_key) { return term; } } } } } } else if (is_immed(Key)) { while (is_list(List)) { if (--max_iter < 0) { BUMP_ALL_REDS(p); BIF_TRAP3(bif_export[Bif], p, Key, Pos, List); } term = CAR(list_val(List)); List = CDR(list_val(List)); if (is_tuple(term)) { Eterm *tuple_ptr = tuple_val(term); if (pos <= arityval(*tuple_ptr)) { Eterm element = tuple_ptr[pos]; if (Key == element) { return term; } } } } } else { while (is_list(List)) { if (--max_iter < 0) { BUMP_ALL_REDS(p); BIF_TRAP3(bif_export[Bif], p, Key, Pos, List); } term = CAR(list_val(List)); List = CDR(list_val(List)); if (is_tuple(term)) { Eterm *tuple_ptr = tuple_val(term); if (pos <= arityval(*tuple_ptr)) { Eterm element = tuple_ptr[pos]; if (CMP(Key, element) == 0) { return term; } } } } } if (is_not_nil(List)) { BIF_ERROR(p, BADARG); } return am_false; }