From 22ebd91b3c1f887960462af3c8b947a5f2057aa1 Mon Sep 17 00:00:00 2001 From: Sven Gestegard Robertz <sven.robertz@cs.lth.se> Date: Fri, 26 Jun 2015 18:03:00 +0200 Subject: [PATCH] added signature argument to encoded_size() to allow a generic sizeof function to be used when creating signature structs from received signatures --- compiler/2014/C_CodeGen.jrag | 6 +++--- lib/c/2014/labcomm2014.c | 2 +- lib/c/2014/labcomm2014_encoder.c | 2 +- lib/c/2014/labcomm2014_type_signature.h | 2 +- lib/c/2014/test/test_labcomm.c | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/compiler/2014/C_CodeGen.jrag b/compiler/2014/C_CodeGen.jrag index b10029e..927a9bb 100644 --- a/compiler/2014/C_CodeGen.jrag +++ b/compiler/2014/C_CodeGen.jrag @@ -1458,7 +1458,7 @@ aspect C_Sizeof { public void SampleDecl.C_emitSizeofDeclaration(C_env env) { env.println("extern int labcomm2014_sizeof_" + env.prefix + getName() + - "(" + env.prefix + getName() + " *v);"); + "( const struct labcomm2014_signature *sig, " + env.prefix + getName() + " *v);"); } public int Decl.C_fixedSizeof() { @@ -1471,7 +1471,7 @@ aspect C_Sizeof { public void SampleDecl.C_emitSizeof(C_env env) { env = env.nestStruct("(*v)"); env.println("int labcomm2014_sizeof_" + env.prefix + getName() + - "(" + env.prefix + getName() + " *v)"); + "( const struct labcomm2014_signature *sig, " + env.prefix + getName() + " *v)"); env.println("{"); env.indent(); env.println("return labcomm2014_internal_sizeof(" + @@ -1535,7 +1535,7 @@ aspect C_Sizeof { public void SampleDecl.C_emitSizeofValue(C_env env) { env = env.nestStruct("(*v)"); - env.println("static int sizeof_" + env.prefix + getName() + "(void *vv)"); + env.println("static int sizeof_" + env.prefix + getName() + "( const struct labcomm2014_signature *sig, void *vv)"); env.println("{"); env.indent(); env.println("int result = 0;"); diff --git a/lib/c/2014/labcomm2014.c b/lib/c/2014/labcomm2014.c index 1cd953a..d66efea 100644 --- a/lib/c/2014/labcomm2014.c +++ b/lib/c/2014/labcomm2014.c @@ -272,7 +272,7 @@ int labcomm2014_get_local_type_index(const struct labcomm2014_signature *signatu int labcomm2014_internal_sizeof(const struct labcomm2014_signature *signature, void *v) { - int length = signature->encoded_size(v); + int length = signature->encoded_size(signature, v); return (labcomm2014_size_packed32(signature->index) + labcomm2014_size_packed32(length) + length); diff --git a/lib/c/2014/labcomm2014_encoder.c b/lib/c/2014/labcomm2014_encoder.c index 09cdc92..d223e48 100644 --- a/lib/c/2014/labcomm2014_encoder.c +++ b/lib/c/2014/labcomm2014_encoder.c @@ -147,7 +147,7 @@ static int do_encode( struct encoder *ie = e->context; index = labcomm2014_get_local_index(signature); - length = (signature->encoded_size(value)); + length = (signature->encoded_size(signature, value)); labcomm2014_scheduler_writer_lock(e->scheduler); if (! LABCOMM_SIGNATURE_ARRAY_GET(ie->registered, int, index, 0)) { result = -EINVAL; diff --git a/lib/c/2014/labcomm2014_type_signature.h b/lib/c/2014/labcomm2014_type_signature.h index dfb7934..20dd2dc 100644 --- a/lib/c/2014/labcomm2014_type_signature.h +++ b/lib/c/2014/labcomm2014_type_signature.h @@ -50,7 +50,7 @@ struct labcomm2014_sample_ref; struct labcomm2014_signature { char *name; - int (*encoded_size)(void *); /* void* refers to sample_data */ + int (*encoded_size)(const struct labcomm2014_signature *sig, void *); /* void* refers to sample_data */ int size; unsigned char *signature; int index; diff --git a/lib/c/2014/test/test_labcomm.c b/lib/c/2014/test/test_labcomm.c index 0b0fbf3..ec6dd66 100644 --- a/lib/c/2014/test/test_labcomm.c +++ b/lib/c/2014/test/test_labcomm.c @@ -217,10 +217,10 @@ static void test_encode_decode(struct labcomm2014_encoder *encoder, err = test_decode_one(decoder); fprintf(stderr, "decode of sample %u * 2 * %u -> size=%d err=%d\n", n_0, n_2, writer.pos, err); - if (writer.pos != labcomm2014_sizeof_test_sample_test_var(&encoder_var)) { + if (writer.pos != labcomm2014_sizeof_test_sample_test_var(NULL, &encoder_var)) { fprintf(stderr, "Incorrect sizeof %u * 2 * %u (%d != %d)\n", n_0, n_2, - writer.pos, labcomm2014_sizeof_test_sample_test_var(&encoder_var)); + writer.pos, labcomm2014_sizeof_test_sample_test_var(NULL, &encoder_var)); exit(1); } if (writer.pos != expected) { -- GitLab