Browse Source

Ckpool changes to jansson 2.10

master
Con Kolivas 8 years ago
parent
commit
d8558c19b4
  1. 8
      src/jansson-2.10/src/dump.c
  2. 2
      src/jansson-2.10/src/jansson.h
  3. 8
      src/jansson-2.10/src/jansson_private.h
  4. 2
      src/jansson-2.10/src/lookup3.h
  5. 26
      src/jansson-2.10/src/memory.c
  6. 21
      src/jansson-2.10/src/strbuffer.c
  7. 6
      src/jansson-2.10/src/utf.c
  8. 2
      src/jansson-2.10/src/utf.h

8
src/jansson-2.10/src/dump.c

@ -1,5 +1,6 @@
/*
* Copyright (c) 2009-2016 Petri Lehtinen <petri@digip.org>
* Copyright (c) 2015,2017 Con Kolivas <kernel@kolivas.org>
*
* Jansson is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
@ -116,7 +117,7 @@ static int dump_string(const char *str, size_t len, json_dump_callback_t dump, v
while(end < lim)
{
end = utf8_iterate(pos, lim - pos, &codepoint);
end = utf8_iterate(pos, lim - pos, &codepoint, flags & JSON_NO_UTF8);
if(!end)
return -1;
@ -444,10 +445,11 @@ char *json_dumps(const json_t *json, size_t flags)
if(json_dump_callback(json, dump_to_strbuffer, (void *)&strbuff, flags))
result = NULL;
else if (flags & JSON_EOL)
result = jsonp_eolstrsteal(&strbuff);
else
result = jsonp_strdup(strbuffer_value(&strbuff));
result = jsonp_strsteal(&strbuff);
strbuffer_close(&strbuff);
return result;
}

2
src/jansson-2.10/src/jansson.h

@ -290,6 +290,8 @@ json_t *json_load_callback(json_load_callback_t callback, void *data, size_t fla
#define JSON_ESCAPE_SLASH 0x400
#define JSON_REAL_PRECISION(n) (((n) & 0x1F) << 11)
#define JSON_EMBED 0x10000
#define JSON_NO_UTF8 0x20000
#define JSON_EOL 0x40000
typedef int (*json_dump_callback_t)(const char *buffer, size_t size, void *data);

8
src/jansson-2.10/src/jansson_private.h

@ -1,5 +1,6 @@
/*
* Copyright (c) 2009-2016 Petri Lehtinen <petri@digip.org>
* Copyright (c) 2015,2017 Con Kolivas <kernel@kolivas.org>
*
* Jansson is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
@ -86,9 +87,14 @@ int jsonp_dtostr(char *buffer, size_t size, double value, int prec);
/* Wrappers for custom memory functions */
void* jsonp_malloc(size_t size);
void jsonp_free(void *ptr);
void jsonp_free(void *ptr);
void _jsonp_free(void **ptr);
#define jsonp_free(ptr) _jsonp_free((void *)&(ptr))
char *jsonp_strndup(const char *str, size_t length);
char *jsonp_strdup(const char *str);
char *jsonp_strndup(const char *str, size_t len);
char *jsonp_strsteal(strbuffer_t *strbuff);
char *jsonp_eolstrsteal(strbuffer_t *strbuff);
/* Windows compatibility */

2
src/jansson-2.10/src/lookup3.h

@ -284,8 +284,6 @@ static uint32_t hashlittle(const void *key, size_t length, uint32_t initval)
case 0 : return c;
}
#endif /* !valgrind */
} else if (HASH_LITTLE_ENDIAN && ((u.i & 0x1) == 0)) {
const uint16_t *k = (const uint16_t *)key; /* read 16-bit chunks */
const uint8_t *k8;

26
src/jansson-2.10/src/memory.c

@ -1,6 +1,7 @@
/*
* Copyright (c) 2009-2016 Petri Lehtinen <petri@digip.org>
* Copyright (c) 2011-2012 Basile Starynkevitch <basile@starynkevitch.net>
* Copyright (c) 2015,2017 Con Kolivas <kernel@kolivas.org>
*
* Jansson is free software; you can redistribute it and/or modify it
* under the terms of the MIT license. See LICENSE for details.
@ -28,12 +29,13 @@ void *jsonp_malloc(size_t size)
return (*do_malloc)(size);
}
void jsonp_free(void *ptr)
void _jsonp_free(void **ptr)
{
if(!ptr)
if(!*ptr)
return;
(*do_free)(ptr);
(*do_free)(*ptr);
*ptr = NULL;
}
char *jsonp_strdup(const char *str)
@ -54,6 +56,24 @@ char *jsonp_strndup(const char *str, size_t len)
return new_str;
}
char *jsonp_strsteal(strbuffer_t *strbuff)
{
size_t len = strbuff->length + 1;
char *ret = realloc(strbuff->value, len);
return ret;
}
char *jsonp_eolstrsteal(strbuffer_t *strbuff)
{
size_t len = strbuff->length + 2;
char *ret = realloc(strbuff->value, len);
ret[strbuff->length] = '\n';
ret[strbuff->length + 1] = '\0';
return ret;
}
void json_set_alloc_funcs(json_malloc_t malloc_fn, json_free_t free_fn)
{
do_malloc = malloc_fn;

21
src/jansson-2.10/src/strbuffer.c

@ -1,5 +1,6 @@
/*
* Copyright (c) 2009-2016 Petri Lehtinen <petri@digip.org>
* Copyright (c) 2015,2017 Con Kolivas <kernel@kolivas.org>
*
* Jansson is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
@ -11,10 +12,11 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "jansson_private.h"
#include "strbuffer.h"
#define STRBUFFER_MIN_SIZE 16
#define STRBUFFER_MIN_SIZE 4096
#define STRBUFFER_FACTOR 2
#define STRBUFFER_SIZE_MAX ((size_t)-1)
@ -67,8 +69,10 @@ int strbuffer_append_byte(strbuffer_t *strbuff, char byte)
int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, size_t size)
{
if(size >= strbuff->size - strbuff->length)
/* Leave room for EOL and NULL bytes */
if(size + 2 > strbuff->size - strbuff->length)
{
int backoff = 1;
size_t new_size;
char *new_value;
@ -81,13 +85,14 @@ int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, size_t size)
new_size = max(strbuff->size * STRBUFFER_FACTOR,
strbuff->length + size + 1);
new_value = jsonp_malloc(new_size);
if(!new_value)
return -1;
memcpy(new_value, strbuff->value, strbuff->length);
while (42) {
new_value = realloc(strbuff->value, new_size);
if (new_value)
break;
usleep(backoff * 1000);
backoff <<= 1;
}
jsonp_free(strbuff->value);
strbuff->value = new_value;
strbuff->size = new_size;
}

6
src/jansson-2.10/src/utf.c

@ -136,17 +136,19 @@ size_t utf8_check_full(const char *buffer, size_t size, int32_t *codepoint)
return 1;
}
const char *utf8_iterate(const char *buffer, size_t bufsize, int32_t *codepoint)
const char *utf8_iterate(const char *buffer, size_t bufsize, int32_t *codepoint, int noutf8)
{
size_t count;
size_t count = 1;
int32_t value;
if(!bufsize)
return buffer;
if (!noutf8) {
count = utf8_check_first(buffer[0]);
if(count <= 0)
return NULL;
}
if(count == 1)
value = (unsigned char)buffer[0];

2
src/jansson-2.10/src/utf.h

@ -20,7 +20,7 @@ int utf8_encode(int32_t codepoint, char *buffer, size_t *size);
size_t utf8_check_first(char byte);
size_t utf8_check_full(const char *buffer, size_t size, int32_t *codepoint);
const char *utf8_iterate(const char *buffer, size_t size, int32_t *codepoint);
const char *utf8_iterate(const char *buffer, size_t size, int32_t *codepoint, int noutf8);
int utf8_check_string(const char *string, size_t length);

Loading…
Cancel
Save