Source

crossroads / crossroads / message.py

Diff from to

File crossroads/message.py

 
     def __init__(self, source=None):
         super(MessageXS, self).__init__()
-        self.dest = xs.msg_t()
-        if isinstance(source, getcls(self)):
+        if source is None:
+            self.dest = xs.msg_t()
+            self.src = None
+            self.rc = xs.msg_init(self.dest)
+            self.size = xs.msg_size(self.dest)
+        elif isinstance(source, getcls(self)):
             self.src = source.dest
-            self.rc = xs.msg_init(self.src)
-            self.size = sizeof(self.src)
-        elif source is None:
-            self.src = self.dest
-            self.rc = xs.msg_init(self.src)
-            self.size = sizeof(self.src)
+            self.dest = None
+            self.size = xs.msg_size(self.src)
         else:
-            self.src = bytes(source)
-            length = self.size = len(self.src)
-            self.rc = xs.msg_init_size(self.dest, length)
-            xs.memmove(xs.msg_data(self.dest), self.src, length)
+            self.src = xs.msg_t()
+            source = bytes(source)
+            length = self.size = len(source)
+            self.rc = xs.msg_init_size(self.src, length)
+            xs.memmove(xs.msg_data(self.src), source, length)
 
     def __len__(self):
         return self.size
         return value
 
     def close(self):
-        self.rc = xs.msg_close(self.dest)
+        if self.src is not None:
+            self.rc = xs.msg_close(self.src)
+        if self.dest is not None:
+            self.rc = xs.msg_close(self.dest)
+#
+#    __del__ = close
+