1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* Invalid parameter handler for MSVC runtime libraries.
4 Copyright (C) 2011-2013 Free Software Foundation, Inc.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 This program 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
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, see <http://www.gnu.org/licenses/>. */
22 #include "msvc-inval.h"
24 #if HAVE_MSVC_INVALID_PARAMETER_HANDLER \
25 && !(MSVC_INVALID_PARAMETER_HANDLING == SANE_LIBRARY_HANDLING)
27 /* Get _invalid_parameter_handler type and _set_invalid_parameter_handler
31 # if MSVC_INVALID_PARAMETER_HANDLING == DEFAULT_HANDLING
34 gl_msvc_invalid_parameter_handler (const wchar_t *expression,
35 const wchar_t *function,
44 /* Get declarations of the native Windows API functions. */
45 # define WIN32_LEAN_AND_MEAN
51 gl_msvc_invalid_parameter_handler (const wchar_t *expression,
52 const wchar_t *function,
57 RaiseException (STATUS_GNULIB_INVALID_PARAMETER, 0, 0, NULL);
62 /* An index to thread-local storage. */
63 static DWORD tls_index;
64 static int tls_initialized /* = 0 */;
66 /* Used as a fallback only. */
67 static struct gl_msvc_inval_per_thread not_per_thread;
69 struct gl_msvc_inval_per_thread *
70 gl_msvc_inval_current (void)
74 tls_index = TlsAlloc ();
77 if (tls_index == TLS_OUT_OF_INDEXES)
78 /* TlsAlloc had failed. */
79 return ¬_per_thread;
82 struct gl_msvc_inval_per_thread *pointer =
83 (struct gl_msvc_inval_per_thread *) TlsGetValue (tls_index);
86 /* First call. Allocate a new 'struct gl_msvc_inval_per_thread'. */
88 (struct gl_msvc_inval_per_thread *)
89 malloc (sizeof (struct gl_msvc_inval_per_thread));
91 /* Could not allocate memory. Use the global storage. */
92 pointer = ¬_per_thread;
93 TlsSetValue (tls_index, pointer);
100 gl_msvc_invalid_parameter_handler (const wchar_t *expression,
101 const wchar_t *function,
106 struct gl_msvc_inval_per_thread *current = gl_msvc_inval_current ();
107 if (current->restart_valid)
108 longjmp (current->restart, 1);
110 /* An invalid parameter notification from outside the gnulib code.
111 Give the caller a chance to intervene. */
112 RaiseException (STATUS_GNULIB_INVALID_PARAMETER, 0, 0, NULL);
119 static int gl_msvc_inval_initialized /* = 0 */;
122 gl_msvc_inval_ensure_handler (void)
124 if (gl_msvc_inval_initialized == 0)
126 _set_invalid_parameter_handler (gl_msvc_invalid_parameter_handler);
127 gl_msvc_inval_initialized = 1;