Debian Codegraph @

libmowgli-2/src/libmowgli/platform/constructor.h

raw
1 /*
2 * constructor.h
3 * Code for setting up automatic initializer functions portably.
4 *
5 * Copyright (c) 2012 William Pitcock <[email protected]>
6 *
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice is present in all copies.
10 *
11 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
12 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
13 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
14 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
15 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
16 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
17 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
19 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
20 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
21 * POSSIBILITY OF SUCH DAMAGE.
22 */
23
24 #ifndef MOWGLI_SRC_LIBMOWGLI_PLATFORM_CONSTRUCTOR_H_INCLUDE_GUARD
25 #define MOWGLI_SRC_LIBMOWGLI_PLATFORM_CONSTRUCTOR_H_INCLUDE_GUARD 1
26
27 #include "platform/machine.h"
28
29 #if defined MOWGLI_COMPILER_MSVC
30
31 /*
32 * Automatic constructors are not yet officially supported in MSVC, however,
33 * there is a similar feature where functions in the ".CRT$XCU" section are
34 * evaluated prior to DllMain(), main() and friends.
35 *
36 * See http://blogs.msdn.com/b/vcblog/archive/2006/10/20/crt-initialization.aspx
37 * for more information.
38 */
39 # define MOWGLI_BOOTSTRAP_FUNC(func) \
40 static void __cdecl func(void); \
41 __declspec(allocate(".CRT$XCU")) void(__cdecl * func##_) (void) = func; \
42 static void __cdecl func(void)
43 #elif defined MOWGLI_COMPILER_GCC_COMPAT
44 # if MOWGLI_COMPILER_GCC_VERSION >= 403000
45 # define MOWGLI_BOOTSTRAP_FUNC(func) \
46 static void func(void) __attribute__((cold, constructor, flatten)); \
47 static void func(void)
48 # else
49 # define MOWGLI_BOOTSTRAP_FUNC(func) \
50 static void func(void) __attribute__((constructor, flatten)); \
51 static void func(void)
52 # endif
53 #elif defined __SUNPRO_C || defined __SUNPRO_CC
54 # define MOWGLI_BOOTSTRAP_FUNC(func) \
55 static void func(void) __attribute__((constructor)); \
56 static void func(void)
57 #else
58 # error MOWGLI_BOOTSTRAP_FUNC not implemented for your platform :(
59 #endif
60
61 #endif /* MOWGLI_SRC_LIBMOWGLI_PLATFORM_CONSTRUCTOR_H_INCLUDE_GUARD */