2
* Copyright (C) 2017 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Pete Woods <pete.woods@canonical.com>
19
#ifndef UNITY_UTIL_GLIBMEMORY_H
20
#define UNITY_UTIL_GLIBMEMORY_H
31
#pragma push_macro("G_DEFINE_AUTOPTR_CLEANUP_FUNC")
32
#undef G_DEFINE_AUTOPTR_CLEANUP_FUNC
33
#define G_DEFINE_AUTOPTR_CLEANUP_FUNC(TypeName, func) \
34
inline std::shared_ptr<TypeName> share_glib(TypeName* ptr) \
36
return std::shared_ptr<TypeName>(ptr, &func); \
38
inline std::unique_ptr<TypeName, decltype(&func)> unique_glib(TypeName* ptr) \
40
return std::unique_ptr<TypeName, decltype(&func)>(ptr, &func); \
43
#pragma push_macro("G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC")
44
#undef G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC
45
#define G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TypeName, func)
47
#define __GLIB_H_INSIDE__
48
#include <glib/glib-autocleanups.h>
49
#undef __GLIB_H_INSIDE__
51
#pragma pop_macro("G_DEFINE_AUTOPTR_CLEANUP_FUNC")
52
#pragma pop_macro("G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC")