tinycbor
authorPhilippe Coval <philippe.coval@osg.samsung.com>
Wed, 29 Mar 2017 16:34:54 +0000 (18:34 +0200)
committerPhilippe Coval <philippe.coval@osg.samsung.com>
Tue, 18 Apr 2017 12:46:47 +0000 (14:46 +0200)
Change-Id: I89a912e869a778eeb1d9cb12303bddaffc4d6d57
Signed-off-by: Philippe Coval <philippe.coval@osg.samsung.com>
extlibs/tinycbor/tinycbor/.travis.yml
extlibs/tinycbor/tinycbor/Makefile
extlibs/tinycbor/tinycbor/Makefile.configure
extlibs/tinycbor/tinycbor/Makefile.nmake
extlibs/tinycbor/tinycbor/VERSION
extlibs/tinycbor/tinycbor/maketag.pl [new file with mode: 0644]
extlibs/tinycbor/tinycbor/src/cbor.h
extlibs/tinycbor/tinycbor/src/cborconstants_p.h
extlibs/tinycbor/tinycbor/src/cborparser.c
extlibs/tinycbor/tinycbor/src/compilersupport_p.h
extlibs/tinycbor/tinycbor/tools/json2cbor/json2cbor.c

index 0948295..c3e1c7c 100644 (file)
@@ -6,7 +6,7 @@ env:
   - CFLAGS="-O0 -g" QMAKEFLAGS="-config debug" PATH=/opt/qt56/bin:/usr/local/opt/qt5/bin:$PATH
 install:
   - if [ "${TRAVIS_OS_NAME}" = "linux" ]; then
-        sudo apt-add-repository -y ppa:beineri/opt-qt561;
+        sudo apt-add-repository -y ppa:beineri/opt-qt562;
         sudo apt-add-repository -y ppa:ubuntu-toolchain-r/test;
         sudo apt-get update -qq;
         sudo apt-get install -y qt56base valgrind g++-5;
index 2377e37..97b292c 100644 (file)
@@ -82,12 +82,12 @@ ifeq ($(open_memstream-pass),)
   endif
 endif
 
-# json2cbor depends on an external library (cJSON)
+# json2cbor depends on an external library (cjson)
 ifneq ($(cjson-pass)$(system-cjson-pass),)
   JSON2CBOR_SOURCES = tools/json2cbor/json2cbor.c
   INSTALL_TARGETS += $(bindir)/json2cbor
   ifeq ($(system-cjson-pass),1)
-    LDFLAGS_CJSON = -lcJSON
+    LDFLAGS_CJSON = -lcjson
   else
     JSON2CBOR_SOURCES += src/cjson/cJSON.c
     json2cbor_CCFLAGS = -I$(SRCDIR)src/cjson
@@ -105,16 +105,16 @@ configure: .config
 .config: Makefile.configure
        $(MAKE) -f $(SRCDIR)Makefile.configure OUT='>&9' configure 9> $@
 
-lib bin:
-       $(MKDIR) $@
-
-lib/libtinycbor.a: $(TINYCBOR_SOURCES:.c=.o) | lib
+lib/libtinycbor.a: $(TINYCBOR_SOURCES:.c=.o)
+       @$(MKDIR) -p lib
        $(AR) cqs $@ $^
 
-bin/cbordump: $(CBORDUMP_SOURCES:.c=.o) lib/libtinycbor.a | bin
+bin/cbordump: $(CBORDUMP_SOURCES:.c=.o) lib/libtinycbor.a
+       @$(MKDIR) -p bin
        $(CC) -o $@ $(LDFLAGS) $^ $(LDLIBS) -lm
 
-bin/json2cbor: $(JSON2CBOR_SOURCES:.c=.o) lib/libtinycbor.a | bin
+bin/json2cbor: $(JSON2CBOR_SOURCES:.c=.o) lib/libtinycbor.a
+       @$(MKDIR) -p bin
        $(CC) -o $@ $(LDFLAGS) $(LDFLAGS_CJSON) $^ $(LDLIBS) -lm
 
 tinycbor.pc: tinycbor.pc.in
@@ -177,29 +177,8 @@ distcheck: .git
        cd $${TMPDIR-/tmp}/tinycbor-distcheck && $(MAKE) silentcheck
        $(RM) -r $${TMPDIR-/tmp}/tinycbor-distcheck
 
-release: .git
-       $(MAKE) -f $(MAKEFILE) distcheck
-ifeq ($(VERSION),)
-       git -C $(SRCDIR). show HEAD:VERSION | \
-         perl -l -n -e '@_ = split /\./; print "$$_[0]." . ($$_[1] + 1)' > $(SRCDIR)VERSION
-else
-       echo "$(VERSION)" > VERSION
-endif
-       if test -n "`git diff VERSION`"; then \
-         git -C $(SRCDIR). commit -s -m "Update version number" VERSION; \
-       fi
-       { echo "TinyCBOR release `cat $(SRCDIR)VERSION`"; \
-         echo; \
-         echo '# Write something nice about this release here'; \
-         tmpl=`git -C $(SRCDIR). config --get commit.template` && \
-               cat "$$tmpl"; \
-         echo '# Commit log:'; \
-         git -C $(SRCDIR). shortlog -e --no-merges HEAD --not `git -C $(SRCDIR). tag` | sed 's,^,#   ,'; \
-         echo '# Header diff:'; \
-         git -C $(SRCDIR). diff HEAD --not `git -C $(SRCDIR). tag` -- 'src/*.h' ':!*_p.h' | sed 's,^,# ,'; \
-       } > $(SRCDIR).git/TAG_EDITMSG
-       @`git -C $(SRCDIR). var GIT_EDITOR` $(SRCDIR).git/TAG_EDITMSG
-       git -C $(SRCDIR). tag -a -F $(SRCDIR).git/TAG_EDITMSG $(GITTAGFLAGS) v`cat $(SRCDIR)VERSION`
+tag: distcheck
+       @cd $(SRCDIR). && perl maketag.pl
 
 .PHONY: all check silentcheck configure install uninstall
 .PHONY: mostlyclean clean distclean
@@ -207,7 +186,7 @@ endif
 .SECONDARY:
 
 cflags := $(CPPFLAGS) -I$(SRCDIR)src
-cflags += -DTINYCBOR_VERSION=\"$(VERSION)$(DIRTYSRC)\"
+cflags += -DTINYCBOR_VERSION_SUFFIX=\"$(DIRTYSRC)\"
 cflags += -std=c99 $(CFLAGS)
 %.o: %.c
        @test -d $(@D) || $(MKDIR) $(@D)
index 28f4c92..424efb3 100644 (file)
@@ -10,11 +10,11 @@ PROGRAM-gc_sections = int main() {}
 CCFLAGS-gc_sections = -Wl,--gc-sections
 
 PROGRAM-cjson  = \#include <stdlib.h>\n
-PROGRAM-cjson += \#include <cJSON.h>\n
+PROGRAM-cjson += \#include <cjson/cJSON.h>\n
 PROGRAM-cjson += int main() { return cJSON_False; }
 CCFLAGS-cjson = -I$(dir $(MAKEFILE))src/cjson
 PROGRAM-system-cjson = $(PROGRAM-cjson)
-CCFLAGS-system-cjson = -lcJSON
+CCFLAGS-system-cjson = -lcjson
 
 sink:
        @echo >&2 Please run from the top-level Makefile.
index abf50da..1e675f6 100644 (file)
@@ -34,7 +34,9 @@ clean: mostlyclean
        if exist tests\Makefile (cd tests & $(MAKE) clean)
 distclean: clean
        if exist tests\Makefile (cd tests & $(MAKE) distclean)
+tag:
+       @perl maketag.pl
 
 {src\}.c{src\}.obj:
-       $(CC) -nologo $(CFLAGS) -Isrc -DTINYCBOR_VERSION="" -c -Fo$@ $<
+       $(CC) -nologo $(CFLAGS) -Isrc -DTINYCBOR_VERSION_SUFFIX="" -c -Fo$@ $<
 
diff --git a/extlibs/tinycbor/tinycbor/maketag.pl b/extlibs/tinycbor/tinycbor/maketag.pl
new file mode 100644 (file)
index 0000000..084ce5f
--- /dev/null
@@ -0,0 +1,69 @@
+#!perl
+use strict;
+sub run(@) {
+    open PROC, "-|", @_ or die("Cannot run $_[0]: $!");
+    my @out;
+    while (<PROC>) {
+        chomp;
+        push @out, $_;
+    }
+    close PROC;
+    return @out;
+}
+
+my @tags = run("git", "tag");
+my @v = run("git", "show", "HEAD:VERSION");
+my $v = $v[0];
+
+my $tagfile = ".git/TAG_EDITMSG";
+open TAGFILE, ">", $tagfile
+    or die("Cannot create file for editing tag message: $!");
+select TAGFILE;
+print "TinyCBOR release $v\n";
+print "\n";
+print "# Write something nice about this release here\n";
+
+# Do we have a commit template?
+my @result = run("git", "config", "--get", "commit.template");
+if (scalar @result) {
+    open TEMPLATE, "<", $result[0];
+    map { print $_; } <TEMPLATE>;
+    close TEMPLATE;
+}
+
+print "\n";
+print "# Commit log\n";
+open LOG, "-|", "git", "shortlog", "-e", "--no-merges", "--not", @tags;
+map { print "#  $_"; } <LOG>;
+close LOG;
+
+print "# Header diff:\n";
+open DIFF, "-|", "git", "diff", "HEAD", "--not", @tags, "--", 'src/*.h', ':!*_p.h';
+map { print "# $_"; } <DIFF>;
+close DIFF;
+
+select STDOUT;
+close TAGFILE;
+
+# Run the editor.
+# We use system so that stdin, stdout and stderr are forwarded.
+@result = run("git", "var", "GIT_EDITOR");
+@result = ($result[0], $tagfile);
+system @result;
+exit ($? >> 8) if $?;
+
+# Create the tag
+# Also using system so that hte user can see the output.
+system("git", "tag", "-a", "-F", $tagfile, split(' ', $ENV{GITTAGFLAGS}), "v$v");
+exit ($? >> 8) if $?;
+
+# Update the version file for the next patch release
+@v = split(/\./, $v);
+if (scalar @v < 3) {
+    push @v, '1';
+} else {
+    ++$v[-1];
+}
+$v = join('.', @v);
+open VERSION, ">", "VERSION" or die("Cannot open VERSION file: $!");
+print VERSION "$v\n";
index ef3f5a9..574bb44 100644 (file)
@@ -151,8 +151,8 @@ typedef enum CborError {
     CborErrorJsonObjectKeyNotString,
     CborErrorJsonNotImplemented,
 
-    CborErrorOutOfMemory = ~0U / 2 + 1,
-    CborErrorInternalError = ~0U
+    CborErrorOutOfMemory = (int) (~0U / 2 + 1),
+    CborErrorInternalError = (int) ~0U
 } CborError;
 
 CBOR_API const char *cbor_error_string(CborError error);
index d5808c3..d412056 100644 (file)
@@ -44,7 +44,7 @@ enum {
     IndefiniteLength        = 31U,
 
     MajorTypeShift          = SmallValueBitLength,
-    MajorTypeMask           = ~0U << MajorTypeShift,
+    MajorTypeMask           = (int) (~0U << MajorTypeShift),
 
     BreakByte               = (unsigned)Break | (SimpleTypesType << MajorTypeShift)
 };
index b8805ec..70cc715 100644 (file)
@@ -915,6 +915,11 @@ static uintptr_t iterate_memcmp(char *s1, const uint8_t *s2, size_t len)
     return memcmp(s1, (const char *)s2, len) == 0;
 }
 
+static uintptr_t iterate_memcpy(char *dest, const uint8_t *src, size_t len)
+{
+    return (uintptr_t)memcpy(dest, src, len);
+}
+
 static CborError iterate_string_chunks(const CborValue *value, char *buffer, size_t *buflen,
                                        bool *result, CborValue *next, IterateFunction func)
 {
@@ -977,8 +982,10 @@ static CborError iterate_string_chunks(const CborValue *value, char *buffer, siz
     }
 
     /* is there enough room for the ending NUL byte? */
-    if (*result && *buflen > total)
-        *result = !!func(buffer + total, (const uint8_t *)"", 1);
+    if (*result && *buflen > total) {
+        uint8_t nul[] = { 0 };
+        *result = !!func(buffer + total, nul, 1);
+    }
     *buflen = total;
 
     if (next) {
@@ -1059,7 +1066,7 @@ CborError _cbor_value_copy_string(const CborValue *value, void *buffer,
 {
     bool copied_all;
     CborError err = iterate_string_chunks(value, (char*)buffer, buflen, &copied_all, next,
-                                          buffer ? (IterateFunction)memcpy : iterate_noop);
+                                          buffer ? iterate_memcpy : iterate_noop);
     return err ? err :
                  copied_all ? CborNoError : CborErrorOutOfMemory;
 }
index 26248e2..5d2282b 100644 (file)
@@ -49,7 +49,7 @@
 
 #if __STDC_VERSION__ >= 201112L || __cplusplus >= 201103L || __cpp_static_assert >= 200410
 #  define cbor_static_assert(x)         static_assert(x, #x)
-#elif !defined(__cplusplus) && defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406)
+#elif !defined(__cplusplus) && defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406) && (__STDC_VERSION__ > 199901L)
 #  define cbor_static_assert(x)         _Static_assert(x, #x)
 #else
 #  define cbor_static_assert(x)         ((void)sizeof(char[2*!!(x) - 1]))
index 96d3ed1..e194299 100644 (file)
@@ -27,7 +27,7 @@
 #include "cbor.h"
 #include "compilersupport_p.h"
 
-#include <cJSON.h>
+#include <cjson/cJSON.h>
 
 #include <errno.h>
 #include <math.h>