1/*
2 * json_init.c
3 *
4 * Copyright (C) 2015 Aerospike, Inc.
5 *
6 * Portions may be licensed to Aerospike, Inc. under one or more contributor
7 * license agreements.
8 *
9 * This program is free software: you can redistribute it and/or modify it under
10 * the terms of the GNU Affero General Public License as published by the Free
11 * Software Foundation, either version 3 of the License, or (at your option) any
12 * later version.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
17 * details.
18 *
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see http://www.gnu.org/licenses/
21 */
22
23#include "jansson.h"
24#include "citrusleaf/alloc.h"
25#include "base/json_init.h"
26
27/* SYNOPSIS
28 * This module handles initialization of the Jansson JSON API by
29 * setting the memory allocation functions to be used internally
30 * by Jansson to the CF allocation-related functions.
31 */
32
33/*
34 * Note that actual wrapper functions are needed instead of simply
35 * using the names of the CF malloc() and free() functions, since the
36 * memory allocation instrumentation infrastructure uses macroexpansion
37 * of the CF allocation-related function names to track all allocations.
38 */
39
40/*
41 * Wrapper function to call the CF malloc() function.
42 */
43static void *as_json_malloc(size_t size)
44{
45 return cf_malloc(size);
46}
47
48/*
49 * Wrapper function to call the CF free() function.
50 */
51static void as_json_free(void *ptr)
52{
53 cf_free(ptr);
54}
55
56/*
57 * Initialize the JSON module by setting the memory allocation functions.
58 */
59void as_json_init()
60{
61 json_set_alloc_funcs(as_json_malloc, as_json_free);
62}
63