Ckpool changes to libjansson 2.14

This commit is contained in:
Con Kolivas 2023-06-01 10:29:27 +10:00
parent ed3fce620e
commit b242242770
7 changed files with 61 additions and 22 deletions

View File

@ -1,5 +1,6 @@
/*
* Copyright (c) 2009-2016 Petri Lehtinen <petri@digip.org>
* Copyright (c) 2015,2017,2023 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.
@ -107,7 +108,7 @@ static int dump_string(const char *str, size_t len, json_dump_callback_t dump, v
int length;
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;
@ -432,10 +433,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;
}

View File

@ -1,5 +1,6 @@
/*
* Copyright (c) 2009-2016 Petri Lehtinen <petri@digip.org>
* Copyright (c) 2015,2017,2023 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.
@ -388,6 +389,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);

View File

@ -1,5 +1,6 @@
/*
* Copyright (c) 2009-2016 Petri Lehtinen <petri@digip.org>
* Copyright (c) 2015,2017,2023 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.
@ -83,10 +84,13 @@ int jsonp_dtostr(char *buffer, size_t size, double value, int prec);
/* Wrappers for custom memory functions */
void *jsonp_malloc(size_t size) JANSSON_ATTRS((warn_unused_result));
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) JANSSON_ATTRS((warn_unused_result));
char *jsonp_strdup(const char *str) JANSSON_ATTRS((warn_unused_result));
char *jsonp_strndup(const char *str, size_t len) JANSSON_ATTRS((warn_unused_result));
char *jsonp_strsteal(strbuffer_t *strbuff);
char *jsonp_eolstrsteal(strbuffer_t *strbuff);
/* Circular reference check*/
/* Space for "0x", double the sizeof a pointer for the hex and a terminator. */

View File

@ -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,2023 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.
@ -27,11 +28,12 @@ void *jsonp_malloc(size_t size) {
return (*do_malloc)(size);
}
void jsonp_free(void *ptr) {
if (!ptr)
void _jsonp_free(void **ptr) {
if (!*ptr)
return;
(*do_free)(ptr);
(*do_free)(*ptr);
*ptr = NULL;
}
char *jsonp_strdup(const char *str) { return jsonp_strndup(str, strlen(str)); }
@ -48,6 +50,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;
do_free = free_fn;

View File

@ -1,5 +1,6 @@
/*
* Copyright (c) 2009-2016 Petri Lehtinen <petri@digip.org>
* Copyright (c) 2015,2017,2023 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.
@ -13,8 +14,9 @@
#include "jansson_private.h"
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define STRBUFFER_MIN_SIZE 16
#define STRBUFFER_MIN_SIZE 4096
#define STRBUFFER_FACTOR 2
#define STRBUFFER_SIZE_MAX ((size_t)-1)
@ -58,7 +60,9 @@ 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;
@ -70,13 +74,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;
while (42) {
new_value = realloc(strbuff->value, new_size);
if (new_value)
break;
usleep(backoff * 1000);
backoff <<= 1;
}
memcpy(new_value, strbuff->value, strbuff->length);
jsonp_free(strbuff->value);
strbuff->value = new_value;
strbuff->size = new_size;
}

View File

@ -1,5 +1,6 @@
/*
* Copyright (c) 2009-2016 Petri Lehtinen <petri@digip.org>
* Copyright (c) 2015,2017,2023 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.
@ -113,16 +114,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) {
size_t count;
const char *utf8_iterate(const char *buffer, size_t bufsize, int32_t *codepoint, int noutf8)
{
size_t count = 1;
int32_t value;
if (!bufsize)
return buffer;
count = utf8_check_first(buffer[0]);
if (count <= 0)
return NULL;
if (!noutf8) {
count = utf8_check_first(buffer[0]);
if(count <= 0)
return NULL;
}
if (count == 1)
value = (unsigned char)buffer[0];

View File

@ -1,5 +1,6 @@
/*
* Copyright (c) 2009-2016 Petri Lehtinen <petri@digip.org>
* Copyright (c) 2015,2017,2023 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.
@ -21,7 +22,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);