From 36d8e674cb1af7f7c5f05d24e5bf0b9c3476347f Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Mon, 9 Jul 2012 13:02:32 -0500 Subject: [PATCH] Merged changes up to yajl 1.0.12 --- src/libCom/yajl/yajl.c | 2 +- src/libCom/yajl/yajl_alloc.c | 2 +- src/libCom/yajl/yajl_alloc.h | 2 +- src/libCom/yajl/yajl_buf.c | 2 +- src/libCom/yajl/yajl_buf.h | 2 +- src/libCom/yajl/yajl_bytestack.h | 2 +- src/libCom/yajl/yajl_common.h | 2 +- src/libCom/yajl/yajl_encode.c | 13 ++++++-- src/libCom/yajl/yajl_encode.h | 2 +- src/libCom/yajl/yajl_gen.c | 51 ++++++++++++++++++++++++-------- src/libCom/yajl/yajl_gen.h | 4 +-- src/libCom/yajl/yajl_lex.c | 2 +- src/libCom/yajl/yajl_lex.h | 2 +- src/libCom/yajl/yajl_parse.h | 4 +-- src/libCom/yajl/yajl_parser.c | 8 ++--- src/libCom/yajl/yajl_parser.h | 2 +- 16 files changed, 67 insertions(+), 35 deletions(-) diff --git a/src/libCom/yajl/yajl.c b/src/libCom/yajl/yajl.c index f353598d8..063e8f8b9 100644 --- a/src/libCom/yajl/yajl.c +++ b/src/libCom/yajl/yajl.c @@ -1,5 +1,5 @@ /* - * Copyright 2007-2009, Lloyd Hilaiel. + * Copyright 2010, Lloyd Hilaiel. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/libCom/yajl/yajl_alloc.c b/src/libCom/yajl/yajl_alloc.c index 5b2544ecd..2f6e5650c 100644 --- a/src/libCom/yajl/yajl_alloc.c +++ b/src/libCom/yajl/yajl_alloc.c @@ -1,5 +1,5 @@ /* - * Copyright 2007-2009, Lloyd Hilaiel. + * Copyright 2010, Lloyd Hilaiel. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/libCom/yajl/yajl_alloc.h b/src/libCom/yajl/yajl_alloc.h index 988a6c50a..cc1e5cf43 100644 --- a/src/libCom/yajl/yajl_alloc.h +++ b/src/libCom/yajl/yajl_alloc.h @@ -1,5 +1,5 @@ /* - * Copyright 2007-2009, Lloyd Hilaiel. + * Copyright 2010, Lloyd Hilaiel. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/libCom/yajl/yajl_buf.c b/src/libCom/yajl/yajl_buf.c index 3bd7ad67b..132633c9a 100644 --- a/src/libCom/yajl/yajl_buf.c +++ b/src/libCom/yajl/yajl_buf.c @@ -1,5 +1,5 @@ /* - * Copyright 2007-2009, Lloyd Hilaiel. + * Copyright 2010, Lloyd Hilaiel. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/libCom/yajl/yajl_buf.h b/src/libCom/yajl/yajl_buf.h index e5b2c8231..a6dcbe9a5 100644 --- a/src/libCom/yajl/yajl_buf.h +++ b/src/libCom/yajl/yajl_buf.h @@ -1,5 +1,5 @@ /* - * Copyright 2007-2009, Lloyd Hilaiel. + * Copyright 2010, Lloyd Hilaiel. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/libCom/yajl/yajl_bytestack.h b/src/libCom/yajl/yajl_bytestack.h index 9ce192fcc..3b49d17f9 100644 --- a/src/libCom/yajl/yajl_bytestack.h +++ b/src/libCom/yajl/yajl_bytestack.h @@ -1,5 +1,5 @@ /* - * Copyright 2009, Lloyd Hilaiel. + * Copyright 2010, Lloyd Hilaiel. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/libCom/yajl/yajl_common.h b/src/libCom/yajl/yajl_common.h index 7cb657470..b9badbf1e 100644 --- a/src/libCom/yajl/yajl_common.h +++ b/src/libCom/yajl/yajl_common.h @@ -1,5 +1,5 @@ /* - * Copyright 2007-2009, Lloyd Hilaiel. + * Copyright 2010, Lloyd Hilaiel. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/libCom/yajl/yajl_encode.c b/src/libCom/yajl/yajl_encode.c index 0d7007da0..d6f9dc0fe 100644 --- a/src/libCom/yajl/yajl_encode.c +++ b/src/libCom/yajl/yajl_encode.c @@ -1,5 +1,5 @@ /* - * Copyright 2007-2009, Lloyd Hilaiel. + * Copyright 2010, Lloyd Hilaiel. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -84,7 +84,7 @@ yajl_string_encode2(const yajl_print_t print, } if (escaped != NULL) { print(ctx, (const char *) (str + beg), end - beg); - print(ctx, escaped, strlen(escaped)); + print(ctx, escaped, (unsigned int)strlen(escaped)); beg = ++end; } else { ++end; @@ -174,12 +174,19 @@ void yajl_string_decode(yajl_buf buf, const unsigned char * str, Utf32toUtf8(codepoint, utf8Buf); unescaped = utf8Buf; + + if (codepoint == 0) { + yajl_buf_append(buf, unescaped, 1); + beg = ++end; + continue; + } + break; } default: assert("this should never happen" == NULL); } - yajl_buf_append(buf, unescaped, strlen(unescaped)); + yajl_buf_append(buf, unescaped, (unsigned int)strlen(unescaped)); beg = ++end; } else { end++; diff --git a/src/libCom/yajl/yajl_encode.h b/src/libCom/yajl/yajl_encode.h index d478baa19..3e3b0923d 100644 --- a/src/libCom/yajl/yajl_encode.h +++ b/src/libCom/yajl/yajl_encode.h @@ -1,5 +1,5 @@ /* - * Copyright 2007-2009, Lloyd Hilaiel. + * Copyright 2010, Lloyd Hilaiel. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/libCom/yajl/yajl_gen.c b/src/libCom/yajl/yajl_gen.c index a10d08297..495d28233 100644 --- a/src/libCom/yajl/yajl_gen.c +++ b/src/libCom/yajl/yajl_gen.c @@ -1,5 +1,5 @@ /* - * Copyright 2007-2009, Lloyd Hilaiel. + * Copyright 2010, Lloyd Hilaiel. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -91,13 +91,32 @@ yajl_gen_alloc2(const yajl_print_t callback, } g = (yajl_gen) YA_MALLOC(afs, sizeof(struct yajl_gen_t)); + if (!g) return NULL; + memset((void *) g, 0, sizeof(struct yajl_gen_t)); /* copy in pointers to allocation routines */ memcpy((void *) &(g->alloc), (void *) afs, sizeof(yajl_alloc_funcs)); if (config) { + const char *indent = config->indentString; g->pretty = config->beautify; - g->indentString = config->indentString ? config->indentString : " "; + g->indentString = config->indentString; + if (indent) { + for (; *indent; indent++) { + if (*indent != '\n' + && *indent != '\v' + && *indent != '\f' + && *indent != '\t' + && *indent != '\r' + && *indent != ' ') { + g->indentString = NULL; + break; + } + } + } + if (!g->indentString) { + g->indentString = " "; + } } if (callback) { @@ -133,15 +152,17 @@ yajl_gen_free(yajl_gen g) if (g->state[g->depth] != yajl_gen_map_val) { \ unsigned int _i; \ for (_i=0;_idepth;_i++) \ - g->print(g->ctx, g->indentString, \ - strlen(g->indentString)); \ + g->print(g->ctx, \ + g->indentString, \ + (unsigned int)strlen(g->indentString)); \ } \ } #define ENSURE_NOT_KEY \ - if (g->state[g->depth] == yajl_gen_map_key) { \ - return yajl_gen_keys_must_be_strings; \ - } \ + if (g->state[g->depth] == yajl_gen_map_key || \ + g->state[g->depth] == yajl_gen_map_start) { \ + return yajl_gen_keys_must_be_strings; \ + } \ /* check that we're not complete, or in error state. in a valid state * to be generating */ @@ -155,6 +176,9 @@ yajl_gen_free(yajl_gen g) #define INCREMENT_DEPTH \ if (++(g->depth) >= YAJL_MAX_DEPTH) return yajl_max_depth_exceeded; +#define DECREMENT_DEPTH \ + if (--(g->depth) >= YAJL_MAX_DEPTH) return yajl_gen_error; + #define APPENDED_ATOM \ switch (g->state[g->depth]) { \ case yajl_gen_start: \ @@ -184,7 +208,7 @@ yajl_gen_integer(yajl_gen g, long int number) char i[32]; ENSURE_VALID_STATE; ENSURE_NOT_KEY; INSERT_SEP; INSERT_WHITESPACE; sprintf(i, "%ld", number); - g->print(g->ctx, i, strlen(i)); + g->print(g->ctx, i, (unsigned int)strlen(i)); APPENDED_ATOM; FINAL_NEWLINE; return yajl_gen_status_ok; @@ -197,8 +221,8 @@ yajl_gen_double(yajl_gen g, double number) ENSURE_VALID_STATE; ENSURE_NOT_KEY; if (isnan(number) || isinf(number)) return yajl_gen_invalid_number; INSERT_SEP; INSERT_WHITESPACE; - sprintf(i, "%g", number); - g->print(g->ctx, i, strlen(i)); + sprintf(i, "%.20g", number); + g->print(g->ctx, i, (unsigned int)strlen(i)); APPENDED_ATOM; FINAL_NEWLINE; return yajl_gen_status_ok; @@ -243,7 +267,7 @@ yajl_gen_bool(yajl_gen g, int boolean) const char * val = boolean ? "true" : "false"; ENSURE_VALID_STATE; ENSURE_NOT_KEY; INSERT_SEP; INSERT_WHITESPACE; - g->print(g->ctx, val, strlen(val)); + g->print(g->ctx, val, (unsigned int)strlen(val)); APPENDED_ATOM; FINAL_NEWLINE; return yajl_gen_status_ok; @@ -266,7 +290,8 @@ yajl_gen_status yajl_gen_map_close(yajl_gen g) { ENSURE_VALID_STATE; - (g->depth)--; + DECREMENT_DEPTH; + if (g->pretty) g->print(g->ctx, "\n", 1); APPENDED_ATOM; INSERT_WHITESPACE; @@ -291,8 +316,8 @@ yajl_gen_status yajl_gen_array_close(yajl_gen g) { ENSURE_VALID_STATE; + DECREMENT_DEPTH; if (g->pretty) g->print(g->ctx, "\n", 1); - (g->depth)--; APPENDED_ATOM; INSERT_WHITESPACE; g->print(g->ctx, "]", 1); diff --git a/src/libCom/yajl/yajl_gen.h b/src/libCom/yajl/yajl_gen.h index 8efabd073..34b147596 100644 --- a/src/libCom/yajl/yajl_gen.h +++ b/src/libCom/yajl/yajl_gen.h @@ -1,5 +1,5 @@ /* - * Copyright 2007-2009, Lloyd Hilaiel. + * Copyright 2010, Lloyd Hilaiel. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -38,7 +38,7 @@ #ifndef __YAJL_GEN_H__ #define __YAJL_GEN_H__ -#include "yajl_common.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/libCom/yajl/yajl_lex.c b/src/libCom/yajl/yajl_lex.c index be83887ff..3abd21698 100644 --- a/src/libCom/yajl/yajl_lex.c +++ b/src/libCom/yajl/yajl_lex.c @@ -1,5 +1,5 @@ /* - * Copyright 2007-2009, Lloyd Hilaiel. + * Copyright 2010, Lloyd Hilaiel. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/libCom/yajl/yajl_lex.h b/src/libCom/yajl/yajl_lex.h index 658885241..559e54dba 100644 --- a/src/libCom/yajl/yajl_lex.h +++ b/src/libCom/yajl/yajl_lex.h @@ -1,5 +1,5 @@ /* - * Copyright 2007-2009, Lloyd Hilaiel. + * Copyright 2010, Lloyd Hilaiel. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are diff --git a/src/libCom/yajl/yajl_parse.h b/src/libCom/yajl/yajl_parse.h index b4de64bbd..a70a8fd56 100644 --- a/src/libCom/yajl/yajl_parse.h +++ b/src/libCom/yajl/yajl_parse.h @@ -1,5 +1,5 @@ /* - * Copyright 2007-2009, Lloyd Hilaiel. + * Copyright 2010, Lloyd Hilaiel. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -38,7 +38,7 @@ #ifndef __YAJL_PARSE_H__ #define __YAJL_PARSE_H__ -#include "yajl_common.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/libCom/yajl/yajl_parser.c b/src/libCom/yajl/yajl_parser.c index 1c15f8e1e..bbcf80880 100644 --- a/src/libCom/yajl/yajl_parser.c +++ b/src/libCom/yajl/yajl_parser.c @@ -1,5 +1,5 @@ /* - * Copyright 2007-2009, Lloyd Hilaiel. + * Copyright 2010, Lloyd Hilaiel. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -112,9 +112,9 @@ yajl_render_error_string(yajl_handle hand, const unsigned char * jsonText, text[i] = 0; { char * newStr = (char *) - YA_MALLOC(&(hand->alloc), (strlen((char *) str) + - strlen((char *) text) + - strlen(arrow) + 1)); + YA_MALLOC(&(hand->alloc), (unsigned int)(strlen((char *) str) + + strlen((char *) text) + + strlen(arrow) + 1)); newStr[0] = 0; strcat((char *) newStr, (char *) str); strcat((char *) newStr, text); diff --git a/src/libCom/yajl/yajl_parser.h b/src/libCom/yajl/yajl_parser.h index c9d29d436..2d59882a3 100644 --- a/src/libCom/yajl/yajl_parser.h +++ b/src/libCom/yajl/yajl_parser.h @@ -1,5 +1,5 @@ /* - * Copyright 2007-2009, Lloyd Hilaiel. + * Copyright 2010, Lloyd Hilaiel. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are