1d0825bca7fe65beaee391d30da42e937db621564Steve Block/* 2d0825bca7fe65beaee391d30da42e937db621564Steve Block * Copyright (C) 2009 Martin Robinson 3d0825bca7fe65beaee391d30da42e937db621564Steve Block * 4d0825bca7fe65beaee391d30da42e937db621564Steve Block * This library is free software; you can redistribute it and/or 5d0825bca7fe65beaee391d30da42e937db621564Steve Block * modify it under the terms of the GNU Lesser General Public 6d0825bca7fe65beaee391d30da42e937db621564Steve Block * License as published by the Free Software Foundation; either 7d0825bca7fe65beaee391d30da42e937db621564Steve Block * version 2 of the License, or (at your option) any later version. 8d0825bca7fe65beaee391d30da42e937db621564Steve Block * 9d0825bca7fe65beaee391d30da42e937db621564Steve Block * This library is distributed in the hope that it will be useful, 10d0825bca7fe65beaee391d30da42e937db621564Steve Block * but WITHOUT ANY WARRANTY; without even the implied warranty of 11d0825bca7fe65beaee391d30da42e937db621564Steve Block * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12d0825bca7fe65beaee391d30da42e937db621564Steve Block * Lesser General Public License for more details. 13d0825bca7fe65beaee391d30da42e937db621564Steve Block * 14d0825bca7fe65beaee391d30da42e937db621564Steve Block * You should have received a copy of the GNU Lesser General Public 15d0825bca7fe65beaee391d30da42e937db621564Steve Block * License along with this library; if not, write to the Free Software 16d0825bca7fe65beaee391d30da42e937db621564Steve Block * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17d0825bca7fe65beaee391d30da42e937db621564Steve Block */ 18d0825bca7fe65beaee391d30da42e937db621564Steve Block 19d0825bca7fe65beaee391d30da42e937db621564Steve Block#include "config.h" 20d0825bca7fe65beaee391d30da42e937db621564Steve Block#include "GRefPtr.h" 21d0825bca7fe65beaee391d30da42e937db621564Steve Block 22bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#if ENABLE(GLIB_SUPPORT) 23bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 24d0825bca7fe65beaee391d30da42e937db621564Steve Block#include <glib.h> 25d0825bca7fe65beaee391d30da42e937db621564Steve Block 26d0825bca7fe65beaee391d30da42e937db621564Steve Blocknamespace WTF { 27d0825bca7fe65beaee391d30da42e937db621564Steve Block 28cad810f21b803229eb11403f9209855525a25d57Steve Blocktemplate <> GHashTable* refGPtr(GHashTable* ptr) 29d0825bca7fe65beaee391d30da42e937db621564Steve Block{ 30d0825bca7fe65beaee391d30da42e937db621564Steve Block if (ptr) 31d0825bca7fe65beaee391d30da42e937db621564Steve Block g_hash_table_ref(ptr); 32d0825bca7fe65beaee391d30da42e937db621564Steve Block return ptr; 33d0825bca7fe65beaee391d30da42e937db621564Steve Block} 34d0825bca7fe65beaee391d30da42e937db621564Steve Block 35cad810f21b803229eb11403f9209855525a25d57Steve Blocktemplate <> void derefGPtr(GHashTable* ptr) 36d0825bca7fe65beaee391d30da42e937db621564Steve Block{ 37d0825bca7fe65beaee391d30da42e937db621564Steve Block g_hash_table_unref(ptr); 38d0825bca7fe65beaee391d30da42e937db621564Steve Block} 39d0825bca7fe65beaee391d30da42e937db621564Steve Block 40f486d19d62f1bc33246748b14b14a9dfa617b57fIain Merrick#if GLIB_CHECK_VERSION(2, 24, 0) 41cad810f21b803229eb11403f9209855525a25d57Steve Blocktemplate <> GVariant* refGPtr(GVariant* ptr) 42f486d19d62f1bc33246748b14b14a9dfa617b57fIain Merrick{ 43f486d19d62f1bc33246748b14b14a9dfa617b57fIain Merrick if (ptr) 44f486d19d62f1bc33246748b14b14a9dfa617b57fIain Merrick g_variant_ref(ptr); 45f486d19d62f1bc33246748b14b14a9dfa617b57fIain Merrick return ptr; 46f486d19d62f1bc33246748b14b14a9dfa617b57fIain Merrick} 47f486d19d62f1bc33246748b14b14a9dfa617b57fIain Merrick 48cad810f21b803229eb11403f9209855525a25d57Steve Blocktemplate <> void derefGPtr(GVariant* ptr) 49f486d19d62f1bc33246748b14b14a9dfa617b57fIain Merrick{ 50f486d19d62f1bc33246748b14b14a9dfa617b57fIain Merrick g_variant_unref(ptr); 51f486d19d62f1bc33246748b14b14a9dfa617b57fIain Merrick} 52e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block 53e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block#else 54e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block 55e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block// We do this so that we can avoid including the glib.h header in GRefPtr.h. 56e8b154fd68f9b33be40a3590e58347f353835f5cSteve Blocktypedef struct _GVariant { 57e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block bool fake; 58e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block} GVariant; 59e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block 60cad810f21b803229eb11403f9209855525a25d57Steve Blocktemplate <> GVariant* refGPtr(GVariant* ptr) 61e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block{ 62e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block return ptr; 63e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block} 64e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block 65cad810f21b803229eb11403f9209855525a25d57Steve Blocktemplate <> void derefGPtr(GVariant* ptr) 66e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block{ 67e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block} 68e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block 69f486d19d62f1bc33246748b14b14a9dfa617b57fIain Merrick#endif 70f486d19d62f1bc33246748b14b14a9dfa617b57fIain Merrick 71cad810f21b803229eb11403f9209855525a25d57Steve Blocktemplate <> GSource* refGPtr(GSource* ptr) 725abb8606fa57c3ebfc8b3c3dbc3fa4a25d2ae306Iain Merrick{ 735abb8606fa57c3ebfc8b3c3dbc3fa4a25d2ae306Iain Merrick if (ptr) 745abb8606fa57c3ebfc8b3c3dbc3fa4a25d2ae306Iain Merrick g_source_ref(ptr); 755abb8606fa57c3ebfc8b3c3dbc3fa4a25d2ae306Iain Merrick return ptr; 765abb8606fa57c3ebfc8b3c3dbc3fa4a25d2ae306Iain Merrick} 775abb8606fa57c3ebfc8b3c3dbc3fa4a25d2ae306Iain Merrick 78cad810f21b803229eb11403f9209855525a25d57Steve Blocktemplate <> void derefGPtr(GSource* ptr) 795abb8606fa57c3ebfc8b3c3dbc3fa4a25d2ae306Iain Merrick{ 805abb8606fa57c3ebfc8b3c3dbc3fa4a25d2ae306Iain Merrick if (ptr) 815abb8606fa57c3ebfc8b3c3dbc3fa4a25d2ae306Iain Merrick g_source_unref(ptr); 825abb8606fa57c3ebfc8b3c3dbc3fa4a25d2ae306Iain Merrick} 835abb8606fa57c3ebfc8b3c3dbc3fa4a25d2ae306Iain Merrick 84d0825bca7fe65beaee391d30da42e937db621564Steve Block} // namespace WTF 85bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen 86bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#endif // ENABLE(GLIB_SUPPORT) 87