// Examples of how to (faulty) attach a raw pointer to a shared_ptr object void AttachToMemory() { const bool printExecutionPath = true; X* x = new X(printExecutionPath); { boost::shared_ptr<X> holder(x); } //std::cout << x->m_y->value; //ERROR x has been deleted when holder whent out of scope //delete x; //ERROR: }
void RootObject::gcProtect(JSObject* jsObject) { ASSERT(m_isValid); if (!m_protectCountSet.contains(jsObject)) { JSC::JSLockHolder holder(&globalObject()->vm()); JSC::gcProtect(jsObject); } m_protectCountSet.add(jsObject); }
static void drawSprite_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, SkGPipeState* state) { BitmapHolder holder(reader, op32, state); bool hasPaint = SkToBool(DrawOp_unpackFlags(op32) & kDrawBitmap_HasPaint_DrawOpFlag); const SkIPoint* point = skip<SkIPoint>(reader); const SkBitmap* bitmap = holder.getBitmap(); if (state->shouldDraw()) { canvas->drawSprite(*bitmap, point->fX, point->fY, hasPaint ? &state->paint() : NULL); } }
void log_wrapper::add_sink(log_handler_t h, level_t::type level_min, level_t::type level_max) { if (h) { log_router_t router; router.handle = h; router.level_min = level_min; router.level_max = level_max; util::lock::write_lock_holder<util::lock::spin_rw_lock> holder(log_sinks_lock_); log_sinks_.push_back(router); }; }
void cLog::xwriteW(LPCWSTR format, ... ) { ZLockHolder holder(&m_formatWriteMutex); va_list vl; va_start (vl, format); vswprintf_s(g_szWideBuffer, MAX_SIZE_BUFFER, format, vl); va_end (vl); writeW(g_szWideBuffer); }
Timer(v8::Local<v8::Function> callback, int32_t timeout, bool repeat = false) : m_timeout(timeout), m_repeat(repeat), m_cancel(false) { wrap()->SetHiddenValue(v8::String::NewFromUtf8(holder()->m_isolate, "callback"), callback); if (m_timeout < 1) m_timeout = 1; sleep(); Ref(); }
result_t SandBox::clone(obj_ptr<SandBox_base> &retVal) { obj_ptr<SandBox> sbox = new SandBox(); sbox->m_name = m_name; sbox->wrap()->SetHiddenValue(holder()->NewFromUtf8("_mods"), mods()->Clone()); retVal = sbox; return 0; }
void Check_PriorDeclaration_Base::checkProgram(const AST_Program::shared_ptr &program) { { ASTTypeCheckingHolder holder(this); // addVarList(program->varList()); addDefList(program->defList()); // checkInternalProgram(program); } }
result_t HttpUploadCollection::_named_enumerator(v8::Local<v8::Array>& retVal) { int32_t i; Isolate* isolate = holder(); retVal = v8::Array::New(isolate->m_isolate); for (i = 0; i < m_count; i++) retVal->Set(i, isolate->NewString(m_map[i].first)); return 0; }
/** * This method is called by the effect system when a material needs * to draw using a cloud texture. */ bool operator()(ID3DXEffect* pEffect, D3DXHANDLE constantHandle) { SimpleMutexHolder holder( mutex_ ); if (pTexture_ && pTexture_->pTexture()) pEffect->SetTexture(constantHandle, pTexture_->pTexture()); else pEffect->SetTexture(constantHandle, NULL); return true; }
Database* Database::removeFirstAtExitDatabase() { LockHolder holder(registrationLock); Database* result = firstDatabase; if (result) { firstDatabase = result->m_nextRegisteredDatabase; result->m_nextRegisteredDatabase = 0; result->m_shouldSaveAtExit = false; } return result; }
void JSLock::lock() { ThreadIdentifier currentThread = WTF::currentThread(); { SpinLockHolder holder(&m_spinLock); if (m_ownerThread == currentThread && m_lockCount) { m_lockCount++; return; } } m_lock.lock(); { SpinLockHolder holder(&m_spinLock); m_ownerThread = currentThread; ASSERT(!m_lockCount); m_lockCount = 1; } }
static void drawBitmap_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, SkGPipeState* state) { BitmapHolder holder(reader, op32, state); bool hasPaint = SkToBool(DrawOp_unpackFlags(op32) & kDrawBitmap_HasPaint_DrawOpFlag); SkScalar left = reader->readScalar(); SkScalar top = reader->readScalar(); const SkBitmap* bitmap = holder.getBitmap(); if (state->shouldDraw()) { canvas->drawBitmap(*bitmap, left, top, hasPaint ? &state->paint() : NULL); } }
result_t MongoDB::runCommand(exlib::string cmd, v8::Local<v8::Value> arg, v8::Local<v8::Object> &retVal) { bson bbq; bson_init(&bbq); encodeValue(holder(), &bbq, cmd.c_str(), arg); bson_finish(&bbq); return bsonHandler(&bbq, retVal); }
void * SipperProxyStatSockAcceptor::_threadStart(void *inData) { pthread_detach(pthread_self()); SipperProxyRefObjHolder<SipperProxyStatSockAcceptor> holder((SipperProxyStatSockAcceptor *)inData); SipperProxyStatSockAcceptor *obj = holder.getObj(); obj->_mgr->addAcceptor(obj); obj->_processIncomingConnections(); obj->_mgr->removeAcceptor(obj); return NULL; }
// ------------------------------------------------------------------ // ciMethod::resolve_invoke // // Given a known receiver klass, find the target for the call. // Return NULL if the call has no target or the target is abstract. ciMethod* ciMethod::resolve_invoke(ciKlass* caller, ciKlass* exact_receiver) { check_is_loaded(); VM_ENTRY_MARK; KlassHandle caller_klass (THREAD, caller->get_Klass()); KlassHandle h_recv (THREAD, exact_receiver->get_Klass()); KlassHandle h_resolved (THREAD, holder()->get_Klass()); Symbol* h_name = name()->get_symbol(); Symbol* h_signature = signature()->get_symbol(); methodHandle m; // Only do exact lookup if receiver klass has been linked. Otherwise, // the vtable has not been setup, and the LinkResolver will fail. if (h_recv->oop_is_array() || InstanceKlass::cast(h_recv())->is_linked() && !exact_receiver->is_interface()) { if (holder()->is_interface()) { m = LinkResolver::resolve_interface_call_or_null(h_recv, h_resolved, h_name, h_signature, caller_klass); } else { m = LinkResolver::resolve_virtual_call_or_null(h_recv, h_resolved, h_name, h_signature, caller_klass); } } if (m.is_null()) { // Return NULL only if there was a problem with lookup (uninitialized class, etc.) return NULL; } ciMethod* result = this; if (m() != get_Method()) { result = CURRENT_THREAD_ENV->get_method(m()); } // Don't return abstract methods because they aren't // optimizable or interesting. if (result->is_abstract()) { return NULL; } else { return result; } }
result_t Queue::toArray(v8::Local<v8::Array> &retVal) { v8::Local<v8::Array> a = v8::Array::New(holder()->m_isolate, (int32_t) m_list.size()); int32_t i = 0; for (std::list<VariantEx>::iterator it = m_list.begin(); it != m_list.end(); ++it) a->Set(i++, *it); retVal = a; return 0; }
TEST(SMARTPOINTER, simplestorage) { double remember = 15.2; { double* test = new double[1]; test[0] = remember; spointer<double> dptr(test); EXPECT_EQ(dptr.use_count(), 1); dcontain::binode<spointer<double> > holder(dptr); EXPECT_EQ(dptr.use_count(), 2); } }
Framework FrameworkFactory::NewFramework( const FrameworkConfiguration& configuration, std::ostream* logger) { std::unique_ptr<CoreBundleContext> ctx( new CoreBundleContext(configuration, logger)); auto fwCtx = ctx.get(); std::shared_ptr<CoreBundleContext> holder( std::make_shared<CoreBundleContextHolder>(std::move(ctx)), fwCtx); holder->SetThis(holder); return Framework(holder->systemBundle); }
inline typename return_rvalue_from_python<T>::result_type return_rvalue_from_python<T>::operator()(PyObject* obj) { // Take possession of the source object here. If the result is in // fact going to be a copy of an lvalue embedded in the object, // and we take possession inside rvalue_result_from_python, it // will be destroyed too early. handle<> holder(obj); return *(T*) (rvalue_result_from_python)(obj, m_data.stage1); }
//------------------------------------------------------------------------------ BackgroundWorker::~BackgroundWorker() { { std::lock_guard< std::mutex > holder(impl_->backgroundJobMutex_); impl_->exit_ = true; impl_->jobWaiter_.notify_all(); } for (size_t i = 0; i < impl_->backgroundThreads_.size(); ++i) { impl_->backgroundThreads_[ i ]->join(); } }
result_t MongoDB::runCommand(v8::Local<v8::Object> cmd, v8::Local<v8::Object> &retVal) { bson bbq; result_t hr; hr = encodeObject(holder(), &bbq, cmd); if (hr < 0) return hr; return bsonHandler(&bbq, retVal); }
//------------------------------------------------------------------------------ void BackgroundWorker::queueBackgroundJob(IBackgroundWorker::JobFunction job) { if (impl_->exit_) { return; } { std::lock_guard< std::mutex > holder(impl_->backgroundJobMutex_); impl_->backgroundJobs_.emplace_back(job); } impl_->jobWaiter_.notify_one(); }
void save(Document& d, xmlpp_holder_type& e) const { xmlpp::element_iterator holder(e); for (InIterator iter = firstIter; iter != endIter; ++iter) { if ( policy.valid(*iter, SAVE) ) { policy.save(d, *holder++, *iter); } } }
bool CallCounter::IsTier0CallCountingEnabled(MethodDesc* pMethodDesc) { WRAPPER_NO_CONTRACT; _ASSERTE(pMethodDesc != NULL); _ASSERTE(pMethodDesc->IsEligibleForTieredCompilation()); _ASSERTE(IsEligibleForTier0CallCounting(pMethodDesc)); SpinLockHolder holder(&m_lock); const CallCounterEntry *entry = m_methodToCallCount.LookupPtr(pMethodDesc); return entry == nullptr || entry->IsTier0CallCountingEnabled(); }
void Database::removeDatabaseFromAtExit() { LockHolder holder(registrationLock); for (Database** current = &firstDatabase; *current; current = &(*current)->m_nextRegisteredDatabase) { if (*current != this) continue; *current = m_nextRegisteredDatabase; m_nextRegisteredDatabase = 0; m_shouldSaveAtExit = false; break; } }
QString QSqlResultPrivate::namedToPositionalBinding(const QString &query) { int n = query.size(); QString result; result.reserve(n); QChar closingQuote; int count = 0; int i = 0; bool ignoreBraces = (sqldriver->d_func()->dbmsType == QSqlDriver::PostgreSQL); while (i < n) { QChar ch = query.at(i); if (!closingQuote.isNull()) { if (ch == closingQuote) { if (closingQuote == QLatin1Char(']') && i + 1 < n && query.at(i + 1) == closingQuote) { // consume the extra character. don't close. ++i; result += ch; } else { closingQuote = QChar(); } } result += ch; ++i; } else { if (ch == QLatin1Char(':') && (i == 0 || query.at(i - 1) != QLatin1Char(':')) && (i + 1 < n && qIsAlnum(query.at(i + 1)))) { int pos = i + 2; while (pos < n && qIsAlnum(query.at(pos))) ++pos; QString holder(query.mid(i, pos - i)); indexes[holder].append(count++); holders.append(QHolder(holder, i)); result += QLatin1Char('?'); i = pos; } else { if (ch == QLatin1Char('\'') || ch == QLatin1Char('"') || ch == QLatin1Char('`')) closingQuote = ch; else if (!ignoreBraces && ch == QLatin1Char('[')) closingQuote = QLatin1Char(']'); result += ch; ++i; } } } result.squeeze(); values.resize(holders.size()); return result; }
void RootObject::gcUnprotect(JSObject* jsObject) { ASSERT(m_isValid); if (!jsObject) return; if (m_protectCountSet.count(jsObject) == 1) { JSC::JSLockHolder holder(&globalObject()->vm()); JSC::gcUnprotect(jsObject); } m_protectCountSet.remove(jsObject); }
result_t Buffer::toArray(v8::Local<v8::Array>& retVal) { Isolate* isolate = holder(); v8::Local<v8::Array> a = v8::Array::New(isolate->m_isolate, (int32_t) m_data.length()); int32_t i; for (i = 0; i < (int32_t) m_data.length(); i++) a->Set(i, v8::Number::New(isolate->m_isolate, (unsigned char) m_data[i])); retVal = a; return 0; }
result_t RedisSortedSet::add(const v8::FunctionCallbackInfo<v8::Value> &args, int32_t &retVal) { v8::Local<v8::Array> mss = v8::Array::New(holder()->m_isolate); int32_t i; for (i = 0; i < (int32_t)args.Length(); i += 2) { mss->Set(i, args[i + 1]); mss->Set(i + 1, args[i]); } return m_rdb->doCommand("ZADD", m_key, mss, retVal); }