(root)/
glib-2.79.0/
glib/
gconstructorprivate.h
       1  /*
       2   * Copyright © 2023 Luca Bacci
       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  #include "gconstructor.h"
      21  
      22  #ifdef _WIN32
      23  #include <windows.h>
      24  #endif
      25  
      26  #ifdef _WIN32
      27  
      28  #ifdef __cplusplus
      29  /* const defaults to static (internal visibility) in C++,
      30   * but we want extern instead */
      31  #define G_EXTERN_CONST extern const
      32  #else
      33  /* Using extern const in C is perfectly valid, but triggers
      34   * a warning in GCC and CLANG, therefore we avoid it */
      35  #define G_EXTERN_CONST const
      36  #endif
      37  
      38  #ifdef _MSC_VER
      39  
      40  #define G_HAS_TLS_CALLBACKS 1
      41  
      42  #define G_DEFINE_TLS_CALLBACK(func) \
      43  __pragma (section (".CRT$XLCE", long, read))                                \
      44                                                                              \
      45  static void NTAPI func (PVOID, DWORD, PVOID);                               \
      46                                                                              \
      47  G_BEGIN_DECLS                                                               \
      48  __declspec (allocate (".CRT$XLCE"))                                         \
      49  G_EXTERN_CONST PIMAGE_TLS_CALLBACK _ptr_##func = func;                      \
      50  G_END_DECLS                                                                 \
      51                                                                              \
      52  __pragma (comment (linker, "/INCLUDE:" G_MSVC_SYMBOL_PREFIX "_tls_used"))   \
      53  __pragma (comment (linker, "/INCLUDE:" G_MSVC_SYMBOL_PREFIX "_ptr_" #func))
      54  
      55  #else
      56  
      57  #define G_HAS_TLS_CALLBACKS 1
      58  
      59  #define G_DEFINE_TLS_CALLBACK(func) \
      60  static void NTAPI func (PVOID, DWORD, PVOID);          \
      61                                                         \
      62  G_BEGIN_DECLS                                          \
      63  __attribute__ ((section (".CRT$XLCE")))                \
      64  G_EXTERN_CONST PIMAGE_TLS_CALLBACK _ptr_##func = func; \
      65  G_END_DECLS
      66  
      67  #endif /* _MSC_VER */
      68  
      69  #endif /* _WIN32 */