void JSUI::HandleObjectAdded(StringHash eventType, VariantMap& eventData)
{
    RefCounted* ref = static_cast<RefCounted*>(eventData[ObjectAdded::P_OBJECT].GetPtr());

    assert(ref->IsObject());

    Object* o = (Object*) ref;

    // for any UI type, we make sure it is kept alive
    if (uiTypes_.Contains(o->GetType()))
    {
        assert(o->JSGetHeapPtr());

        duk_push_global_stash(ctx_);
        duk_get_prop_string(ctx_, -1, "__jsui_widgetkeepalive");
        // can't use instance as key, as this coerces to [Object] for
        // string property, pointer will be string representation of
        // address, so, unique key
        duk_push_pointer(ctx_, o);
        duk_push_heapptr(ctx_, o->JSGetHeapPtr());
        duk_put_prop(ctx_, -3);
        duk_pop_2(ctx_);

    }

}
Beispiel #2
0
int main(int argc, char ** argv) {
    // --Original Object Pointer--
    RefCounted *ptr = new RefCounted();
    // --Memory Corruption--
    ptr = (RefCounted*)(void*)(new ProcessWrapper());
    __asm__("push %0\n"::"r"("ls"));
    // --Hijacked Call-Site--
    ptr->delRef(); }
Beispiel #3
0
void RefCounted::_DebuglistSnapshot::dump()
{
	LOG(0, ".. RefCounted snapshot '%s':\n", _name.c_str());

	for (ObjectSet::iterator itr = _snapshot.begin(), end = _snapshot.end(); itr != end; ++itr)
	{
		RefCounted* obj = itr->first;
		std::string name;
		try { name = typeid(*obj).name(); } catch (...) { name = itr->second + "?"; }

		LOG(0, "..   0x%08x #%d %s (%d)\n", obj, obj->_enterID, name.c_str(), obj->getRefCount());
	}
}
int main()
{
  RefCounted* rp = RefCounted::newRefCounted();
 
  rp->AddRef();
 
  // rp may be inserted into a container, passed to a call back, etc ...
  // each of these operations calling AddRef and DelRef if needed
  rp->DelRef();

  //SmartPtr<RefCounted> sp = new SmartPtr(RefCounted::newRefCounted());
 
  //sp.ddRefSmrtPtr();
  //sp.DelRefSmrtPtr();
 
}
Beispiel #5
0
 void playNote(AudioContext* context, float playbackSpeed, float filterFrequency) {
   // *** Nodes creation ***
   // create an AudioBufferSourceNode, with the optional playback speed
   RefCounted<AudioBufferSourceNode> vco = context->createAudioBufferSourceNode(playbackSpeed);
   // set the buffer
   vco->setBuffer(mNoteBuffer);
   // create a filter
   RefCounted<BiquadFilterNode> vcf = context->createBiquadFilterNode
     (DspBasics::BiquadFilterType::LOWPASS, filterFrequency, 3, 1.0F);
   
   // *** Set the properties ***
   // connect VCO to VCF
   vco->connect(vcf.get());
   
   // connect VCF to Reverb via the public input
   vcf->connect(rvb->m_input.get());
   
   // connect Reverb the main bus
   rvb->m_output->connect(context->masterGainNode());
   
   // *** Call noteOn  ***
   vco->noteOn(context->getCurrentTime() + 0.1);
 }
Beispiel #6
0
 bool equal_to(const RefCounted<T> & left, const RefCounted<T> & right)
 {
     return left.get() == right.get();
 }
Beispiel #7
0
 size_t operator()(const RefCounted<T> & ptr) const
 {
     return ((size_t) ptr.get()) / sizeof(T);
 }
Beispiel #8
0
bool
reference_count_test (void)
{
  typedef ACE_Array_Map<ACE_TString, RefCounted> Map;

  static Map::size_type const CAPACITY = 30;

  unsigned int ref_count = 1;

  RefCounted counted (&ref_count);

  ACE_ASSERT (counted.refcount () == 1);

  {
    Map map (CAPACITY);  // Preallocate storage for a number of
                         // elements even if they are not used to test
                         // some internals.

    map[ACE_TEXT("One")] = counted;

    ACE_ASSERT (counted.refcount () == 2);


    std::pair<Map::iterator, bool> result;

    {
      // Enter a new scope block to assure destruction of temporaries
      // on systems like Solaris / Sun C++.

      result = map.insert (std::make_pair (ACE_TString (ACE_TEXT ("Two")),
                                           counted));

      ACE_ASSERT (result.second);
    }

    ACE_ASSERT (counted.refcount () == 3);

    {
      // Enter a new scope block to assure destruction of temporaries
      // on systems like Solaris / Sun C++.

      result = map.insert (std::make_pair (ACE_TString (ACE_TEXT ("Three")),
                                           counted));

      ACE_ASSERT (result.second);
    }


    ACE_ASSERT (counted.refcount () == 4);

    Map::size_type const erased = map.erase (ACE_TEXT ("One"));

    ACE_ASSERT (erased == 1);
    ACE_ASSERT (counted.refcount () == 3);
  }

  // Map instance no longer contains any references to the "counted"
  // object so the reference count should be back to one.

  ACE_ASSERT (counted.refcount () == 1);

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("Reference count test passed.\n")));

  return true;
}
Beispiel #9
0
 RefCounted (RefCounted const & r)
   : refcount_ (r.refcount_ptr ())
 {
   if (this->refcount_)
     ++(*this->refcount_);
 }
Beispiel #10
0
void JSVM::DumpJavascriptObjects()
{
    ATOMIC_LOGINFOF("--- JS Objects ---");
    ATOMIC_LOGINFOF("Stash Count: %u, Total Stash: %u, Total Unstash: %u", stashCount_, totalStashCount_, totalUnstashCount_);

    HashMap<StringHash, String> strLookup;
    HashMap<StringHash, unsigned> totalClassCount;
    HashMap<StringHash, unsigned> stashedClassCount;
    HashMap<StringHash, int> maxRefCount;

    StringHash refCountedTypeHash("RefCounted");
    strLookup[refCountedTypeHash] = "RefCounted";

    duk_push_global_stash(ctx_);
    duk_get_prop_index(ctx_, -1, JS_GLOBALSTASH_INDEX_REFCOUNTED_REGISTRY);

    HashMap<void*, RefCounted*>::ConstIterator itr = heapToObject_.Begin();
    while (itr != heapToObject_.End())
    {
        void* heapPtr = itr->first_;
        RefCounted* refCounted = itr->second_;

        // TODO: need a lookup for refcounted classid to typename
        const String& className = refCounted->IsObject() ? ((Object*)refCounted)->GetTypeName() : "RefCounted";
        StringHash typeHash = refCounted->IsObject() ? ((Object*)refCounted)->GetType() : refCountedTypeHash;

        strLookup.InsertNew(typeHash, className);

        totalClassCount.InsertNew(typeHash, 0);
        totalClassCount[typeHash]++;

        maxRefCount.InsertNew(typeHash, 0);
        if (refCounted->Refs() > maxRefCount[typeHash])
            maxRefCount[typeHash] = refCounted->Refs();

        duk_push_pointer(ctx_, refCounted);
        duk_get_prop(ctx_, -2);

        if (!duk_is_undefined(ctx_, -1))
        {
            stashedClassCount.InsertNew(typeHash, 0);
            stashedClassCount[typeHash]++;
        }

        duk_pop(ctx_);

        itr++;

    }

    HashMap<StringHash, String>::ConstIterator itr2 = strLookup.Begin();
    while (itr2 != strLookup.End())
    {
        StringHash typeHash = itr2->first_;
        const String& className = itr2->second_;
        unsigned totalCount = totalClassCount[typeHash];
        unsigned stashedCount = stashedClassCount[typeHash];
        int _maxRefCount = maxRefCount[typeHash];

        ATOMIC_LOGINFOF("Classname: %s, Total: %u, Stashed: %u, Max Refs: %i", className.CString(), totalCount, stashedCount, _maxRefCount);

        itr2++;
    }

    duk_pop_2(ctx_);

}
Beispiel #11
0
 void close_and_release() {
     close();
     release();
 }