diff options
author | Lloyd Hilaiel <lloyd@hilaiel.com> | 2010-08-10 13:40:00 -0600 |
---|---|---|
committer | Lloyd Hilaiel <lloyd@hilaiel.com> | 2010-08-10 13:44:53 -0600 |
commit | 390748e29e39ac8bbe03e04ba6ebde985c36830a (patch) | |
tree | ed970901e32f5b84bbbe639c46faa0ebde600c8d | |
parent | d564f36928cb340094fe3609bc9fb457063589ab (diff) | |
download | yajl-390748e29e39ac8bbe03e04ba6ebde985c36830a.tar.gz |
use size_t rather than unsigned int for representing buffer lengths for yajl 2.x
-rw-r--r-- | reformatter/json_reformat.c | 8 | ||||
-rw-r--r-- | src/api/yajl_common.h | 6 | ||||
-rw-r--r-- | src/api/yajl_gen.h | 10 | ||||
-rw-r--r-- | src/api/yajl_parse.h | 14 | ||||
-rw-r--r-- | src/yajl | 8 | ||||
-rw-r--r-- | src/yajl.c | 6 | ||||
-rw-r--r-- | src/yajl_alloc.c | 4 | ||||
-rw-r--r-- | src/yajl_buf.c | 14 | ||||
-rw-r--r-- | src/yajl_buf.h | 6 | ||||
-rw-r--r-- | src/yajl_bytestack.h | 4 | ||||
-rw-r--r-- | src/yajl_encode.c | 14 | ||||
-rw-r--r-- | src/yajl_encode.h | 6 | ||||
-rw-r--r-- | src/yajl_gen.c | 6 | ||||
-rw-r--r-- | src/yajl_lex.c | 32 | ||||
-rw-r--r-- | src/yajl_lex.h | 12 | ||||
-rw-r--r-- | src/yajl_parser.c | 16 | ||||
-rw-r--r-- | src/yajl_parser.h | 6 | ||||
-rw-r--r-- | test/yajl_test.c | 20 |
18 files changed, 99 insertions, 93 deletions
diff --git a/reformatter/json_reformat.c b/reformatter/json_reformat.c index fbfc02c..5584ec5 100644 --- a/reformatter/json_reformat.c +++ b/reformatter/json_reformat.c @@ -51,7 +51,7 @@ static int reformat_boolean(void * ctx, int boolean) return 1; } -static int reformat_number(void * ctx, const char * s, unsigned int l) +static int reformat_number(void * ctx, const char * s, size_t l) { yajl_gen g = (yajl_gen) ctx; yajl_gen_number(g, s, l); @@ -59,7 +59,7 @@ static int reformat_number(void * ctx, const char * s, unsigned int l) } static int reformat_string(void * ctx, const unsigned char * stringVal, - unsigned int stringLen) + size_t stringLen) { yajl_gen g = (yajl_gen) ctx; yajl_gen_string(g, stringVal, stringLen); @@ -67,7 +67,7 @@ static int reformat_string(void * ctx, const unsigned char * stringVal, } static int reformat_map_key(void * ctx, const unsigned char * stringVal, - unsigned int stringLen) + size_t stringLen) { yajl_gen g = (yajl_gen) ctx; yajl_gen_string(g, stringVal, stringLen); @@ -201,7 +201,7 @@ main(int argc, char ** argv) break; } else { const unsigned char * buf; - unsigned int len; + size_t len; yajl_gen_get_buf(g, &buf, &len); fwrite(buf, 1, len, stdout); yajl_gen_clear(g); diff --git a/src/api/yajl_common.h b/src/api/yajl_common.h index 0e75db1..00254e2 100644 --- a/src/api/yajl_common.h +++ b/src/api/yajl_common.h @@ -33,6 +33,8 @@ #ifndef __YAJL_COMMON_H__ #define __YAJL_COMMON_H__ +#include <stddef.h> + #ifdef __cplusplus extern "C" { #endif @@ -58,14 +60,14 @@ extern "C" { /** pointer to a malloc function, supporting client overriding memory * allocation routines */ -typedef void * (*yajl_malloc_func)(void *ctx, unsigned int sz); +typedef void * (*yajl_malloc_func)(void *ctx, size_t sz); /** pointer to a free function, supporting client overriding memory * allocation routines */ typedef void (*yajl_free_func)(void *ctx, void * ptr); /** pointer to a realloc function which can resize an allocation. */ -typedef void * (*yajl_realloc_func)(void *ctx, void * ptr, unsigned int sz); +typedef void * (*yajl_realloc_func)(void *ctx, void * ptr, size_t sz); /** A structure which can be passed to yajl_*_alloc routines to allow the * client to specify memory allocation functions to be used. */ diff --git a/src/api/yajl_gen.h b/src/api/yajl_gen.h index cd1b9fa..ced3090 100644 --- a/src/api/yajl_gen.h +++ b/src/api/yajl_gen.h @@ -40,6 +40,8 @@ #ifndef __YAJL_GEN_H__ #define __YAJL_GEN_H__ +#include <stddef.h> + #ifdef __cplusplus extern "C" { #endif @@ -72,7 +74,7 @@ extern "C" { /** a callback used for "printing" the results. */ typedef void (*yajl_print_t)(void * ctx, const char * str, - unsigned int len); + size_t len); /** configuration structure for the generator */ typedef struct { @@ -129,10 +131,10 @@ extern "C" { YAJL_API yajl_gen_status yajl_gen_double(yajl_gen hand, double number); YAJL_API yajl_gen_status yajl_gen_number(yajl_gen hand, const char * num, - unsigned int len); + size_t len); YAJL_API yajl_gen_status yajl_gen_string(yajl_gen hand, const unsigned char * str, - unsigned int len); + size_t len); YAJL_API yajl_gen_status yajl_gen_null(yajl_gen hand); YAJL_API yajl_gen_status yajl_gen_bool(yajl_gen hand, int boolean); YAJL_API yajl_gen_status yajl_gen_map_open(yajl_gen hand); @@ -145,7 +147,7 @@ extern "C" { * buffer. This allows stream generation. */ YAJL_API yajl_gen_status yajl_gen_get_buf(yajl_gen hand, const unsigned char ** buf, - unsigned int * len); + size_t * len); /** clear yajl's output buffer, but maintain all internal generation * state. This function will not "reset" the generator state, and is diff --git a/src/api/yajl_parse.h b/src/api/yajl_parse.h index 76177dd..e7b00b0 100644 --- a/src/api/yajl_parse.h +++ b/src/api/yajl_parse.h @@ -40,6 +40,8 @@ #ifndef __YAJL_PARSE_H__ #define __YAJL_PARSE_H__ +#include <stddef.h> + #ifdef __cplusplus extern "C" { #endif @@ -93,16 +95,16 @@ extern "C" { /** A callback which passes the string representation of the number * back to the client. Will be used for all numbers when present */ int (* yajl_number)(void * ctx, const char * numberVal, - unsigned int numberLen); + size_t numberLen); /** strings are returned as pointers into the JSON text when, * possible, as a result, they are _not_ null padded */ int (* yajl_string)(void * ctx, const unsigned char * stringVal, - unsigned int stringLen); + size_t stringLen); int (* yajl_start_map)(void * ctx); int (* yajl_map_key)(void * ctx, const unsigned char * key, - unsigned int stringLen); + size_t stringLen); int (* yajl_end_map)(void * ctx); int (* yajl_start_array)(void * ctx); @@ -142,7 +144,7 @@ extern "C" { */ YAJL_API yajl_status yajl_parse(yajl_handle hand, const unsigned char * jsonText, - unsigned int jsonTextLength); + size_t jsonTextLength); /** Parse any remaining buffered json. * Since yajl is a stream-based parser, without an explicit end of @@ -167,7 +169,7 @@ extern "C" { */ YAJL_API unsigned char * yajl_get_error(yajl_handle hand, int verbose, const unsigned char * jsonText, - unsigned int jsonTextLength); + size_t jsonTextLength); /** * get the amount of data consumed from the last chunk passed to YAJL. @@ -181,7 +183,7 @@ extern "C" { * chunk where the error occured. 0 will be returned if no error * was encountered. */ - YAJL_API unsigned int yajl_get_bytes_consumed(yajl_handle hand); + YAJL_API size_t yajl_get_bytes_consumed(yajl_handle hand); /** free an error returned from yajl_get_error */ YAJL_API void yajl_free_error(yajl_handle hand, unsigned char * str); @@ -43,7 +43,7 @@ static int reformat_boolean(void * ctx, int boolean) return 1; } -static int reformat_number(void * ctx, const char * s, unsigned int l) +static int reformat_number(void * ctx, const char * s, size_t l) { yajl_gen g = (yajl_gen) ctx; yajl_gen_number(g, s, l); @@ -51,7 +51,7 @@ static int reformat_number(void * ctx, const char * s, unsigned int l) } static int reformat_string(void * ctx, const unsigned char * stringVal, - unsigned int stringLen) + size_t stringLen) { yajl_gen g = (yajl_gen) ctx; yajl_gen_string(g, stringVal, stringLen); @@ -59,7 +59,7 @@ static int reformat_string(void * ctx, const unsigned char * stringVal, } static int reformat_map_key(void * ctx, const unsigned char * stringVal, - unsigned int stringLen) + size_t stringLen) { yajl_gen g = (yajl_gen) ctx; yajl_gen_string(g, stringVal, stringLen); @@ -180,7 +180,7 @@ main(int argc, char ** argv) yajl_free_error(hand, str); } else { const unsigned char * buf; - unsigned int len; + size_tnq len; yajl_gen_get_buf(g, &buf, &len); fwrite(buf, 1, len, stdout); yajl_gen_clear(g); @@ -115,7 +115,7 @@ yajl_free(yajl_handle handle) yajl_status yajl_parse(yajl_handle hand, const unsigned char * jsonText, - unsigned int jsonTextLen) + size_t jsonTextLen) { yajl_status status; status = yajl_do_parse(hand, jsonText, jsonTextLen); @@ -136,12 +136,12 @@ yajl_parse_complete(yajl_handle hand) unsigned char * yajl_get_error(yajl_handle hand, int verbose, - const unsigned char * jsonText, unsigned int jsonTextLen) + const unsigned char * jsonText, size_t jsonTextLen) { return yajl_render_error_string(hand, jsonText, jsonTextLen, verbose); } -unsigned int +size_t yajl_get_bytes_consumed(yajl_handle hand) { if (!hand) return 0; diff --git a/src/yajl_alloc.c b/src/yajl_alloc.c index ccfb7c3..efc4a4f 100644 --- a/src/yajl_alloc.c +++ b/src/yajl_alloc.c @@ -39,13 +39,13 @@ #include "yajl_alloc.h" #include <stdlib.h> -static void * yajl_internal_malloc(void *ctx, unsigned int sz) +static void * yajl_internal_malloc(void *ctx, size_t sz) { return malloc(sz); } static void * yajl_internal_realloc(void *ctx, void * previous, - unsigned int sz) + size_t sz) { return realloc(previous, sz); } diff --git a/src/yajl_buf.c b/src/yajl_buf.c index 04e608a..f061048 100644 --- a/src/yajl_buf.c +++ b/src/yajl_buf.c @@ -39,16 +39,16 @@ #define YAJL_BUF_INIT_SIZE 2048 struct yajl_buf_t { - unsigned int len; - unsigned int used; + size_t len; + size_t used; unsigned char * data; yajl_alloc_funcs * alloc; }; static -void yajl_buf_ensure_available(yajl_buf buf, unsigned int want) +void yajl_buf_ensure_available(yajl_buf buf, size_t want) { - unsigned int need; + size_t need; assert(buf != NULL); @@ -84,7 +84,7 @@ void yajl_buf_free(yajl_buf buf) YA_FREE(buf->alloc, buf); } -void yajl_buf_append(yajl_buf buf, const void * data, unsigned int len) +void yajl_buf_append(yajl_buf buf, const void * data, size_t len) { yajl_buf_ensure_available(buf, len); if (len > 0) { @@ -106,13 +106,13 @@ const unsigned char * yajl_buf_data(yajl_buf buf) return buf->data; } -unsigned int yajl_buf_len(yajl_buf buf) +size_t yajl_buf_len(yajl_buf buf) { return buf->used; } void -yajl_buf_truncate(yajl_buf buf, unsigned int len) +yajl_buf_truncate(yajl_buf buf, size_t len) { assert(len <= buf->used); buf->used = len; diff --git a/src/yajl_buf.h b/src/yajl_buf.h index e330f33..82223fc 100644 --- a/src/yajl_buf.h +++ b/src/yajl_buf.h @@ -56,7 +56,7 @@ yajl_buf yajl_buf_alloc(yajl_alloc_funcs * alloc); void yajl_buf_free(yajl_buf buf); /* append a number of bytes to the buffer */ -void yajl_buf_append(yajl_buf buf, const void * data, unsigned int len); +void yajl_buf_append(yajl_buf buf, const void * data, size_t len); /* empty the buffer */ void yajl_buf_clear(yajl_buf buf); @@ -65,9 +65,9 @@ void yajl_buf_clear(yajl_buf buf); const unsigned char * yajl_buf_data(yajl_buf buf); /* get the length of the buffer */ -unsigned int yajl_buf_len(yajl_buf buf); +size_t yajl_buf_len(yajl_buf buf); /* truncate the buffer */ -void yajl_buf_truncate(yajl_buf buf, unsigned int len); +void yajl_buf_truncate(yajl_buf buf, size_t len); #endif diff --git a/src/yajl_bytestack.h b/src/yajl_bytestack.h index 872ede1..36ecb4a 100644 --- a/src/yajl_bytestack.h +++ b/src/yajl_bytestack.h @@ -45,8 +45,8 @@ typedef struct yajl_bytestack_t { unsigned char * stack; - unsigned int size; - unsigned int used; + size_t size; + size_t used; yajl_alloc_funcs * yaf; } yajl_bytestack; diff --git a/src/yajl_encode.c b/src/yajl_encode.c index ad5b1c5..c5b45d3 100644 --- a/src/yajl_encode.c +++ b/src/yajl_encode.c @@ -46,7 +46,7 @@ static void CharToHex(unsigned char c, char * hexBuf) void yajl_string_encode(yajl_buf buf, const unsigned char * str, - unsigned int len) + size_t len) { yajl_string_encode2((const yajl_print_t) &yajl_buf_append, buf, str, len); } @@ -55,10 +55,10 @@ void yajl_string_encode2(const yajl_print_t print, void * ctx, const unsigned char * str, - unsigned int len) + size_t len) { - unsigned int beg = 0; - unsigned int end = 0; + size_t beg = 0; + size_t end = 0; char hexBuf[7]; hexBuf[0] = '\\'; hexBuf[1] = 'u'; hexBuf[2] = '0'; hexBuf[3] = '0'; hexBuf[6] = 0; @@ -131,10 +131,10 @@ static void Utf32toUtf8(unsigned int codepoint, char * utf8Buf) } void yajl_string_decode(yajl_buf buf, const unsigned char * str, - unsigned int len) + size_t len) { - unsigned int beg = 0; - unsigned int end = 0; + size_t beg = 0; + size_t end = 0; while (end < len) { if (str[end] == '\\') { diff --git a/src/yajl_encode.h b/src/yajl_encode.h index f242779..a804f1b 100644 --- a/src/yajl_encode.h +++ b/src/yajl_encode.h @@ -39,12 +39,12 @@ void yajl_string_encode2(const yajl_print_t printer, void * ctx, const unsigned char * str, - unsigned int length); + size_t length); void yajl_string_encode(yajl_buf buf, const unsigned char * str, - unsigned int length); + size_t length); void yajl_string_decode(yajl_buf buf, const unsigned char * str, - unsigned int length); + size_t length); #endif diff --git a/src/yajl_gen.c b/src/yajl_gen.c index 97e19d8..a77e764 100644 --- a/src/yajl_gen.c +++ b/src/yajl_gen.c @@ -210,7 +210,7 @@ yajl_gen_double(yajl_gen g, double number) } yajl_gen_status -yajl_gen_number(yajl_gen g, const char * s, unsigned int l) +yajl_gen_number(yajl_gen g, const char * s, size_t l) { ENSURE_VALID_STATE; ENSURE_NOT_KEY; INSERT_SEP; INSERT_WHITESPACE; g->print(g->ctx, s, l); @@ -221,7 +221,7 @@ yajl_gen_number(yajl_gen g, const char * s, unsigned int l) yajl_gen_status yajl_gen_string(yajl_gen g, const unsigned char * str, - unsigned int len) + size_t len) { ENSURE_VALID_STATE; INSERT_SEP; INSERT_WHITESPACE; g->print(g->ctx, "\"", 1); @@ -307,7 +307,7 @@ yajl_gen_array_close(yajl_gen g) yajl_gen_status yajl_gen_get_buf(yajl_gen g, const unsigned char ** buf, - unsigned int * len) + size_t * len) { if (g->print != (yajl_print_t)&yajl_buf_append) return yajl_gen_no_buf; *buf = yajl_buf_data((yajl_buf)g->ctx); diff --git a/src/yajl_lex.c b/src/yajl_lex.c index 11e5f7b..5ad1632 100644 --- a/src/yajl_lex.c +++ b/src/yajl_lex.c @@ -83,8 +83,8 @@ tokToStr(yajl_tok tok) struct yajl_lexer_t { /* the overal line and char offset into the data */ - unsigned int lineOff; - unsigned int charOff; + size_t lineOff; + size_t charOff; /* error */ yajl_lex_error error; @@ -95,7 +95,7 @@ struct yajl_lexer_t { /* in the case where we have data in the lexBuf, bufOff holds * the current offset into the lexBuf. */ - unsigned int bufOff; + size_t bufOff; /* are we using the lex buf? */ unsigned int bufInUse; @@ -206,7 +206,7 @@ static const char charLookupTable[256] = static yajl_tok yajl_lex_utf8_char(yajl_lexer lexer, const unsigned char * jsonText, - unsigned int jsonTextLen, unsigned int * offset, + size_t jsonTextLen, size_t * offset, unsigned char curChar) { if (curChar <= 0x7f) { @@ -262,7 +262,7 @@ if (*offset >= jsonTextLen) { \ static yajl_tok yajl_lex_string(yajl_lexer lexer, const unsigned char * jsonText, - unsigned int jsonTextLen, unsigned int * offset) + size_t jsonTextLen, size_t * offset) { yajl_tok tok = yajl_tok_error; int hasEscapes = 0; @@ -343,7 +343,7 @@ yajl_lex_string(yajl_lexer lexer, const unsigned char * jsonText, static yajl_tok yajl_lex_number(yajl_lexer lexer, const unsigned char * jsonText, - unsigned int jsonTextLen, unsigned int * offset) + size_t jsonTextLen, size_t * offset) { /** XXX: numbers are the only entities in json that we must lex * _beyond_ in order to know that they are complete. There @@ -430,7 +430,7 @@ yajl_lex_number(yajl_lexer lexer, const unsigned char * jsonText, static yajl_tok yajl_lex_comment(yajl_lexer lexer, const unsigned char * jsonText, - unsigned int jsonTextLen, unsigned int * offset) + size_t jsonTextLen, size_t * offset) { unsigned char c; @@ -471,12 +471,12 @@ yajl_lex_comment(yajl_lexer lexer, const unsigned char * jsonText, yajl_tok yajl_lex_lex(yajl_lexer lexer, const unsigned char * jsonText, - unsigned int jsonTextLen, unsigned int * offset, - const unsigned char ** outBuf, unsigned int * outLen) + size_t jsonTextLen, size_t * offset, + const unsigned char ** outBuf, size_t * outLen) { yajl_tok tok = yajl_tok_error; unsigned char c; - unsigned int startOffset = *offset; + size_t startOffset = *offset; *outBuf = NULL; *outLen = 0; @@ -706,23 +706,23 @@ yajl_lex_get_error(yajl_lexer lexer) return lexer->error; } -unsigned int yajl_lex_current_line(yajl_lexer lexer) +size_t yajl_lex_current_line(yajl_lexer lexer) { return lexer->lineOff; } -unsigned int yajl_lex_current_char(yajl_lexer lexer) +size_t yajl_lex_current_char(yajl_lexer lexer) { return lexer->charOff; } yajl_tok yajl_lex_peek(yajl_lexer lexer, const unsigned char * jsonText, - unsigned int jsonTextLen, unsigned int offset) + size_t jsonTextLen, size_t offset) { const unsigned char * outBuf; - unsigned int outLen; - unsigned int bufLen = yajl_buf_len(lexer->buf); - unsigned int bufOff = lexer->bufOff; + size_t outLen; + size_t bufLen = yajl_buf_len(lexer->buf); + size_t bufOff = lexer->bufOff; unsigned int bufInUse = lexer->bufInUse; yajl_tok tok; diff --git a/src/yajl_lex.h b/src/yajl_lex.h index 6791a29..5c4d1f5 100644 --- a/src/yajl_lex.h +++ b/src/yajl_lex.h @@ -92,12 +92,12 @@ n * error messages. * size to get adequate performance. */ yajl_tok yajl_lex_lex(yajl_lexer lexer, const unsigned char * jsonText, - unsigned int jsonTextLen, unsigned int * offset, - const unsigned char ** outBuf, unsigned int * outLen); + size_t jsonTextLen, size_t * offset, + const unsigned char ** outBuf, size_t * outLen); /** have a peek at the next token, but don't move the lexer forward */ yajl_tok yajl_lex_peek(yajl_lexer lexer, const unsigned char * jsonText, - unsigned int jsonTextLen, unsigned int offset); + size_t jsonTextLen, size_t offset); typedef enum { @@ -121,13 +121,13 @@ const char * yajl_lex_error_to_string(yajl_lex_error error); yajl_lex_error yajl_lex_get_error(yajl_lexer lexer); /** get the current offset into the most recently lexed json string. */ -unsigned int yajl_lex_current_offset(yajl_lexer lexer); +size_t yajl_lex_current_offset(yajl_lexer lexer); /** get the number of lines lexed by this lexer instance */ -unsigned int yajl_lex_current_line(yajl_lexer lexer); +size_t yajl_lex_current_line(yajl_lexer lexer); /** get the number of chars lexed by this lexer instance since the last * \n or \r */ -unsigned int yajl_lex_current_char(yajl_lexer lexer); +size_t yajl_lex_current_char(yajl_lexer lexer); #endif diff --git a/src/yajl_parser.c b/src/yajl_parser.c index 8eafded..59c93f6 100644 --- a/src/yajl_parser.c +++ b/src/yajl_parser.c @@ -46,9 +46,9 @@ unsigned char * yajl_render_error_string(yajl_handle hand, const unsigned char * jsonText, - unsigned int jsonTextLen, int verbose) + size_t jsonTextLen, int verbose) { - unsigned int offset = hand->bytesConsumed; + size_t offset = hand->bytesConsumed; unsigned char * str; const char * errorType = NULL; const char * errorText = NULL; @@ -66,7 +66,7 @@ yajl_render_error_string(yajl_handle hand, const unsigned char * jsonText, } { - unsigned int memneeded = 0; + size_t memneeded = 0; memneeded += strlen(errorType); memneeded += strlen(" error"); if (errorText != NULL) { @@ -87,8 +87,8 @@ yajl_render_error_string(yajl_handle hand, const unsigned char * jsonText, /* now we append as many spaces as needed to make sure the error * falls at char 41, if verbose was specified */ if (verbose) { - unsigned int start, end, i; - unsigned int spacesNeeded; + size_t start, end, i; + size_t spacesNeeded; spacesNeeded = (offset < 30 ? 40 - offset : 10); start = (offset >= 30 ? offset - 30 : 0); @@ -137,12 +137,12 @@ yajl_render_error_string(yajl_handle hand, const unsigned char * jsonText, yajl_status yajl_do_parse(yajl_handle hand, const unsigned char * jsonText, - unsigned int jsonTextLen) + size_t jsonTextLen) { yajl_tok tok; const unsigned char * buf; - unsigned int bufLen; - unsigned int * offset = &(hand->bytesConsumed); + size_t bufLen; + size_t * offset = &(hand->bytesConsumed); *offset = 0; diff --git a/src/yajl_parser.h b/src/yajl_parser.h index f72f3de..5d1a6aa 100644 --- a/src/yajl_parser.h +++ b/src/yajl_parser.h @@ -61,7 +61,7 @@ struct yajl_handle_t { /* the number of bytes consumed from the last client buffer, * in the case of an error this will be an error offset, in the * case of an error this can be used as the error offset */ - unsigned int bytesConsumed; + size_t bytesConsumed; /* temporary storage for decoded strings */ yajl_buf decodeBuf; /* a stack of states. access with yajl_state_XXX routines */ @@ -72,11 +72,11 @@ struct yajl_handle_t { yajl_status yajl_do_parse(yajl_handle handle, const unsigned char * jsonText, - unsigned int jsonTextLen); + size_t jsonTextLen); unsigned char * yajl_render_error_string(yajl_handle hand, const unsigned char * jsonText, - unsigned int jsonTextLen, int verbose); + size_t jsonTextLen, int verbose); #endif diff --git a/test/yajl_test.c b/test/yajl_test.c index 07c9f17..9ac7168 100644 --- a/test/yajl_test.c +++ b/test/yajl_test.c @@ -42,8 +42,8 @@ /* memory debugging routines */ typedef struct { - unsigned int numFrees; - unsigned int numMallocs; + size_t numFrees; + size_t numMallocs; /* XXX: we really need a hash table here with per-allocation * information */ } yajlTestMemoryContext; @@ -58,14 +58,14 @@ static void yajlTestFree(void * ctx, void * ptr) free(ptr); } -static void * yajlTestMalloc(void * ctx, unsigned int sz) +static void * yajlTestMalloc(void * ctx, size_t sz) { assert(sz != 0); TEST_CTX(ctx)->numMallocs++; return malloc(sz); } -static void * yajlTestRealloc(void * ctx, void * ptr, unsigned int sz) +static void * yajlTestRealloc(void * ctx, void * ptr, size_t sz) { if (ptr == NULL) { assert(sz != 0); @@ -106,7 +106,7 @@ static int test_yajl_double(void *ctx, double doubleVal) } static int test_yajl_string(void *ctx, const unsigned char * stringVal, - unsigned int stringLen) + size_t stringLen) { printf("string: '"); fwrite(stringVal, 1, stringLen, stdout); @@ -115,7 +115,7 @@ static int test_yajl_string(void *ctx, const unsigned char * stringVal, } static int test_yajl_map_key(void *ctx, const unsigned char * stringVal, - unsigned int stringLen) + size_t stringLen) { char * str = (char *) malloc(stringLen + 1); str[stringLen] = 0; @@ -180,7 +180,7 @@ main(int argc, char ** argv) yajl_handle hand; const char * fileName; static unsigned char * fileData = NULL; - unsigned int bufSize = BUF_SIZE; + size_t bufSize = BUF_SIZE; yajl_status stat; size_t rd; yajl_parser_config cfg = { 0, 1 }; @@ -218,7 +218,7 @@ main(int argc, char ** argv) bufSize = atoi(argv[i]); if (!bufSize) { - fprintf(stderr, "%d is an invalid buffer size\n", + fprintf(stderr, "%zu is an invalid buffer size\n", bufSize); } } else { @@ -232,7 +232,7 @@ main(int argc, char ** argv) if (fileData == NULL) { fprintf(stderr, - "failed to allocate read buffer of %u bytes, exiting.", + "failed to allocate read buffer of %zu bytes, exiting.", bufSize); exit(2); } @@ -285,7 +285,7 @@ main(int argc, char ** argv) */ fflush(stderr); fflush(stdout); - printf("memory leaks:\t%u\n", memCtx.numMallocs - memCtx.numFrees); + printf("memory leaks:\t%zu\n", memCtx.numMallocs - memCtx.numFrees); return 0; } |