From 9819a5725d97b93dd9c28673800a9c115d0e6edb Mon Sep 17 00:00:00 2001 From: Jeroen van der Heijden Date: Thu, 4 Apr 2024 17:24:16 +0200 Subject: [PATCH] Upd test, CI, bug in compiler --- .github/workflows/ci.yml | 2 +- docker/Dockerfile | 2 +- docker/full.Dockerfile | 5 +++-- docker/gcloud.Dockerfile | 2 +- docker/tls.Dockerfile | 2 +- inc/ti/pkg.h | 8 ++++++++ inc/util/mpack.h | 2 +- itest/Dockerfile | 4 ++-- src/ti/mod/github.c | 3 ++- src/ti/module.c | 4 +--- 10 files changed, 21 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e66c22bb..400dca68 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: - name: Install dependencies run: | sudo apt-get update - sudo apt-get install -y libuv1-dev libpcre2-dev libyajl-dev libcurl4-nss-dev valgrind + sudo apt-get install -y libuv1-dev libpcre2-dev libyajl-dev libcurl4-nss-dev libwebsockets-dev valgrind - name: Run tests run: | cd ./Release/ diff --git a/docker/Dockerfile b/docker/Dockerfile index a5913795..2cbd1cbd 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -9,7 +9,7 @@ RUN apk update && \ FROM amd64/alpine:latest RUN apk update && \ - apk add pcre2 libuv yajl curl tzdata && \ + apk add pcre2 libuv yajl curl libwebsockets tzdata && \ mkdir -p /var/lib/thingsdb COPY --from=0 /tmp/thingsdb/Release/thingsdb /usr/local/bin/ diff --git a/docker/full.Dockerfile b/docker/full.Dockerfile index b9373f31..54930476 100644 --- a/docker/full.Dockerfile +++ b/docker/full.Dockerfile @@ -6,7 +6,7 @@ RUN apt-get update && apt-get install -y \ libuv1-dev \ libpcre2-dev \ libyajl-dev \ - libcurl4-nss-dev && \ + libcurl4-nss-dev \ libwebsockets-dev && \ cd /tmp/thingsdb/Release && \ make clean && \ @@ -19,7 +19,8 @@ RUN mkdir -p /var/lib/thingsdb && \ libuv1 \ libpcre2-8-0 \ libyajl2 \ - libcurl3-nss && \ + libcurl3-nss \ + libwebsockets16 && \ pip3 install py-timod COPY --from=0 /tmp/thingsdb/Release/thingsdb /usr/local/bin/ diff --git a/docker/gcloud.Dockerfile b/docker/gcloud.Dockerfile index 3eea8506..a21c6a8e 100644 --- a/docker/gcloud.Dockerfile +++ b/docker/gcloud.Dockerfile @@ -9,7 +9,7 @@ RUN apk update && \ FROM google/cloud-sdk:alpine RUN apk update && \ - apk add pcre2 libuv yajl curl tzdata && \ + apk add pcre2 libuv yajl curl libwebsockets tzdata && \ mkdir -p /var/lib/thingsdb COPY --from=0 /tmp/thingsdb/Release/thingsdb /usr/local/bin/ diff --git a/docker/tls.Dockerfile b/docker/tls.Dockerfile index 646eb5c3..89663f1a 100644 --- a/docker/tls.Dockerfile +++ b/docker/tls.Dockerfile @@ -11,7 +11,7 @@ FROM ghcr.io/cesbit/tlsproxy:v0.1.1 FROM amd64/alpine:latest RUN apk update && \ - apk add pcre2 libuv yajl curl tzdata && \ + apk add pcre2 libuv yajl curl libwebsockets tzdata && \ mkdir -p /var/lib/thingsdb COPY --from=0 /tmp/thingsdb/Release/thingsdb /usr/local/bin/ COPY --from=1 /tlsproxy /usr/local/bin/ diff --git a/inc/ti/pkg.h b/inc/ti/pkg.h index 51c4cb7d..9f0a4722 100644 --- a/inc/ti/pkg.h +++ b/inc/ti/pkg.h @@ -19,9 +19,17 @@ void ti_pkg_log(ti_pkg_t * pkg); void ti_pkg_set_tp(ti_pkg_t * pkg, uint8_t tp); static inline size_t ti_pkg_sz(ti_pkg_t * pkg); +/* +In fact, this code should work but gives an annoying warning due to a bug in +the gcc compiler. #define ti_pkg_check(pkg__) (\ (pkg__)->tp == ((pkg__)->ntp ^ 0xff) && \ (pkg__)->n <= TI_PKG_MAX_SIZE) +*/ + +#define ti_pkg_check(pkg__) (\ + (pkg__)->tp + (pkg__)->ntp == 0xff && \ + (pkg__)->n <= TI_PKG_MAX_SIZE) /* return total package size, header + data size */ static inline size_t ti_pkg_sz(ti_pkg_t * pkg) diff --git a/inc/util/mpack.h b/inc/util/mpack.h index 62313887..24e375ca 100644 --- a/inc/util/mpack.h +++ b/inc/util/mpack.h @@ -127,7 +127,7 @@ static inline int mp_sbuffer_alloc_init( { assert(alloc >= size); buffer->alloc = alloc; - buffer->data = alloc == size ? NULL : malloc(alloc); + buffer->data = (alloc == size) ? NULL : malloc(alloc); buffer->size = size; return alloc != size && buffer->data == NULL; } diff --git a/itest/Dockerfile b/itest/Dockerfile index f5c982ac..11a5f2ad 100644 --- a/itest/Dockerfile +++ b/itest/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:22.04 as builder +FROM python as builder RUN apt-get update && \ apt-get install -y \ libuv1-dev \ @@ -23,7 +23,7 @@ RUN apt-get update && \ libpcre2-8-0 \ libyajl2 \ libcurl3-nss \ - libwebsockets + libwebsockets17 COPY --from=builder ./Release/thingsdb /Release/thingsdb COPY ./itest/ /itest/ COPY ./inc/doc.h /inc/doc.h diff --git a/src/ti/mod/github.c b/src/ti/mod/github.c index 497ff326..06b5ae6c 100644 --- a/src/ti/mod/github.c +++ b/src/ti/mod/github.c @@ -540,13 +540,14 @@ static CURLcode gh__download_file( } ok = fx_is_dir(dest) || mkdir(dest, FX_DEFAULT_DIR_ACCESS) == 0; - free(dest); if (!ok) { log_warn_errno_file("cannot create directory", errno, dest); curle_code = CURLE_WRITE_ERROR; + free(dest); goto cleanup; } + free(dest); } } diff --git a/src/ti/module.c b/src/ti/module.c index e956f969..86cc9ad9 100644 --- a/src/ti/module.c +++ b/src/ti/module.c @@ -191,7 +191,7 @@ static void module__cb(ti_future_t * future) * Future have fixed pack flags; thus always with ID's etc. */ if (ti_thing_to_client_pk(thing, &vp, ti_future_deep(future) + 1, 0)) - goto mem_error1; + goto mem_error0; future->pkg = (ti_pkg_t *) buffer.data; pkg_init(future->pkg, 0, TI_PROTO_MODULE_REQ, buffer.size); @@ -207,8 +207,6 @@ static void module__cb(ti_future_t * future) } return; -mem_error1: - msgpack_sbuffer_destroy(&buffer); mem_error0: { ex_t e;