2 * Copyright (c) 2009-2011 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
14 #include "hashtable.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))
26 hashtable_t hashtable;
54 #define json_to_object(json_) container_of(json_, json_object_t, json)
55 #define json_to_array(json_) container_of(json_, json_array_t, json)
56 #define json_to_string(json_) container_of(json_, json_string_t, json)
57 #define json_to_real(json_) container_of(json_, json_real_t, json)
58 #define json_to_integer(json_) container_of(json_, json_integer_t, json)
60 size_t jsonp_hash_key(const void *ptr);
61 int jsonp_key_equal(const void *ptr1, const void *ptr2);
68 const object_key_t *jsonp_object_iter_fullkey(void *iter);
70 void jsonp_error_init(json_error_t *error, const char *source);
71 void jsonp_error_set(json_error_t *error, int line, int column,
72 const char *msg, ...);
73 void jsonp_error_vset(json_error_t *error, int line, int column,
74 const char *msg, va_list ap);
76 /* Wrappers for custom memory functions */
77 void* jsonp_malloc(size_t size);
78 void jsonp_free(void *ptr);
79 char *jsonp_strdup(const char *str);