2 * Copyright (c) 2009-2012 Petri Lehtinen <petri@digip.org>
4 * Jansson is free software; you can redistribute it and/or modify
5 * it under the terms of the MIT license. See LICENSE for details.
8 #ifndef JANSSON_PRIVATE_H
9 #define JANSSON_PRIVATE_H
13 #include "hashtable.h"
14 #include "strbuffer.h"
16 #define container_of(ptr_, type_, member_) \
17 ((type_ *)((char *)ptr_ - offsetof(type_, member_)))
19 /* On some platforms, max() may already be defined */
21 #define max(a, b) ((a) > (b) ? (a) : (b))
24 /* va_copy is a C99 feature. In C89 implementations, it's sometimes
25 available as __va_copy. If not, memcpy() should do the trick. */
28 #define va_copy __va_copy
30 #define va_copy(a, b) memcpy(&(a), &(b), sizeof(va_list))
36 hashtable_t hashtable;
64 #define json_to_object(json_) container_of(json_, json_object_t, json)
65 #define json_to_array(json_) container_of(json_, json_array_t, json)
66 #define json_to_string(json_) container_of(json_, json_string_t, json)
67 #define json_to_real(json_) container_of(json_, json_real_t, json)
68 #define json_to_integer(json_) container_of(json_, json_integer_t, json)
70 void jsonp_error_init(json_error_t *error, const char *source);
71 void jsonp_error_set_source(json_error_t *error, const char *source);
72 void jsonp_error_set(json_error_t *error, int line, int column,
73 size_t position, const char *msg, ...);
74 void jsonp_error_vset(json_error_t *error, int line, int column,
75 size_t position, const char *msg, va_list ap);
77 /* Locale independent string<->double conversions */
78 int jsonp_strtod(strbuffer_t *strbuffer, double *out);
79 int jsonp_dtostr(char *buffer, size_t size, double value);
81 /* Wrappers for custom memory functions */
82 void* jsonp_malloc(size_t size);
83 void jsonp_free(void *ptr);
84 char *jsonp_strdup(const char *str);
86 /* Windows compatibility */
88 #define snprintf _snprintf
89 #define vsnprintf _vsnprintf