1.5.3: Fixes compilation on mac os (due to sprintf being deprecated) #209

This commit is contained in:
Krzysztof Gabis 2023-10-31 20:44:37 +01:00
parent b800e9db07
commit ba29f4eda9
7 changed files with 38 additions and 13 deletions

View File

@ -3,7 +3,7 @@ project(parson C)
include (GNUInstallDirs) include (GNUInstallDirs)
set(PARSON_VERSION 1.5.2) set(PARSON_VERSION 1.5.3)
add_library(parson parson.c) add_library(parson parson.c)
target_include_directories(parson PUBLIC $<INSTALL_INTERFACE:include>) target_include_directories(parson PUBLIC $<INSTALL_INTERFACE:include>)

View File

@ -1,8 +1,8 @@
CC = gcc CC = gcc
CFLAGS = -O0 -g -Wall -Wextra -Wno-deprecated-declarations -std=c89 -pedantic-errors -DTESTS_MAIN CFLAGS = -O0 -g -Wall -Wextra -std=c89 -pedantic-errors -DTESTS_MAIN
CPPC = g++ CPPC = g++
CPPFLAGS = -O0 -g -Wall -Wextra -Wno-deprecated-declarations -DTESTS_MAIN CPPFLAGS = -O0 -g -Wall -Wextra -DTESTS_MAIN
all: test testcpp test_hash_collisions all: test testcpp test_hash_collisions

View File

@ -1,5 +1,5 @@
project('parson', 'c', project('parson', 'c',
version : '1.5.2', version : '1.5.3',
license : 'MIT', license : 'MIT',
meson_version : '>=0.46.0', meson_version : '>=0.46.0',
default_options : [ default_options : [

View File

@ -1,6 +1,6 @@
{ {
"name": "parson", "name": "parson",
"version": "1.5.2", "version": "1.5.3",
"repo": "kgabis/parson", "repo": "kgabis/parson",
"description": "Small json parser and reader", "description": "Small json parser and reader",
"keywords": [ "json", "parser" ], "keywords": [ "json", "parser" ],

View File

@ -1,7 +1,7 @@
/* /*
SPDX-License-Identifier: MIT SPDX-License-Identifier: MIT
Parson 1.5.2 (https://github.com/kgabis/parson) Parson 1.5.3 (https://github.com/kgabis/parson)
Copyright (c) 2012 - 2023 Krzysztof Gabis Copyright (c) 2012 - 2023 Krzysztof Gabis
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
@ -32,7 +32,7 @@
#define PARSON_IMPL_VERSION_MAJOR 1 #define PARSON_IMPL_VERSION_MAJOR 1
#define PARSON_IMPL_VERSION_MINOR 5 #define PARSON_IMPL_VERSION_MINOR 5
#define PARSON_IMPL_VERSION_PATCH 2 #define PARSON_IMPL_VERSION_PATCH 3
#if (PARSON_VERSION_MAJOR != PARSON_IMPL_VERSION_MAJOR)\ #if (PARSON_VERSION_MAJOR != PARSON_IMPL_VERSION_MAJOR)\
|| (PARSON_VERSION_MINOR != PARSON_IMPL_VERSION_MINOR)\ || (PARSON_VERSION_MINOR != PARSON_IMPL_VERSION_MINOR)\
@ -40,6 +40,7 @@
#error "parson version mismatch between parson.c and parson.h" #error "parson version mismatch between parson.c and parson.h"
#endif #endif
#include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -152,6 +153,8 @@ static char * read_file(const char *filename);
static void remove_comments(char *string, const char *start_token, const char *end_token); static void remove_comments(char *string, const char *start_token, const char *end_token);
static char * parson_strndup(const char *string, size_t n); static char * parson_strndup(const char *string, size_t n);
static char * parson_strdup(const char *string); static char * parson_strdup(const char *string);
static int parson_sprintf(char * s, const char * format, ...);
static int hex_char_to_int(char c); static int hex_char_to_int(char c);
static JSON_Status parse_utf16_hex(const char *string, unsigned int *result); static JSON_Status parse_utf16_hex(const char *string, unsigned int *result);
static int num_bytes_in_utf8_sequence(unsigned char c); static int num_bytes_in_utf8_sequence(unsigned char c);
@ -283,6 +286,25 @@ static char * parson_strdup(const char *string) {
return parson_strndup(string, strlen(string)); return parson_strndup(string, strlen(string));
} }
static int parson_sprintf(char * s, const char * format, ...) {
int result;
va_list args;
va_start(args, format);
#if defined(__APPLE__) && defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
result = vsprintf(s, format, args);
#if defined(__APPLE__) && defined(__clang__)
#pragma clang diagnostic pop
#endif
va_end(args);
return result;
}
static int hex_char_to_int(char c) { static int hex_char_to_int(char c) {
if (c >= '0' && c <= '9') { if (c >= '0' && c <= '9') {
return c - '0'; return c - '0';
@ -1243,10 +1265,9 @@ static int json_serialize_to_buffer_r(const JSON_Value *value, char *buf, int le
} }
if (parson_number_serialization_function) { if (parson_number_serialization_function) {
written = parson_number_serialization_function(num, num_buf); written = parson_number_serialization_function(num, num_buf);
} else if (parson_float_format) {
written = sprintf(num_buf, parson_float_format, num);
} else { } else {
written = sprintf(num_buf, PARSON_DEFAULT_FLOAT_FORMAT, num); const char *float_format = parson_float_format ? parson_float_format : PARSON_DEFAULT_FLOAT_FORMAT;
written = parson_sprintf(num_buf, float_format, num);
} }
if (written < 0) { if (written < 0) {
return -1; return -1;

View File

@ -1,7 +1,7 @@
/* /*
SPDX-License-Identifier: MIT SPDX-License-Identifier: MIT
Parson 1.5.2 (https://github.com/kgabis/parson) Parson 1.5.3 (https://github.com/kgabis/parson)
Copyright (c) 2012 - 2023 Krzysztof Gabis Copyright (c) 2012 - 2023 Krzysztof Gabis
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
@ -36,9 +36,9 @@ extern "C"
#define PARSON_VERSION_MAJOR 1 #define PARSON_VERSION_MAJOR 1
#define PARSON_VERSION_MINOR 5 #define PARSON_VERSION_MINOR 5
#define PARSON_VERSION_PATCH 2 #define PARSON_VERSION_PATCH 3
#define PARSON_VERSION_STRING "1.5.2" #define PARSON_VERSION_STRING "1.5.3"
#include <stddef.h> /* size_t */ #include <stddef.h> /* size_t */

View File

@ -26,6 +26,10 @@
#define _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS
#endif #endif
#if defined(__APPLE__) && defined(__clang__)
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
#include "parson.h" #include "parson.h"
#include <assert.h> #include <assert.h>