From 80668031707f8ca41b8e6db25676e9c798d52fb6 Mon Sep 17 00:00:00 2001 From: hoxovic <9694402+hoxovic@users.noreply.github.com> Date: Fri, 10 Jan 2020 13:25:02 +0100 Subject: [PATCH] Fix emit_go error (#294) * Add check if: - fingerprint suffix is requested, and - member is primitive type If not, don't bother calling lcm_find_struct() when creating array --- CMakeLists.txt | 5 +---- lcmgen/emit_go.c | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9922e9c24..6d3a4c26b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,10 +77,7 @@ endif() lcm_option( LCM_ENABLE_GO "Build Go utilities, bindings is source distributed" - - # Disable until #294 is resolved - FALSE Go) - # GO_FOUND Go) + GO_FOUND Go) option(LCM_ENABLE_TESTS "Build unit tests" ON) if(LCM_ENABLE_TESTS) diff --git a/lcmgen/emit_go.c b/lcmgen/emit_go.c index 2c5495560..be048428e 100644 --- a/lcmgen/emit_go.c +++ b/lcmgen/emit_go.c @@ -278,7 +278,8 @@ uint64_t __lcm_recursive_fingerprint(lcmgen_t *lcm, lcm_struct_t *ls, if (ls_ != NULL) { fingerprint += __lcm_recursive_fingerprint(lcm, ls_, &fp); } else { - fprintf(stderr, "Unable to locate fingerprint for member '%s' of '%s'\n", + fprintf(stderr, "Unable to locate fingerprint for member '%s' of '%s'. " + "Are you missing any .lcm files?\n", lm->membername, ls->structname->shortname); return 0; } @@ -567,8 +568,18 @@ static unsigned int emit_go_array_loops(FILE *f, lcmgen_t *lcm, lcm_struct_t *ls map_builtintype_name(lcm_find_member(ls, dim->size)->type->lctypename); if (slice_emit){ - lcm_struct_t *ls_lm = lcm_find_struct(lcm, lm); - uint64_t lm_fingerprint = lcm_get_fingerprint(lcm, ls_lm); + uint64_t lm_fingerprint = 0; + if (!lcm_is_primitive_type(lm->type->lctypename)) { + if (fingerprint != 0) { + lcm_struct_t *ls_lm = lcm_find_struct(lcm, lm); + if (ls_lm == NULL) { + fprintf(stderr, "Unable to locate %s.\n", + lm->membername); + return -1; + } + lm_fingerprint = lcm_get_fingerprint(lcm, ls_lm); + } + } emit_go_slice_make(f, n + 1, ls->structname->package, lm, n, slicestr->str, size, lm_fingerprint); }