[Tinyos-2-commits] CVS: tinyos-2.x/tos/lib/tossim TOSSIM.py, 1.1.2.7, 1.1.2.8 TossimActiveMessageP.nc, 1.1.2.8, 1.1.2.9 TossimRadioMsg.h, 1.1.2.1, 1.1.2.2 hashtable.h, 1.1.2.1, 1.1.2.2 sim_packet.c, 1.1.2.3, 1.1.2.4 tos.h, 1.1.2.10, 1.1.2.11 tossim.c, 1.1.2.9, 1.1.2.10 tossim.h, 1.1.2.8, 1.1.2.9 tossim_wrap.cxx, 1.1.2.7, 1.1.2.8

Phil Levis scipio at users.sourceforge.net
Thu Aug 3 18:41:18 PDT 2006


Update of /cvsroot/tinyos/tinyos-2.x/tos/lib/tossim
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv16682

Modified Files:
      Tag: tinyos-2_0_devel-BRANCH
	TOSSIM.py TossimActiveMessageP.nc TossimRadioMsg.h hashtable.h 
	sim_packet.c tos.h tossim.c tossim.h tossim_wrap.cxx 
Log Message:
Removed memory leak in variable allocation. Support new AM source
address.


Index: TOSSIM.py
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/tossim/TOSSIM.py,v
retrieving revision 1.1.2.7
retrieving revision 1.1.2.8
diff -C2 -d -r1.1.2.7 -r1.1.2.8
*** TOSSIM.py	7 Mar 2006 02:35:48 -0000	1.1.2.7
--- TOSSIM.py	4 Aug 2006 01:41:15 -0000	1.1.2.8
***************
*** 5,9 ****
  import _TOSSIM
  
! def _swig_setattr(self,class_type,name,value):
      if (name == "this"):
          if isinstance(value, class_type):
--- 5,9 ----
  import _TOSSIM
  
! def _swig_setattr_nondynamic(self,class_type,name,value,static=1):
      if (name == "this"):
          if isinstance(value, class_type):
***************
*** 14,18 ****
      method = class_type.__swig_setmethods__.get(name,None)
      if method: return method(self,value)
!     self.__dict__[name] = value
  
  def _swig_getattr(self,class_type,name):
--- 14,24 ----
      method = class_type.__swig_setmethods__.get(name,None)
      if method: return method(self,value)
!     if (not static) or hasattr(self,name) or (name == "thisown"):
!         self.__dict__[name] = value
!     else:
!         raise AttributeError("You cannot add attributes to %s" % self)
! 
! def _swig_setattr(self,class_type,name,value):
!     return _swig_setattr_nondynamic(self,class_type,name,value,0)
  
  def _swig_getattr(self,class_type,name):
***************
*** 37,41 ****
      __getattr__ = lambda self, name: _swig_getattr(self, MAC, name)
      def __repr__(self):
!         return "<C MAC instance at %s>" % (self.this,)
      def __init__(self, *args):
          _swig_setattr(self, MAC, 'this', _TOSSIM.new_MAC(*args))
--- 43,47 ----
      __getattr__ = lambda self, name: _swig_getattr(self, MAC, name)
      def __repr__(self):
!         return "<%s.%s; proxy of C++ MAC instance at %s>" % (self.__class__.__module__, self.__class__.__name__, self.this,)
      def __init__(self, *args):
          _swig_setattr(self, MAC, 'this', _TOSSIM.new_MAC(*args))
***************
*** 45,48 ****
--- 51,55 ----
              if self.thisown: destroy(self)
          except: pass
+ 
      def initHigh(*args): return _TOSSIM.MAC_initHigh(*args)
      def initLow(*args): return _TOSSIM.MAC_initLow(*args)
***************
*** 83,87 ****
      __getattr__ = lambda self, name: _swig_getattr(self, Radio, name)
      def __repr__(self):
!         return "<C Radio instance at %s>" % (self.this,)
      def __init__(self, *args):
          _swig_setattr(self, Radio, 'this', _TOSSIM.new_Radio(*args))
--- 90,94 ----
      __getattr__ = lambda self, name: _swig_getattr(self, Radio, name)
      def __repr__(self):
!         return "<%s.%s; proxy of C++ Radio instance at %s>" % (self.__class__.__module__, self.__class__.__name__, self.this,)
      def __init__(self, *args):
          _swig_setattr(self, Radio, 'this', _TOSSIM.new_Radio(*args))
***************
*** 91,94 ****
--- 98,102 ----
              if self.thisown: destroy(self)
          except: pass
+ 
      def add(*args): return _TOSSIM.Radio_add(*args)
      def gain(*args): return _TOSSIM.Radio_gain(*args)
***************
*** 111,115 ****
      __getattr__ = lambda self, name: _swig_getattr(self, Packet, name)
      def __repr__(self):
!         return "<C Packet instance at %s>" % (self.this,)
      def __init__(self, *args):
          _swig_setattr(self, Packet, 'this', _TOSSIM.new_Packet(*args))
--- 119,123 ----
      __getattr__ = lambda self, name: _swig_getattr(self, Packet, name)
      def __repr__(self):
!         return "<%s.%s; proxy of C++ Packet instance at %s>" % (self.__class__.__module__, self.__class__.__name__, self.this,)
      def __init__(self, *args):
          _swig_setattr(self, Packet, 'this', _TOSSIM.new_Packet(*args))
***************
*** 119,122 ****
--- 127,131 ----
              if self.thisown: destroy(self)
          except: pass
+ 
      def setDestination(*args): return _TOSSIM.Packet_setDestination(*args)
      def destination(*args): return _TOSSIM.Packet_destination(*args)
***************
*** 145,149 ****
      __getattr__ = lambda self, name: _swig_getattr(self, variable_string_t, name)
      def __repr__(self):
!         return "<C variable_string_t instance at %s>" % (self.this,)
      __swig_setmethods__["type"] = _TOSSIM.variable_string_t_type_set
      __swig_getmethods__["type"] = _TOSSIM.variable_string_t_type_get
--- 154,158 ----
      __getattr__ = lambda self, name: _swig_getattr(self, variable_string_t, name)
      def __repr__(self):
!         return "<%s.%s; proxy of C++ variable_string_t instance at %s>" % (self.__class__.__module__, self.__class__.__name__, self.this,)
      __swig_setmethods__["type"] = _TOSSIM.variable_string_t_type_set
      __swig_getmethods__["type"] = _TOSSIM.variable_string_t_type_get
***************
*** 166,169 ****
--- 175,179 ----
          except: pass
  
+ 
  class variable_string_tPtr(variable_string_t):
      def __init__(self, this):
***************
*** 179,183 ****
      __getattr__ = lambda self, name: _swig_getattr(self, nesc_app_t, name)
      def __repr__(self):
!         return "<C nesc_app_t instance at %s>" % (self.this,)
      __swig_setmethods__["numVariables"] = _TOSSIM.nesc_app_t_numVariables_set
      __swig_getmethods__["numVariables"] = _TOSSIM.nesc_app_t_numVariables_get
--- 189,193 ----
      __getattr__ = lambda self, name: _swig_getattr(self, nesc_app_t, name)
      def __repr__(self):
!         return "<%s.%s; proxy of C++ nesc_app_t instance at %s>" % (self.__class__.__module__, self.__class__.__name__, self.this,)
      __swig_setmethods__["numVariables"] = _TOSSIM.nesc_app_t_numVariables_set
      __swig_getmethods__["numVariables"] = _TOSSIM.nesc_app_t_numVariables_get
***************
*** 200,203 ****
--- 210,214 ----
          except: pass
  
+ 
  class nesc_app_tPtr(nesc_app_t):
      def __init__(self, this):
***************
*** 213,217 ****
      __getattr__ = lambda self, name: _swig_getattr(self, Variable, name)
      def __repr__(self):
!         return "<C Variable instance at %s>" % (self.this,)
      def __init__(self, *args):
          _swig_setattr(self, Variable, 'this', _TOSSIM.new_Variable(*args))
--- 224,228 ----
      __getattr__ = lambda self, name: _swig_getattr(self, Variable, name)
      def __repr__(self):
!         return "<%s.%s; proxy of C++ Variable instance at %s>" % (self.__class__.__module__, self.__class__.__name__, self.this,)
      def __init__(self, *args):
          _swig_setattr(self, Variable, 'this', _TOSSIM.new_Variable(*args))
***************
*** 221,224 ****
--- 232,236 ----
              if self.thisown: destroy(self)
          except: pass
+ 
      def getData(*args): return _TOSSIM.Variable_getData(*args)
  
***************
*** 236,240 ****
      __getattr__ = lambda self, name: _swig_getattr(self, Mote, name)
      def __repr__(self):
!         return "<C Mote instance at %s>" % (self.this,)
      def __init__(self, *args):
          _swig_setattr(self, Mote, 'this', _TOSSIM.new_Mote(*args))
--- 248,252 ----
      __getattr__ = lambda self, name: _swig_getattr(self, Mote, name)
      def __repr__(self):
!         return "<%s.%s; proxy of C++ Mote instance at %s>" % (self.__class__.__module__, self.__class__.__name__, self.this,)
      def __init__(self, *args):
          _swig_setattr(self, Mote, 'this', _TOSSIM.new_Mote(*args))
***************
*** 244,247 ****
--- 256,260 ----
              if self.thisown: destroy(self)
          except: pass
+ 
      def id(*args): return _TOSSIM.Mote_id(*args)
      def euid(*args): return _TOSSIM.Mote_euid(*args)
***************
*** 267,271 ****
      __getattr__ = lambda self, name: _swig_getattr(self, Tossim, name)
      def __repr__(self):
!         return "<C Tossim instance at %s>" % (self.this,)
      def __init__(self, *args):
          _swig_setattr(self, Tossim, 'this', _TOSSIM.new_Tossim(*args))
--- 280,284 ----
      __getattr__ = lambda self, name: _swig_getattr(self, Tossim, name)
      def __repr__(self):
!         return "<%s.%s; proxy of C++ Tossim instance at %s>" % (self.__class__.__module__, self.__class__.__name__, self.this,)
      def __init__(self, *args):
          _swig_setattr(self, Tossim, 'this', _TOSSIM.new_Tossim(*args))
***************
*** 275,278 ****
--- 288,292 ----
              if self.thisown: destroy(self)
          except: pass
+ 
      def init(*args): return _TOSSIM.Tossim_init(*args)
      def time(*args): return _TOSSIM.Tossim_time(*args)

Index: TossimActiveMessageP.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/tossim/TossimActiveMessageP.nc,v
retrieving revision 1.1.2.8
retrieving revision 1.1.2.9
diff -C2 -d -r1.1.2.8 -r1.1.2.9
*** TossimActiveMessageP.nc	18 May 2006 00:18:26 -0000	1.1.2.8
--- TossimActiveMessageP.nc	4 Aug 2006 01:41:15 -0000	1.1.2.9
***************
*** 63,67 ****
      tossim_header_t* header = getHeader(amsg);
      header->type = id;
!     header->addr = addr;
      header->length = len;
      return call Model.send((int)addr, amsg, len + sizeof(tossim_header_t));
--- 63,68 ----
      tossim_header_t* header = getHeader(amsg);
      header->type = id;
!     header->dest = addr;
!     header->src = call AMPacket.address();
      header->length = len;
      return call Model.send((int)addr, amsg, len + sizeof(tossim_header_t));
***************
*** 121,125 ****
    event bool Model.shouldAck(message_t* msg) {
      tossim_header_t* header = getHeader(msg);
!     if (header->addr == call amAddress()) {
        dbg("Acks", "addressed to me so ack it,");
        return TRUE;
--- 122,126 ----
    event bool Model.shouldAck(message_t* msg) {
      tossim_header_t* header = getHeader(msg);
!     if (header->dest == call amAddress()) {
        dbg("Acks", "addressed to me so ack it,");
        return TRUE;
***************
*** 134,145 ****
    command am_addr_t AMPacket.destination(message_t* amsg) {
      tossim_header_t* header = getHeader(amsg);
!     return header->addr;
    }
  
    command void AMPacket.setDestination(message_t* amsg, am_addr_t addr) {
      tossim_header_t* header = getHeader(amsg);
!     header->addr = addr;
    }
  
    command bool AMPacket.isForMe(message_t* amsg) {
      return (call AMPacket.destination(amsg) == call AMPacket.address() ||
--- 135,156 ----
    command am_addr_t AMPacket.destination(message_t* amsg) {
      tossim_header_t* header = getHeader(amsg);
!     return header->dest;
    }
  
    command void AMPacket.setDestination(message_t* amsg, am_addr_t addr) {
      tossim_header_t* header = getHeader(amsg);
!     header->dest = addr;
    }
  
+   command am_addr_t AMPacket.source(message_t* amsg) {
+     tossim_header_t* header = getHeader(amsg);
+     return header->src;
+   }
+ 
+   command void AMPacket.setSource(message_t* amsg, am_addr_t addr) {
+     tossim_header_t* header = getHeader(amsg);
+     header->src = addr;
+   }
+   
    command bool AMPacket.isForMe(message_t* amsg) {
      return (call AMPacket.destination(amsg) == call AMPacket.address() ||

Index: TossimRadioMsg.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/tossim/TossimRadioMsg.h,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -d -r1.1.2.1 -r1.1.2.2
*** TossimRadioMsg.h	19 Dec 2005 23:51:20 -0000	1.1.2.1
--- TossimRadioMsg.h	4 Aug 2006 01:41:15 -0000	1.1.2.2
***************
*** 5,9 ****
  
  typedef nx_struct tossim_header {
!   nx_am_addr_t addr;
    nx_uint8_t length;
    nx_am_id_t type;
--- 5,10 ----
  
  typedef nx_struct tossim_header {
!   nx_am_addr_t dest;
!   nx_am_addr_t src;
    nx_uint8_t length;
    nx_am_id_t type;

Index: hashtable.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/tossim/hashtable.h,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -d -r1.1.2.1 -r1.1.2.2
*** hashtable.h	22 Nov 2005 23:29:13 -0000	1.1.2.1
--- hashtable.h	4 Aug 2006 01:41:15 -0000	1.1.2.2
***************
*** 3,6 ****
--- 3,9 ----
  #ifndef __HASHTABLE_CWC22_H__
  #define __HASHTABLE_CWC22_H__
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
  
  struct hashtable;
***************
*** 164,167 ****
--- 167,175 ----
  hashtable_destroy(struct hashtable *h, int free_values);
  
+ #ifdef __cplusplus
+ }
+ #endif
+ 
+ 
  #endif /* __HASHTABLE_CWC22_H__ */
  
***************
*** 198,199 ****
--- 206,208 ----
   * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
+ 

Index: sim_packet.c
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/tossim/sim_packet.c,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -C2 -d -r1.1.2.3 -r1.1.2.4
*** sim_packet.c	16 Mar 2006 19:59:11 -0000	1.1.2.3
--- sim_packet.c	4 Aug 2006 01:41:15 -0000	1.1.2.4
***************
*** 46,54 ****
  void sim_packet_set_destination(sim_packet_t* msg, uint16_t dest)__attribute__ ((C, spontaneous)) {
    tossim_header_t* hdr = getHeader((message_t*)msg);
!   hdr->addr = dest;
  }__attribute__ ((C, spontaneous))
  uint16_t sim_packet_destination(sim_packet_t* msg)__attribute__ ((C, spontaneous)) {
    tossim_header_t* hdr = getHeader((message_t*)msg);
!   return hdr->addr;
  }
    
--- 46,55 ----
  void sim_packet_set_destination(sim_packet_t* msg, uint16_t dest)__attribute__ ((C, spontaneous)) {
    tossim_header_t* hdr = getHeader((message_t*)msg);
!   hdr->dest = dest;
  }__attribute__ ((C, spontaneous))
+ 
  uint16_t sim_packet_destination(sim_packet_t* msg)__attribute__ ((C, spontaneous)) {
    tossim_header_t* hdr = getHeader((message_t*)msg);
!   return hdr->dest;
  }
    

Index: tos.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/tossim/tos.h,v
retrieving revision 1.1.2.10
retrieving revision 1.1.2.11
diff -C2 -d -r1.1.2.10 -r1.1.2.11
*** tos.h	31 Jan 2006 19:25:51 -0000	1.1.2.10
--- tos.h	4 Aug 2006 01:41:15 -0000	1.1.2.11
***************
*** 87,91 ****
  #include <sim_event_queue.c>
  #include <sim_tossim.c>
- #include <hashtable.c>
  #include <sim_mac.c>
  #include <sim_packet.c>
--- 87,90 ----

Index: tossim.c
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/tossim/tossim.c,v
retrieving revision 1.1.2.9
retrieving revision 1.1.2.10
diff -C2 -d -r1.1.2.9 -r1.1.2.10
*** tossim.c	7 Mar 2006 02:35:48 -0000	1.1.2.9
--- tossim.c	4 Aug 2006 01:41:15 -0000	1.1.2.10
***************
*** 40,43 ****
--- 40,44 ----
  #include <stdio.h>
  #include <string.h>
+ #include <hashtable.h>
  
  #include <mac.c>
***************
*** 75,84 ****
--- 76,106 ----
      ptr = NULL;
    }
+   printf("Allocated variable %s\n", realName);
  }
  
  Variable::~Variable() {
+   printf("Freeing variable %s\n", realName);
    free(data);
+   free(realName);
  }
  
+ /* This is the sdbm algorithm, taken from
+    http://www.cs.yorku.ca/~oz/hash.html -pal */
+ static unsigned int tossim_hash(void* key) {
+   char* str = (char*)key;
+   unsigned int hashVal = 0;
+   int c;
+   
+   while ((c = *str++))
+     hashVal = c + (hashVal << 6) + (hashVal << 16) - hashVal;
+   
+   return hashVal;
+ }
+ 
+ static int tossim_hash_eq(void* key1, void* key2) {
+   return strcmp((char*)key1, (char*)key2) == 0;
+ }
+ 
+ 
  variable_string_t Variable::getData() {
    if (data != NULL && ptr != NULL) {
***************
*** 101,105 ****
--- 123,129 ----
  Mote::Mote(nesc_app_t* n) {
    app = n;
+   varTable = create_hashtable(128, tossim_hash, tossim_hash_eq);
  }
+ 
  Mote::~Mote(){}
  
***************
*** 144,161 ****
    char* typeStr = "";
    int isArray;
!   // Could hash this for greater efficiency,
!   // but that would either require transformation
!   // in Tossim class or a more complex typemap.
!   if (app != NULL) {
!     for (int i = 0; i < app->numVariables; i++) {
!       if(strcmp(name, app->variableNames[i]) == 0) {
! 	typeStr = app->variableTypes[i];
! 	isArray = app->variableArray[i];
! 	break;
        }
      }
    }
!   //  printf("Getting variable %s of type %s %s\n", name, typeStr, isArray? "[]" : "");
!   return new Variable(name, typeStr, isArray, nodeID);
  }
  
--- 168,192 ----
    char* typeStr = "";
    int isArray;
!   Variable* var;
!   
!   var = (Variable*)hashtable_search(varTable, name);
!   if (var == NULL) {
!     // Could hash this for greater efficiency,
!     // but that would either require transformation
!     // in Tossim class or a more complex typemap.
!     if (app != NULL) {
!       for (int i = 0; i < app->numVariables; i++) {
! 	if(strcmp(name, app->variableNames[i]) == 0) {
! 	  typeStr = app->variableTypes[i];
! 	  isArray = app->variableArray[i];
! 	  break;
! 	}
        }
      }
+     //  printf("Getting variable %s of type %s %s\n", name, typeStr, isArray? "[]" : "");
+     var = new Variable(name, typeStr, isArray, nodeID);
+     hashtable_insert(varTable, name, var);
    }
!   return var;
  }
  

Index: tossim.h
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/tossim/tossim.h,v
retrieving revision 1.1.2.8
retrieving revision 1.1.2.9
diff -C2 -d -r1.1.2.8 -r1.1.2.9
*** tossim.h	7 Mar 2006 02:35:48 -0000	1.1.2.8
--- tossim.h	4 Aug 2006 01:41:15 -0000	1.1.2.9
***************
*** 41,44 ****
--- 41,45 ----
  #include <radio.h>
  #include <packet.h>
+ #include <hashtable.h>
  
  typedef struct variable_string {
***************
*** 97,100 ****
--- 98,102 ----
    unsigned long nodeID;
    nesc_app_t* app;
+   struct hashtable* varTable;
  };
  

Index: tossim_wrap.cxx
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/tossim/tossim_wrap.cxx,v
retrieving revision 1.1.2.7
retrieving revision 1.1.2.8
diff -C2 -d -r1.1.2.7 -r1.1.2.8
*** tossim_wrap.cxx	7 Mar 2006 02:35:48 -0000	1.1.2.7
--- tossim_wrap.cxx	4 Aug 2006 01:41:15 -0000	1.1.2.8
***************
*** 1,5 ****
  /* ----------------------------------------------------------------------------
   * This file was automatically generated by SWIG (http://www.swig.org).
!  * Version 1.3.21
   * 
   * This file is not intended to be easily readable and contains a number of 
--- 1,5 ----
  /* ----------------------------------------------------------------------------
   * This file was automatically generated by SWIG (http://www.swig.org).
!  * Version 1.3.24
   * 
[...6212 lines suppressed...]
--- 5093,5111 ----
      int       i;
      if (!SWIG_globals) SWIG_globals = SWIG_newvarlink();
+     
+     /* Fix SwigMethods to carry the callback ptrs when needed */
+     SWIG_Python_FixMethods(SwigMethods, swig_const_table, swig_types, swig_types_initial);
+     
      m = Py_InitModule((char *) SWIG_name, SwigMethods);
      d = PyModule_GetDict(m);
      
      if (!typeinit) {
+ #ifdef SWIG_LINK_RUNTIME
+         swig_type_list_handle = (swig_type_info **) SWIG_ReturnGlobalTypeList(swig_type_list_handle);
+ #else
+ #  ifndef SWIG_STATIC_RUNTIME
+         swig_type_list_handle = SWIG_Python_LookupTypePointer(swig_type_list_handle);
+ #  endif
+ #endif
          for (i = 0; swig_types_initial[i]; i++) {
              swig_types[i] = SWIG_TypeRegister(swig_types_initial[i]);



More information about the Tinyos-2-commits mailing list