2020-11-09 05:23:58 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
2013-10-16 17:00:13 +02:00
|
|
|
#ifndef foosdcommonhfoo
|
|
|
|
#define foosdcommonhfoo
|
|
|
|
|
|
|
|
/***
|
|
|
|
systemd is free software; you can redistribute it and/or modify it
|
|
|
|
under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
systemd is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
***/
|
|
|
|
|
2014-03-25 04:14:28 +01:00
|
|
|
/* This is a private header; never even think of including this directly! */
|
2013-10-16 17:00:13 +02:00
|
|
|
|
2020-08-05 23:53:40 +02:00
|
|
|
#if defined(__INCLUDE_LEVEL__) && __INCLUDE_LEVEL__ <= 1 && !defined(__COVERITY__)
|
2017-03-13 08:11:24 +01:00
|
|
|
# error "Do not include _sd-common.h directly; it is a private header."
|
2013-11-19 01:09:48 +01:00
|
|
|
#endif
|
|
|
|
|
2018-11-28 16:28:53 +01:00
|
|
|
typedef void (*_sd_destroy_t)(void *userdata);
|
|
|
|
|
2013-10-16 17:00:13 +02:00
|
|
|
#ifndef _sd_printf_
|
|
|
|
# if __GNUC__ >= 4
|
2018-12-03 13:15:09 +01:00
|
|
|
# define _sd_printf_(a,b) __attribute__((__format__(printf, a, b)))
|
2013-10-16 17:00:13 +02:00
|
|
|
# else
|
|
|
|
# define _sd_printf_(a,b)
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _sd_sentinel_
|
2018-11-20 04:34:08 +01:00
|
|
|
# define _sd_sentinel_ __attribute__((__sentinel__))
|
2013-10-16 17:00:13 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _sd_packed_
|
2018-11-20 04:34:08 +01:00
|
|
|
# define _sd_packed_ __attribute__((__packed__))
|
2013-10-16 17:00:13 +02:00
|
|
|
#endif
|
|
|
|
|
2013-11-11 23:40:00 +01:00
|
|
|
#ifndef _sd_pure_
|
2018-11-20 04:34:08 +01:00
|
|
|
# define _sd_pure_ __attribute__((__pure__))
|
2013-11-11 23:40:00 +01:00
|
|
|
#endif
|
|
|
|
|
2019-11-26 11:23:52 +01:00
|
|
|
/* Note that strictly speaking __deprecated__ has been available before GCC 6. However, starting with GCC 6
|
|
|
|
* it also works on enum values, which we are interested in. Since this is a developer-facing feature anyway
|
|
|
|
* (as opposed to build engineer-facing), let's hence conditionalize this to gcc 6, given that the developers
|
|
|
|
* are probably going to use something newer anyway. */
|
|
|
|
#ifndef _sd_deprecated_
|
|
|
|
# if __GNUC__ >= 6
|
|
|
|
# define _sd_deprecated_ __attribute__((__deprecated__))
|
|
|
|
# else
|
|
|
|
# define _sd_deprecated_
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2013-11-07 16:44:48 +01:00
|
|
|
#ifndef _SD_STRINGIFY
|
|
|
|
# define _SD_XSTRINGIFY(x) #x
|
|
|
|
# define _SD_STRINGIFY(x) _SD_XSTRINGIFY(x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _SD_BEGIN_DECLARATIONS
|
|
|
|
# ifdef __cplusplus
|
|
|
|
# define _SD_BEGIN_DECLARATIONS \
|
|
|
|
extern "C" { \
|
2015-11-27 20:29:42 +01:00
|
|
|
struct _sd_useless_struct_to_allow_trailing_semicolon_
|
2013-11-07 16:44:48 +01:00
|
|
|
# else
|
|
|
|
# define _SD_BEGIN_DECLARATIONS \
|
2015-11-27 20:29:42 +01:00
|
|
|
struct _sd_useless_struct_to_allow_trailing_semicolon_
|
2013-11-07 16:44:48 +01:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _SD_END_DECLARATIONS
|
|
|
|
# ifdef __cplusplus
|
|
|
|
# define _SD_END_DECLARATIONS \
|
|
|
|
} \
|
2015-11-27 20:29:42 +01:00
|
|
|
struct _sd_useless_cpp_struct_to_allow_trailing_semicolon_
|
2013-11-07 16:44:48 +01:00
|
|
|
# else
|
|
|
|
# define _SD_END_DECLARATIONS \
|
2015-11-27 20:29:42 +01:00
|
|
|
struct _sd_useless_struct_to_allow_trailing_semicolon_
|
2013-11-07 16:44:48 +01:00
|
|
|
# endif
|
2013-10-16 17:00:13 +02:00
|
|
|
#endif
|
|
|
|
|
2019-01-04 12:37:10 +01:00
|
|
|
#ifndef _SD_ARRAY_STATIC
|
|
|
|
# if __STDC_VERSION__ >= 199901L
|
|
|
|
# define _SD_ARRAY_STATIC static
|
|
|
|
# else
|
|
|
|
# define _SD_ARRAY_STATIC
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
tree-wide: expose "p"-suffix unref calls in public APIs to make gcc cleanup easy
GLIB has recently started to officially support the gcc cleanup
attribute in its public API, hence let's do the same for our APIs.
With this patch we'll define an xyz_unrefp() call for each public
xyz_unref() call, to make it easy to use inside a
__attribute__((cleanup())) expression. Then, all code is ported over to
make use of this.
The new calls are also documented in the man pages, with examples how to
use them (well, I only added docs where the _unref() call itself already
had docs, and the examples, only cover sd_bus_unrefp() and
sd_event_unrefp()).
This also renames sd_lldp_free() to sd_lldp_unref(), since that's how we
tend to call our destructors these days.
Note that this defines no public macro that wraps gcc's attribute and
makes it easier to use. While I think it's our duty in the library to
make our stuff easy to use, I figure it's not our duty to make gcc's own
features easy to use on its own. Most likely, client code which wants to
make use of this should define its own:
#define _cleanup_(function) __attribute__((cleanup(function)))
Or similar, to make the gcc feature easier to use.
Making this logic public has the benefit that we can remove three header
files whose only purpose was to define these functions internally.
See #2008.
2015-11-27 19:13:45 +01:00
|
|
|
#define _SD_DEFINE_POINTER_CLEANUP_FUNC(type, func) \
|
2016-03-11 19:41:49 +01:00
|
|
|
static __inline__ void func##p(type **p) { \
|
tree-wide: expose "p"-suffix unref calls in public APIs to make gcc cleanup easy
GLIB has recently started to officially support the gcc cleanup
attribute in its public API, hence let's do the same for our APIs.
With this patch we'll define an xyz_unrefp() call for each public
xyz_unref() call, to make it easy to use inside a
__attribute__((cleanup())) expression. Then, all code is ported over to
make use of this.
The new calls are also documented in the man pages, with examples how to
use them (well, I only added docs where the _unref() call itself already
had docs, and the examples, only cover sd_bus_unrefp() and
sd_event_unrefp()).
This also renames sd_lldp_free() to sd_lldp_unref(), since that's how we
tend to call our destructors these days.
Note that this defines no public macro that wraps gcc's attribute and
makes it easier to use. While I think it's our duty in the library to
make our stuff easy to use, I figure it's not our duty to make gcc's own
features easy to use on its own. Most likely, client code which wants to
make use of this should define its own:
#define _cleanup_(function) __attribute__((cleanup(function)))
Or similar, to make the gcc feature easier to use.
Making this logic public has the benefit that we can remove three header
files whose only purpose was to define these functions internally.
See #2008.
2015-11-27 19:13:45 +01:00
|
|
|
if (*p) \
|
|
|
|
func(*p); \
|
|
|
|
} \
|
2015-11-27 20:29:42 +01:00
|
|
|
struct _sd_useless_struct_to_allow_trailing_semicolon_
|
tree-wide: expose "p"-suffix unref calls in public APIs to make gcc cleanup easy
GLIB has recently started to officially support the gcc cleanup
attribute in its public API, hence let's do the same for our APIs.
With this patch we'll define an xyz_unrefp() call for each public
xyz_unref() call, to make it easy to use inside a
__attribute__((cleanup())) expression. Then, all code is ported over to
make use of this.
The new calls are also documented in the man pages, with examples how to
use them (well, I only added docs where the _unref() call itself already
had docs, and the examples, only cover sd_bus_unrefp() and
sd_event_unrefp()).
This also renames sd_lldp_free() to sd_lldp_unref(), since that's how we
tend to call our destructors these days.
Note that this defines no public macro that wraps gcc's attribute and
makes it easier to use. While I think it's our duty in the library to
make our stuff easy to use, I figure it's not our duty to make gcc's own
features easy to use on its own. Most likely, client code which wants to
make use of this should define its own:
#define _cleanup_(function) __attribute__((cleanup(function)))
Or similar, to make the gcc feature easier to use.
Making this logic public has the benefit that we can remove three header
files whose only purpose was to define these functions internally.
See #2008.
2015-11-27 19:13:45 +01:00
|
|
|
|
2013-10-16 17:00:13 +02:00
|
|
|
#endif
|