]> git.saurik.com Git - apple/javascriptcore.git/blame - wtf/gobject/GRefPtr.cpp
JavaScriptCore-903.tar.gz
[apple/javascriptcore.git] / wtf / gobject / GRefPtr.cpp
CommitLineData
b37bf2e1 1/*
f9bf01c6 2 * Copyright (C) 2009 Martin Robinson
b37bf2e1
A
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
b37bf2e1
A
17 */
18
9dae56ea 19#include "config.h"
f9bf01c6 20#include "GRefPtr.h"
9dae56ea 21
14957cd0
A
22#if ENABLE(GLIB_SUPPORT)
23
f9bf01c6 24#include <glib.h>
b37bf2e1 25
f9bf01c6 26namespace WTF {
b37bf2e1 27
f9bf01c6 28template <> GHashTable* refGPtr(GHashTable* ptr)
9dae56ea
A
29{
30 if (ptr)
f9bf01c6
A
31 g_hash_table_ref(ptr);
32 return ptr;
9dae56ea 33}
b37bf2e1 34
f9bf01c6 35template <> void derefGPtr(GHashTable* ptr)
ba379fdc 36{
f9bf01c6 37 g_hash_table_unref(ptr);
ba379fdc
A
38}
39
14957cd0
A
40#if GLIB_CHECK_VERSION(2, 24, 0)
41template <> GVariant* refGPtr(GVariant* ptr)
42{
43 if (ptr)
44 g_variant_ref(ptr);
45 return ptr;
46}
47
48template <> void derefGPtr(GVariant* ptr)
49{
50 g_variant_unref(ptr);
51}
52
53#else
54
55// We do this so that we can avoid including the glib.h header in GRefPtr.h.
56typedef struct _GVariant {
57 bool fake;
58} GVariant;
59
60template <> GVariant* refGPtr(GVariant* ptr)
61{
62 return ptr;
63}
64
65template <> void derefGPtr(GVariant* ptr)
66{
67}
68
69#endif
70
71template <> GSource* refGPtr(GSource* ptr)
72{
73 if (ptr)
74 g_source_ref(ptr);
75 return ptr;
76}
77
78template <> void derefGPtr(GSource* ptr)
79{
80 if (ptr)
81 g_source_unref(ptr);
82}
83
9dae56ea 84} // namespace WTF
14957cd0
A
85
86#endif // ENABLE(GLIB_SUPPORT)