1
/*===========================================================================
3
* About : Global object handlings
5
* Copyright (C) 2006 YAMAMOTO Kengo <yamaken AT bp.iij4u.or.jp>
6
* Copyright (c) 2007 SigScheme Project <uim AT freedesktop.org>
10
* Redistribution and use in source and binary forms, with or without
11
* modification, are permitted provided that the following conditions
14
* 1. Redistributions of source code must retain the above copyright
15
* notice, this list of conditions and the following disclaimer.
16
* 2. Redistributions in binary form must reproduce the above copyright
17
* notice, this list of conditions and the following disclaimer in the
18
* documentation and/or other materials provided with the distribution.
19
* 3. Neither the name of authors nor the names of its contributors
20
* may be used to endorse or promote products derived from this software
21
* without specific prior written permission.
23
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
24
* IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
25
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
27
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
30
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
===========================================================================*/
36
/* FIXME: SCM_WRITABLE_STATICLESS_PLATFORM is not available yet */
38
#ifndef __SCM_GLOBAL_H
39
#define __SCM_GLOBAL_H
41
#include <sigscheme/config.h>
43
#if (defined(__SYMBIAN32__) && !defined(EKA2))
47
#elif BREW_MAJ_VER /* FIXME: inappropriate detection method */
48
#include "AEEStdLib.h"
57
/*=======================================
59
=======================================*/
60
/* Consumes sizeof(void *) per struct to suppress the extra semicolon warnings
61
* by default. Disable SCM_USE_WARNING_SUPPRESSOR to minimize memory
63
#if SCM_USE_WARNING_SUPPRESSOR
64
#define SCM_GLOBAL_STRUCT_WARNING_SUPPRESSOR void *dummy
66
#define SCM_GLOBAL_STRUCT_WARNING_SUPPRESSOR
69
#if SCM_USE_AGGREGATED_GLOBAL_VARS
70
#define SCM_AGGREGATED_GLOBAL_VARS_BEGIN \
71
/* dummy statement to prevent static prefix */ \
72
struct scm_g_dummy_aggregated_begin { int dummy; }; \
73
struct scm_g_aggregated { \
74
SCM_GLOBAL_STRUCT_WARNING_SUPPRESSOR
75
#define SCM_AGGREGATED_GLOBAL_VARS(_name) \
76
struct scm_g_##_name _name
77
#define SCM_AGGREGATED_GLOBAL_VARS_END \
80
#if (defined(__SYMBIAN32__) && !defined(EKA2))
81
/*** EXPERIMENTAL AND NOT TESTED ***/
83
#define SCM_DECLARE_AGGREGATED_GLOBAL_VARS() extern int scm_g_dummy
84
#define SCM_DEFINE_AGGREGATED_GLOBAL_VARS() extern int scm_g_dummy
86
#define SCM_AGGREGATED_GLOBAL_VARS_INIT() (scm_aggregated_global_vars_init())
87
#define SCM_AGGREGATED_GLOBAL_VARS_FIN() (scm_aggregated_global_vars_fin())
88
#define SCM_AGGREGATED_GLOBAL_VARS_INSTANCE() \
89
((struct scm_g_aggregated *)Dll::Tls())
91
#elif BREW_MAJ_VER /* FIXME: inappropriate detection method */
92
/*** EXPERIMENTAL AND NOT TESTED ***/
94
#define SCM_DECLARE_AGGREGATED_GLOBAL_VARS() extern int scm_g_dummy
95
#define SCM_DEFINE_AGGREGATED_GLOBAL_VARS() extern int scm_g_dummy
97
#define SCM_AGGREGATED_GLOBAL_VARS_INIT() (scm_aggregated_global_vars_init())
98
#define SCM_AGGREGATED_GLOBAL_VARS_FIN() SCM_EMPTY_EXPR
99
#define SCM_AGGREGATED_GLOBAL_VARS_INSTANCE() \
100
(&((SCM_BREW_USER_APPLET_T *)GETAPPINSTANCE())->m_scm_g_aggregated_instance)
102
#elif SCM_HAVE_WRITABLE_GLOBAL_VARS
103
#define SCM_DECLARE_AGGREGATED_GLOBAL_VARS() \
104
SCM_EXTERN(struct scm_g_aggregated scm_g_aggregated_instance)
105
#define SCM_DEFINE_AGGREGATED_GLOBAL_VARS() \
106
/* dummy statement to prevent static prefix */ \
107
struct scm_g_dummy_aggregated_define { int dummy; }; \
108
SCM_EXPORT struct scm_g_aggregated scm_g_aggregated_instance
110
#define SCM_AGGREGATED_GLOBAL_VARS_INIT() (scm_aggregated_global_vars_init())
111
#define SCM_AGGREGATED_GLOBAL_VARS_FIN() SCM_EMPTY_EXPR
112
#define SCM_AGGREGATED_GLOBAL_VARS_INSTANCE() (scm_g_aggregated_instance)
114
#error "This platform is not supported yet"
117
#define SCM_DEFINE_STATIC_VARS(_namespace) \
118
static struct scm_g_##_namespace *scm_g_instance_##_namespace(void)
120
#define SCM_GLOBAL_VARS_INIT(_namespace) SCM_EMPTY_EXPR
121
#define SCM_GLOBAL_VARS_FIN(_namespace) SCM_EMPTY_EXPR
123
#define SCM_GLOBAL_VARS_INSTANCE(_namespace) (*scm_g_instance_##_namespace())
125
#define SCM_DEFINE_GLOBAL_VARS_INSTANCE_ACCESSOR(_namespace) \
126
SCM_EXPORT struct scm_g_##_namespace * \
127
scm_g_instance_##_namespace(void) \
129
return &SCM_AGGREGATED_GLOBAL_VARS_INSTANCE()._namespace; \
131
extern int scm_g_dummy_##_namespace
133
#else /* SCM_USE_AGGREGATED_GLOBAL_VARS */
135
#define SCM_DECLARE_AGGREGATED_GLOBAL_VARS() \
136
extern int scm_g_dummy
137
#define SCM_DEFINE_AGGREGATED_GLOBAL_VARS() \
138
extern int scm_g_dummy
140
#define SCM_AGGREGATED_GLOBAL_VARS_INIT() SCM_EMPTY_EXPR
141
#define SCM_AGGREGATED_GLOBAL_VARS_FIN() SCM_EMPTY_EXPR
143
#define SCM_DEFINE_STATIC_VARS(_namespace) \
144
static struct scm_g_##_namespace scm_g_instance_##_namespace
145
#define SCM_GLOBAL_VARS_INIT(_namespace) \
146
(memset(&scm_g_instance_##_namespace, 0, \
147
sizeof(scm_g_instance_##_namespace)))
148
#define SCM_GLOBAL_VARS_FIN(_namespace) SCM_EMPTY_EXPR
150
#define SCM_GLOBAL_VARS_INSTANCE(_namespace) \
151
(scm_g_instance_##_namespace)
152
#endif /* SCM_USE_AGGREGATED_GLOBAL_VARS */
154
#define SCM_GLOBAL_VARS_BEGIN(_namespace) \
155
struct scm_g_##_namespace { \
156
SCM_GLOBAL_STRUCT_WARNING_SUPPRESSOR
157
#define SCM_GLOBAL_VARS_END(_namespace) \
160
#define SCM_GLOBAL_VAR(_namespace, _var_name) \
161
(SCM_GLOBAL_VARS_INSTANCE(_namespace)._var_name)
163
#if SCM_USE_AGGREGATED_GLOBAL_VARS
164
#define SCM_DECLARE_EXPORTED_VARS(_namespace) \
165
SCM_EXPORT struct scm_g_##_namespace *scm_g_instance_##_namespace(void)
166
#define SCM_DEFINE_EXPORTED_VARS(_namespace) \
167
extern int scm_g_dummy_##_namespace
168
#if !SCM_COMBINED_SOURCE
169
#error "(SCM_USE_AGGREGATED_GLOBAL_VARS && !SCM_COMBINED_SOURCE) is not supported"
170
#endif /* SCM_COMBINED_SOURCE */
171
#else /* SCM_USE_AGGREGATED_GLOBAL_VARS */
172
#if SCM_COMBINED_SOURCE
173
/* define at declaration in the header file */
174
#define SCM_DECLARE_EXPORTED_VARS(_namespace) \
175
SCM_DEFINE_STATIC_VARS(_namespace)
176
#define SCM_DEFINE_EXPORTED_VARS(_namespace) \
177
/* dummy statement to prevent static prefix */ \
178
struct scm_g_dummy_##_namespace { int dummy; }
179
#else /* SCM_COMBINED_SOURCE */
180
#define SCM_DECLARE_EXPORTED_VARS(_namespace) \
181
SCM_EXTERN(struct scm_g_##_namespace scm_g_instance_##_namespace)
182
#define SCM_DEFINE_EXPORTED_VARS(_namespace) \
183
/* dummy statement to prevent static prefix */ \
184
struct scm_g_dummy_##_namespace { int dummy; }; \
185
SCM_EXPORT struct scm_g_##_namespace scm_g_instance_##_namespace
186
#endif /* SCM_COMBINED_SOURCE */
187
#endif /* SCM_USE_AGGREGATED_GLOBAL_VARS */
189
#if (SCM_COMBINED_SOURCE && !SCM_EXPORT_API)
190
#define SCM_EXTERN(_decl) extern int scm_g_dummy
191
#define SCM_EXPORT static
193
/* FIXME: reflect SCM_COMBINED_SOURCE */
194
#elif defined(__SYMBIAN32__)
195
#define SCM_EXTERN(_decl) extern _decl
196
#if SCM_COMPILING_LIBSSCM
197
#define SCM_EXPORT EXPORT_C
198
#else /* SCM_COMPILING_LIBSSCM */
199
#define SCM_EXPORT IMPORT_C
200
#endif /* SCM_COMPILING_LIBSSCM */
202
#elif BREW_MAJ_VER /* FIXME: inappropriate detection method */
203
#define SCM_EXTERN(_decl) extern _decl
204
#define SCM_EXPORT extern /* respect coding style of BREW */
206
/* FIXME: reflect SCM_COMBINED_SOURCE */
207
#elif (defined(_WIN32) || defined(_WIN64))
208
#define SCM_EXTERN(_decl) extern _decl
209
#if SCM_COMPILING_LIBSSCM
210
#define SCM_EXPORT __declspec(dllexport)
211
#else /* SCM_COMPILING_LIBSSCM */
212
#define SCM_EXPORT __declspec(dllimport)
213
#endif /* SCM_COMPILING_LIBSSCM */
216
#define SCM_EXTERN(_decl) extern _decl
220
/*=======================================
222
=======================================*/
224
/*=======================================
225
Variable Declarations
226
=======================================*/
228
/*=======================================
229
Function Declarations
230
=======================================*/
231
#if SCM_USE_AGGREGATED_GLOBAL_VARS
232
SCM_EXPORT void scm_aggregated_global_vars_init(void);
233
#if (defined(__SYMBIAN32__) && !defined(EKA2))
234
SCM_EXPORT void scm_aggregated_global_vars_fin(void);
235
#endif /* (defined(__SYMBIAN32__) && !defined(EKA2)) */
236
#endif /* SCM_USE_AGGREGATED_GLOBAL_VARS */
243
#endif /* __SCM_GLOBAL_H */