/*! @decl int value() *! Return the current path element that the iterator is pointing at. */ static void f_path_iterator_value(INT32 args) { struct cairo_mod_path* pw; struct object* o; struct cairo_mod_path_element* pew; cairo_path_t* path; cairo_path_data_t* data = NULL; int j,i; pw = (struct cairo_mod_path*)get_storage(THIS->path_obj, cairo_mod_path_program); path = pw->path; for (i=0, j=0; i<path->num_data; i+= path->data[i].header.length, j++) { if (j == THIS->idx) { data = &path->data[i]; break; } } if (!data) { } o = clone_object(cairo_mod_path_element_program, 0); pew = (struct cairo_mod_path_element*)get_storage(o, cairo_mod_path_element_program); pew->path_obj = THIS->path_obj; add_ref(THIS->path_obj); pew->element = data; ref_push_object(o); }
void lds::add_vertex(const mpoint p) { size_t p_id = get_storage().get_id(new mpoint(p)); std::list<edge *> nearest = locate(p); mpoint p_tmp = *get_storage().get_point(nearest.front()->get_vertex_id()); if (p_tmp == p) { return; } int index = 0; do { if (lds_.size() <= index || !nearest.size()) { lds_.push_back(new tds()); edge *n = lds_[index]->locate(p); lds_[index++]->add_vertex(p_id, n); } else { lds_[index++]->add_vertex(p_id, nearest.front()); nearest.pop_front(); } } while (get_storage().get_rand(100) < MAGIC_CONST); }
string& operator=(const string& other) { std::string str(other.c_str()); if (type_ == std_string) *static_cast<std::string*>(get_storage()) = std::move(str); else { free(); ::new (get_storage()) std::string(std::move(str)); } length_ = other.length_; return *this; }
void image_pvr_f_encode(INT32 args) { struct object *imgo; struct mapping *optm = NULL; struct image *alpha = NULL, *img; INT32 gbix=0, sz, attr=0; int has_gbix=0, twiddle=0, compress = 0; struct pike_string *res; unsigned char *dst; struct gla_state *gla_st = NULL; get_all_args("Image.PVR.encode", args, (args>1 && !UNSAFE_IS_ZERO(&sp[1-args])? "%o%m":"%o"), &imgo, &optm); if((img=(struct image*)get_storage(imgo, image_program))==NULL) Pike_error("Image.PVR.encode: illegal argument 1\n"); if(optm != NULL) { struct svalue *s; if((s = simple_mapping_string_lookup(optm, "alpha"))!=NULL && !UNSAFE_IS_ZERO(s)) if(s->type != T_OBJECT || (alpha=(struct image*)get_storage(s->u.object, image_program))==NULL) Pike_error("Image.PVR.encode: option (arg 2) \"alpha\" has illegal type\n"); if((s = simple_mapping_string_lookup(optm, "global_index"))!=NULL && !IS_UNDEFINED(s)) { if(s->type == T_INT) { gbix = s->u.integer; has_gbix=1; } else Pike_error("Image.PVR.encode: option (arg 2) \"global_index\" has illegal type\n"); } if((s = simple_mapping_string_lookup(optm, "vq"))!=NULL && !UNSAFE_IS_ZERO(s)) compress = 1; } if (!img->img) Pike_error("Image.PVR.encode: no image\n"); if (alpha && !alpha->img) Pike_error("Image.PVR.encode: no alpha image\n"); if (alpha && (alpha->xsize != img->xsize || alpha->ysize != img->ysize)) Pike_error("Image.PVR.encode: alpha and image size differ\n"); if(compress) sz=8+256*4*2+(img->xsize>>1)*(img->ysize>>1); else
void mp_subthread_locate(void * pt, rozorpc_srv_ctx_t *req_ctx_p) { mp_locate_arg_t * args = (mp_locate_arg_t*) pt; storage_t * st = 0; static mp_locate_ret_t ret; START_PROFILING(locate); /* ** Use received buffer for the response */ req_ctx_p->xmitBuf = req_ctx_p->recv_buf; req_ctx_p->recv_buf = NULL; if ((st = get_storage(args->cid, args->sid, req_ctx_p->socketRef)) == 0) { goto error; } if (storaged_sub_thread_intf_send_req(MP_LOCATE,req_ctx_p,st,tic)==0) { return; } error: ret.status = MP_FAILURE; ret.mp_locate_ret_t_u.error = errno; rozorpc_srv_forward_reply(req_ctx_p,(char*)&ret); /* ** release the context */ rozorpc_srv_release_context(req_ctx_p); STOP_PROFILING(locate); }
bool stdin_fd_tracker_is_stdin(int target) { pthread_mutex_lock(&storage_mutex); intset_t* fds = get_storage(); bool is = intset_contains(fds, target); pthread_mutex_unlock(&storage_mutex); return is; }
void confidence_weighted::update( const common::sfv_t& sfv, float step_width, const string& pos_label, const string& neg_label) { storage::storage_base* sto = get_storage(); for (common::sfv_t::const_iterator it = sfv.begin(); it != sfv.end(); ++it) { const string& feature = it->first; float val = it->second; storage::feature_val2_t val2; sto->get2(feature, val2); storage::val2_t pos_val(0.f, 1.f); storage::val2_t neg_val(0.f, 1.f); ClassifierUtil::get_two(val2, pos_label, neg_label, pos_val, neg_val); const float C = config_.C; float covar_pos_step = 2.f * step_width * val * val * C; float covar_neg_step = 2.f * step_width * val * val * C; sto->set2( feature, pos_label, storage::val2_t(pos_val.v1 + step_width * pos_val.v2 * val, 1.f / (1.f / pos_val.v2 + covar_pos_step))); if (neg_label != "") { sto->set2( feature, neg_label, storage::val2_t(neg_val.v1 - step_width * neg_val.v2 * val, 1.f / (1.f / neg_val.v2 + covar_neg_step))); } } }
void image_hrz_f_encode(INT32 args ) { struct object *io; struct image *i; struct pike_string *s; int x,y; get_all_args( NULL, args, "%o", &io); if(!(i = get_storage( io, image_program))) Pike_error("Wrong argument 1 to Image.HRZ.encode\n"); s = begin_shared_string( 256*240*3 ); memset(s->str, 0, s->len ); for(y=0; y<240; y++) if(y < i->ysize) for(x=0; x<256; x++) if(x < i->xsize) { int in = (x + y*256)*3; rgb_group pix = i->img[y*i->xsize+x]; s->str[in+0] = pix.r >> 2; s->str[in+1] = pix.g >> 2; s->str[in+2] = pix.b >> 2; }
static void image_ttf_faceinstance_set_height(INT32 args) { struct image_ttf_face_struct *face_s; struct image_ttf_faceinstance_struct *face_i=THISi; int h=0; if (!args) Pike_error("Image.TTF.FaceInstance->set_height(): missing arguments\n"); if (sp[-args].type==T_INT) h = sp[-args].u.integer*64; else if (sp[-args].type==T_FLOAT) h = DOUBLE_TO_INT(sp[-args].u.float_number*64); else Pike_error("Image.TTF.FaceInstance->set_height(): illegal argument 1\n"); if (h<1) h=1; if (!(face_s=(struct image_ttf_face_struct*) get_storage(THISi->faceobj,image_ttf_face_program))) Pike_error("Image.TTF.FaceInstance->write(): lost Face\n"); ttf_instance_setc(face_s,face_i,h,"Image.TTF.FaceInstance->set_height()"); pop_n_elems(args); ref_push_object(THISOBJ); }
void arow::update( const common::sfv_t& sfv, float alpha, float beta, const std::string& pos_label, const std::string& neg_label) { storage::storage_base* sto = get_storage(); for (common::sfv_t::const_iterator it = sfv.begin(); it != sfv.end(); ++it) { const string& feature = it->first; float val = it->second; storage::feature_val2_t ret; sto->get2(feature, ret); storage::val2_t pos_val(0.f, 1.f); storage::val2_t neg_val(0.f, 1.f); ClassifierUtil::get_two(ret, pos_label, neg_label, pos_val, neg_val); sto->set2( feature, pos_label, storage::val2_t( pos_val.v1 + alpha * pos_val.v2 * val, pos_val.v2 - beta * pos_val.v2 * pos_val.v2 * val * val)); if (neg_label != "") { sto->set2( feature, neg_label, storage::val2_t( neg_val.v1 - alpha * neg_val.v2 * val, neg_val.v2 - beta * neg_val.v2 * neg_val.v2 * val * val)); } } }
void mp_remove2_1_svc_nb(void * pt_req, rozorpc_srv_ctx_t *rozorpc_srv_ctx_p, void * pt_resp, uint32_t cnx_id) { mp_status_ret_t * ret = (mp_status_ret_t *) pt_resp; mp_remove2_arg_t * args = (mp_remove2_arg_t*) pt_req; storage_t *st = 0; DEBUG_FUNCTION; START_PROFILING(remove); ret->status = MP_FAILURE; if ((st = get_storage(args->cid, args->sid, cnx_id)) == 0) { ret->mp_status_ret_t_u.error = errno; goto out; } if (storage_rm2_file(st, (unsigned char *) args->fid, args->spare) != 0) { ret->mp_status_ret_t_u.error = errno; goto out; } ret->status = MP_SUCCESS; out: STOP_PROFILING(remove); }
void stdin_fd_tracker_did_close(int target) { pthread_mutex_lock(&storage_mutex); intset_t* fds = get_storage(); if (intset_contains(fds, target)) { D("removing %d\n as dup of stdin", target); remove_from_intset(fds, target); } pthread_mutex_unlock(&storage_mutex); }
void stdin_fd_tracker_did_dup(int orig, int dup) { pthread_mutex_lock(&storage_mutex); intset_t* fds = get_storage(); if (intset_contains(fds, orig)) { D("adding %d as dup of %d\n", dup, orig); add_to_intset(fds, dup); } pthread_mutex_unlock(&storage_mutex); }
int get_color_from_pikecolor(struct object *o, INT_TYPE *r, INT_TYPE *g, INT_TYPE *b) { struct color_struct *col; col=(struct color_struct *)get_storage(o,image_color_program); if (!col) return 0; *r=col->rgbl.r/(COLORLMAX/65535); *g=col->rgbl.g/(COLORLMAX/65535); *b=col->rgbl.b/(COLORLMAX/65535); return 1; }
void normal_herd::train(const common::sfv_t& sfv, const string& label) { string incorrect_label; float variance = 0.f; float margin = -calc_margin_and_variance(sfv, label, incorrect_label, variance); if (margin >= 1.f) { get_storage()->register_label(label); return; } update(sfv, margin, variance, label, incorrect_label); }
static void f_path_iterator_next(INT32 args) { struct cairo_mod_path* pw; cairo_path_t* path; int j,i; pw = (struct cairo_mod_path*)get_storage(THIS->path_obj, cairo_mod_path_program); path = pw->path; THIS->idx++; for (i=0,j=0; j<=THIS->idx && i<path->num_data; i+= path->data[i].header.length, j++); push_int(THIS->idx >= 0 && THIS->idx < j); }
static void f_path_iterator_first(INT32 args) { struct cairo_mod_path* pw; cairo_path_t* path; int j,i; pw = (struct cairo_mod_path*)get_storage(THIS->path_obj, cairo_mod_path_program); path = pw->path; THIS->idx = 0; push_int(path->num_data > 0); }
static struct object *load_xbm( struct pike_string *data ) { int width, height; int x, y; struct buffer buff; struct buffer *b = &buff; rgb_group *dest; struct object *io; buff.str = data->str; buff.len = data->len; if(!buf_search( b, '#' ) || !buf_search( b, ' ' ) || !buf_search( b, ' ' )) Pike_error("This is not a XBM image!\n"); width = atoi(b->str); if(width <= 0) Pike_error("This is not a XBM image!\n"); if(!buf_search( b, '#' ) || !buf_search( b, ' ' ) || !buf_search( b, ' ' )) Pike_error("This is not a XBM image!\n"); height = atoi(b->str); if(height <= 0) Pike_error("This is not a XBM image!\n"); if(!buf_search( b, '{' )) Pike_error("This is not a XBM image!\n"); push_int( width ); push_int( height ); io = clone_object( image_program, 2 ); dest = ((struct image *)get_storage(io, image_program))->img; /* .. the code below asumes black if the read fails.. */ for(y=0; y<height; y++) { int next_byte, cnt; for(x=0; x<width;) { if(buf_search( b, 'x' )) { next_byte = (hextoint(buf_getc( b ))*0x10) | hextoint(buf_getc( b )); for(cnt=0; cnt<8&&x<width; cnt++,x++) { if((next_byte&(1<<(x%8)))) dest->r = dest->g = dest->b = 255; dest++; } } else Pike_error("This is not a XBM image!\n"); } } return io; }
/*! @decl PathIterator _get_iterator() *! *! Get an iterator for a given path. The iterator is implicitly used in the *! @tt{foreach(;;)@} statement. *! *! @example *! *! Cairo.Context ctx = ...; *! Cairo.Path p = ctx->copy_path(); *! foreach(p; int i; Cairo.PathElement e) *! { *! ... examine e here ... *! } *! */ static void f_path_get_iterator(INT32 args) { struct object* iterator_object; struct cairo_mod_path_iterator* iterator; iterator_object = clone_object(cairo_mod_path_iterator_program, 0); iterator = (struct cairo_mod_path_iterator*)get_storage(iterator_object, cairo_mod_path_iterator_program); assert(iterator); iterator->path_obj = Pike_fp->current_object; add_ref(Pike_fp->current_object); push_object(iterator_object); }
void arow::train(const common::sfv_t& sfv, const string& label) { string incorrect_label; float variance = 0.f; float margin = -calc_margin_and_variance(sfv, label, incorrect_label, variance); if (margin >= 1.f) { get_storage()->register_label(label); return; } float beta = 1.f / (variance + 1.f / config_.C); float alpha = (1.f - margin) * beta; // max(0, 1 - margin) = 1 - margin update(sfv, alpha, beta, label, incorrect_label); }
/* void create(object(AVS.Index)) */ static void f_create(INT32 args) { struct private_index_data *index; if (!args) Pike_error("Too few arguments to Search->create()\n"); if ((Pike_sp[-args].type != T_OBJECT) || (!(index = (struct private_index_data *) get_storage(Pike_sp[-args].u.object, index_program)))) Pike_error("Bad argument 1 to Search->create()\n"); memcpy(PIKE_SEARCH, &index->tmp_search, sizeof(struct private_search_data)); pop_n_elems(args); }
static void _image_orient(struct image *source, struct object *o[5], struct image *img[5]) { int i; struct { int x,y; } or[4]={ {1,0}, {1,1}, {0,1}, {-1,1} }; int x,y; for (i=0; i<5; i++) { push_int(source->xsize); push_int(source->ysize); o[i]=clone_object(image_program,2); img[i]=get_storage(o[i],image_program); push_object(o[i]); } THREADS_ALLOW(); CHRONO("start"); for (i=0; i<4; i++) /* four directions */ { rgb_group *d=img[i]->img; rgb_group *s=source->img; int xz=source->xsize; int yz=source->ysize; int xd=or[i].x; int yd=or[i].y; for(x=1; x<xz-1; x++) for(y=1; y<yz-1; y++) { #define FOOBAR(CO) \ d[x+y*xz].CO \ = \ (COLORTYPE) \ my_abs( s[(x+xd)+(y+yd)*xz].CO - s[(x-xd)+(y-yd)*xz].CO ) FOOBAR(r); FOOBAR(g); FOOBAR(b); #undef FOOBAR } } CHRONO("end"); THREADS_DISALLOW(); }
void mp_list_bins_files_1_svc_nb(void * pt_req, rozorpc_srv_ctx_t *rozorpc_srv_ctx_p, void * pt_resp, uint32_t cnx_id) { mp_list_bins_files_ret_t * ret = (mp_list_bins_files_ret_t *) pt_resp; mp_list_bins_files_arg_t * args = (mp_list_bins_files_arg_t*) pt_req; storage_t *st = 0; ret->status = MP_FAILURE; START_PROFILING(list_bins_files); DEBUG_FUNCTION; if ((st = get_storage(args->cid, args->sid, cnx_id)) == 0) { ret->mp_list_bins_files_ret_t_u.error = errno; goto out; } // It's necessary memset(ret, 0, sizeof(mp_list_bins_files_ret_t)); if (storage_list_bins_files_to_rebuild(st, args->rebuild_sid, &args->device, &args->spare, &args->slice, &args->cookie, (bins_file_rebuild_t **) & ret->mp_list_bins_files_ret_t_u.reply.children, (uint8_t *) & ret->mp_list_bins_files_ret_t_u.reply.eof) != 0) { ret->mp_list_bins_files_ret_t_u.error = errno; goto out; } ret->mp_list_bins_files_ret_t_u.reply.cookie = args->cookie; ret->mp_list_bins_files_ret_t_u.reply.spare = args->spare; ret->mp_list_bins_files_ret_t_u.reply.device = args->device; ret->mp_list_bins_files_ret_t_u.reply.slice = args->slice; ret->status = MP_SUCCESS; out: STOP_PROFILING(list_bins_files); }
static void finished_p(struct callback *foo, void *b, void *c) { extern void f_low_aap_reqo__init( struct c_request_object * ); aap_clean_cache(); while(request) { struct args *arg; struct object *o; struct c_request_object *obj; mt_lock(&queue_mutex); arg = request; request = arg->next; mt_unlock(&queue_mutex); o = clone_object( request_program, 0 ); /* see requestobject.c */ obj = (struct c_request_object *)get_storage(o, c_request_program ); MEMSET(obj, 0, sizeof(struct c_request_object)); obj->request = arg; obj->done_headers = allocate_mapping( 20 ); obj->misc_variables = allocate_mapping( 40 ); f_low_aap_reqo__init( obj ); push_object( o ); assign_svalue_no_free(sp++, &arg->args); /* { */ /* JMP_BUF recovery; */ /* free_svalue(& throw_value); */ /* mark_free_svalue (&throw_value); */ /* if(SETJMP(recovery)) */ /* { */ /* } */ /* else */ /* { */ apply_svalue(&arg->cb, 2); /* } */ /* } */ pop_stack(); } }
void normal_herd::update( const common::sfv_t& sfv, float margin, float variance, const string& pos_label, const string& neg_label) { storage::storage_base* sto = get_storage(); for (common::sfv_t::const_iterator it = sfv.begin(); it != sfv.end(); ++it) { const string& feature = it->first; float val = it->second; storage::feature_val2_t ret; sto->get2(feature, ret); storage::val2_t pos_val(0.f, 1.f); storage::val2_t neg_val(0.f, 1.f); ClassifierUtil::get_two(ret, pos_label, neg_label, pos_val, neg_val); float val_covariance_pos = val * pos_val.v2; float val_covariance_neg = val * neg_val.v2; const float C = config_.C; sto->set2( feature, pos_label, storage::val2_t( pos_val.v1 + (1.f - margin) * val_covariance_pos / (val_covariance_pos * val + 1.f / C), 1.f / ((1.f / pos_val.v2) + (2 * C + C * C * variance) * val * val))); if (neg_label != "") { sto->set2( feature, neg_label, storage::val2_t( neg_val.v1 - (1.f - margin) * val_covariance_neg / (val_covariance_neg * val + 1.f / C), 1.f / ((1.f / neg_val.v2) + (2 * C + C * C * variance) * val * val))); } } }
/*! @decl void set_backend (Pike.Backend backend) *! *! Set the backend used for the accept callback. *! *! @note *! The backend keeps a reference to this object as long as the port *! is accepting connections, but this object does not keep a *! reference to the backend. *! *! @seealso *! @[query_backend] */ static void port_set_backend (INT32 args) { struct port *p = THIS; struct Backend_struct *backend; if (args!=1) SIMPLE_WRONG_NUM_ARGS_ERROR ("set_backend", 1); if (TYPEOF(Pike_sp[-args]) != PIKE_T_OBJECT) SIMPLE_ARG_TYPE_ERROR ("set_backend", 1, "object(Pike.Backend)"); backend = get_storage (Pike_sp[-args].u.object, Backend_program); if (!backend) SIMPLE_ARG_TYPE_ERROR ("set_backend", 1, "object(Pike.Backend)"); if (p->box.backend) change_backend_for_box (&p->box, backend); else INIT_FD_CALLBACK_BOX (&p->box, backend, p->box.ref_obj, p->box.fd, 0, got_port_event, 0); }
/* main program */ int main(int argc, const char *argv[]) { sock.set_broadcast(); printf("Starting DSP code\n"); send_storage(); ardupilot_start(); while (true) { uint64_t now = micros64(); if (now - last_get_storage_us > 1000*1000) { printf("tick t=%.6f\n", now*1.0e-6f); ardupilot_heartbeat(); get_storage(); last_get_storage_us = now; } socket_check(); usleep(5000); } }
/** * Erase substring * @bug wont work for ROM... * @param index * @param count * @return */ CSTRING& CSTRING::erase(unsigned int index, unsigned int count) { str_storage * tmp; if(count && length() > index) { tmp = get_storage(); if(!tmp) { CSTRING str(c_str() ,index); if(count < length() - index) { str.append(c_str() + index + count); } *this = str; } else { if(index < tmp->len) { if(tmp->len > count) { tmp->len -= count; while(index < tmp->len) { tmp->buf[index] = tmp->buf[index+count]; index++; } } //cut rightmost tmp->len = index; tmp->buf[index] = 0; } } } return (*this); }
static void image_ttf_faceinstance_create(INT32 args) { struct image_ttf_face_struct *face_s = NULL; struct image_ttf_faceinstance_struct *face_i=THISi; int res; if (!args) Pike_error("Image.TTF.FaceInstance(): too few arguments\n"); if (sp[-args].type!=T_OBJECT || !(face_s=(struct image_ttf_face_struct*) get_storage(sp[-args].u.object,image_ttf_face_program))) Pike_error("Image.TTF.FaceInstance(): illegal argument 1\n"); if ((res=TT_New_Instance(face_s->face,&(face_i->instance)))) my_tt_error("Image.TTF.FaceInstance()","TT_New_Instance: ",res); face_i->load_flags = TTLOAD_SCALE_GLYPH|TTLOAD_HINT_GLYPH; add_ref(face_i->faceobj=sp[-args].u.object); ttf_instance_setc(face_s,face_i,32*64,"Image.TTF.FaceInstance()"); }
/****************************************************************************** * OleCreateFromDataEx [OLE32.@] * * Creates an embedded object from data transfer object retrieved from * the clipboard or OLE drag and drop. */ HRESULT WINAPI OleCreateFromDataEx(IDataObject *data, REFIID iid, DWORD flags, DWORD renderopt, ULONG num_cache_fmts, DWORD *adv_flags, FORMATETC *cache_fmts, IAdviseSink *sink, DWORD *conns, IOleClientSite *client_site, IStorage *stg, void **obj) { HRESULT hr; UINT src_cf; FIXME("(%p, %s, %08x, %08x, %d, %p, %p, %p, %p, %p, %p, %p): stub\n", data, debugstr_guid(iid), flags, renderopt, num_cache_fmts, adv_flags, cache_fmts, sink, conns, client_site, stg, obj); hr = get_storage(data, stg, &src_cf); if(FAILED(hr)) return hr; hr = OleLoad(stg, iid, client_site, obj); if(FAILED(hr)) return hr; /* FIXME: Init cache */ return hr; }