glib-private.c: Add private API to override invalid parameter handler

...if supported, as in the previous commit.  We will eventually use
these private API to override the invalid parameter handler as needed
in the other parts of GLib and the tests.

We also now use _set_thread_local_invalid_parameter_handler()
instead of just _set_invalid_parameter_handler() to be safer, if
that is available.

This can be expanded upon in the future if we desire to use a stricter
or more customized invalid parameter handler.
This commit is contained in:
Chun-wei Fan
2022-11-03 00:00:31 +08:00
parent b92b17f021
commit 08e0fef632
2 changed files with 102 additions and 0 deletions

View File

@@ -127,6 +127,21 @@ GMainContext * g_main_context_new_with_next_id (guint next_id);
# define USE_INVALID_PARAMETER_HANDLER
#endif
#ifdef USE_INVALID_PARAMETER_HANDLER
struct _GWin32InvalidParameterHandler
{
_invalid_parameter_handler old_handler;
_invalid_parameter_handler pushed_handler;
int prev_report_mode;
int pushed_report_mode;
};
#else
struct _GWin32InvalidParameterHandler
{
int unused_really;
};
#endif
#ifdef G_OS_WIN32
GLIB_AVAILABLE_IN_ALL
gchar *_glib_get_locale_dir (void);
@@ -135,8 +150,13 @@ gchar *_glib_get_locale_dir (void);
GDir * g_dir_open_with_errno (const gchar *path, guint flags);
GDir * g_dir_new_from_dirp (gpointer dirp);
typedef struct _GWin32InvalidParameterHandler GWin32InvalidParameterHandler;
void g_win32_push_empty_invalid_parameter_handler (GWin32InvalidParameterHandler *items);
void g_win32_pop_invalid_parameter_handler (GWin32InvalidParameterHandler *items);
#define GLIB_PRIVATE_CALL(symbol) (glib__private__()->symbol)
typedef struct {
/* See gwakeup.c */
GWakeup * (* g_wakeup_new) (void);
@@ -188,6 +208,10 @@ typedef struct {
#endif
/* See glib-private.c */
void (* g_win32_push_empty_invalid_parameter_handler) (GWin32InvalidParameterHandler *items);
void (* g_win32_pop_invalid_parameter_handler) (GWin32InvalidParameterHandler *items);
/* Add other private functions here, initialize them in glib-private.c */
} GLibPrivateVTable;