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);
124 #if (defined (HAVE__SET_THREAD_LOCAL_INVALID_PARAMETER_HANDLER) || \
125 defined (HAVE__SET_INVALID_PARAMETER_HANDLER)) && \
126 defined (HAVE__CRT_SET_REPORT_MODE)
127 # define USE_INVALID_PARAMETER_HANDLER
130 #ifdef USE_INVALID_PARAMETER_HANDLER
131 struct _GWin32InvalidParameterHandler
133 _invalid_parameter_handler old_handler;
134 _invalid_parameter_handler pushed_handler;
135 int prev_report_mode;
136 int pushed_report_mode;
139 struct _GWin32InvalidParameterHandler
146 GLIB_AVAILABLE_IN_ALL
147 gchar *_glib_get_locale_dir (void);
150 GDir * g_dir_open_with_errno (const gchar *path, guint flags);
151 GDir * g_dir_new_from_dirp (gpointer dirp);
153 typedef struct _GWin32InvalidParameterHandler GWin32InvalidParameterHandler;
154 void g_win32_push_empty_invalid_parameter_handler (GWin32InvalidParameterHandler *items);
155 void g_win32_pop_invalid_parameter_handler (GWin32InvalidParameterHandler *items);
157 char *g_find_program_for_path (const char *program,
159 const char *working_dir);
161 int g_uri_get_default_scheme_port (const char *scheme);
163 #define GLIB_PRIVATE_CALL(symbol) (glib__private__()->symbol)
168 GWakeup * (* g_wakeup_new) (void);
169 void (* g_wakeup_free) (GWakeup *wakeup);
170 void (* g_wakeup_get_pollfd) (GWakeup *wakeup,
172 void (* g_wakeup_signal) (GWakeup *wakeup);
173 void (* g_wakeup_acknowledge) (GWakeup *wakeup);
176 GMainContext * (* g_get_worker_context) (void);
178 gboolean (* g_check_setuid) (void);
179 GMainContext * (* g_main_context_new_with_next_id) (guint next_id);
181 GDir * (* g_dir_open_with_errno) (const gchar *path,
183 GDir * (* g_dir_new_from_dirp) (gpointer dirp);
185 /* See glib-init.c */
186 void (* glib_init) (void);
190 int (* g_win32_stat_utf8) (const gchar *filename,
191 GWin32PrivateStat *buf);
193 int (* g_win32_lstat_utf8) (const gchar *filename,
194 GWin32PrivateStat *buf);
196 int (* g_win32_readlink_utf8) (const gchar *filename,
202 int (* g_win32_fstat) (int fd,
203 GWin32PrivateStat *buf);
206 gchar *(*g_win32_find_helper_executable_path) (const gchar *process_name,
209 int (* g_win32_reopen_noninherited) (int fd,
213 gboolean (* g_win32_handle_is_socket) (void *handle);
217 /* See glib-private.c */
218 void (* g_win32_push_empty_invalid_parameter_handler) (GWin32InvalidParameterHandler *items);
220 void (* g_win32_pop_invalid_parameter_handler) (GWin32InvalidParameterHandler *items);
223 char *(* g_find_program_for_path) (const char *program,
225 const char *working_dir);
228 int (* g_uri_get_default_scheme_port) (const char *scheme);
230 /* Add other private functions here, initialize them in glib-private.c */
233 GLIB_AVAILABLE_IN_ALL
234 GLibPrivateVTable *glib__private__ (void);
236 /* Please see following for the use of ".ACP" over ""
237 * on Windows, although both are accepted at compile-time
238 * but "" renders translated console messages unreadable if
239 * built with Visual Studio 2012 and later (this is, unfortunately,
242 * https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/setlocale-wsetlocale
243 * https://gitlab.gnome.org/GNOME/glib/merge_requests/895#note_525881
244 * https://gitlab.gnome.org/GNOME/glib/merge_requests/895#note_525900
246 * Additional related items:
247 * https://stackoverflow.com/questions/22604329/php-5-5-setlocale-not-working-in-cli-on-windows
248 * https://bugs.php.net/bug.php?id=66265
252 # define GLIB_DEFAULT_LOCALE ".ACP"
254 # define GLIB_DEFAULT_LOCALE ""
257 #endif /* __GLIB_PRIVATE_H__ */