// zenity backend for under linux merged in dev branch - soon in master // https://github.com/mlabbe/nativefiledialog/pull/34 cstr imgui_bind_file_popup(Object& e, cstr mixin, cstr attr, std::string& data, cstr filters) { ImGui::PushItemWidth(200); ImGui::InputText("##input", data.data(), data.length(), ImGuiInputTextFlags_ReadOnly); ImGui::PopItemWidth(); ImGui::SameLine(); char buf[200]; snprintf(buf, HA_COUNT_OF(buf), "browse##%s", no_prefix(attr)); if(ImGui::Button(buf)) { nfdchar_t* outPath = nullptr; nfdresult_t result = NFD_OpenDialog(filters, nullptr, &outPath); hassert(result != NFD_ERROR, "Error: %s\n", NFD_GetError()); if(result == NFD_OKAY) { JsonData old_val = mixin_attr_state(mixin, attr, data); data = outPath; JsonData new_val = mixin_attr_state(mixin, attr, data); edit::add_changed_attribute(World::get().editor(), e.id(), old_val, new_val, attr_changed_text(mixin, attr)); free(outPath); return attr; } } ImGui::SameLine(); ImGui::LabelText("##text", attr); return nullptr; }
void ObjectMemory::snapshot(STATE) { // Assign all objects an object id... ObjectMemory::GCInhibit inhibitor(root_state_->om); // Walk the heap over and over until we don't create // any more objects... size_t last_seen = 0; while(last_object_id != last_seen) { last_seen = last_object_id; ObjectWalker walker(root_state_->om); GCData gc_data(state->vm()); // Seed it with the root objects. walker.seed(gc_data); Object* obj = walker.next(); while(obj) { obj->id(state); obj = walker.next(); } } // Now, save the current value of last_object_id, since thats // so we can compare later to find all new objects. last_snapshot_id = last_object_id; std::cout << "Snapshot taken: " << last_snapshot_id << "\n"; }
TideDataset::TideDataset(const std::string& tide_uri) { pert::ProtoTableReader<Object> tide_reader; CHECK(tide_reader.Open(tide_uri)) << "failed to open uri: " << tide_uri; string key; Object object; while (tide_reader.NextProto(&key, &object)){ uint32 object_id = object.id(); ObjectData& object_data = objectid_to_objectdata_[object_id]; object_data.id = object_id; object_data.name = object.name(); for (int i=0; i < object.photos_size(); ++i){ const tide::Photo& photo = object.photos(i); imageid_to_objectid_[photo.id()] = object_id; if (photo.label() == tide::POSITIVE){ object_data.primary.push_back(photo.id()); primary_images_.insert(photo.id()); } else if (photo.label() == tide::NEGATIVE){ object_data.neg.push_back(photo.id()); } else if (photo.label() == tide::NONE){ object_data.aux.push_back(photo.id()); } } } }
VALUE rb_protect_inspect(VALUE (*func)(VALUE a, VALUE b), VALUE h_obj, VALUE h_arg) { NativeMethodEnvironment* env = NativeMethodEnvironment::get(); STATE = env->state(); Thread* thr = Thread::current(state); LookupTable* rectbl = thr->recursive_objects(); Object* obj = env->get_object(h_obj); Object* id = obj->id(state); bool found = false; rectbl->fetch(state, id, &found); if(found) { return (*func)(h_obj, h_arg); } rectbl->store(state, id, cTrue); VALUE ret = Qnil; ExceptionPoint ep(env); PLACE_EXCEPTION_POINT(ep); bool unwinding = false; if(unlikely(ep.jumped_to())) { unwinding = true; } else { ret = (*func)(h_obj, h_arg); } ep.pop(env); // Get the thread and table again, the GC might have fun. thr = Thread::current(state); rectbl = thr->recursive_objects(); obj = env->get_object(h_obj); id = obj->id(state); rectbl->remove(state, id); if(unwinding) env->current_ep()->return_to(env); return ret; }
/* This is the execute implementation used by normal Ruby code, * as opposed to Primitives or FFI functions. * It prepares a Ruby method for execution. * Here, +exec+ is a VMMethod instance accessed via the +vmm+ slot on * CompiledMethod. */ ExecuteStatus VMMethod::execute(STATE, Task* task, Message& msg) { CompiledMethod* cm = as<CompiledMethod>(msg.method); MethodContext* ctx = MethodContext::create(state, msg.recv, cm); VMMethod* vmm = cm->backend_method_; // Copy in things we all need. ctx->module(state, msg.module); ctx->name(state, msg.name); ctx->block(state, msg.block); ctx->args = msg.args(); // If argument handling fails.. GenericArguments args; if(args.call(state, vmm, ctx, msg) == false) { // Clear the values from the caller task->active()->clear_stack(msg.stack); // TODO we've got full control here, we should just raise the exception // in the runtime here rather than throwing a C++ exception and raising // it later. Exception::argument_error(state, vmm->required_args, msg.args()); // never reached! } #if 0 if(!probe_->nil_p()) { probe_->start_method(this, msg); } #endif // Clear the values from the caller task->active()->clear_stack(msg.stack); task->make_active(ctx); if(unlikely(task->profiler)) { profiler::Method* prof_meth; if(MetaClass* mc = try_as<MetaClass>(msg.module)) { Object* attached = mc->attached_instance(); if(Module* mod = try_as<Module>(attached)) { prof_meth = task->profiler->enter_method(msg.name, mod->name(), profiler::kNormal); } else { prof_meth = task->profiler->enter_method(msg.name, attached->id(state), profiler::kNormal); } } else { prof_meth = task->profiler->enter_method(msg.name, msg.module->name(), profiler::kSingleton); } if(!prof_meth->file()) { prof_meth->set_position(cm->file(), cm->start_line(state)); } } return cExecuteRestart; }
Object *Object::clone(QHash<Id, Object*> &objHash) const { Id resultId = id().sameTypeId(); Object *result = new Object(resultId); objHash.insert(resultId, result); foreach (Id childId, mChildren) { Object *child = objHash[childId]->clone(id(), objHash); result->addChild(child->id()); }
cstr imgui_bind_attribute(Object& e, cstr mixin, cstr attr, bool& data) { if(ImGui::Checkbox(no_prefix(attr), &data)) { JsonData old_val = mixin_attr_state(mixin, attr, !data); JsonData new_val = mixin_attr_state(mixin, attr, data); edit::add_changed_attribute(World::get().editor(), e.id(), old_val, new_val, attr_changed_text(mixin, attr)); return attr; } return nullptr; }
cstr imgui_bind_attribute(Object& e, cstr mixin, cstr attr, std::string& data) { static char buf[128] = ""; Utils::strncpy(buf, data.c_str(), HA_COUNT_OF(buf)); if(ImGui::InputText(no_prefix(attr), buf, HA_COUNT_OF(buf), ImGuiInputTextFlags_EnterReturnsTrue)) { JsonData old_val = mixin_attr_state(mixin, attr, data); data = buf; JsonData new_val = mixin_attr_state(mixin, attr, data); edit::add_changed_attribute(World::get().editor(), e.id(), old_val, new_val, attr_changed_text(mixin, attr)); return attr; } return nullptr; }
VALUE rb_inspecting_p(VALUE h_obj) { NativeMethodEnvironment* env = NativeMethodEnvironment::get(); STATE = env->state(); Thread* thr = Thread::current(state); LookupTable* rectbl = thr->recursive_objects(); Object* obj = env->get_object(h_obj); Object* id = obj->id(state); bool found = false; rectbl->fetch(state, id, &found); if(found) return Qtrue; return Qfalse; }
cstr bind_ints(Object& e, cstr mixin, cstr attr, T& data, int num_elements) { static T data_on_start; bool justReleased = false; bool justActivated = false; DragInts(no_prefix(attr), (int*)&data, num_elements, &justReleased, &justActivated); if(justActivated) { data_on_start = data; } if(justReleased && data != data_on_start) { JsonData old_val = mixin_attr_state(mixin, attr, data_on_start); JsonData new_val = mixin_attr_state(mixin, attr, data); edit::add_changed_attribute(World::get().editor(), e.id(), old_val, new_val, attr_changed_text(mixin, attr)); return attr; } return nullptr; }
void redis_store<Object>::get(const timestamp& key, const long lp_id, obj_ptr& ret) { boost::lock_guard<boost::mutex> guard(get_mutex_); std::stringstream lpid_ss_; lpid_ss_ << lp_id; std::stringstream time_ss_; time_ss_ << key.time(); std::string command = "ZRANGEBYSCORE " + type_rank_ + lpid_ss_.str() + " " + time_ss_.str() + " " + time_ss_.str(); reply = (redisReply*) redisCommand(context, command.c_str()); if (reply->type == REDIS_REPLY_ARRAY) { Object obj; for (int i = 0; i < reply->elements; ++i) { std::stringstream ss; ss << reply->element[i]->str; boost::archive::text_iarchive iar(ss); iar >> obj; if (obj.id() == key.id()) break; } ret = boost::make_shared<Object>(obj); }
void ObjectMemory::print_new_since_snapshot(STATE) { // Assign all objects an object id... ObjectMemory::GCInhibit inhibitor(root_state_->om); ObjectWalker walker(root_state_->om); GCData gc_data(root_state_); // Seed it with the root objects. walker.seed(gc_data); Object* obj = walker.next(); // All reference ids are shifted up native_int check_id = (native_int)last_snapshot_id << 1; int count = 0; int bytes = 0; while(obj) { if(!obj->has_id(state) || obj->id(state)->to_native() > check_id) { count++; bytes += obj->size_in_bytes(state->vm()); if(kind_of<String>(obj)) { std::cout << "#<String:" << obj << ">\n"; } else { std::cout << obj->to_s(state, true)->c_str(state) << "\n"; } } obj = walker.next(); } std::cout << count << " objects since snapshot.\n"; std::cout << bytes << " bytes since snapshot.\n"; }
void test(void) { ObjectManager<> m; Object<>* obj = Create<Item>(); m.add(obj->id(), obj); printf("%u\n", obj->id()); obj = Create<Item>(); m.add(obj->id(), obj); printf("%u\n", obj->id()); obj = Create<Item>(); m.add(obj->id(), obj); printf("%u\n", obj->id()); obj = Create<Object<> >(); m.add(obj->id(), obj); printf("%u\n", obj->id()); obj = Create<Object<> >(); m.add(obj->id(), obj); printf("%u\n", obj->id()); obj = Create<Object<> >(); m.add(obj->id(), obj); printf("%u\n", obj->id()); m.del(2); ItemNT* itemn = CreateNT<ItemNT>("hello"); printf("%u, %s, %u\n", itemn->id(), itemn->name().c_str(), itemn->tempid()); while (!m.add(itemn->id(), itemn)) itemn->id()++; printf("%u, %s, %u\n", itemn->id(), itemn->name().c_str(), itemn->tempid()); }
void SignalThread::print_backtraces() { STATE = shared_.env()->state; ThreadList* threads = shared_.thread_nexus()->threads(); for(ThreadList::iterator i = threads->begin(); i != threads->end(); ++i) { VM* vm = (*i)->as_vm(); if(!vm) continue; bool first = true; CallFrame* frame = vm->call_frame(); while(frame) { if(first) { logger::fatal("--- %s %d backtrace ---", vm->kind_name(), vm->thread_id()); first = false; } std::ostringstream stream; if(NativeMethodFrame* nmf = frame->native_method_frame()) { stream << static_cast<void*>(frame) << ": "; NativeMethod* nm = try_as<NativeMethod>(nmf->get_object(nmf->method())); if(nm && nm->name()->symbol_p()) { stream << "capi:" << nm->name()->debug_str(state) << " at "; stream << nm->file()->c_str(state); } else { stream << "unknown capi"; } } else if(frame->compiled_code) { if(frame->is_block_p(state)) { stream << "__block__"; } else { if(SingletonClass* sc = try_as<SingletonClass>(frame->module())) { Object* obj = sc->singleton(); if(Module* mod = try_as<Module>(obj)) { stream << mod->debug_str(state) << "."; } else { if(obj == G(main)) { stream << "MAIN."; } else { stream << "#<" << obj->class_object(state)->debug_str(state) << ":" << (void*)obj->id(state)->to_native() << ">."; } } } else if(IncludedModule* im = try_as<IncludedModule>(frame->module())) { stream << im->module()->debug_str(state) << "#"; } else { Symbol* name; std::string mod_name; if(frame->module()->nil_p()) { mod_name = frame->lexical_scope()->module()->debug_str(state); } else { if((name = try_as<Symbol>(frame->module()->module_name()))) { mod_name = name->debug_str(state); } else if((name = try_as<Symbol>( frame->lexical_scope()->module()->module_name()))) { mod_name = name->debug_str(state); } else { mod_name = "<anonymous module>"; } } stream << mod_name << "#"; } Symbol* name = try_as<Symbol>(frame->name()); if(name) { stream << name->debug_str(state); } else { stream << frame->compiled_code->name()->debug_str(state); } } stream << " in "; if(Symbol* file_sym = try_as<Symbol>(frame->compiled_code->file())) { stream << file_sym->debug_str(state) << ":" << frame->line(state); } else { stream << "<unknown>"; } stream << " (+" << frame->ip(); if(frame->is_inline_frame()) { stream << " inline"; } else if(frame->jitted_p()) { stream << " jit"; } stream << ")"; } logger::fatal(stream.str().c_str()); frame = frame->previous; } } }
void CallFrame::print_backtrace(STATE, std::ostream& stream, int total, bool filter) { CallFrame* cf = this; int i = -1; while(cf) { i++; if(total > 0 && i == total) return; if(NativeMethodFrame* nmf = cf->native_method_frame()) { stream << static_cast<void*>(cf) << ": "; NativeMethod* nm = try_as<NativeMethod>(nmf->get_object(nmf->method())); if(nm && nm->name()->symbol_p()) { stream << "capi:" << nm->name()->debug_str(state) << " at "; stream << nm->file()->c_str(state); } else { stream << "unknown capi"; } stream << std::endl; cf = cf->previous; continue; } if(!cf->compiled_code) { cf = cf->previous; continue; } if(filter && cf->compiled_code->kernel_method(state)) { cf = cf->previous; continue; } stream << static_cast<void*>(cf) << ": "; if(cf->is_block_p(state)) { stream << "__block__"; } else { if(SingletonClass* sc = try_as<SingletonClass>(cf->module())) { Object* obj = sc->attached_instance(); if(Module* mod = try_as<Module>(obj)) { stream << mod->debug_str(state) << "."; } else { if(obj == G(main)) { stream << "MAIN."; } else { stream << "#<" << obj->class_object(state)->debug_str(state) << ":" << (void*)obj->id(state)->to_native() << ">."; } } } else if(IncludedModule* im = try_as<IncludedModule>(cf->module())) { stream << im->module()->debug_str(state) << "#"; } else { Symbol* name; std::string mod_name; if(cf->module()->nil_p()) { mod_name = cf->constant_scope()->module()->debug_str(state); } else { if((name = try_as<Symbol>(cf->module()->module_name()))) { mod_name = name->debug_str(state); } else if((name = try_as<Symbol>( cf->constant_scope()->module()->module_name()))) { mod_name = name->debug_str(state); } else { mod_name = "<anonymous module>"; } } stream << mod_name << "#"; } Symbol* name = try_as<Symbol>(cf->name()); if(name) { stream << name->debug_str(state); } else { stream << cf->compiled_code->name()->debug_str(state); } } stream << " in "; if(Symbol* file_sym = try_as<Symbol>(cf->compiled_code->file())) { stream << file_sym->debug_str(state) << ":" << cf->line(state); } else { stream << "<unknown>"; } stream << " (+" << cf->ip(); if(cf->is_inline_frame()) { stream << " inline"; } else if(cf->jitted_p()) { stream << " jit"; } stream << ")"; stream << std::endl; cf = cf->previous; } }
bool Pointer::operator==(const Object &other) const { return !other.isNew() && id() == other.id(); }
Pointer::Pointer(const Object &obj) : className_(obj.className()), objectId_(obj.id()) { }