// ### %read-from-string string eof-error-p eof-value start end preserve-whitespace // => object, position Value SYS_read_from_string_internal(Value arg1, Value arg2, Value arg3, Value arg4, Value arg5, Value arg6) { AbstractString * string = check_string(arg1); bool eof_error_p = (arg2 != NIL); bool preserve_whitespace = (arg6 != NIL); INDEX start; if (arg4 != NIL) start = check_index(arg4); else start = 0; INDEX end; if (arg5 != NIL) end = check_index(arg5); else end = string->length(); StringInputStream * in = new StringInputStream(string, start, end); Thread * const thread = current_thread(); Value result; Readtable * rt = check_readtable(thread->symbol_value(S_current_readtable)); if (preserve_whitespace) result = stream_read_preserving_whitespace(make_value(in), eof_error_p, arg3, false, thread, rt); else result = stream_read(make_value(in), eof_error_p, arg3, false, thread, rt); return thread->set_values(result, make_fixnum(in->offset())); }
void unsigned_union_find::make_union(size_type j, size_type k) { check_index(j); check_index(k); // make sure j, k are roots j=find(j); k=find(k); if(j==k) return; // already in same set // weight it if(nodes[j].count < nodes[k].count) // j is the smaller set { nodes[k].count+=nodes[j].count; // so k becomes parent to j nodes[j].parent=k; nodes[j].count=0; } else // j is NOT the smaller { nodes[j].count+=nodes[k].count; // so j becomes parent to k nodes[k].parent=j; nodes[k].count=0; } }
// ### fasl-sharp-left-paren stream sub-char numarg => value Value SYS_fasl_sharp_left_paren(Value streamarg, Value subchar, Value numarg) { Thread * thread = current_thread(); if (thread->symbol_value(S_read_suppress) != NIL) { stream_read_list(streamarg, true, thread, FASL_READTABLE); return NIL; } if (numarg != NIL && thread->symbol_value(S_backquote_count) == FIXNUM_ZERO) return stream_read_vector(streamarg, check_index(numarg), thread, FASL_READTABLE); Value list = stream_read_list(streamarg, true, thread, FASL_READTABLE); if (thread->symbol_value(S_backquote_count) == FIXNUM_ZERO) { if (numarg != NIL) { INDEX len = check_index(numarg); SimpleVector * vector = new_simple_vector(len); for (INDEX i = 0; i < len; i++) { vector->inline_xaset(i, car(list)); if (cdr(list) != NIL) list = xcdr(list); } return make_value(vector); } return make_value(new_simple_vector(list)); } return make_cons(thread->symbol_value(S_backquote_vector_flag), list); }
void unsigned_union_find::re_root(size_type old_root, size_type new_root) { check_index(old_root); check_index(new_root); // make sure old_root is a root old_root=find(old_root); // same set? // assert(find(new_root)==old_root); if(find(new_root)!=old_root) return; // make sure we actually do something assert(new_root!=old_root); assert(nodes[old_root].count>=2); nodes[new_root].parent=new_root; nodes[new_root].count=nodes[old_root].count; nodes[old_root].parent=new_root; nodes[old_root].count=0; // the order here is important! for(size_type i=0; i<size(); i++) if(i!=new_root && i!=old_root && !is_root(i)) { size_type r=find(i); if(r==old_root || r==new_root) nodes[i].parent=new_root; } }
void Matrix::do_jacobi_rotation(int p, int q, /*out*/ Matrix & current_transformation) { check_index(p); check_index(q); // check for invalid rotation if(p == q) { Logger::warning("incorrect jacobi rotation: `p` and `q` must be different indices", __FILE__, __LINE__); return; } // if element is already zeroed if(0 == get_at(p,q)) return; // r is the remaining index: not p and not q int r = 3 - p - q; // theta is cotangent of Real rotation angle Real theta = (get_at(q,q) - get_at(p,p))/get_at(p,q)/2; // t is sin/cos of rotation angle // it is determined from equation t^2 + 2*t*theta - 1 = 0, // which implies from definition of theta as (cos^2 - sin^2)/(2*sin*cos) Real t = (0 != theta) ? sign(theta)/(abs(theta) + sqrt(theta*theta + 1)) : 1; Real cosine = 1/sqrt(t*t + 1); Real sine = t*cosine; // tau is tangent of half of rotation angle Real tau = sine/(1 + cosine); add_at(p, p, - t*get_at(p,q)); add_at(q, q, + t*get_at(p,q)); // correction to element at (r,p) Real rp_correction = - sine*(get_at(r,q) + tau*get_at(r,p)); // correction to element at (r,q) Real rq_correction = + sine*(get_at(r,p) - tau*get_at(r,q)); add_at(r, p, rp_correction); add_at(p, r, rp_correction); add_at(r, q, rq_correction); add_at(q, r, rq_correction); set_at(p, q, 0); set_at(q, p, 0); // construct matrix of applied jacobi rotation Matrix rotation = Matrix::IDENTITY; rotation.set_at(p, p, cosine); rotation.set_at(q, q, cosine); rotation.set_at(p, q, sine); rotation.set_at(q, p, - sine); current_transformation = current_transformation*rotation; }
void unsigned_union_find::isolate(size_type a) { check_index(a); // is a itself a root? if(is_root(a)) { size_type c=nodes[a].count; // already isolated? if(c==1) return; assert(c>=2); // find a new root size_type new_root=get_other(a); assert(new_root!=a); re_root(a, new_root); } // now it's not a root // get its root size_type r=find(a); // assert(r!=a); nodes[r].count--; nodes[a].parent=a; nodes[a].count=1; }
T* dag<T>::get_arg(std::stringstream& in, const int i) { char a; in >> a; int offset; in >> offset; T* arg = 0; int ub = 0; if (a == 'n') { ub = num_of_nums; arg = num; } else if (a == 'v') { ub = num_of_vars; arg = var; } else if (a == 't') { ub = i; arg = tmp; } else { error("incorrect argument"); } check_index(offset, ub); arg += offset; return arg; }
/* * call-seq: * set_page_image(pos,iid) -> self * * sets the image idx of the given page. * ===Arguments * * pos is a Integer * * iid Integer index of the image in the image_list * * ===Return value * self * === Exceptions * [IndexError] * * pos is greater than the count of pages * * iid is greater than the count of images in the image_list */ DLL_LOCAL VALUE _set_page_image(VALUE self,VALUE idx,VALUE iid) { rb_check_frozen(self); int cidx(NUM2INT(idx)); if(check_index(cidx,_self->GetPageCount())) { int ciid(NUM2INT(iid)); wxImageList *imglist = _self->GetImageList(); if(imglist && check_index(ciid,imglist->GetImageCount())) { _self->SetPageImage(cidx,ciid); } } return self; }
const BoundingBox &RStarTreeNode::get_element_bounding_box( const Uint32 index) const { assert(check_index(index)); return m_elements[index]->get_bounding_box(); }
/*! \brief Get number of feature types for given layer index G_fatal_error() is called when index not found. \param Map pointer to Map_info structure \param field_index layer index \return number of feature types \return -1 on error */ int Vect_cidx_get_num_types_by_index(const struct Map_info *Map, int field_index) { check_status(Map); check_index(Map, field_index); return Map->plus.cidx[field_index].n_types; }
void BytecodePrinter::print_constant(int i, outputStream* st) { int orig_i = i; if (!check_index(orig_i, i, st)) return; ConstantPool* constants = method()->constants(); constantTag tag = constants->tag_at(i); if (tag.is_int()) { st->print_cr(" " INT32_FORMAT, constants->int_at(i)); } else if (tag.is_long()) { st->print_cr(" " INT64_FORMAT, constants->long_at(i)); } else if (tag.is_float()) { st->print_cr(" %f", constants->float_at(i)); } else if (tag.is_double()) { st->print_cr(" %f", constants->double_at(i)); } else if (tag.is_string()) { const char* string = constants->string_at_noresolve(i); st->print_cr(" %s", string); } else if (tag.is_klass()) { st->print_cr(" %s", constants->resolved_klass_at(i)->external_name()); } else if (tag.is_unresolved_klass()) { st->print_cr(" <unresolved klass at %d>", i); } else if (tag.is_method_type()) { int i2 = constants->method_type_index_at(i); st->print(" <MethodType> %d", i2); print_symbol(constants->symbol_at(i2), st); } else if (tag.is_method_handle()) { int kind = constants->method_handle_ref_kind_at(i); int i2 = constants->method_handle_index_at(i); st->print(" <MethodHandle of kind %d>", kind, i2); print_field_or_method(-i, i2, st); } else { st->print_cr(" bad tag=%d at %d", tag.value(), i); } }
void G1BlockOffsetSharedArray::set_offset_array(size_t index, HeapWord* high, HeapWord* low) { check_index(index, "index out of range"); assert(high >= low, "addresses out of order"); size_t offset = pointer_delta(high, low); check_offset(offset, "offset too large"); set_offset_array(index, (u_char)offset); }
DLL_LOCAL VALUE _getItem(VALUE self,VALUE index) { int cidx = RB_NUM2INT(index); if(check_index(cidx,_self->GetItemCount())) return wrap(_self->GetItem(cidx)); return Qnil; }
/*! \brief Get layer number for given index G_fatal_error() is called when index not found. \param Map pointer to Map_info structure \param index layer index: from 0 to Vect_cidx_get_num_fields() - 1 \return layer number */ int Vect_cidx_get_field_number(const struct Map_info *Map, int index) { check_status(Map); check_index(Map, index); return Map->plus.cidx[index].field; }
void BytecodePrinter::print_constant(int i, outputStream* st) { int orig_i = i; if (!check_index(orig_i, false, i, st)) return; constantPoolOop constants = method()->constants(); constantTag tag = constants->tag_at(i); if (tag.is_int()) { st->print_cr(" " INT32_FORMAT, constants->int_at(i)); } else if (tag.is_long()) { st->print_cr(" " INT64_FORMAT, constants->long_at(i)); } else if (tag.is_float()) { st->print_cr(" %f", constants->float_at(i)); } else if (tag.is_double()) { st->print_cr(" %f", constants->double_at(i)); } else if (tag.is_string()) { oop string = constants->resolved_string_at(i); print_oop(string, st); } else if (tag.is_unresolved_string()) { st->print_cr(" <unresolved string at %d>", i); } else if (tag.is_klass()) { st->print_cr(" %s", constants->resolved_klass_at(i)->klass_part()->external_name()); } else if (tag.is_unresolved_klass()) { st->print_cr(" <unresolved klass at %d>", i); } else if (tag.is_object()) { st->print_cr(" " PTR_FORMAT, constants->object_at(i)); } else { st->print_cr(" bad tag=%d at %d", tag.value(), i); } }
static PyObject * curve_segment(SKCurveObject * self, PyObject * args) { int idx; CurveSegment * segment; PyObject * result, *p1, *p2, *p; if (!PyArg_ParseTuple(args, "i", &idx)) return NULL; idx = check_index(self, idx, "path.Segment"); if (idx < 0) return NULL; segment = self->segments + idx; p = SKPoint_FromXY(segment->x, segment->y); if (segment->type == CurveBezier) { p1 = SKPoint_FromXY(segment->x1, segment->y1); p2 = SKPoint_FromXY(segment->x2, segment->y2); result = Py_BuildValue("i(OO)Oi", segment->type, p1, p2, p, segment->cont); Py_XDECREF(p1); Py_XDECREF(p2); } else { result = Py_BuildValue("i()Oi", segment->type, p, segment->cont); } Py_XDECREF(p); return result; }
/*! \brief Get number of categories for given layer index \param Map pointer to Map_info structure \param index layer index \return number of categories \return -1 on error */ int Vect_cidx_get_num_cats_by_index(const struct Map_info *Map, int index) { check_status(Map); check_index(Map, index); return Map->plus.cidx[index].n_cats; }
// ### digit-char-p char &optional radix => weight Value CL_digit_char_p(unsigned int numargs, Value args[]) { if (numargs < 1 || numargs > 2) return wrong_number_of_arguments(S_digit_char_p, numargs, 1, 2); BASE_CHAR c = char_value(args[0]); int radix; if (numargs == 2) radix = check_index(args[1], 2, 36); else radix = 10; if (c >= '0') { int n = c - '0'; if (radix <= 10) return (n < radix) ? make_fixnum(n) : NIL; if (n < 10) return make_fixnum(n); if (c >= 'A') { // A-Z n -= 7; if (n >= 10 && n < radix) return make_fixnum(n); if (c >= 'a') { // a-z n -= 32; if (n >= 10 && n < radix) return make_fixnum(n); } } } return NIL; }
DLL_LOCAL VALUE _remove(VALUE self,VALUE index) { rb_check_frozen(self); int cidx = RB_NUM2INT(index); if(check_index(cidx,_self->GetItemCount())) return wrap(_self->Remove(cidx)); return Qnil; }
/** * @brief Get element. * * Returns the pointer of the element at the given * position. * @param index The index of the element. * @return The pointer of the element. */ inline const BoundedObjectSharedPtr &get_element( const Uint32 index) const noexcept { assert(check_index(index)); assert(m_elements[index].get() != nullptr); return m_elements[index]; }
/// for setDeferHash where you've left some gaps (default constructed elements in vals_) void rehash_except_pow2(I capacityPowerOf2, T const& except = T()) { init_empty_hash(capacityPowerOf2); for (I vali = 0, valn = vals_.size(); vali < valn; ++vali) { T const& val = vals_[vali]; if (val != except) add_index(vali, val); } check_index(); }
/* * Implement sequence item sub-script for the type. */ static PyObject *sipVoidPtr_item(PyObject *self, SIP_SSIZE_T idx) { if (check_size(self) < 0 || check_index(self, idx) < 0) return NULL; return SIPBytes_FromStringAndSize( (char *)((sipVoidPtrObject *)self)->voidptr + idx, 1); }
/* * Implement sequence item sub-script for the type. */ static PyObject *sipArray_item(PyObject *self, SIP_SSIZE_T idx) { sipArrayObject *array = (sipArrayObject *)self; PyObject *py_item; void *data; if (check_index(array, idx) < 0) return NULL; data = element(array, idx); if (array->td != NULL) { py_item = sip_api_convert_from_type(data, array->td, NULL); } else { switch (*array->format) { case 'b': py_item = SIPLong_FromLong(*(char *)data); break; case 'B': py_item = PyLong_FromUnsignedLong(*(unsigned char *)data); break; case 'h': py_item = SIPLong_FromLong(*(short *)data); break; case 'H': py_item = PyLong_FromUnsignedLong(*(unsigned short *)data); break; case 'i': py_item = SIPLong_FromLong(*(int *)data); break; case 'I': py_item = PyLong_FromUnsignedLong(*(unsigned int *)data); break; case 'f': py_item = PyFloat_FromDouble(*(float *)data); break; case 'd': py_item = PyFloat_FromDouble(*(double *)data); break; default: py_item = NULL; } } return py_item; }
// ### make-string-input-stream string &optional start end => string-stream Value CL_make_string_input_stream(unsigned int numargs, Value args[]) { if (numargs < 1 || numargs > 3) return wrong_number_of_arguments(S_make_string_input_stream, numargs, 1, 3); AbstractString * string = check_string(args[0]); unsigned long start; if (numargs >= 2) start = check_index(args[1]); else start = 0; unsigned long end; if (numargs == 3 && args[2] != NIL) end = check_index(args[2]); else end = string->length(); return make_value(new StringInputStream(string, start, end)); }
/* * call-seq: * insert_child(pos,property) -> WX::Property * insert_child(pos,property) { |property| } -> WX::Property * * adds a new Property as child into this one * ===Arguments * * pos position of the new child property. Integer * * property WX::Property or class that inherits from WX::Property * ===Return value * WX::Property * === Exceptions * [IndexError] * * pos is greater than the count of children * */ DLL_LOCAL VALUE _insert_child(VALUE self,VALUE idx,VALUE prop) { int cidx = NUM2INT(idx); if(check_index(cidx,_self->GetChildCount()+1)) return wrap(_self->InsertChild(cidx,unwrap<wxPGProperty*>(prop))); return Qnil; }
bool SimpleString::typep(Value type) const { if (classp(type)) return (type == C_string || type == C_vector || type == C_array || type == C_sequence || type == C_t); if (symbolp(type)) return (type == S_string || type == S_base_string || type == S_simple_string || type == S_simple_base_string || type == S_vector || type == S_simple_array || type == S_array || type == S_sequence || type == S_atom || type == T); if (consp(type)) { Value type_specifier_atom = xcar(type); Value tail = xcdr(type); if (type_specifier_atom == S_array || type_specifier_atom == S_simple_array) { if (consp(tail)) { Value element_type = xcar(tail); tail = xcdr(tail); if (element_type == UNSPECIFIED || element_type == S_character || element_type == S_base_char) { if (tail == NIL) return true; if (cdr(tail) == NIL) // i.e. length(tail) == 1 { Value dimensions = xcar(tail); if (dimensions == UNSPECIFIED) return true; if (dimensions == FIXNUM_ONE) return true; if (consp(dimensions)) { if (::length(dimensions) == 1) { Value dim = xcar(dimensions); if (dim == UNSPECIFIED || dim == make_fixnum(_capacity)) return true; } } } } } } else if (type_specifier_atom == S_string || type_specifier_atom == S_base_string || type_specifier_atom == S_simple_string || type_specifier_atom == S_simple_base_string) { Value size = car(tail); return (size == UNSPECIFIED || check_index(size) == _capacity); } } return false; }
inline size_t G1BlockOffsetSharedArray::index_for(const void* p) const { char* pc = (char*)p; assert(pc >= (char*)_reserved.start() && pc < (char*)_reserved.end(), err_msg("p (" PTR_FORMAT ") not in reserved [" PTR_FORMAT ", " PTR_FORMAT ")", p2i(p), p2i(_reserved.start()), p2i(_reserved.end()))); size_t result = index_for_raw(p); check_index(result, "bad index from address"); return result; }
/** * @brief Set element. * * Sets the pointer of the element at the given * position. * @param value The pointer of the element. * @param index The index of the element. */ inline void set_element( const BoundedObjectSharedPtr &element, const Uint32 index) noexcept { assert(check_index(index)); assert(element.get() != nullptr); assert(m_elements[index].get() == nullptr); m_elements[index] = element; }
/* * Implement mapping assignment sub-script for the type. */ static int sipArray_ass_subscript(PyObject *self, PyObject *key, PyObject *value) { sipArrayObject *array = (sipArrayObject *)self; SIP_SSIZE_T start, len; void *value_data; if (check_writable(array) < 0) return -1; if (PyIndex_Check(key)) { start = PyNumber_AsSsize_t(key, PyExc_IndexError); if (start == -1 && PyErr_Occurred()) return -1; if (start < 0) start += array->len; if (check_index(array, start) < 0) return -1; if ((value_data = get_value(array, value)) == NULL) return -1; len = 1; } else if (PySlice_Check(key)) { Py_ssize_t stop, step; if (sipConvertFromSliceObject(key, array->len, &start, &stop, &step, &len) < 0) return -1; if (step != 1) { PyErr_SetNone(PyExc_NotImplementedError); return -1; } if ((value_data = get_slice(array, value, len)) == NULL) return -1; } else { bad_key(key); return -1; } memmove(element(array, start), value_data, len * array->stride); return 0; }
sval h_remove(struct cpu_thread *thread, uval flags, uval ptex, uval avpn) { union pte *cur_htab = (union pte *)GET_HTAB(thread->cpu->os); union pte *pte; uval *shadow; if (check_index(thread->cpu->os, ptex)) return H_Parameter; /* * XXX acquire & release per-pte lock (bit 57) * specified in 18.5.4.1.1 */ pte = &cur_htab[ptex]; shadow = &thread->cpu->os->htab.shadow[ptex]; if ((flags & H_AVPN) && ((pte->bits.avpn << 7) != avpn)) return H_Not_Found; if ((flags & H_ANDCOND) && ((avpn & pte->words.vsidWord) != 0)) return H_Not_Found; /* return old PTE in regs 4 and 5 */ save_pte(pte, shadow, thread, 4, 5); /* XXX - I'm very skeptical of doing ANYTHING if not bits.v */ /* XXX - I think the spec should be questioned in this case (MFM) */ if (pte->bits.v) { struct logical_chunk_info *lci; uval laddr = *shadow << LOG_PGSIZE; lci = laddr_to_lci(thread->cpu->os, laddr); if (!lci) return H_Parameter; if (lci->lci_arch_ops->amo_rem_ptep) { lci->lci_arch_ops->amo_rem_ptep(lci, laddr, pte->bits.rpn, pte); } atomic_add32(&lci->lci_ptecount, ~0); /* subtract 1 */ } /* * invalidating the pte is the only update required, * though the memory consistency requirements are large. */ pte->bits.v = 0; ptesync(); do_tlbie(pte, ptex); return H_Success; }