Imported Upstream version 2.70.0
[platform/upstream/glib.git] / glib / glib-private.h
1 /* glib-private.h - GLib-internal private API, shared between glib, gobject, gio
2  * Copyright (C) 2011 Red Hat, Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; if not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #ifndef __GLIB_PRIVATE_H__
19 #define __GLIB_PRIVATE_H__
20
21 #include <glib.h>
22 #include "gwakeup.h"
23 #include "gstdioprivate.h"
24
25 /* gcc defines __SANITIZE_ADDRESS__, clang sets the address_sanitizer
26  * feature flag */
27 #if defined(__SANITIZE_ADDRESS__) || g_macro__has_feature(address_sanitizer)
28
29 /*
30  * %_GLIB_ADDRESS_SANITIZER:
31  *
32  * Private macro defined if the AddressSanitizer is in use.
33  */
34 #define _GLIB_ADDRESS_SANITIZER
35
36 #include <sanitizer/lsan_interface.h>
37
38 #endif
39
40 /*
41  * g_ignore_leak:
42  * @p: any pointer
43  *
44  * Tell AddressSanitizer and similar tools that if the object pointed to
45  * by @p is leaked, it is not a problem. Use this to suppress memory leak
46  * reports when a potentially unreachable pointer is deliberately not
47  * going to be deallocated.
48  */
49 static inline void
50 g_ignore_leak (gconstpointer p)
51 {
52 #ifdef _GLIB_ADDRESS_SANITIZER
53   if (p != NULL)
54     __lsan_ignore_object (p);
55 #endif
56 }
57
58 /*
59  * g_ignore_strv_leak:
60  * @strv: (nullable) (array zero-terminated=1): an array of strings
61  *
62  * The same as g_ignore_leak(), but for the memory pointed to by @strv,
63  * and for each element of @strv.
64  */
65 static inline void
66 g_ignore_strv_leak (GStrv strv)
67 {
68 #ifdef _GLIB_ADDRESS_SANITIZER
69   gchar **item;
70
71   if (strv)
72     {
73       g_ignore_leak (strv);
74
75       for (item = strv; *item != NULL; item++)
76         g_ignore_leak (*item);
77     }
78 #endif
79 }
80
81 GMainContext *          g_get_worker_context            (void);
82 gboolean                g_check_setuid                  (void);
83 GMainContext *          g_main_context_new_with_next_id (guint next_id);
84
85 #ifdef G_OS_WIN32
86 gchar *_glib_get_dll_directory (void);
87 GLIB_AVAILABLE_IN_ALL
88 gchar *_glib_get_locale_dir    (void);
89 #endif
90
91 GDir * g_dir_open_with_errno (const gchar *path, guint flags);
92 GDir * g_dir_new_from_dirp (gpointer dirp);
93
94 #define GLIB_PRIVATE_CALL(symbol) (glib__private__()->symbol)
95
96 typedef struct {
97   /* See gwakeup.c */
98   GWakeup *             (* g_wakeup_new)                (void);
99   void                  (* g_wakeup_free)               (GWakeup *wakeup);
100   void                  (* g_wakeup_get_pollfd)         (GWakeup *wakeup,
101                                                         GPollFD *poll_fd);
102   void                  (* g_wakeup_signal)             (GWakeup *wakeup);
103   void                  (* g_wakeup_acknowledge)        (GWakeup *wakeup);
104
105   /* See gmain.c */
106   GMainContext *        (* g_get_worker_context)        (void);
107
108   gboolean              (* g_check_setuid)              (void);
109   GMainContext *        (* g_main_context_new_with_next_id) (guint next_id);
110
111   GDir *                (* g_dir_open_with_errno)       (const gchar *path,
112                                                          guint        flags);
113   GDir *                (* g_dir_new_from_dirp)         (gpointer dirp);
114
115   /* See glib-init.c */
116   void                  (* glib_init)                   (void);
117
118   /* See gstdio.c */
119 #ifdef G_OS_WIN32
120   int                   (* g_win32_stat_utf8)           (const gchar        *filename,
121                                                          GWin32PrivateStat  *buf);
122
123   int                   (* g_win32_lstat_utf8)          (const gchar        *filename,
124                                                          GWin32PrivateStat  *buf);
125
126   int                   (* g_win32_readlink_utf8)       (const gchar        *filename,
127                                                          gchar              *buf,
128                                                          gsize               buf_size,
129                                                          gchar             **alloc_buf,
130                                                          gboolean            terminate);
131
132   int                   (* g_win32_fstat)               (int                 fd,
133                                                          GWin32PrivateStat  *buf);
134 #endif
135
136
137   /* Add other private functions here, initialize them in glib-private.c */
138 } GLibPrivateVTable;
139
140 GLIB_AVAILABLE_IN_ALL
141 GLibPrivateVTable *glib__private__ (void);
142
143 /* Please see following for the use of ".ACP" over ""
144  * on Windows, although both are accepted at compile-time
145  * but "" renders translated console messages unreadable if
146  * built with Visual Studio 2012 and later (this is, unfortunately,
147  * undocumented):
148  *
149  * https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/setlocale-wsetlocale
150  * https://gitlab.gnome.org/GNOME/glib/merge_requests/895#note_525881
151  * https://gitlab.gnome.org/GNOME/glib/merge_requests/895#note_525900
152  *
153  * Additional related items:
154  * https://stackoverflow.com/questions/22604329/php-5-5-setlocale-not-working-in-cli-on-windows
155  * https://bugs.php.net/bug.php?id=66265
156  */
157
158 #ifdef G_OS_WIN32
159 # define GLIB_DEFAULT_LOCALE ".ACP"
160 #else
161 # define GLIB_DEFAULT_LOCALE ""
162 #endif
163
164 #endif /* __GLIB_PRIVATE_H__ */