merging more memory fixes
This commit is contained in:
		
				
					committed by
					
						
						Peli de Halleux
					
				
			
			
				
	
			
			
			
						parent
						
							0a380a70d1
						
					
				
				
					commit
					7556796eb6
				
			@@ -79,7 +79,7 @@ namespace pxt {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
      intcheck(vtable->methods[0] == &RefRecord_destroy, ERR_SIZE, 3);
 | 
					      intcheck(vtable->methods[0] == &RefRecord_destroy, ERR_SIZE, 3);
 | 
				
			||||||
      intcheck(vtable->methods[1] == &RefRecord_print, ERR_SIZE, 4);
 | 
					      intcheck(vtable->methods[1] == &RefRecord_print, ERR_SIZE, 4);
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
      void *ptr = ::operator new(vtable->numbytes);
 | 
					      void *ptr = ::operator new(vtable->numbytes);
 | 
				
			||||||
      RefRecord *r = new (ptr) RefRecord(PXT_VTABLE_TO_INT(vtable));
 | 
					      RefRecord *r = new (ptr) RefRecord(PXT_VTABLE_TO_INT(vtable));
 | 
				
			||||||
      memset(r->fields, 0, vtable->numbytes - sizeof(RefRecord));
 | 
					      memset(r->fields, 0, vtable->numbytes - sizeof(RefRecord));
 | 
				
			||||||
@@ -117,7 +117,6 @@ namespace pxt {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    void RefObject::destroy() {
 | 
					    void RefObject::destroy() {
 | 
				
			||||||
      ((RefObjectMethod)getVTable()->methods[0])(this);
 | 
					      ((RefObjectMethod)getVTable()->methods[0])(this);
 | 
				
			||||||
      delete this;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void RefObject::print() {
 | 
					    void RefObject::print() {
 | 
				
			||||||
@@ -245,6 +244,7 @@ namespace pxt {
 | 
				
			|||||||
          this->data[i] = 0;
 | 
					          this->data[i] = 0;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      this->data.resize(0);
 | 
					      this->data.resize(0);
 | 
				
			||||||
 | 
					      delete this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void RefCollection::print()
 | 
					    void RefCollection::print()
 | 
				
			||||||
@@ -278,6 +278,7 @@ namespace pxt {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    void RefLocal::destroy()
 | 
					    void RefLocal::destroy()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					      delete this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    PXT_VTABLE_CTOR(RefLocal) {
 | 
					    PXT_VTABLE_CTOR(RefLocal) {
 | 
				
			||||||
@@ -296,6 +297,7 @@ namespace pxt {
 | 
				
			|||||||
    void RefRefLocal::destroy()
 | 
					    void RefRefLocal::destroy()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      decr(v);
 | 
					      decr(v);
 | 
				
			||||||
 | 
					      delete this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    PXT_VTABLE_BEGIN(RefMap, 0, RefMapMarker)
 | 
					    PXT_VTABLE_BEGIN(RefMap, 0, RefMapMarker)
 | 
				
			||||||
@@ -310,6 +312,7 @@ namespace pxt {
 | 
				
			|||||||
        data[i].val = 0;
 | 
					        data[i].val = 0;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      data.resize(0);
 | 
					      data.resize(0);
 | 
				
			||||||
 | 
					      delete this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int RefMap::findIdx(uint32_t key) {
 | 
					    int RefMap::findIdx(uint32_t key) {
 | 
				
			||||||
@@ -334,7 +337,7 @@ namespace pxt {
 | 
				
			|||||||
    for(std::set<RefObject*>::iterator itr = allptrs.begin();itr!=allptrs.end();itr++)
 | 
					    for(std::set<RefObject*>::iterator itr = allptrs.begin();itr!=allptrs.end();itr++)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      (*itr)->print();
 | 
					      (*itr)->print();
 | 
				
			||||||
    }    
 | 
					    }
 | 
				
			||||||
    printf("\n");
 | 
					    printf("\n");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
@@ -347,16 +350,16 @@ namespace pxt {
 | 
				
			|||||||
    // ---------------------------------------------------------------------------
 | 
					    // ---------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    map<pair<int, int>, Action> handlersMap;
 | 
					    map<pair<int, int>, Action> handlersMap;
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    MicroBitEvent lastEvent;
 | 
					    MicroBitEvent lastEvent;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // We have the invariant that if [dispatchEvent] is registered against the DAL
 | 
					    // We have the invariant that if [dispatchEvent] is registered against the DAL
 | 
				
			||||||
    // for a given event, then [handlersMap] contains a valid entry for that
 | 
					    // for a given event, then [handlersMap] contains a valid entry for that
 | 
				
			||||||
    // event.
 | 
					    // event.
 | 
				
			||||||
    void dispatchEvent(MicroBitEvent e) {
 | 
					    void dispatchEvent(MicroBitEvent e) {
 | 
				
			||||||
      
 | 
					
 | 
				
			||||||
      lastEvent = e;
 | 
					      lastEvent = e;
 | 
				
			||||||
      
 | 
					
 | 
				
			||||||
      Action curr = handlersMap[{ e.source, e.value }];
 | 
					      Action curr = handlersMap[{ e.source, e.value }];
 | 
				
			||||||
      if (curr)
 | 
					      if (curr)
 | 
				
			||||||
        runAction1(curr, e.value);
 | 
					        runAction1(curr, e.value);
 | 
				
			||||||
@@ -389,7 +392,7 @@ namespace pxt {
 | 
				
			|||||||
        create_fiber((void(*)(void*))runAction0, (void*)a, fiberDone);
 | 
					        create_fiber((void(*)(void*))runAction0, (void*)a, fiberDone);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void error(ERROR code, int subcode)
 | 
					  void error(ERROR code, int subcode)
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
@@ -441,10 +444,10 @@ namespace pxt {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    // unique group for radio based on source hash
 | 
					    // unique group for radio based on source hash
 | 
				
			||||||
    // ::touch_develop::micro_bit::radioDefaultGroup = programHash();
 | 
					    // ::touch_develop::micro_bit::radioDefaultGroup = programHash();
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    // repeat error 4 times and restart as needed
 | 
					    // repeat error 4 times and restart as needed
 | 
				
			||||||
    microbit_panic_timeout(4);
 | 
					    microbit_panic_timeout(4);
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    int32_t ver = *pc++;
 | 
					    int32_t ver = *pc++;
 | 
				
			||||||
    checkStr(ver == 0x4209, ":( Bad runtime version");
 | 
					    checkStr(ver == 0x4209, ":( Bad runtime version");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -473,6 +476,6 @@ namespace pxt {
 | 
				
			|||||||
  {
 | 
					  {
 | 
				
			||||||
    exec_binary((int32_t*)functionsAndBytecode);
 | 
					    exec_binary((int32_t*)functionsAndBytecode);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}  
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// vim: ts=2 sw=2 expandtab
 | 
					// vim: ts=2 sw=2 expandtab
 | 
				
			||||||
		Reference in New Issue
	
	Block a user