LibreOffice Module o3tl (master) 1
deleter.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10#ifndef INCLUDED_O3TL_DELETER_HXX
11#define INCLUDED_O3TL_DELETER_HXX
12
13#include <sal/config.h>
14
15#include <cstdlib>
16
17#if defined(__COVERITY__)
18#define suppress_fun_call_w_exception(expr) \
19 do \
20 { \
21 try \
22 { \
23 expr; \
24 } \
25 catch (...) \
26 { \
27 std::terminate(); \
28 } \
29 } while (false)
30#else
31#define suppress_fun_call_w_exception(expr) \
32 do \
33 { \
34 expr; \
35 } while (false)
36#endif
37
38namespace o3tl
39{
44template <typename T> struct default_delete
45{
46 void operator()(T* p) noexcept { suppress_fun_call_w_exception(delete p); }
47};
48
50{
51 void operator()(void* p) { std::free(p); }
52};
53
54template <typename uniqueptr> void reset_preserve_ptr_during(uniqueptr& ptr)
55{
56 // HACK: for the case where the dtor of the obj held by ptr will trigger
57 // functions which expect ptr to still be set during the dtor.
58 // e.g. SdrObject::GetBroadcaster() is called during the destructor
59 // in SdrEdgeObj::Notify(). So delete first, then clear the pointer
60 delete ptr.get();
61 // coverity[leaked_storage] - not a leak, deleted on line above
62 (void)ptr.release();
63}
64}
65
66#endif
67
68/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define suppress_fun_call_w_exception(expr)
Definition: deleter.hxx:31
void * p
void reset_preserve_ptr_during(uniqueptr &ptr)
Definition: deleter.hxx:54
To markup std::unique_ptr that coverity warns might throw exceptions which won't throw in practice,...
Definition: deleter.hxx:45
void operator()(T *p) noexcept
Definition: deleter.hxx:46
void operator()(void *p)
Definition: deleter.hxx:51