From 41e5bb26bbde3c84858ba90e32aa39fcccfdf567 Mon Sep 17 00:00:00 2001 From: Anders Blomdell <anders.blomdell@control.lth.se> Date: Fri, 23 Aug 2013 16:07:44 +0200 Subject: [PATCH] Various C99 compliance fixes. --- compiler/C_CodeGen.jrag | 3 +-- examples/twoway/Makefile | 6 +++--- lib/c/Makefile | 2 +- lib/c/labcomm_decoder.c | 2 +- lib/c/labcomm_default_scheduler.c | 2 +- lib/c/labcomm_pthread_scheduler.c | 7 ++++--- lib/c/labcomm_scheduler.c | 2 +- lib/c/labcomm_scheduler.h | 5 +++-- lib/c/labcomm_scheduler_private.h | 4 ++-- lib/c/labcomm_time.c | 2 +- lib/c/test/test_labcomm.c | 4 ++++ test/Makefile | 3 +-- 12 files changed, 23 insertions(+), 19 deletions(-) diff --git a/compiler/C_CodeGen.jrag b/compiler/C_CodeGen.jrag index 576698f..240ee7f 100644 --- a/compiler/C_CodeGen.jrag +++ b/compiler/C_CodeGen.jrag @@ -951,8 +951,7 @@ aspect C_Signature { } public void Program.C_emitConstructorDeclaration(C_env env) { - env.println("LABCOMM_CONSTRUCTOR void init_" + - env.prefix + "_signatures(void);"); + env.println("void init_" + env.prefix + "_signatures(void);"); } } diff --git a/examples/twoway/Makefile b/examples/twoway/Makefile index 76da45e..b14550b 100644 --- a/examples/twoway/Makefile +++ b/examples/twoway/Makefile @@ -2,7 +2,7 @@ TARGETS=client server LABCOMM_JAR=../../compiler/labComm.jar LABCOMM=java -jar $(LABCOMM_JAR) -CFLAGS=-O3 -g -Wall -Werror -I../../lib/c -I. -lpthread +CFLAGS=-O3 -g -Wall -Werror -I../../lib/c -I. all: $(TARGETS:%=gen/%) @@ -26,11 +26,11 @@ gen/%.c gen/%.h: %.lc | gen/.dir gen/client: client.c $(CC) -o $@ $(CFLAGS) $^ -lpthread \ - -L../../lib/c -llabcomm -Tlabcomm.linkscript + -L../../lib/c -llabcomm gen/server: server.c $(CC) -o $@ $(CFLAGS) $^ -lpthread \ - -L../../lib/c -llabcomm -Tlabcomm.linkscript + -L../../lib/c -llabcomm .PHONY: clean clean: diff --git a/lib/c/Makefile b/lib/c/Makefile index 7ada2b7..886d818 100644 --- a/lib/c/Makefile +++ b/lib/c/Makefile @@ -2,7 +2,7 @@ UNAME_S=$(shell uname -s) ifeq ($(UNAME_S),Linux) CC=gcc - CFLAGS=-g -Wall -Werror -O3 -I. -Itest + CFLAGS=-std=c99 -g -Wall -Werror -O3 -I. -Itest LDFLAGS=-L. LDLIBS=-llabcomm -lrt MAKESHARED=gcc -o $1 -shared -Wl,-soname,$2 $3 -lc -lrt diff --git a/lib/c/labcomm_decoder.c b/lib/c/labcomm_decoder.c index 3bbc8e1..d6ecd5e 100644 --- a/lib/c/labcomm_decoder.c +++ b/lib/c/labcomm_decoder.c @@ -226,7 +226,7 @@ static int decode_typedef_or_sample(struct labcomm_decoder *d, int kind) s->signature->type == signature.type && s->signature->size == signature.size && strcmp(s->signature->name, signature.name) == 0 && - bcmp((void*)s->signature->signature, (void*)signature.signature, + memcmp((void*)s->signature->signature, (void*)signature.signature, signature.size) == 0) { s->remote_index = remote_index; local_signature = s->signature; diff --git a/lib/c/labcomm_default_scheduler.c b/lib/c/labcomm_default_scheduler.c index cbc4640..a567b61 100644 --- a/lib/c/labcomm_default_scheduler.c +++ b/lib/c/labcomm_default_scheduler.c @@ -79,7 +79,7 @@ static int scheduler_wakeup(struct labcomm_scheduler *s) } static int scheduler_enqueue(struct labcomm_scheduler *s, - useconds_t delay, + uint32_t delay, void (*deferred)(void *context), void *context) { diff --git a/lib/c/labcomm_pthread_scheduler.c b/lib/c/labcomm_pthread_scheduler.c index f4d82a5..a9b516a 100644 --- a/lib/c/labcomm_pthread_scheduler.c +++ b/lib/c/labcomm_pthread_scheduler.c @@ -18,6 +18,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#define _POSIX_C_SOURCE (200112L) #include <stdio.h> #include <stdlib.h> #include <errno.h> @@ -64,7 +65,7 @@ static int queue_empty(struct pthread_deferred *queue) return queue->next == queue; } -static void timespec_add_usec(struct timespec *t, useconds_t usec) +static void timespec_add_usec(struct timespec *t, uint32_t usec) { time_t sec = usec / 1000000; long nsec = (usec % 1000000) * 1000; @@ -125,7 +126,7 @@ static int time_free(struct labcomm_time *t) return 0; } -static int time_add_usec(struct labcomm_time *t, useconds_t usec) +static int time_add_usec(struct labcomm_time *t, uint32_t usec) { struct pthread_time *time = t->context; @@ -297,7 +298,7 @@ static int scheduler_wakeup(struct labcomm_scheduler *s) } static int scheduler_enqueue(struct labcomm_scheduler *s, - useconds_t delay, + uint32_t delay, void (*deferred)(void *context), void *context) { diff --git a/lib/c/labcomm_scheduler.c b/lib/c/labcomm_scheduler.c index 6fe283a..3ef62f3 100644 --- a/lib/c/labcomm_scheduler.c +++ b/lib/c/labcomm_scheduler.c @@ -75,7 +75,7 @@ int labcomm_scheduler_wakeup(struct labcomm_scheduler *s) } int labcomm_scheduler_enqueue(struct labcomm_scheduler *s, - useconds_t delay, + uint32_t delay, void (*func)(void *context), void *context) { diff --git a/lib/c/labcomm_scheduler.h b/lib/c/labcomm_scheduler.h index f9a0778..4aef48d 100644 --- a/lib/c/labcomm_scheduler.h +++ b/lib/c/labcomm_scheduler.h @@ -23,11 +23,12 @@ #define _LABCOMM_SCHEDULER_H_ #include <unistd.h> +#include <stdint.h> struct labcomm_time; int labcomm_time_free(struct labcomm_time *t); -int labcomm_time_add_usec(struct labcomm_time *t, useconds_t usec); +int labcomm_time_add_usec(struct labcomm_time *t, uint32_t usec); struct labcomm_scheduler; @@ -47,7 +48,7 @@ int labcomm_scheduler_wakeup(struct labcomm_scheduler *s); /* Deferred action handling */ int labcomm_scheduler_enqueue(struct labcomm_scheduler *s, - useconds_t delay, + uint32_t delay, void (*deferred)(void *context), void *context); diff --git a/lib/c/labcomm_scheduler_private.h b/lib/c/labcomm_scheduler_private.h index bca2d53..cc4d50e 100644 --- a/lib/c/labcomm_scheduler_private.h +++ b/lib/c/labcomm_scheduler_private.h @@ -28,7 +28,7 @@ struct labcomm_time { const struct labcomm_time_action { int (*free)(struct labcomm_time *t); - int (*add_usec)(struct labcomm_time *t, useconds_t usec); + int (*add_usec)(struct labcomm_time *t, uint32_t usec); } *action; void *context; }; @@ -45,7 +45,7 @@ struct labcomm_scheduler { struct labcomm_time *wakeup); int (*wakeup)(struct labcomm_scheduler *s); int (*enqueue)(struct labcomm_scheduler *s, - useconds_t delay, + uint32_t delay, void (*deferred)(void *context), void *context); } *action; diff --git a/lib/c/labcomm_time.c b/lib/c/labcomm_time.c index c10c7b6..a1a5235 100644 --- a/lib/c/labcomm_time.c +++ b/lib/c/labcomm_time.c @@ -35,7 +35,7 @@ int labcomm_time_free(struct labcomm_time *s) TIME(free, s); } -int labcomm_time_add_usec(struct labcomm_time *s, useconds_t usec) +int labcomm_time_add_usec(struct labcomm_time *s, uint32_t usec) { TIME(add_usec, s, usec); } diff --git a/lib/c/test/test_labcomm.c b/lib/c/test/test_labcomm.c index 3addcf2..dbb3c21 100644 --- a/lib/c/test/test_labcomm.c +++ b/lib/c/test/test_labcomm.c @@ -164,6 +164,10 @@ int main(void) encoder_var, decoder_var); exit(1); } + fprintf(stderr, "Size: %d %d\n", + labcomm_sizeof_test_sample_test_var(NULL, NULL), + writer.pos); +// exit(1); return 0; } diff --git a/test/Makefile b/test/Makefile index b006c9e..7401102 100644 --- a/test/Makefile +++ b/test/Makefile @@ -52,8 +52,7 @@ gen/%/c_relay.c: gen/%/typeinfo relay_gen_c.py Makefile .PRECIOUS: gen/%/c_relay gen/%/c_relay: gen/%/c_relay.c gen/%/c_code.c Makefile $(CC) $(CFLAGS) -o $@ $< -I../lib/c -I. -L..//lib/c \ - gen/$*/c_code.c \ - -llabcomm -Tlabcomm.linkscript + gen/$*/c_code.c -llabcomm # C# relay test rules .PRECIOUS: gen/%/cs_code.cs -- GitLab