aboutsummaryrefslogtreecommitdiff
path: root/lib/cpluff/libcpluff/win32/cpluffdef.h
blob: 7e3d55f2693155e9ef2791cd8ff067cb5726bd25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*-------------------------------------------------------------------------
 * C-Pluff, a plug-in framework for C
 * Copyright 2007 Johannes Lehtinen
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *-----------------------------------------------------------------------*/

/** @file
 * Common defines shared by C-Pluff C and C++ APIs.
 * This file is automatically included by the top level C and C++
 * API header files. There should be no need to include it explicitly.
 */

#ifndef CPLUFFDEF_H_
#define CPLUFFDEF_H_


/* ------------------------------------------------------------------------
 * Version information
 * ----------------------------------------------------------------------*/

/**
 * @defgroup versionInfo Version information
 * @ingroup cDefines cxxDefines
 *
 * C-Pluff version information. Notice that this version information
 * is static version information included in header files. The
 * macros introduced here can be used for compile time checks.
 */
/*@{*/

/**
 * The C-Pluff release version string. This string identifies a specific
 * version of the C-Pluff distribution. Compile time software compatibility
 * checks should use #CP_VERSION_MAJOR and #CP_VERSION_MINOR instead.
 */
#define CP_VERSION "0.1.4"

/**
 * The major version number component of the release version. This is an
 * integer.
 */
#define CP_VERSION_MAJOR 0

/**
 * The minor version number component of the release version. This is an
 * integer.
 */
#define CP_VERSION_MINOR 1

/*@}*/


/* ------------------------------------------------------------------------
 * Symbol visibility
 * ----------------------------------------------------------------------*/

/**
 * @defgroup symbolVisibility Symbol visibility
 * @ingroup cDefines cxxDefines
 *
 * Macros for controlling inter-module symbol visibility and linkage. These
 * macros have platform specific values. #CP_EXPORT, #CP_IMPORT and #CP_HIDDEN
 * can be reused by plug-in implementations for better portability. The
 * complexity is mostly due to Windows DLL exports and imports.
 *
 * @anchor symbolVisibilityExample
 * Each module should usually define its own macro to declare API symbols with
 * #CP_EXPORT and #CP_IMPORT as necessary. For example, a mobule could define
 * a macro @c MY_API in the API header file as follows.
 *
 * @code
 * #ifndef MY_API
 * #  define MY_API CP_IMPORT
 * #endif
 * @endcode
 *
 * By default the API symbols would then be marked for import which is correct
 * when client modules are including the API header file. When compiling the
 * module itself the option @c -DMY_API=CP_EXPORT would be passed to the compiler to
 * override the API header file and to mark the API symbols for export.
 * The overriding definition could also be included in module source files or
 * in an internal header file before including the API header file.
 */
/*@{*/

/**
 * @def CP_EXPORT
 *
 * Declares a symbol to be exported for inter-module usage. When compiling the
 * module which defines the symbol this macro should be placed
 * at the start of the symbol declaration to ensure that the symbol is exported
 * to other modules. However, when compiling other modules the declaration of
 * the symbol should start with #CP_IMPORT.
 * See @ref symbolVisibilityExample "the example" of how to do this.
 */

/**
 * @def CP_IMPORT
 *
 * Declares a symbol to be imported from another module. When compiling a
 * module which uses the symbol this macro should be placed at the start of
 * the symbol declaration to ensure that the symbol is imported from the
 * defining module. However, when compiling the defining module the declaration
 * of the symbol should start with #CP_EXPORT.
 * See @ref symbolVisibilityExample "the example" of how to do this.
 */

/**
 * @def CP_HIDDEN
 *
 * Declares a symbol hidden from other modules. This macro should be
 * placed at the start of the symbol declaration to hide the symbol from other
 * modules (if supported by the platform). This macro is not intended to be
 * used with symbols declared as "static" which are already internal to the
 * object file. Some platforms do not support hiding of symbols and therefore
 * unique prefixes should be used for global symbols internal to the module
 * even when they are declared using this macro.
 */

#if defined(_WIN32)
#  define CP_EXPORT __declspec(dllexport)
#if defined(_WINDLL)
#  define CP_IMPORT extern __declspec(dllimport)
#else
#  define CP_IMPORT
#endif
#  define CP_HIDDEN
#elif defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))
#  define CP_EXPORT
#  define CP_IMPORT extern
#  define CP_HIDDEN __attribute__ ((visibility ("hidden")))
#else
#  define CP_EXPORT
#  define CP_IMPORT extern
#  define CP_HIDDEN
#endif

/*@}*/


/* ------------------------------------------------------------------------
 * GCC attributes
 * ----------------------------------------------------------------------*/

/**
 * @defgroup cDefinesGCCAttributes GCC attributes
 * @ingroup cDefines cxxDefines
 *
 * These macros conditionally define GCC attributes for declarations.
 * They are used in C-Pluff API declarations to enable better optimization
 * and error checking when using GCC. In non-GCC platforms they have
 * empty values.
 */
/*@{*/

/**
 * @def CP_GCC_PURE
 *
 * Declares a function as pure function having no side effects.
 * This attribute is supported in GCC since version 2.96.
 * Such functions can be subject to common subexpression elimination
 * and loop optimization.
 */

/**
 * @def CP_GCC_NONNULL
 *
 * Specifies that some pointer arguments to a function should have
 * non-NULL values. Takes a variable length list of argument indexes as
 * arguments. This attribute is supported in GCC since version 3.3.
 * It can be used for enhanced error checking and some optimizations.
 */

#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
#define CP_GCC_PURE __attribute__((pure))
#else
#define CP_GCC_PURE
#endif
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
#define CP_GCC_NONNULL(...) __attribute__((nonnull (__VA_ARGS__)))
#else
#define CP_GCC_NONNULL(...)
#endif

/*@}*/

#ifdef _WIN32
#ifndef __func__
#  define __func__ __FUNCTION__
#endif
#ifndef snprintf
#define snprintf _snprintf
#endif
#define CP_HOST "win32"
#define CP_SHREXT ".dll"
#define CP_FNAMESEP_CHAR '\\' // If we switch back to special:// paths then this can be '/' instead
#define CP_THREADS
#endif
#endif /*CPLUFFDEF_H_*/