1 /* glib-private.h - GLib-internal private API, shared between glib, gobject, gio
2 * Copyright (C) 2011 Red Hat, Inc.
4 * SPDX-License-Identifier: LGPL-2.1-or-later
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.
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.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this library; if not, see <http://www.gnu.org/licenses/>.
20 #ifndef __GLIB_PRIVATE_H__
21 #define __GLIB_PRIVATE_H__
25 #include "gstdioprivate.h"
27 /* gcc defines __SANITIZE_ADDRESS__, clang sets the address_sanitizer
30 * MSVC defines __SANITIZE_ADDRESS__ as well when AddressSanitizer
31 * is enabled but __lsan_ignore_object() equivalent method is not supported
33 * https://docs.microsoft.com/en-us/cpp/sanitizers/asan-building?view=msvc-160
35 #if !defined(_MSC_VER) && (defined(__SANITIZE_ADDRESS__) || g_macro__has_feature(address_sanitizer))
38 * %_GLIB_ADDRESS_SANITIZER:
40 * Private macro defined if the AddressSanitizer is in use.
42 #define _GLIB_ADDRESS_SANITIZER
44 #include <sanitizer/lsan_interface.h>
52 * Tell AddressSanitizer and similar tools that if the object pointed to
53 * by @p is leaked, it is not a problem. Use this to suppress memory leak
54 * reports when a potentially unreachable pointer is deliberately not
55 * going to be deallocated.
58 g_ignore_leak (gconstpointer p)
60 #ifdef _GLIB_ADDRESS_SANITIZER
62 __lsan_ignore_object (p);
68 * @strv: (nullable) (array zero-terminated=1): an array of strings
70 * The same as g_ignore_leak(), but for the memory pointed to by @strv,
71 * and for each element of @strv.
74 g_ignore_strv_leak (GStrv strv)
76 #ifdef _GLIB_ADDRESS_SANITIZER
83 for (item = strv; *item != NULL; item++)
84 g_ignore_leak (*item);
90 * g_begin_ignore_leaks:
92 * Tell AddressSanitizer and similar tools to ignore all leaks from this point
93 * onwards, until g_end_ignore_leaks() is called.
95 * Try to use g_ignore_leak() where possible to target deliberate leaks more
99 g_begin_ignore_leaks (void)
101 #ifdef _GLIB_ADDRESS_SANITIZER
107 * g_end_ignore_leaks:
109 * Start ignoring leaks again; this must be paired with a previous call to
110 * g_begin_ignore_leaks().
113 g_end_ignore_leaks (void)
115 #ifdef _GLIB_ADDRESS_SANITIZER
120 GMainContext * g_get_worker_context (void);
121 gboolean g_check_setuid (void);
122 GMainContext * g_main_context_new_with_next_id (guint next_id);
125 GLIB_AVAILABLE_IN_ALL
126 gchar *_glib_get_locale_dir (void);
129 GDir * g_dir_open_with_errno (const gchar *path, guint flags);
130 GDir * g_dir_new_from_dirp (gpointer dirp);
132 #define GLIB_PRIVATE_CALL(symbol) (glib__private__()->symbol)
136 GWakeup * (* g_wakeup_new) (void);
137 void (* g_wakeup_free) (GWakeup *wakeup);
138 void (* g_wakeup_get_pollfd) (GWakeup *wakeup,
140 void (* g_wakeup_signal) (GWakeup *wakeup);
141 void (* g_wakeup_acknowledge) (GWakeup *wakeup);
144 GMainContext * (* g_get_worker_context) (void);
146 gboolean (* g_check_setuid) (void);
147 GMainContext * (* g_main_context_new_with_next_id) (guint next_id);
149 GDir * (* g_dir_open_with_errno) (const gchar *path,
151 GDir * (* g_dir_new_from_dirp) (gpointer dirp);
153 /* See glib-init.c */
154 void (* glib_init) (void);
158 int (* g_win32_stat_utf8) (const gchar *filename,
159 GWin32PrivateStat *buf);
161 int (* g_win32_lstat_utf8) (const gchar *filename,
162 GWin32PrivateStat *buf);
164 int (* g_win32_readlink_utf8) (const gchar *filename,
170 int (* g_win32_fstat) (int fd,
171 GWin32PrivateStat *buf);
174 gchar *(*g_win32_find_helper_executable_path) (const gchar *process_name,
177 int (* g_win32_reopen_noninherited) (int fd,
181 gboolean (* g_win32_handle_is_socket) (void *handle);
186 /* Add other private functions here, initialize them in glib-private.c */
189 GLIB_AVAILABLE_IN_ALL
190 GLibPrivateVTable *glib__private__ (void);
192 /* Please see following for the use of ".ACP" over ""
193 * on Windows, although both are accepted at compile-time
194 * but "" renders translated console messages unreadable if
195 * built with Visual Studio 2012 and later (this is, unfortunately,
198 * https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/setlocale-wsetlocale
199 * https://gitlab.gnome.org/GNOME/glib/merge_requests/895#note_525881
200 * https://gitlab.gnome.org/GNOME/glib/merge_requests/895#note_525900
202 * Additional related items:
203 * https://stackoverflow.com/questions/22604329/php-5-5-setlocale-not-working-in-cli-on-windows
204 * https://bugs.php.net/bug.php?id=66265
208 # define GLIB_DEFAULT_LOCALE ".ACP"
210 # define GLIB_DEFAULT_LOCALE ""
213 #endif /* __GLIB_PRIVATE_H__ */