From 4b3b52eed3127f6cc20bae1c164512ee9cb62517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Schr=C3=B6der?= Date: Sat, 10 Sep 2016 00:22:13 +0200 Subject: [PATCH] avr port --- src/blob.c | 4 ++-- src/blob.h | 4 ++++ src/blob_json.c | 4 ++-- src/blob_ujson.c | 8 +++++--- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/blob.c b/src/blob.c index c97a38f..17ae650 100644 --- a/src/blob.c +++ b/src/blob.c @@ -213,7 +213,7 @@ blob_offset_t blob_open_array(struct blob *buf){ } void blob_close_array(struct blob *buf, blob_offset_t offset){ - if((int)offset > blob_size(buf)) return; + if((long)offset > (long)blob_size(buf)) return; struct blob_field *attr = blob_offset_to_attr(buf, offset); int len = (buf->buf + blob_field_raw_len(blob_head(buf))) - (void*)attr; blob_field_set_raw_len(attr, len); @@ -225,7 +225,7 @@ blob_offset_t blob_open_table(struct blob *buf){ } void blob_close_table(struct blob *buf, blob_offset_t offset){ - if((int)offset > blob_size(buf)) return; + if((long)offset > (long)blob_size(buf)) return; struct blob_field *attr = blob_offset_to_attr(buf, offset); int len = (buf->buf + blob_field_raw_len(blob_head(buf))) - (void*)attr; blob_field_set_raw_len(attr, len); diff --git a/src/blob.h b/src/blob.h index 7c95ea9..607a757 100644 --- a/src/blob.h +++ b/src/blob.h @@ -81,7 +81,11 @@ static inline struct blob_field *blob_head(struct blob *self){ //! returns size of the whole buffer (including header element and padding) static inline uint32_t blob_size(struct blob *self){ return blob_field_raw_pad_len(blob_head(self)); } +#ifdef __AVR +typedef uint16_t blob_offset_t; +#else typedef void* blob_offset_t; +#endif /******************************** ** NESTED ELEMENTS diff --git a/src/blob_json.c b/src/blob_json.c index d0c4c24..c9e3c1d 100644 --- a/src/blob_json.c +++ b/src/blob_json.c @@ -239,10 +239,10 @@ static void blob_format_element(struct strbuf *s, struct blob_field *attr, bool sprintf(buf, "%d", be16_to_cpu(*(uint16_t *)data)); break; case BLOB_FIELD_INT32: - sprintf(buf, "%lu", (int32_t) be32_to_cpu(*(uint32_t *)data)); + sprintf(buf, "%d", (int) be32_to_cpu(*(uint32_t *)data)); break; case BLOB_FIELD_INT64: - sprintf(buf, "%llu", (int64_t) be64_to_cpu(*(uint64_t *)data)); + sprintf(buf, "%lld", (long long int) be64_to_cpu(*(uint64_t *)data)); break; case BLOB_FIELD_FLOAT32: sprintf(buf, "%f", (double) unpack754_32(be32_to_cpu(*(uint32_t*)data))); diff --git a/src/blob_ujson.c b/src/blob_ujson.c index 442a2f0..edb0995 100644 --- a/src/blob_ujson.c +++ b/src/blob_ujson.c @@ -85,12 +85,12 @@ JSOBJ Object_newNull(void *prv){ JSOBJ Object_newObject(void *prv){ DEBUG("new object\n"); - return blob_open_table(prv); + return (JSOBJ)blob_open_table(prv); } JSOBJ Object_newArray(void *prv){ DEBUG("new array\n"); - return blob_open_array(prv); + return (JSOBJ)blob_open_array(prv); } JSOBJ Object_newInteger(void *prv, JSINT32 value){ @@ -116,7 +116,7 @@ JSOBJ Object_newDouble(void *prv, double value){ static void Object_releaseObject(void *prv, JSOBJ obj){ DEBUG("close array\n"); // with blobs close_table and close_array is the same function - blob_close_table(prv, obj); + blob_close_table(prv, (blob_offset_t)obj); } static void *Object_Malloc(size_t size){ @@ -186,6 +186,8 @@ bool blob_init_from_json(struct blob *self, const char *json){ } #ifdef HAVE_UNISTD_H +#include +#include bool blob_put_json_from_file(struct blob *self, const char *file){ // this is a rather simplistic approach where we just load the whole file into memory and then parse the buffer. // there can probably be better ways where we parse data in place..