Skip to content

Commit

Permalink
1.5.3: Fixes compilation on mac os (due to sprintf being deprecated) #…
Browse files Browse the repository at this point in the history
  • Loading branch information
kgabis committed Oct 31, 2023
1 parent b800e9d commit ba29f4e
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ project(parson C)

include (GNUInstallDirs)

set(PARSON_VERSION 1.5.2)
set(PARSON_VERSION 1.5.3)
add_library(parson parson.c)
target_include_directories(parson PUBLIC $<INSTALL_INTERFACE:include>)

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
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++
CPPFLAGS = -O0 -g -Wall -Wextra -Wno-deprecated-declarations -DTESTS_MAIN
CPPFLAGS = -O0 -g -Wall -Wextra -DTESTS_MAIN

all: test testcpp test_hash_collisions

Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
project('parson', 'c',
version : '1.5.2',
version : '1.5.3',
license : 'MIT',
meson_version : '>=0.46.0',
default_options : [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "parson",
"version": "1.5.2",
"version": "1.5.3",
"repo": "kgabis/parson",
"description": "Small json parser and reader",
"keywords": [ "json", "parser" ],
Expand Down
31 changes: 26 additions & 5 deletions parson.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
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
Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down Expand Up @@ -32,14 +32,15 @@

#define PARSON_IMPL_VERSION_MAJOR 1
#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)\
|| (PARSON_VERSION_MINOR != PARSON_IMPL_VERSION_MINOR)\
|| (PARSON_VERSION_PATCH != PARSON_IMPL_VERSION_PATCH)
#error "parson version mismatch between parson.c and parson.h"
#endif

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -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 char * parson_strndup(const char *string, size_t n);
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 JSON_Status parse_utf16_hex(const char *string, unsigned int *result);
static int num_bytes_in_utf8_sequence(unsigned char c);
Expand Down Expand Up @@ -283,6 +286,25 @@ static char * parson_strdup(const char *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) {
if (c >= '0' && c <= '9') {
return c - '0';
Expand Down Expand Up @@ -1243,10 +1265,9 @@ static int json_serialize_to_buffer_r(const JSON_Value *value, char *buf, int le
}
if (parson_number_serialization_function) {
written = parson_number_serialization_function(num, num_buf);
} else if (parson_float_format) {
written = sprintf(num_buf, parson_float_format, num);
} 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) {
return -1;
Expand Down
6 changes: 3 additions & 3 deletions parson.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
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
Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down Expand Up @@ -36,9 +36,9 @@ extern "C"

#define PARSON_VERSION_MAJOR 1
#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 */

Expand Down
4 changes: 4 additions & 0 deletions tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
#define _CRT_SECURE_NO_WARNINGS
#endif

#if defined(__APPLE__) && defined(__clang__)
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif

#include "parson.h"

#include <assert.h>
Expand Down

1 comment on commit ba29f4e

@kgabis
Copy link
Owner Author

@kgabis kgabis commented on ba29f4e Oct 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was meant to be issue #207

Please sign in to comment.