Coverage Report

Created: 2025-07-11 06:47

/src/tinysparql/subprojects/glib-2.80.3/glib/glib-private.c
Line
Count
Source (jump to first uncovered line)
1
/* GLIB - Library of useful routines for C programming
2
 * Copyright (C) 2011 Red Hat, Inc.
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
 * Author: Colin Walters <walters@verbum.org>
20
 */
21
22
#include "config.h"
23
24
#include "glib-private.h"
25
#include "glib-init.h"
26
#include "gutilsprivate.h"
27
#include "gdatasetprivate.h"
28
29
#ifdef USE_INVALID_PARAMETER_HANDLER
30
#include <crtdbg.h>
31
#endif
32
33
/**
34
 * glib__private__:
35
 * @arg: Do not use this argument
36
 *
37
 * Do not call this function; it is used to share private
38
 * API between glib, gobject, and gio.
39
 */
40
const GLibPrivateVTable *
41
glib__private__ (void)
42
10
{
43
10
  static const GLibPrivateVTable table = {
44
10
    g_wakeup_new,
45
10
    g_wakeup_free,
46
10
    g_wakeup_get_pollfd,
47
10
    g_wakeup_signal,
48
10
    g_wakeup_acknowledge,
49
50
10
    g_get_worker_context,
51
52
10
    g_check_setuid,
53
10
    g_main_context_new_with_next_id,
54
55
10
    g_dir_open_with_errno,
56
10
    g_dir_new_from_dirp,
57
58
10
    glib_init,
59
60
#ifdef G_OS_WIN32
61
    g_win32_stat_utf8,
62
    g_win32_lstat_utf8,
63
    g_win32_readlink_utf8,
64
    g_win32_fstat,
65
    g_win32_find_helper_executable_path,
66
    g_win32_reopen_noninherited,
67
    g_win32_handle_is_socket,
68
#endif
69
70
10
    g_win32_push_empty_invalid_parameter_handler,
71
10
    g_win32_pop_invalid_parameter_handler,
72
73
10
    g_find_program_for_path,
74
75
10
    g_uri_get_default_scheme_port,
76
77
10
    g_set_prgname_once,
78
79
10
    g_datalist_id_update_atomic,
80
10
  };
81
82
10
  return &table;
83
10
}
84
85
#ifdef USE_INVALID_PARAMETER_HANDLER
86
/*
87
 * This is the (empty) invalid parameter handler
88
 * that is used for Visual C++ 2005 (and later) builds
89
 * so that we can use this instead of the system automatically
90
 * aborting the process, when calling _get_osfhandle(), isatty()
91
 * and _commit() (via g_fsync()) and so on with an invalid file
92
 * descriptor.
93
 *
94
 * This is necessary so that the gspawn helper and the test programs
95
 * will continue to run as expected, since we are purposely or
96
 * forced to use invalid FDs.
97
 *
98
 * Please see https://learn.microsoft.com/en-us/cpp/c-runtime-library/parameter-validation?view=msvc-170
99
 * for an explanation on this.
100
 */
101
static void
102
empty_invalid_parameter_handler (const wchar_t *expression,
103
                                 const wchar_t *function,
104
                                 const wchar_t *file,
105
                                 unsigned int   line,
106
                                 uintptr_t      pReserved)
107
{
108
}
109
110
/* fallback to _set_invalid_parameter_handler() if we don't have _set_thread_local_invalid_parameter_handler() */
111
#ifndef HAVE__SET_THREAD_LOCAL_INVALID_PARAMETER_HANDLER
112
# define _set_thread_local_invalid_parameter_handler _set_invalid_parameter_handler
113
#endif
114
115
#endif
116
/*
117
 * g_win32_push_empty_invalid_parameter_handler:
118
 * @handler: a possibly uninitialized GWin32InvalidParameterHandler
119
 */
120
void
121
g_win32_push_empty_invalid_parameter_handler (GWin32InvalidParameterHandler *handler)
122
0
{
123
#ifdef USE_INVALID_PARAMETER_HANDLER
124
  /* use the empty invalid parameter handler to override the default invalid parameter_handler */
125
  handler->pushed_handler = empty_invalid_parameter_handler;
126
  handler->old_handler = _set_thread_local_invalid_parameter_handler (handler->pushed_handler);
127
128
  /* Disable the message box for assertions. */
129
  handler->pushed_report_mode = 0;
130
  handler->prev_report_mode = _CrtSetReportMode(_CRT_ASSERT, handler->pushed_report_mode);
131
#endif
132
0
}
133
134
/*
135
 * g_win32_pop_invalid_parameter_handler:
136
 * @handler: a GWin32InvalidParameterHandler processed with
137
 * g_win32_push_empty_invalid_parameter_handler()
138
 */
139
void
140
g_win32_pop_invalid_parameter_handler (GWin32InvalidParameterHandler *handler)
141
0
{
142
#ifdef USE_INVALID_PARAMETER_HANDLER
143
  G_GNUC_UNUSED _invalid_parameter_handler popped_handler;
144
  G_GNUC_UNUSED int popped_report_mode;
145
146
  /* Restore previous/default invalid parameter handler, check the value returned matches the one we previously pushed */
147
  popped_handler = _set_thread_local_invalid_parameter_handler (handler->old_handler);
148
  g_return_if_fail (handler->pushed_handler == popped_handler);
149
150
  /* Restore the message box for assertions, check the value returned matches the one we previously pushed */
151
  popped_report_mode = _CrtSetReportMode(_CRT_ASSERT, handler->prev_report_mode);
152
  g_return_if_fail (handler->pushed_report_mode == popped_report_mode);
153
#endif
154
0
}