gmacros.h 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433
  1. /* GLIB - Library of useful routines for C programming
  2. * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
  3. *
  4. * SPDX-License-Identifier: LGPL-2.1-or-later
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /*
  20. * Modified by the GLib Team and others 1997-2000. See the AUTHORS
  21. * file for a list of people on the GLib Team. See the ChangeLog
  22. * files for a list of changes. These files are distributed with
  23. * GLib at ftp://ftp.gtk.org/pub/gtk/.
  24. */
  25. /* This file must not include any other glib header file and must thus
  26. * not refer to variables from glibconfig.h
  27. */
  28. #ifndef __G_MACROS_H__
  29. #define __G_MACROS_H__
  30. #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
  31. #error "Only <glib.h> can be included directly."
  32. #endif
  33. /* We include stddef.h to get the system's definition of NULL
  34. */
  35. #include <stddef.h>
  36. /*
  37. * Note: Clang (but not clang-cl) defines __GNUC__ and __GNUC_MINOR__.
  38. * Both Clang 11.1 on current Arch Linux and Apple's Clang 12.0 define
  39. * __GNUC__ = 4 and __GNUC_MINOR__ = 2. So G_GNUC_CHECK_VERSION(4, 2) on
  40. * current Clang will be 1.
  41. */
  42. #ifdef __GNUC__
  43. #define G_GNUC_CHECK_VERSION(major, minor) \
  44. ((__GNUC__ > (major)) || \
  45. ((__GNUC__ == (major)) && \
  46. (__GNUC_MINOR__ >= (minor))))
  47. #else
  48. #define G_GNUC_CHECK_VERSION(major, minor) 0
  49. #endif
  50. /* Here we provide G_GNUC_EXTENSION as an alias for __extension__,
  51. * where this is valid. This allows for warningless compilation of
  52. * "long long" types even in the presence of '-ansi -pedantic'.
  53. */
  54. #if G_GNUC_CHECK_VERSION(2, 8)
  55. #define G_GNUC_EXTENSION __extension__
  56. #else
  57. #define G_GNUC_EXTENSION
  58. #endif
  59. #if !defined (__cplusplus)
  60. # undef G_CXX_STD_VERSION
  61. # define G_CXX_STD_CHECK_VERSION(version) (0)
  62. # if defined (__STDC_VERSION__)
  63. # define G_C_STD_VERSION __STDC_VERSION__
  64. # else
  65. # define G_C_STD_VERSION 199000L
  66. # endif /* defined (__STDC_VERSION__) */
  67. # define G_C_STD_CHECK_VERSION(version) ( \
  68. ((version) >= 199000L && (version) <= G_C_STD_VERSION) || \
  69. ((version) == 89 && G_C_STD_VERSION >= 199000L) || \
  70. ((version) == 90 && G_C_STD_VERSION >= 199000L) || \
  71. ((version) == 99 && G_C_STD_VERSION >= 199901L) || \
  72. ((version) == 11 && G_C_STD_VERSION >= 201112L) || \
  73. ((version) == 17 && G_C_STD_VERSION >= 201710L) || \
  74. 0)
  75. #else /* defined (__cplusplus) */
  76. # undef G_C_STD_VERSION
  77. # define G_C_STD_CHECK_VERSION(version) (0)
  78. # if defined (_MSVC_LANG)
  79. # define G_CXX_STD_VERSION (_MSVC_LANG > __cplusplus ? _MSVC_LANG : __cplusplus)
  80. # else
  81. # define G_CXX_STD_VERSION __cplusplus
  82. # endif /* defined(_MSVC_LANG) */
  83. # define G_CXX_STD_CHECK_VERSION(version) ( \
  84. ((version) >= 199711L && (version) <= G_CXX_STD_VERSION) || \
  85. ((version) == 98 && G_CXX_STD_VERSION >= 199711L) || \
  86. ((version) == 03 && G_CXX_STD_VERSION >= 199711L) || \
  87. ((version) == 11 && G_CXX_STD_VERSION >= 201103L) || \
  88. ((version) == 14 && G_CXX_STD_VERSION >= 201402L) || \
  89. ((version) == 17 && G_CXX_STD_VERSION >= 201703L) || \
  90. ((version) == 20 && G_CXX_STD_VERSION >= 202002L) || \
  91. 0)
  92. #endif /* !defined (__cplusplus) */
  93. /* Every compiler that we target supports inlining, but some of them may
  94. * complain about it if we don't say "__inline". If we have C99, or if
  95. * we are using C++, then we can use "inline" directly.
  96. * Otherwise, we say "__inline" to avoid the warning.
  97. * Unfortunately Visual Studio does not define __STDC_VERSION__ (if not
  98. * using /std:cXX) so we need to check whether we are on Visual Studio 2013
  99. * or earlier to see whether we need to say "__inline" in C mode.
  100. */
  101. #define G_CAN_INLINE
  102. #ifdef G_C_STD_VERSION
  103. # ifdef _MSC_VER
  104. # if (_MSC_VER < 1900)
  105. # define G_INLINE_DEFINE_NEEDED
  106. # endif
  107. # elif !G_C_STD_CHECK_VERSION (99)
  108. # define G_INLINE_DEFINE_NEEDED
  109. # endif
  110. #endif
  111. #ifdef G_INLINE_DEFINE_NEEDED
  112. # undef inline
  113. # define inline __inline
  114. #endif
  115. #undef G_INLINE_DEFINE_NEEDED
  116. /**
  117. * G_INLINE_FUNC:
  118. *
  119. * This macro used to be used to conditionally define inline functions
  120. * in a compatible way before this feature was supported in all
  121. * compilers. These days, GLib requires inlining support from the
  122. * compiler, so your GLib-using programs can safely assume that the
  123. * "inline" keyword works properly.
  124. *
  125. * Never use this macro anymore. Just say "static inline".
  126. *
  127. * Deprecated: 2.48: Use "static inline" instead
  128. */
  129. /* For historical reasons we need to continue to support those who
  130. * define G_IMPLEMENT_INLINES to mean "don't implement this here".
  131. */
  132. #ifdef G_IMPLEMENT_INLINES
  133. # define G_INLINE_FUNC extern GLIB_DEPRECATED_MACRO_IN_2_48_FOR(static inline)
  134. # undef G_CAN_INLINE
  135. #else
  136. # define G_INLINE_FUNC static inline GLIB_DEPRECATED_MACRO_IN_2_48_FOR(static inline)
  137. #endif /* G_IMPLEMENT_INLINES */
  138. /*
  139. * Attribute support detection. Works on clang and GCC >= 5
  140. * https://clang.llvm.org/docs/LanguageExtensions.html#has-attribute
  141. * https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005fattribute.html
  142. */
  143. #ifdef __has_attribute
  144. #define g_macro__has_attribute __has_attribute
  145. #else
  146. /*
  147. * Fallback for GCC < 5 and other compilers not supporting __has_attribute.
  148. */
  149. #define g_macro__has_attribute(x) g_macro__has_attribute_##x
  150. #define g_macro__has_attribute___alloc_size__ G_GNUC_CHECK_VERSION (4, 3)
  151. #define g_macro__has_attribute___always_inline__ G_GNUC_CHECK_VERSION (2, 0)
  152. #define g_macro__has_attribute___const__ G_GNUC_CHECK_VERSION (2, 4)
  153. #define g_macro__has_attribute___deprecated__ G_GNUC_CHECK_VERSION (3, 1)
  154. #define g_macro__has_attribute___format__ G_GNUC_CHECK_VERSION (2, 4)
  155. #define g_macro__has_attribute___format_arg__ G_GNUC_CHECK_VERSION (2, 4)
  156. #define g_macro__has_attribute___malloc__ G_GNUC_CHECK_VERSION (2, 96)
  157. #define g_macro__has_attribute___no_instrument_function__ G_GNUC_CHECK_VERSION (2, 4)
  158. #define g_macro__has_attribute___noinline__ G_GNUC_CHECK_VERSION (2, 96)
  159. #define g_macro__has_attribute___noreturn__ (G_GNUC_CHECK_VERSION (2, 8) || (0x5110 <= __SUNPRO_C))
  160. #define g_macro__has_attribute___pure__ G_GNUC_CHECK_VERSION (2, 96)
  161. #define g_macro__has_attribute___sentinel__ G_GNUC_CHECK_VERSION (4, 0)
  162. #define g_macro__has_attribute___unused__ G_GNUC_CHECK_VERSION (2, 4)
  163. #define g_macro__has_attribute___weak__ G_GNUC_CHECK_VERSION (2, 8)
  164. #define g_macro__has_attribute_cleanup G_GNUC_CHECK_VERSION (3, 3)
  165. #define g_macro__has_attribute_fallthrough G_GNUC_CHECK_VERSION (6, 0)
  166. #define g_macro__has_attribute_may_alias G_GNUC_CHECK_VERSION (3, 3)
  167. #define g_macro__has_attribute_warn_unused_result G_GNUC_CHECK_VERSION (3, 4)
  168. #endif
  169. /* Provide macros to feature the GCC function attribute.
  170. */
  171. /**
  172. * G_GNUC_PURE:
  173. *
  174. * Expands to the GNU C `pure` function attribute if the compiler is gcc.
  175. * Declaring a function as `pure` enables better optimization of calls to
  176. * the function. A `pure` function has no effects except its return value
  177. * and the return value depends only on the parameters and/or global
  178. * variables.
  179. *
  180. * Place the attribute after the declaration, just before the semicolon.
  181. *
  182. * |[<!-- language="C" -->
  183. * gboolean g_type_check_value (const GValue *value) G_GNUC_PURE;
  184. * ]|
  185. *
  186. * See the [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-pure-function-attribute) for more details.
  187. */
  188. /**
  189. * G_GNUC_MALLOC:
  190. *
  191. * Expands to the
  192. * [GNU C `malloc` function attribute](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-functions-that-behave-like-malloc)
  193. * if the compiler is gcc.
  194. * Declaring a function as `malloc` enables better optimization of the function,
  195. * but must only be done if the allocation behaviour of the function is fully
  196. * understood, otherwise miscompilation can result.
  197. *
  198. * A function can have the `malloc` attribute if it returns a pointer which is
  199. * guaranteed to not alias with any other pointer valid when the function
  200. * returns, and moreover no pointers to valid objects occur in any storage
  201. * addressed by the returned pointer.
  202. *
  203. * In practice, this means that `G_GNUC_MALLOC` can be used with any function
  204. * which returns unallocated or zeroed-out memory, but not with functions which
  205. * return initialised structures containing other pointers, or with functions
  206. * that reallocate memory. This definition changed in GLib 2.58 to match the
  207. * stricter definition introduced around GCC 5.
  208. *
  209. * Place the attribute after the declaration, just before the semicolon.
  210. *
  211. * |[<!-- language="C" -->
  212. * gpointer g_malloc (gsize n_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
  213. * ]|
  214. *
  215. * See the
  216. * [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-functions-that-behave-like-malloc)
  217. * for more details.
  218. *
  219. * Since: 2.6
  220. */
  221. /**
  222. * G_GNUC_NO_INLINE:
  223. *
  224. * Expands to the GNU C `noinline` function attribute if the compiler is gcc.
  225. * If the compiler is not gcc, this macro expands to nothing.
  226. *
  227. * Declaring a function as `noinline` prevents the function from being
  228. * considered for inlining.
  229. *
  230. * This macro is provided for retro-compatibility and will be eventually
  231. * deprecated, but %G_NO_INLINE should be used instead.
  232. *
  233. * The attribute may be placed before the declaration or definition,
  234. * right before the `static` keyword.
  235. *
  236. * |[<!-- language="C" -->
  237. * G_GNUC_NO_INLINE
  238. * static int
  239. * do_not_inline_this (void)
  240. * {
  241. * ...
  242. * }
  243. * ]|
  244. *
  245. * See the
  246. * [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noinline-function-attribute)
  247. * for more details.
  248. *
  249. * See also: %G_NO_INLINE, %G_ALWAYS_INLINE.
  250. *
  251. * Since: 2.58
  252. */
  253. #if g_macro__has_attribute(__pure__)
  254. #define G_GNUC_PURE __attribute__((__pure__))
  255. #else
  256. #define G_GNUC_PURE
  257. #endif
  258. #if g_macro__has_attribute(__malloc__)
  259. #define G_GNUC_MALLOC __attribute__ ((__malloc__))
  260. #else
  261. #define G_GNUC_MALLOC
  262. #endif
  263. #if g_macro__has_attribute(__noinline__)
  264. #define G_GNUC_NO_INLINE __attribute__ ((__noinline__)) \
  265. GLIB_AVAILABLE_MACRO_IN_2_58
  266. #else
  267. #define G_GNUC_NO_INLINE \
  268. GLIB_AVAILABLE_MACRO_IN_2_58
  269. #endif
  270. /**
  271. * G_GNUC_NULL_TERMINATED:
  272. *
  273. * Expands to the GNU C `sentinel` function attribute if the compiler is gcc.
  274. * This function attribute only applies to variadic functions and instructs
  275. * the compiler to check that the argument list is terminated with an
  276. * explicit %NULL.
  277. *
  278. * Place the attribute after the declaration, just before the semicolon.
  279. *
  280. * |[<!-- language="C" -->
  281. * gchar *g_strconcat (const gchar *string1,
  282. * ...) G_GNUC_NULL_TERMINATED;
  283. * ]|
  284. *
  285. * See the [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-sentinel-function-attribute) for more details.
  286. *
  287. * Since: 2.8
  288. */
  289. #if g_macro__has_attribute(__sentinel__)
  290. #define G_GNUC_NULL_TERMINATED __attribute__((__sentinel__))
  291. #else
  292. #define G_GNUC_NULL_TERMINATED
  293. #endif
  294. /*
  295. * Clang feature detection: http://clang.llvm.org/docs/LanguageExtensions.html
  296. * These are not available on GCC, but since the pre-processor doesn't do
  297. * operator short-circuiting, we can't use it in a statement or we'll get:
  298. *
  299. * error: missing binary operator before token "("
  300. *
  301. * So we define it to 0 to satisfy the pre-processor.
  302. */
  303. #ifdef __has_feature
  304. #define g_macro__has_feature __has_feature
  305. #else
  306. #define g_macro__has_feature(x) 0
  307. #endif
  308. #ifdef __has_builtin
  309. #define g_macro__has_builtin __has_builtin
  310. #else
  311. #define g_macro__has_builtin(x) 0
  312. #endif
  313. #ifdef __has_extension
  314. #define g_macro__has_extension __has_extension
  315. #else
  316. #define g_macro__has_extension(x) 0
  317. #endif
  318. /**
  319. * G_GNUC_ALLOC_SIZE:
  320. * @x: the index of the argument specifying the allocation size
  321. *
  322. * Expands to the GNU C `alloc_size` function attribute if the compiler
  323. * is a new enough gcc. This attribute tells the compiler that the
  324. * function returns a pointer to memory of a size that is specified
  325. * by the @xth function parameter.
  326. *
  327. * Place the attribute after the function declaration, just before the
  328. * semicolon.
  329. *
  330. * |[<!-- language="C" -->
  331. * gpointer g_malloc (gsize n_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
  332. * ]|
  333. *
  334. * See the [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-alloc_005fsize-function-attribute) for more details.
  335. *
  336. * Since: 2.18
  337. */
  338. /**
  339. * G_GNUC_ALLOC_SIZE2:
  340. * @x: the index of the argument specifying one factor of the allocation size
  341. * @y: the index of the argument specifying the second factor of the allocation size
  342. *
  343. * Expands to the GNU C `alloc_size` function attribute if the compiler is a
  344. * new enough gcc. This attribute tells the compiler that the function returns
  345. * a pointer to memory of a size that is specified by the product of two
  346. * function parameters.
  347. *
  348. * Place the attribute after the function declaration, just before the
  349. * semicolon.
  350. *
  351. * |[<!-- language="C" -->
  352. * gpointer g_malloc_n (gsize n_blocks,
  353. * gsize n_block_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE2(1, 2);
  354. * ]|
  355. *
  356. * See the [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-alloc_005fsize-function-attribute) for more details.
  357. *
  358. * Since: 2.18
  359. */
  360. #if g_macro__has_attribute(__alloc_size__)
  361. #define G_GNUC_ALLOC_SIZE(x) __attribute__((__alloc_size__(x)))
  362. #define G_GNUC_ALLOC_SIZE2(x,y) __attribute__((__alloc_size__(x,y)))
  363. #else
  364. #define G_GNUC_ALLOC_SIZE(x)
  365. #define G_GNUC_ALLOC_SIZE2(x,y)
  366. #endif
  367. /**
  368. * G_GNUC_PRINTF:
  369. * @format_idx: the index of the argument corresponding to the
  370. * format string (the arguments are numbered from 1)
  371. * @arg_idx: the index of the first of the format arguments, or 0 if
  372. * there are no format arguments
  373. *
  374. * Expands to the GNU C `format` function attribute if the compiler is gcc.
  375. * This is used for declaring functions which take a variable number of
  376. * arguments, with the same syntax as `printf()`. It allows the compiler
  377. * to type-check the arguments passed to the function.
  378. *
  379. * Place the attribute after the function declaration, just before the
  380. * semicolon.
  381. *
  382. * See the
  383. * [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-Wformat-3288)
  384. * for more details.
  385. *
  386. * |[<!-- language="C" -->
  387. * gint g_snprintf (gchar *string,
  388. * gulong n,
  389. * gchar const *format,
  390. * ...) G_GNUC_PRINTF (3, 4);
  391. * ]|
  392. */
  393. /**
  394. * G_GNUC_SCANF:
  395. * @format_idx: the index of the argument corresponding to
  396. * the format string (the arguments are numbered from 1)
  397. * @arg_idx: the index of the first of the format arguments, or 0 if
  398. * there are no format arguments
  399. *
  400. * Expands to the GNU C `format` function attribute if the compiler is gcc.
  401. * This is used for declaring functions which take a variable number of
  402. * arguments, with the same syntax as `scanf()`. It allows the compiler
  403. * to type-check the arguments passed to the function.
  404. *
  405. * |[<!-- language="C" -->
  406. * int my_scanf (MyStream *stream,
  407. * const char *format,
  408. * ...) G_GNUC_SCANF (2, 3);
  409. * int my_vscanf (MyStream *stream,
  410. * const char *format,
  411. * va_list ap) G_GNUC_SCANF (2, 0);
  412. * ]|
  413. *
  414. * See the
  415. * [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-Wformat-3288)
  416. * for details.
  417. */
  418. /**
  419. * G_GNUC_STRFTIME:
  420. * @format_idx: the index of the argument corresponding to
  421. * the format string (the arguments are numbered from 1)
  422. *
  423. * Expands to the GNU C `strftime` format function attribute if the compiler
  424. * is gcc. This is used for declaring functions which take a format argument
  425. * which is passed to `strftime()` or an API implementing its formats. It allows
  426. * the compiler check the format passed to the function.
  427. *
  428. * |[<!-- language="C" -->
  429. * gsize my_strftime (MyBuffer *buffer,
  430. * const char *format,
  431. * const struct tm *tm) G_GNUC_STRFTIME (2);
  432. * ]|
  433. *
  434. * See the
  435. * [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-Wformat-3288)
  436. * for details.
  437. *
  438. * Since: 2.60
  439. */
  440. /**
  441. * G_GNUC_FORMAT:
  442. * @arg_idx: the index of the argument
  443. *
  444. * Expands to the GNU C `format_arg` function attribute if the compiler
  445. * is gcc. This function attribute specifies that a function takes a
  446. * format string for a `printf()`, `scanf()`, `strftime()` or `strfmon()` style
  447. * function and modifies it, so that the result can be passed to a `printf()`,
  448. * `scanf()`, `strftime()` or `strfmon()` style function (with the remaining
  449. * arguments to the format function the same as they would have been
  450. * for the unmodified string).
  451. *
  452. * Place the attribute after the function declaration, just before the
  453. * semicolon.
  454. *
  455. * See the [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-Wformat-nonliteral-1) for more details.
  456. *
  457. * |[<!-- language="C" -->
  458. * gchar *g_dgettext (gchar *domain_name, gchar *msgid) G_GNUC_FORMAT (2);
  459. * ]|
  460. */
  461. /**
  462. * G_GNUC_NORETURN:
  463. *
  464. * Expands to the GNU C `noreturn` function attribute if the compiler is gcc.
  465. * It is used for declaring functions which never return. It enables
  466. * optimization of the function, and avoids possible compiler warnings.
  467. *
  468. * Since 2.68, it is recommended that code uses %G_NORETURN instead of
  469. * %G_GNUC_NORETURN, as that works on more platforms and compilers (in
  470. * particular, MSVC and C++11) than %G_GNUC_NORETURN, which works with GCC and
  471. * Clang only. %G_GNUC_NORETURN continues to work, so has not been deprecated
  472. * yet.
  473. *
  474. * Place the attribute after the declaration, just before the semicolon.
  475. *
  476. * |[<!-- language="C" -->
  477. * void g_abort (void) G_GNUC_NORETURN;
  478. * ]|
  479. *
  480. * See the [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noreturn-function-attribute) for more details.
  481. */
  482. /**
  483. * G_GNUC_CONST:
  484. *
  485. * Expands to the GNU C `const` function attribute if the compiler is gcc.
  486. * Declaring a function as `const` enables better optimization of calls to
  487. * the function. A `const` function doesn't examine any values except its
  488. * parameters, and has no effects except its return value.
  489. *
  490. * Place the attribute after the declaration, just before the semicolon.
  491. *
  492. * |[<!-- language="C" -->
  493. * gchar g_ascii_tolower (gchar c) G_GNUC_CONST;
  494. * ]|
  495. *
  496. * See the [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-const-function-attribute) for more details.
  497. *
  498. * A function that has pointer arguments and examines the data pointed to
  499. * must not be declared `const`. Likewise, a function that calls a non-`const`
  500. * function usually must not be `const`. It doesn't make sense for a `const`
  501. * function to return `void`.
  502. */
  503. /**
  504. * G_GNUC_UNUSED:
  505. *
  506. * Expands to the GNU C `unused` function attribute if the compiler is gcc.
  507. * It is used for declaring functions and arguments which may never be used.
  508. * It avoids possible compiler warnings.
  509. *
  510. * For functions, place the attribute after the declaration, just before the
  511. * semicolon. For arguments, place the attribute at the beginning of the
  512. * argument declaration.
  513. *
  514. * |[<!-- language="C" -->
  515. * void my_unused_function (G_GNUC_UNUSED gint unused_argument,
  516. * gint other_argument) G_GNUC_UNUSED;
  517. * ]|
  518. *
  519. * See the [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-unused-function-attribute) for more details.
  520. */
  521. /**
  522. * G_GNUC_NO_INSTRUMENT:
  523. *
  524. * Expands to the GNU C `no_instrument_function` function attribute if the
  525. * compiler is gcc. Functions with this attribute will not be instrumented
  526. * for profiling, when the compiler is called with the
  527. * `-finstrument-functions` option.
  528. *
  529. * Place the attribute after the declaration, just before the semicolon.
  530. *
  531. * |[<!-- language="C" -->
  532. * int do_uninteresting_things (void) G_GNUC_NO_INSTRUMENT;
  533. * ]|
  534. *
  535. * See the [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-no_005finstrument_005ffunction-function-attribute) for more details.
  536. */
  537. #if g_macro__has_attribute(__format__)
  538. #if !defined (__clang__) && G_GNUC_CHECK_VERSION (4, 4)
  539. #define G_GNUC_PRINTF( format_idx, arg_idx ) \
  540. __attribute__((__format__ (gnu_printf, format_idx, arg_idx)))
  541. #define G_GNUC_SCANF( format_idx, arg_idx ) \
  542. __attribute__((__format__ (gnu_scanf, format_idx, arg_idx)))
  543. #define G_GNUC_STRFTIME( format_idx ) \
  544. __attribute__((__format__ (gnu_strftime, format_idx, 0))) \
  545. GLIB_AVAILABLE_MACRO_IN_2_60
  546. #else
  547. #define G_GNUC_PRINTF( format_idx, arg_idx ) \
  548. __attribute__((__format__ (__printf__, format_idx, arg_idx)))
  549. #define G_GNUC_SCANF( format_idx, arg_idx ) \
  550. __attribute__((__format__ (__scanf__, format_idx, arg_idx)))
  551. #define G_GNUC_STRFTIME( format_idx ) \
  552. __attribute__((__format__ (__strftime__, format_idx, 0))) \
  553. GLIB_AVAILABLE_MACRO_IN_2_60
  554. #endif
  555. #else
  556. #define G_GNUC_PRINTF( format_idx, arg_idx )
  557. #define G_GNUC_SCANF( format_idx, arg_idx )
  558. #define G_GNUC_STRFTIME( format_idx ) \
  559. GLIB_AVAILABLE_MACRO_IN_2_60
  560. #endif
  561. #if g_macro__has_attribute(__format_arg__)
  562. #define G_GNUC_FORMAT(arg_idx) \
  563. __attribute__ ((__format_arg__ (arg_idx)))
  564. #else
  565. #define G_GNUC_FORMAT( arg_idx )
  566. #endif
  567. #if g_macro__has_attribute(__noreturn__)
  568. #define G_GNUC_NORETURN \
  569. __attribute__ ((__noreturn__))
  570. #else
  571. /* NOTE: MSVC has __declspec(noreturn) but unlike GCC __attribute__,
  572. * __declspec can only be placed at the start of the function prototype
  573. * and not at the end, so we can't use it without breaking API.
  574. */
  575. #define G_GNUC_NORETURN
  576. #endif
  577. #if g_macro__has_attribute(__const__)
  578. #define G_GNUC_CONST \
  579. __attribute__ ((__const__))
  580. #else
  581. #define G_GNUC_CONST
  582. #endif
  583. #if g_macro__has_attribute(__unused__)
  584. #define G_GNUC_UNUSED \
  585. __attribute__ ((__unused__))
  586. #else
  587. #define G_GNUC_UNUSED
  588. #endif
  589. #if g_macro__has_attribute(__no_instrument_function__)
  590. #define G_GNUC_NO_INSTRUMENT \
  591. __attribute__ ((__no_instrument_function__))
  592. #else
  593. #define G_GNUC_NO_INSTRUMENT
  594. #endif
  595. /**
  596. * G_GNUC_FALLTHROUGH:
  597. *
  598. * Expands to the GNU C `fallthrough` statement attribute if the compiler supports it.
  599. * This allows declaring case statement to explicitly fall through in switch
  600. * statements. To enable this feature, use `-Wimplicit-fallthrough` during
  601. * compilation.
  602. *
  603. * Put the attribute right before the case statement you want to fall through
  604. * to.
  605. *
  606. * |[<!-- language="C" -->
  607. * switch (foo)
  608. * {
  609. * case 1:
  610. * g_message ("it's 1");
  611. * G_GNUC_FALLTHROUGH;
  612. * case 2:
  613. * g_message ("it's either 1 or 2");
  614. * break;
  615. * }
  616. * ]|
  617. *
  618. *
  619. * See the [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html#index-fallthrough-statement-attribute) for more details.
  620. *
  621. * Since: 2.60
  622. */
  623. #if g_macro__has_attribute(fallthrough)
  624. #define G_GNUC_FALLTHROUGH __attribute__((fallthrough)) \
  625. GLIB_AVAILABLE_MACRO_IN_2_60
  626. #else
  627. #define G_GNUC_FALLTHROUGH \
  628. GLIB_AVAILABLE_MACRO_IN_2_60
  629. #endif
  630. /**
  631. * G_GNUC_DEPRECATED:
  632. *
  633. * Expands to the GNU C `deprecated` attribute if the compiler is gcc.
  634. * It can be used to mark `typedef`s, variables and functions as deprecated.
  635. * When called with the `-Wdeprecated-declarations` option,
  636. * gcc will generate warnings when deprecated interfaces are used.
  637. *
  638. * Place the attribute after the declaration, just before the semicolon.
  639. *
  640. * |[<!-- language="C" -->
  641. * int my_mistake (void) G_GNUC_DEPRECATED;
  642. * ]|
  643. *
  644. * See the [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-deprecated-function-attribute) for more details.
  645. *
  646. * Since: 2.2
  647. */
  648. #if g_macro__has_attribute(__deprecated__)
  649. #define G_GNUC_DEPRECATED __attribute__((__deprecated__))
  650. #else
  651. #define G_GNUC_DEPRECATED
  652. #endif /* __GNUC__ */
  653. /**
  654. * G_GNUC_DEPRECATED_FOR:
  655. * @f: the intended replacement for the deprecated symbol,
  656. * such as the name of a function
  657. *
  658. * Like %G_GNUC_DEPRECATED, but names the intended replacement for the
  659. * deprecated symbol if the version of gcc in use is new enough to support
  660. * custom deprecation messages.
  661. *
  662. * Place the attribute after the declaration, just before the semicolon.
  663. *
  664. * |[<!-- language="C" -->
  665. * int my_mistake (void) G_GNUC_DEPRECATED_FOR(my_replacement);
  666. * ]|
  667. *
  668. * See the [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-deprecated-function-attribute) for more details.
  669. *
  670. * Note that if @f is a macro, it will be expanded in the warning message.
  671. * You can enclose it in quotes to prevent this. (The quotes will show up
  672. * in the warning, but it's better than showing the macro expansion.)
  673. *
  674. * Since: 2.26
  675. */
  676. #if G_GNUC_CHECK_VERSION(4, 5) || defined(__clang__)
  677. #define G_GNUC_DEPRECATED_FOR(f) \
  678. __attribute__((deprecated("Use " #f " instead"))) \
  679. GLIB_AVAILABLE_MACRO_IN_2_26
  680. #else
  681. #define G_GNUC_DEPRECATED_FOR(f) G_GNUC_DEPRECATED \
  682. GLIB_AVAILABLE_MACRO_IN_2_26
  683. #endif /* __GNUC__ */
  684. #ifdef __ICC
  685. #define G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
  686. _Pragma ("warning (push)") \
  687. _Pragma ("warning (disable:1478)")
  688. #define G_GNUC_END_IGNORE_DEPRECATIONS \
  689. _Pragma ("warning (pop)")
  690. #elif G_GNUC_CHECK_VERSION(4, 6)
  691. #define G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
  692. _Pragma ("GCC diagnostic push") \
  693. _Pragma ("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
  694. #define G_GNUC_END_IGNORE_DEPRECATIONS \
  695. _Pragma ("GCC diagnostic pop")
  696. #elif defined (_MSC_VER) && (_MSC_VER >= 1500) && !defined (__clang__)
  697. #define G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
  698. __pragma (warning (push)) \
  699. __pragma (warning (disable : 4996))
  700. #define G_GNUC_END_IGNORE_DEPRECATIONS \
  701. __pragma (warning (pop))
  702. #elif defined (__clang__)
  703. #define G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
  704. _Pragma("clang diagnostic push") \
  705. _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
  706. #define G_GNUC_END_IGNORE_DEPRECATIONS \
  707. _Pragma("clang diagnostic pop")
  708. #else
  709. #define G_GNUC_BEGIN_IGNORE_DEPRECATIONS
  710. #define G_GNUC_END_IGNORE_DEPRECATIONS
  711. #define GLIB_CANNOT_IGNORE_DEPRECATIONS
  712. #endif
  713. /**
  714. * G_GNUC_MAY_ALIAS:
  715. *
  716. * Expands to the GNU C `may_alias` type attribute if the compiler is gcc.
  717. * Types with this attribute will not be subjected to type-based alias
  718. * analysis, but are assumed to alias with any other type, just like `char`.
  719. *
  720. * See the [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-may_005falias-type-attribute) for details.
  721. *
  722. * Since: 2.14
  723. */
  724. #if g_macro__has_attribute(may_alias)
  725. #define G_GNUC_MAY_ALIAS __attribute__((may_alias))
  726. #else
  727. #define G_GNUC_MAY_ALIAS
  728. #endif
  729. /**
  730. * G_GNUC_WARN_UNUSED_RESULT:
  731. *
  732. * Expands to the GNU C `warn_unused_result` function attribute if the compiler
  733. * is gcc. This function attribute makes the compiler emit a warning if the
  734. * result of a function call is ignored.
  735. *
  736. * Place the attribute after the declaration, just before the semicolon.
  737. *
  738. * |[<!-- language="C" -->
  739. * GList *g_list_append (GList *list,
  740. * gpointer data) G_GNUC_WARN_UNUSED_RESULT;
  741. * ]|
  742. *
  743. * See the [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-warn_005funused_005fresult-function-attribute) for more details.
  744. *
  745. * Since: 2.10
  746. */
  747. #if g_macro__has_attribute(warn_unused_result)
  748. #define G_GNUC_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
  749. #else
  750. #define G_GNUC_WARN_UNUSED_RESULT
  751. #endif /* __GNUC__ */
  752. /**
  753. * G_GNUC_FUNCTION:
  754. *
  755. * Expands to "" on all modern compilers, and to __FUNCTION__ on gcc
  756. * version 2.x. Don't use it.
  757. *
  758. * Deprecated: 2.16: Use G_STRFUNC() instead
  759. */
  760. /**
  761. * G_GNUC_PRETTY_FUNCTION:
  762. *
  763. * Expands to "" on all modern compilers, and to __PRETTY_FUNCTION__
  764. * on gcc version 2.x. Don't use it.
  765. *
  766. * Deprecated: 2.16: Use G_STRFUNC() instead
  767. */
  768. /* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with
  769. * macros, so we can refer to them as strings unconditionally.
  770. * usage not-recommended since gcc-3.0
  771. *
  772. * Mark them as deprecated since 2.26, since that’s when version macros were
  773. * introduced.
  774. */
  775. #if defined (__GNUC__) && (__GNUC__ < 3)
  776. #define G_GNUC_FUNCTION __FUNCTION__ GLIB_DEPRECATED_MACRO_IN_2_26_FOR(G_STRFUNC)
  777. #define G_GNUC_PRETTY_FUNCTION __PRETTY_FUNCTION__ GLIB_DEPRECATED_MACRO_IN_2_26_FOR(G_STRFUNC)
  778. #else /* !__GNUC__ */
  779. #define G_GNUC_FUNCTION "" GLIB_DEPRECATED_MACRO_IN_2_26_FOR(G_STRFUNC)
  780. #define G_GNUC_PRETTY_FUNCTION "" GLIB_DEPRECATED_MACRO_IN_2_26_FOR(G_STRFUNC)
  781. #endif /* !__GNUC__ */
  782. #if g_macro__has_feature(attribute_analyzer_noreturn) && defined(__clang_analyzer__)
  783. #define G_ANALYZER_ANALYZING 1
  784. #define G_ANALYZER_NORETURN __attribute__((analyzer_noreturn))
  785. #elif defined(__COVERITY__)
  786. #define G_ANALYZER_ANALYZING 1
  787. #define G_ANALYZER_NORETURN __attribute__((noreturn))
  788. #else
  789. #define G_ANALYZER_ANALYZING 0
  790. #define G_ANALYZER_NORETURN
  791. #endif
  792. #define G_STRINGIFY(macro_or_string) G_STRINGIFY_ARG (macro_or_string)
  793. #define G_STRINGIFY_ARG(contents) #contents
  794. #define G_PASTE_ARGS(identifier1,identifier2) identifier1 ## identifier2
  795. #define G_PASTE(identifier1,identifier2) G_PASTE_ARGS (identifier1, identifier2)
  796. #ifndef __GI_SCANNER__ /* The static assert macro really confuses the introspection parser */
  797. #if G_CXX_STD_CHECK_VERSION (11)
  798. #define G_STATIC_ASSERT(expr) static_assert (expr, "Expression evaluates to false")
  799. #elif (G_C_STD_CHECK_VERSION (11) || \
  800. g_macro__has_feature(c_static_assert) || g_macro__has_extension(c_static_assert))
  801. #define G_STATIC_ASSERT(expr) _Static_assert (expr, "Expression evaluates to false")
  802. #else
  803. #ifdef __COUNTER__
  804. #define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __COUNTER__)[(expr) ? 1 : -1] G_GNUC_UNUSED
  805. #else
  806. #define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __LINE__)[(expr) ? 1 : -1] G_GNUC_UNUSED
  807. #endif
  808. #endif /* G_CXX_STD_CHECK_VERSION (11) */
  809. #define G_STATIC_ASSERT_EXPR(expr) ((void) sizeof (char[(expr) ? 1 : -1]))
  810. #else /* __GI_SCANNER__ */
  811. #define G_STATIC_ASSERT(expr) static int G_PASTE (_GStaticAssertGiScannerNoop, __LINE__) G_GNUC_UNUSED
  812. #define G_STATIC_ASSERT_EXPR(expr) static int G_PASTE (_GStaticAssertGiScannerNoop, __LINE__) G_GNUC_UNUSED
  813. #endif /* __GI_SCANNER__ */
  814. /* Provide a string identifying the current code position */
  815. #if defined (__GNUC__) && (__GNUC__ < 3) && !defined (G_CXX_STD_VERSION)
  816. #define G_STRLOC __FILE__ ":" G_STRINGIFY (__LINE__) ":" __PRETTY_FUNCTION__ "()"
  817. #else
  818. #define G_STRLOC __FILE__ ":" G_STRINGIFY (__LINE__)
  819. #endif
  820. /* Provide a string identifying the current function, non-concatenatable */
  821. #if defined (__GNUC__) && defined (G_CXX_STD_VERSION)
  822. #define G_STRFUNC ((const char*) (__PRETTY_FUNCTION__))
  823. #elif G_C_STD_CHECK_VERSION (99)
  824. #define G_STRFUNC ((const char*) (__func__))
  825. #elif defined (__GNUC__) || (defined(_MSC_VER) && (_MSC_VER > 1300))
  826. #define G_STRFUNC ((const char*) (__FUNCTION__))
  827. #else
  828. #define G_STRFUNC ((const char*) ("???"))
  829. #endif
  830. /* Guard C code in headers, while including them from C++ */
  831. #ifdef G_CXX_STD_VERSION
  832. #define G_BEGIN_DECLS extern "C" {
  833. #define G_END_DECLS }
  834. #else
  835. #define G_BEGIN_DECLS
  836. #define G_END_DECLS
  837. #endif
  838. /* Provide definitions for some commonly used macros.
  839. * Some of them are only provided if they haven't already
  840. * been defined. It is assumed that if they are already
  841. * defined then the current definition is correct.
  842. */
  843. #ifndef NULL
  844. # if G_CXX_STD_CHECK_VERSION (11)
  845. # define NULL (nullptr)
  846. # elif defined (G_CXX_STD_VERSION)
  847. # define NULL (0L)
  848. # else
  849. # define NULL ((void*) 0)
  850. # endif /* G_CXX_STD_CHECK_VERSION (11) */
  851. #endif
  852. #ifndef FALSE
  853. #define FALSE (0)
  854. #endif
  855. #ifndef TRUE
  856. #define TRUE (!FALSE)
  857. #endif
  858. #undef MAX
  859. #define MAX(a, b) (((a) > (b)) ? (a) : (b))
  860. #undef MIN
  861. #define MIN(a, b) (((a) < (b)) ? (a) : (b))
  862. #undef ABS
  863. #define ABS(a) (((a) < 0) ? -(a) : (a))
  864. #undef CLAMP
  865. #define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
  866. #define G_APPROX_VALUE(a, b, epsilon) \
  867. (((a) > (b) ? (a) - (b) : (b) - (a)) < (epsilon))
  868. /* Count the number of elements in an array. The array must be defined
  869. * as such; using this with a dynamically allocated array will give
  870. * incorrect results.
  871. */
  872. #define G_N_ELEMENTS(arr) (sizeof (arr) / sizeof ((arr)[0]))
  873. /* Macros by analogy to GINT_TO_POINTER, GPOINTER_TO_INT
  874. */
  875. #define GPOINTER_TO_SIZE(p) ((gsize) (p))
  876. #define GSIZE_TO_POINTER(s) ((gpointer) (guintptr) (gsize) (s))
  877. /* Provide convenience macros for handling structure
  878. * fields through their offsets.
  879. */
  880. #if G_GNUC_CHECK_VERSION(4, 0) || defined(_MSC_VER)
  881. #define G_STRUCT_OFFSET(struct_type, member) \
  882. ((glong) offsetof (struct_type, member))
  883. #else
  884. #define G_STRUCT_OFFSET(struct_type, member) \
  885. ((glong) ((guint8*) &((struct_type*) 0)->member))
  886. #endif
  887. #define G_STRUCT_MEMBER_P(struct_p, struct_offset) \
  888. ((gpointer) ((guint8*) (struct_p) + (glong) (struct_offset)))
  889. #define G_STRUCT_MEMBER(member_type, struct_p, struct_offset) \
  890. (*(member_type*) G_STRUCT_MEMBER_P ((struct_p), (struct_offset)))
  891. /* Provide simple macro statement wrappers:
  892. * G_STMT_START { statements; } G_STMT_END;
  893. * This can be used as a single statement, like:
  894. * if (x) G_STMT_START { ... } G_STMT_END; else ...
  895. * This intentionally does not use compiler extensions like GCC's '({...})' to
  896. * avoid portability issue or side effects when compiled with different compilers.
  897. * MSVC complains about "while(0)": C4127: "Conditional expression is constant",
  898. * so we use __pragma to avoid the warning since the use here is intentional.
  899. */
  900. #if !(defined (G_STMT_START) && defined (G_STMT_END))
  901. #define G_STMT_START do
  902. #if defined (_MSC_VER) && (_MSC_VER >= 1500)
  903. #define G_STMT_END \
  904. __pragma(warning(push)) \
  905. __pragma(warning(disable:4127)) \
  906. while(0) \
  907. __pragma(warning(pop))
  908. #else
  909. #define G_STMT_END while (0)
  910. #endif
  911. #endif
  912. /* Provide G_ALIGNOF alignment macro.
  913. *
  914. * Note we cannot use the gcc __alignof__ operator here, as that returns the
  915. * preferred alignment rather than the minimal alignment. See
  916. * https://gitlab.gnome.org/GNOME/glib/merge_requests/538/diffs#note_390790.
  917. */
  918. /**
  919. * G_ALIGNOF
  920. * @type: a type-name
  921. *
  922. * Return the minimal alignment required by the platform ABI for values of the given
  923. * type. The address of a variable or struct member of the given type must always be
  924. * a multiple of this alignment. For example, most platforms require int variables
  925. * to be aligned at a 4-byte boundary, so `G_ALIGNOF (int)` is 4 on most platforms.
  926. *
  927. * Note this is not necessarily the same as the value returned by GCC’s
  928. * `__alignof__` operator, which returns the preferred alignment for a type.
  929. * The preferred alignment may be a stricter alignment than the minimal
  930. * alignment.
  931. *
  932. * Since: 2.60
  933. */
  934. #if G_C_STD_CHECK_VERSION (11)
  935. #define G_ALIGNOF(type) _Alignof (type) \
  936. GLIB_AVAILABLE_MACRO_IN_2_60
  937. #else
  938. #define G_ALIGNOF(type) (G_STRUCT_OFFSET (struct { char a; type b; }, b)) \
  939. GLIB_AVAILABLE_MACRO_IN_2_60
  940. #endif
  941. /**
  942. * G_CONST_RETURN:
  943. *
  944. * If %G_DISABLE_CONST_RETURNS is defined, this macro expands
  945. * to nothing. By default, the macro expands to const. The macro
  946. * can be used in place of const for functions that return a value
  947. * that should not be modified. The purpose of this macro is to allow
  948. * us to turn on const for returned constant strings by default, while
  949. * allowing programmers who find that annoying to turn it off. This macro
  950. * should only be used for return values and for "out" parameters, it
  951. * doesn't make sense for "in" parameters.
  952. *
  953. * Deprecated: 2.30: API providers should replace all existing uses with
  954. * const and API consumers should adjust their code accordingly
  955. */
  956. #ifdef G_DISABLE_CONST_RETURNS
  957. #define G_CONST_RETURN GLIB_DEPRECATED_MACRO_IN_2_30_FOR(const)
  958. #else
  959. #define G_CONST_RETURN const GLIB_DEPRECATED_MACRO_IN_2_30_FOR(const)
  960. #endif
  961. /**
  962. * G_NORETURN:
  963. *
  964. * Expands to the GNU C or MSVC `noreturn` function attribute depending on
  965. * the compiler. It is used for declaring functions which never return.
  966. * Enables optimization of the function, and avoids possible compiler warnings.
  967. *
  968. * Note that %G_NORETURN supersedes the previous %G_GNUC_NORETURN macro, which
  969. * will eventually be deprecated. %G_NORETURN supports more platforms.
  970. *
  971. * Place the attribute before the function declaration as follows:
  972. *
  973. * |[<!-- language="C" -->
  974. * G_NORETURN void g_abort (void);
  975. * ]|
  976. *
  977. * Since: 2.68
  978. */
  979. /* Note: We can’t annotate this with GLIB_AVAILABLE_MACRO_IN_2_68 because it’s
  980. * used within the GLib headers in function declarations which are always
  981. * evaluated when a header is included. This results in warnings in third party
  982. * code which includes glib.h, even if the third party code doesn’t use the new
  983. * macro itself. */
  984. #if G_CXX_STD_CHECK_VERSION (11)
  985. /* Use ISO C++11 syntax when the compiler supports it. */
  986. # define G_NORETURN [[noreturn]]
  987. #elif g_macro__has_attribute(__noreturn__)
  988. /* For compatibility with G_NORETURN_FUNCPTR on clang, use
  989. __attribute__((__noreturn__)), not _Noreturn. */
  990. # define G_NORETURN __attribute__ ((__noreturn__))
  991. #elif defined (_MSC_VER) && (1200 <= _MSC_VER)
  992. /* Use MSVC specific syntax. */
  993. # define G_NORETURN __declspec (noreturn)
  994. /* Use ISO C11 syntax when the compiler supports it. */
  995. #elif G_C_STD_CHECK_VERSION (11)
  996. # define G_NORETURN _Noreturn
  997. #else
  998. # define G_NORETURN /* empty */
  999. #endif
  1000. /**
  1001. * G_NORETURN_FUNCPTR:
  1002. *
  1003. * Expands to the GNU C or MSVC `noreturn` function attribute depending on
  1004. * the compiler. It is used for declaring function pointers which never return.
  1005. * Enables optimization of the function, and avoids possible compiler warnings.
  1006. *
  1007. * Place the attribute before the function declaration as follows:
  1008. *
  1009. * |[<!-- language="C" -->
  1010. * G_NORETURN_FUNCPTR void (*funcptr) (void);
  1011. * ]|
  1012. *
  1013. * Note that if the function is not a function pointer, you can simply use
  1014. * the %G_NORETURN macro as follows:
  1015. *
  1016. * |[<!-- language="C" -->
  1017. * G_NORETURN void g_abort (void);
  1018. * ]|
  1019. *
  1020. * Since: 2.68
  1021. */
  1022. #if g_macro__has_attribute(__noreturn__)
  1023. # define G_NORETURN_FUNCPTR __attribute__ ((__noreturn__)) \
  1024. GLIB_AVAILABLE_MACRO_IN_2_68
  1025. #else
  1026. # define G_NORETURN_FUNCPTR /* empty */ \
  1027. GLIB_AVAILABLE_MACRO_IN_2_68
  1028. #endif
  1029. /**
  1030. * G_ALWAYS_INLINE:
  1031. *
  1032. * Expands to the GNU C `always_inline` or MSVC `__forceinline` function
  1033. * attribute depending on the compiler. It is used for declaring functions
  1034. * as always inlined, ignoring the compiler optimization levels.
  1035. *
  1036. * The attribute may be placed before the declaration or definition,
  1037. * right before the `static` keyword.
  1038. *
  1039. * |[<!-- language="C" -->
  1040. * G_ALWAYS_INLINE
  1041. * static int
  1042. * do_inline_this (void)
  1043. * {
  1044. * ...
  1045. * }
  1046. * ]|
  1047. *
  1048. * See the
  1049. * [GNU C documentation](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-always_005finline-function-attribute)
  1050. * and the
  1051. * [MSVC documentation](https://docs.microsoft.com/en-us/visualstudio/misc/inline-inline-forceinline)
  1052. *
  1053. * Since: 2.74
  1054. */
  1055. /* Note: We can’t annotate this with GLIB_AVAILABLE_MACRO_IN_2_74 because it’s
  1056. * used within the GLib headers in function declarations which are always
  1057. * evaluated when a header is included. This results in warnings in third party
  1058. * code which includes glib.h, even if the third party code doesn’t use the new
  1059. * macro itself. */
  1060. #if g_macro__has_attribute(__always_inline__)
  1061. # if G_CXX_STD_CHECK_VERSION (11)
  1062. /* Use ISO C++11 syntax when the compiler supports it. */
  1063. # define G_ALWAYS_INLINE [[gnu::always_inline]]
  1064. # else
  1065. # define G_ALWAYS_INLINE __attribute__ ((__always_inline__))
  1066. # endif
  1067. #elif defined (_MSC_VER)
  1068. /* Use MSVC specific syntax. */
  1069. # if G_CXX_STD_CHECK_VERSION (20) && _MSC_VER >= 1927
  1070. # define G_ALWAYS_INLINE [[msvc::forceinline]]
  1071. # else
  1072. # define G_ALWAYS_INLINE __forceinline
  1073. # endif
  1074. #else
  1075. # define G_ALWAYS_INLINE /* empty */
  1076. #endif
  1077. /**
  1078. * G_NO_INLINE:
  1079. *
  1080. * Expands to the GNU C or MSVC `noinline` function attribute
  1081. * depending on the compiler. It is used for declaring functions
  1082. * preventing from being considered for inlining.
  1083. *
  1084. * Note that %G_NO_INLINE supersedes the previous %G_GNUC_NO_INLINE
  1085. * macro, which will eventually be deprecated.
  1086. * %G_NO_INLINE supports more platforms.
  1087. *
  1088. * The attribute may be placed before the declaration or definition,
  1089. * right before the `static` keyword.
  1090. *
  1091. * |[<!-- language="C" -->
  1092. * G_NO_INLINE
  1093. * static int
  1094. * do_not_inline_this (void)
  1095. * {
  1096. * ...
  1097. * }
  1098. * ]|
  1099. *
  1100. * Since: 2.74
  1101. */
  1102. /* Note: We can’t annotate this with GLIB_AVAILABLE_MACRO_IN_2_74 because it’s
  1103. * used within the GLib headers in function declarations which are always
  1104. * evaluated when a header is included. This results in warnings in third party
  1105. * code which includes glib.h, even if the third party code doesn’t use the new
  1106. * macro itself. */
  1107. #if g_macro__has_attribute(__noinline__)
  1108. # if G_CXX_STD_CHECK_VERSION (11)
  1109. /* Use ISO C++11 syntax when the compiler supports it. */
  1110. # if defined (__GNUC__)
  1111. # define G_NO_INLINE [[gnu::noinline]]
  1112. # elif defined (_MSC_VER)
  1113. # if G_CXX_STD_CHECK_VERSION (20) && _MSC_VER >= 1927
  1114. # define G_NO_INLINE [[msvc::noinline]]
  1115. # else
  1116. # define G_NO_INLINE __declspec (noinline)
  1117. # endif
  1118. # endif
  1119. # else
  1120. # define G_NO_INLINE __attribute__ ((__noinline__))
  1121. # endif
  1122. #elif defined (_MSC_VER) && (1200 <= _MSC_VER)
  1123. /* Use MSVC specific syntax. */
  1124. /* Use ISO C++11 syntax when the compiler supports it. */
  1125. # if G_CXX_STD_CHECK_VERSION (20) && _MSC_VER >= 1927
  1126. # define G_NO_INLINE [[msvc::noinline]]
  1127. # else
  1128. # define G_NO_INLINE __declspec (noinline)
  1129. # endif
  1130. #else
  1131. # define G_NO_INLINE /* empty */
  1132. #endif
  1133. /*
  1134. * The G_LIKELY and G_UNLIKELY macros let the programmer give hints to
  1135. * the compiler about the expected result of an expression. Some compilers
  1136. * can use this information for optimizations.
  1137. *
  1138. * The _G_BOOLEAN_EXPR macro is intended to trigger a gcc warning when
  1139. * putting assignments in g_return_if_fail ().
  1140. */
  1141. #if G_GNUC_CHECK_VERSION(2, 0) && defined(__OPTIMIZE__)
  1142. #define _G_BOOLEAN_EXPR_IMPL(uniq, expr) \
  1143. G_GNUC_EXTENSION ({ \
  1144. int G_PASTE (_g_boolean_var_, uniq); \
  1145. if (expr) \
  1146. G_PASTE (_g_boolean_var_, uniq) = 1; \
  1147. else \
  1148. G_PASTE (_g_boolean_var_, uniq) = 0; \
  1149. G_PASTE (_g_boolean_var_, uniq); \
  1150. })
  1151. #define _G_BOOLEAN_EXPR(expr) _G_BOOLEAN_EXPR_IMPL (__COUNTER__, expr)
  1152. #define G_LIKELY(expr) (__builtin_expect (_G_BOOLEAN_EXPR(expr), 1))
  1153. #define G_UNLIKELY(expr) (__builtin_expect (_G_BOOLEAN_EXPR(expr), 0))
  1154. #else
  1155. #define G_LIKELY(expr) (expr)
  1156. #define G_UNLIKELY(expr) (expr)
  1157. #endif
  1158. #if __GNUC__ >= 4 && !defined(_WIN32) && !defined(__CYGWIN__)
  1159. #define G_HAVE_GNUC_VISIBILITY 1
  1160. #endif
  1161. /* GLIB_CANNOT_IGNORE_DEPRECATIONS is defined above for compilers that do not
  1162. * have a way to temporarily suppress deprecation warnings. In these cases,
  1163. * suppress the deprecated attribute altogether (otherwise a simple #include
  1164. * <glib.h> will emit a barrage of warnings).
  1165. */
  1166. #if defined(GLIB_CANNOT_IGNORE_DEPRECATIONS)
  1167. #define G_DEPRECATED
  1168. #elif G_GNUC_CHECK_VERSION(3, 1) || defined(__clang__)
  1169. #define G_DEPRECATED __attribute__((__deprecated__))
  1170. #elif defined(_MSC_VER) && (_MSC_VER >= 1300)
  1171. #define G_DEPRECATED __declspec(deprecated)
  1172. #else
  1173. #define G_DEPRECATED
  1174. #endif
  1175. #if defined(GLIB_CANNOT_IGNORE_DEPRECATIONS)
  1176. #define G_DEPRECATED_FOR(f) G_DEPRECATED
  1177. #elif G_GNUC_CHECK_VERSION(4, 5) || defined(__clang__)
  1178. #define G_DEPRECATED_FOR(f) __attribute__((__deprecated__("Use '" #f "' instead")))
  1179. #elif defined(_MSC_FULL_VER) && (_MSC_FULL_VER > 140050320)
  1180. #define G_DEPRECATED_FOR(f) __declspec(deprecated("is deprecated. Use '" #f "' instead"))
  1181. #else
  1182. #define G_DEPRECATED_FOR(f) G_DEPRECATED
  1183. #endif
  1184. #if G_GNUC_CHECK_VERSION(4, 5) || defined(__clang__)
  1185. #define G_UNAVAILABLE(maj,min) __attribute__((deprecated("Not available before " #maj "." #min)))
  1186. #elif defined(_MSC_FULL_VER) && (_MSC_FULL_VER > 140050320)
  1187. #define G_UNAVAILABLE(maj,min) __declspec(deprecated("is not available before " #maj "." #min))
  1188. #else
  1189. #define G_UNAVAILABLE(maj,min) G_DEPRECATED
  1190. #endif
  1191. /* These macros are used to mark deprecated symbols in GLib headers,
  1192. * and thus have to be exposed in installed headers. But please
  1193. * do *not* use them in other projects. Instead, use G_DEPRECATED
  1194. * or define your own wrappers around it.
  1195. */
  1196. #if !defined(GLIB_DISABLE_DEPRECATION_WARNINGS) && \
  1197. (G_GNUC_CHECK_VERSION(4, 6) || \
  1198. __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 4))
  1199. #define _GLIB_GNUC_DO_PRAGMA(x) _Pragma(G_STRINGIFY (x))
  1200. #define GLIB_DEPRECATED_MACRO _GLIB_GNUC_DO_PRAGMA(GCC warning "Deprecated pre-processor symbol")
  1201. #define GLIB_DEPRECATED_MACRO_FOR(f) \
  1202. _GLIB_GNUC_DO_PRAGMA(GCC warning G_STRINGIFY (Deprecated pre-processor symbol: replace with #f))
  1203. #define GLIB_UNAVAILABLE_MACRO(maj,min) \
  1204. _GLIB_GNUC_DO_PRAGMA(GCC warning G_STRINGIFY (Not available before maj.min))
  1205. #else
  1206. #define GLIB_DEPRECATED_MACRO
  1207. #define GLIB_DEPRECATED_MACRO_FOR(f)
  1208. #define GLIB_UNAVAILABLE_MACRO(maj,min)
  1209. #endif
  1210. #if !defined(GLIB_DISABLE_DEPRECATION_WARNINGS) && \
  1211. (G_GNUC_CHECK_VERSION(6, 1) || \
  1212. (defined (__clang_major__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 0))))
  1213. #define GLIB_DEPRECATED_ENUMERATOR G_DEPRECATED
  1214. #define GLIB_DEPRECATED_ENUMERATOR_FOR(f) G_DEPRECATED_FOR(f)
  1215. #define GLIB_UNAVAILABLE_ENUMERATOR(maj,min) G_UNAVAILABLE(maj,min)
  1216. #else
  1217. #define GLIB_DEPRECATED_ENUMERATOR
  1218. #define GLIB_DEPRECATED_ENUMERATOR_FOR(f)
  1219. #define GLIB_UNAVAILABLE_ENUMERATOR(maj,min)
  1220. #endif
  1221. #if !defined(GLIB_DISABLE_DEPRECATION_WARNINGS) && \
  1222. (G_GNUC_CHECK_VERSION(3, 1) || \
  1223. (defined (__clang_major__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 0))))
  1224. #define GLIB_DEPRECATED_TYPE G_DEPRECATED
  1225. #define GLIB_DEPRECATED_TYPE_FOR(f) G_DEPRECATED_FOR(f)
  1226. #define GLIB_UNAVAILABLE_TYPE(maj,min) G_UNAVAILABLE(maj,min)
  1227. #else
  1228. #define GLIB_DEPRECATED_TYPE
  1229. #define GLIB_DEPRECATED_TYPE_FOR(f)
  1230. #define GLIB_UNAVAILABLE_TYPE(maj,min)
  1231. #endif
  1232. #ifndef __GI_SCANNER__
  1233. #if g_macro__has_attribute(cleanup)
  1234. /* these macros are private; note that gstdio.h also uses _GLIB_CLEANUP */
  1235. #define _GLIB_AUTOPTR_FUNC_NAME(TypeName) glib_autoptr_cleanup_##TypeName
  1236. #define _GLIB_AUTOPTR_CLEAR_FUNC_NAME(TypeName) glib_autoptr_clear_##TypeName
  1237. #define _GLIB_AUTOPTR_DESTROY_FUNC_NAME(TypeName) glib_autoptr_destroy_##TypeName
  1238. #define _GLIB_AUTOPTR_TYPENAME(TypeName) TypeName##_autoptr
  1239. #define _GLIB_AUTOPTR_LIST_FUNC_NAME(TypeName) glib_listautoptr_cleanup_##TypeName
  1240. #define _GLIB_AUTOPTR_LIST_TYPENAME(TypeName) TypeName##_listautoptr
  1241. #define _GLIB_AUTOPTR_SLIST_FUNC_NAME(TypeName) glib_slistautoptr_cleanup_##TypeName
  1242. #define _GLIB_AUTOPTR_SLIST_TYPENAME(TypeName) TypeName##_slistautoptr
  1243. #define _GLIB_AUTOPTR_QUEUE_FUNC_NAME(TypeName) glib_queueautoptr_cleanup_##TypeName
  1244. #define _GLIB_AUTOPTR_QUEUE_TYPENAME(TypeName) TypeName##_queueautoptr
  1245. #define _GLIB_AUTO_FUNC_NAME(TypeName) glib_auto_cleanup_##TypeName
  1246. #define _GLIB_CLEANUP(func) __attribute__((cleanup(func)))
  1247. #define _GLIB_DEFINE_AUTOPTR_CLEANUP_FUNCS(TypeName, ParentName, cleanup) \
  1248. typedef TypeName *_GLIB_AUTOPTR_TYPENAME(TypeName); \
  1249. typedef GList *_GLIB_AUTOPTR_LIST_TYPENAME(TypeName); \
  1250. typedef GSList *_GLIB_AUTOPTR_SLIST_TYPENAME(TypeName); \
  1251. typedef GQueue *_GLIB_AUTOPTR_QUEUE_TYPENAME(TypeName); \
  1252. G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
  1253. static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_CLEAR_FUNC_NAME(TypeName) (TypeName *_ptr) \
  1254. { if (_ptr) (cleanup) ((ParentName *) _ptr); } \
  1255. static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_FUNC_NAME(TypeName) (TypeName **_ptr) \
  1256. { _GLIB_AUTOPTR_CLEAR_FUNC_NAME(TypeName) (*_ptr); } \
  1257. static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_DESTROY_FUNC_NAME(TypeName) (void *_ptr) \
  1258. { (cleanup) ((ParentName *) _ptr); } \
  1259. static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_LIST_FUNC_NAME(TypeName) (GList **_l) \
  1260. { g_list_free_full (*_l, _GLIB_AUTOPTR_DESTROY_FUNC_NAME(TypeName)); } \
  1261. static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_SLIST_FUNC_NAME(TypeName) (GSList **_l) \
  1262. { g_slist_free_full (*_l, _GLIB_AUTOPTR_DESTROY_FUNC_NAME(TypeName)); } \
  1263. static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_QUEUE_FUNC_NAME(TypeName) (GQueue **_q) \
  1264. { if (*_q) g_queue_free_full (*_q, _GLIB_AUTOPTR_DESTROY_FUNC_NAME(TypeName)); } \
  1265. G_GNUC_END_IGNORE_DEPRECATIONS
  1266. #define _GLIB_DEFINE_AUTOPTR_CHAINUP(ModuleObjName, ParentName) \
  1267. _GLIB_DEFINE_AUTOPTR_CLEANUP_FUNCS(ModuleObjName, ParentName, _GLIB_AUTOPTR_CLEAR_FUNC_NAME(ParentName))
  1268. /* these macros are API */
  1269. #define G_DEFINE_AUTOPTR_CLEANUP_FUNC(TypeName, func) \
  1270. _GLIB_DEFINE_AUTOPTR_CLEANUP_FUNCS(TypeName, TypeName, func)
  1271. #define G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TypeName, func) \
  1272. G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
  1273. static G_GNUC_UNUSED inline void _GLIB_AUTO_FUNC_NAME(TypeName) (TypeName *_ptr) { (func) (_ptr); } \
  1274. G_GNUC_END_IGNORE_DEPRECATIONS
  1275. #define G_DEFINE_AUTO_CLEANUP_FREE_FUNC(TypeName, func, none) \
  1276. G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
  1277. static G_GNUC_UNUSED inline void _GLIB_AUTO_FUNC_NAME(TypeName) (TypeName *_ptr) { if (*_ptr != none) (func) (*_ptr); } \
  1278. G_GNUC_END_IGNORE_DEPRECATIONS
  1279. #define g_autoptr(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_TYPENAME(TypeName)
  1280. #define g_autolist(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_LIST_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_LIST_TYPENAME(TypeName)
  1281. #define g_autoslist(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_SLIST_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_SLIST_TYPENAME(TypeName)
  1282. #define g_autoqueue(TypeName) _GLIB_CLEANUP(_GLIB_AUTOPTR_QUEUE_FUNC_NAME(TypeName)) _GLIB_AUTOPTR_QUEUE_TYPENAME(TypeName)
  1283. #define g_auto(TypeName) _GLIB_CLEANUP(_GLIB_AUTO_FUNC_NAME(TypeName)) TypeName
  1284. #define g_autofree _GLIB_CLEANUP(g_autoptr_cleanup_generic_gfree)
  1285. #else /* not GNU C */
  1286. /* this (dummy) macro is private */
  1287. #define _GLIB_DEFINE_AUTOPTR_CHAINUP(ModuleObjName, ParentName)
  1288. /* these (dummy) macros are API */
  1289. #define G_DEFINE_AUTOPTR_CLEANUP_FUNC(TypeName, func)
  1290. #define G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TypeName, func)
  1291. #define G_DEFINE_AUTO_CLEANUP_FREE_FUNC(TypeName, func, none)
  1292. /* no declaration of g_auto() or g_autoptr() here */
  1293. #endif /* __GNUC__ */
  1294. #else
  1295. #define _GLIB_DEFINE_AUTOPTR_CHAINUP(ModuleObjName, ParentName)
  1296. #define G_DEFINE_AUTOPTR_CLEANUP_FUNC(TypeName, func)
  1297. #define G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TypeName, func)
  1298. #define G_DEFINE_AUTO_CLEANUP_FREE_FUNC(TypeName, func, none)
  1299. #endif /* __GI_SCANNER__ */
  1300. /**
  1301. * G_SIZEOF_MEMBER:
  1302. * @struct_type: a structure type, e.g. #GOutputVector
  1303. * @member: a field in the structure, e.g. `size`
  1304. *
  1305. * Returns the size of @member in the struct definition without having a
  1306. * declared instance of @struct_type.
  1307. *
  1308. * Returns: the size of @member in bytes.
  1309. *
  1310. * Since: 2.64
  1311. */
  1312. #define G_SIZEOF_MEMBER(struct_type, member) \
  1313. GLIB_AVAILABLE_MACRO_IN_2_64 \
  1314. sizeof (((struct_type *) 0)->member)
  1315. #endif /* __G_MACROS_H__ */