From 6ac4ee60f73308bc909d52dd7afa3208e366a36b Mon Sep 17 00:00:00 2001
From: Anders Blomdell <anders.blomdell@control.lth.se>
Date: Tue, 14 Oct 2014 14:49:32 +0200
Subject: [PATCH] 2006 tests passes

---
 compiler/C_CodeGen.jrag          | 6 +++---
 lib/c/2006/labcomm2006.c         | 8 ++++++++
 lib/c/2006/labcomm2006.h         | 3 +--
 lib/c/2006/labcomm2006_decoder.c | 2 --
 lib/c/2006/labcomm2006_encoder.c | 3 +--
 lib/c/2006/labcomm2006_private.h | 3 +++
 6 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/compiler/C_CodeGen.jrag b/compiler/C_CodeGen.jrag
index 1c72a7d..9064f53 100644
--- a/compiler/C_CodeGen.jrag
+++ b/compiler/C_CodeGen.jrag
@@ -1269,7 +1269,7 @@ aspect C_Sizeof {
 		"(" + env.prefix + getName() + " *v)");
     env.println("{");
     env.indent();
-    env.println("return labcomm_internal_sizeof(" +
+    env.println("return labcomm"+env.verStr+"_internal_sizeof(" +
                 "&labcomm" + env.verStr+"_signature_" + env.prefix + getName() +
                 ", v);");
     env.unindent();
@@ -1353,8 +1353,8 @@ aspect C_Sizeof {
   public void PrimType.C_emitSizeof(C_env env) {
     switch (getToken()) {
       case LABCOMM_STRING: { 
-        env.print("{ int length = strlen(" + env.qualid + "); ");
-	env.println("result += labcomm_size_packed32(length) + length; }"); 
+        env.print("{ int l = strlen(" + env.qualid + "); ");
+	env.println("result += labcomm"+env.verStr+"_size_packed32(l) + l; }"); 
       } break;
       default: { 
 	throw new Error(this.getClass().getName() + 
diff --git a/lib/c/2006/labcomm2006.c b/lib/c/2006/labcomm2006.c
index 34a13ec..cbb0ea8 100644
--- a/lib/c/2006/labcomm2006.c
+++ b/lib/c/2006/labcomm2006.c
@@ -260,3 +260,11 @@ int labcomm2006_get_local_index(struct labcomm2006_signature *signature)
   }
   return signature->index;
 }
+
+int labcomm2006_internal_sizeof(struct labcomm2006_signature *signature,
+                            void *v)
+{
+  int length = signature->encoded_size(v);
+  return (labcomm2006_size_packed32(signature->index) +
+          length);
+}
diff --git a/lib/c/2006/labcomm2006.h b/lib/c/2006/labcomm2006.h
index 938aa2d..fc7919e 100644
--- a/lib/c/2006/labcomm2006.h
+++ b/lib/c/2006/labcomm2006.h
@@ -44,9 +44,8 @@ struct labcomm2006_decoder;
  * Signature entry
  */
 struct labcomm2006_signature {
-  int type;
   char *name;
-  int (*encoded_size)(struct labcomm2006_signature *, void *); // void * == encoded_sample *
+  int (*encoded_size)(void *); /* void* refers to sample_data */
   int size;
   unsigned char *signature; 
   int index;
diff --git a/lib/c/2006/labcomm2006_decoder.c b/lib/c/2006/labcomm2006_decoder.c
index a936f3e..36a075a 100644
--- a/lib/c/2006/labcomm2006_decoder.c
+++ b/lib/c/2006/labcomm2006_decoder.c
@@ -190,7 +190,6 @@ static int decode_typedef_or_sample(struct labcomm2006_decoder *d, int kind)
   labcomm2006_writer_start(&writer, writer.action_context, 0, NULL, NULL);
   remote_index = labcomm2006_read_packed32(d->reader);
   signature.name = labcomm2006_read_string(d->reader);
-  signature.type = kind;
   collect_flat_signature(d, &writer);
   labcomm2006_writer_end(&writer, writer.action_context);
   err = writer_ioctl(&writer, 
@@ -221,7 +220,6 @@ static int decode_typedef_or_sample(struct labcomm2006_decoder *d, int kind)
       s = LABCOMM_SIGNATURE_ARRAY_REF(d->memory, 
 				      d->local,  struct sample_entry, i);
       if (s->signature &&
-	  s->signature->type == signature.type &&
 	  s->signature->size == signature.size &&
 	  strcmp(s->signature->name, signature.name) == 0 &&
 	  memcmp((void*)s->signature->signature, (void*)signature.signature,
diff --git a/lib/c/2006/labcomm2006_encoder.c b/lib/c/2006/labcomm2006_encoder.c
index 06eb4dc..28674e1 100644
--- a/lib/c/2006/labcomm2006_encoder.c
+++ b/lib/c/2006/labcomm2006_encoder.c
@@ -77,7 +77,6 @@ int labcomm2006_internal_encoder_register(
 
   index = labcomm2006_get_local_index(signature);
   labcomm2006_scheduler_writer_lock(e->scheduler);
-  if (signature->type != LABCOMM_SAMPLE) { goto out; }
   if (index <= 0) { goto out; }
   done = LABCOMM_SIGNATURE_ARRAY_REF(e->memory, e->registered, int, index);
   if (*done) { goto out; }
@@ -86,7 +85,7 @@ int labcomm2006_internal_encoder_register(
 			     index, signature, NULL);
   if (err == -EALREADY) { result = 0; goto out; }
   if (err != 0) { result = err; goto out; }
-  labcomm2006_write_packed32(e->writer, signature->type);
+  labcomm2006_write_packed32(e->writer, LABCOMM_SAMPLE);
   labcomm2006_write_packed32(e->writer, index);
   labcomm2006_write_string(e->writer, signature->name);
   for (i = 0 ; i < signature->size ; i++) {
diff --git a/lib/c/2006/labcomm2006_private.h b/lib/c/2006/labcomm2006_private.h
index 1be45d2..fa2ec14 100644
--- a/lib/c/2006/labcomm2006_private.h
+++ b/lib/c/2006/labcomm2006_private.h
@@ -377,6 +377,9 @@ int labcomm2006_internal_encoder_ioctl(struct labcomm2006_encoder *encoder,
 				   struct labcomm2006_signature *signature,
 				   uint32_t ioctl_action, va_list args);
 
+int labcomm2006_internal_sizeof(struct labcomm2006_signature *signature,
+                                void *v);
+
 #if __BYTE_ORDER == __LITTLE_ENDIAN
 
 #define LABCOMM_ENCODE(name, type)					\
-- 
GitLab