55a01ee81edc6e8defbfd08465a062d3e5bf5a04
[platform/upstream/fribidi.git] / lib / common.h
1 /* FriBidi
2  * common.h - common include for library sources
3  *
4  * $Id: common.h,v 1.21 2010-02-24 19:40:04 behdad Exp $
5  * $Author: behdad $
6  * $Date: 2010-02-24 19:40:04 $
7  * $Revision: 1.21 $
8  * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/common.h,v $
9  *
10  * Author:
11  *   Behdad Esfahbod, 2004
12  *
13  * Copyright (C) 2004 Sharif FarsiWeb, Inc.
14  * 
15  * This library is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU Lesser General Public
17  * License as published by the Free Software Foundation; either
18  * version 2.1 of the License, or (at your option) any later version.
19  * 
20  * This library is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23  * Lesser General Public License for more details.
24  * 
25  * You should have received a copy of the GNU Lesser General Public License
26  * along with this library, in a file named COPYING; if not, write to the
27  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
28  * Boston, MA 02110-1301, USA
29  *
30  * For licensing issues, contact <license@farsiweb.info>.
31  */
32 #ifndef _COMMON_H
33 #define _COMMON_H
34
35 #if HAVE_CONFIG_H+0
36 # include <config.h>
37 #endif
38
39 #include <fribidi-common.h>
40
41 /* FRIBIDI_PRIVATESPACE is a macro used to name library internal symbols. */
42 #ifndef FRIBIDI_PRIVATESPACE
43 # define FRIBIDI_PRIVATESPACE1(A,B) A##B
44 # define FRIBIDI_PRIVATESPACE0(A,B) FRIBIDI_PRIVATESPACE1(A,B)
45 # define FRIBIDI_PRIVATESPACE(SYMBOL) FRIBIDI_PRIVATESPACE0(_,FRIBIDI_NAMESPACE(_##SYMBOL##__internal__))
46 #endif /* !FRIBIDI_PRIVATESPACE */
47
48 #if (defined(WIN32)) || (defined(_WIN32_WCE))
49 # define FRIBIDI_ENTRY __declspec(dllexport)
50 #endif /* WIN32 */
51
52 #if FRIBIDI_USE_GLIB+0
53 # ifndef SIZEOF_LONG
54 #  define SIZEOF_LONG GLIB_SIZEOF_LONG
55 # endif /* !SIZEOF_LONG */
56 # ifndef SIZEOF_VOID_P
57 #  define SIZEOF_VOID_P GLIB_SIZEOF_VOID_P
58 # endif /* !SIZEOF_VOID_P */
59 # ifndef __FRIBIDI_DOC
60 #  include <glib.h>
61 # endif /* !__FRIBIDI_DOC */
62 # ifndef fribidi_malloc
63 #  define fribidi_malloc g_try_malloc
64 #  define fribidi_free g_free
65 # endif /* !fribidi_malloc */
66 # ifndef fribidi_assert
67 #  ifndef __FRIBIDI_DOC
68 #   include <glib.h>
69 #  endif /* !__FRIBIDI_DOC */
70 #  define fribidi_assert g_assert
71 # endif /* !fribidi_assert */
72 # ifndef __FRIBIDI_DOC
73 #  include <glib.h>
74 # endif /* !__FRIBIDI_DOC */
75 # ifndef FRIBIDI_BEGIN_STMT
76 #  define FRIBIDI_BEGIN_STMT G_STMT_START {
77 #  define FRIBIDI_END_STMT } G_STMT_END
78 # endif /* !FRIBIDI_BEGIN_STMT */
79 # ifndef LIKELY
80 #  define LIKELY G_LIKELY
81 #  define UNLIKELY G_UNLIKELY
82 # endif /* !LIKELY */
83 # ifndef false
84 #  define false FALSE
85 # endif /* !false */
86 # ifndef true
87 #  define true TRUE
88 # endif /* !true */
89 #endif /* FRIBIDI_USE_GLIB */
90
91 #ifndef false
92 # define false (0)
93 # endif /* !false */
94 # ifndef true
95 #  define true (!false)
96 # endif /* !true */
97
98 #ifndef NULL
99 #  ifdef __cplusplus
100 #    define NULL        (0L)
101 #  else /* !__cplusplus */
102 #    define NULL        ((void*) 0)
103 #  endif /* !__cplusplus */
104 #endif /* !NULL */
105
106 /* fribidi_malloc and fribidi_free should be used instead of malloc and free. 
107  * No need to include any headers. */
108 #ifndef fribidi_malloc
109 # if HAVE_STDLIB_H
110 #  ifndef __FRIBIDI_DOC
111 #   include <stdlib.h>
112 #  endif /* __FRIBIDI_DOC */
113 #  define fribidi_malloc malloc
114 # else /* !HAVE_STDLIB_H */
115 #  define fribidi_malloc (void *) malloc
116 # endif /* !HAVE_STDLIB_H */
117 # define fribidi_free free
118 #else /* fribidi_malloc */
119 # ifndef fribidi_free
120 #  error You should define fribidi_free too when you define fribidi_malloc.
121 # endif /* !fribidi_free */
122 #endif /* fribidi_malloc */
123
124 #if HAVE_STRING_H+0
125 # if !STDC_HEADERS && HAVE_MEMORY_H
126 #  include <memory.h>
127 # endif
128 # include <string.h>
129 #endif
130 #if HAVE_STRINGS_H+0
131 # include <strings.h>
132 #endif
133
134 /* FRIBIDI_CHUNK_SIZE is the number of bytes in each chunk of memory being
135  * allocated for data structure pools. */
136 #ifndef FRIBIDI_CHUNK_SIZE
137 # if HAVE_ASM_PAGE_H
138 #  ifndef __FRIBIDI_DOC
139 #   include <asm/page.h>
140 #  endif /* __FRIBIDI_DOC */
141 #  define FRIBIDI_CHUNK_SIZE (PAGE_SIZE - 16)
142 # else /* !HAVE_ASM_PAGE_H */
143 #  define FRIBIDI_CHUNK_SIZE (4096 - 16)
144 # endif /* !HAVE_ASM_PAGE_H */
145 #else /* FRIBIDI_CHUNK_SIZE */
146 # if FRIBIDI_CHUNK_SIZE < 256
147 #  error FRIBIDI_CHUNK_SIZE now should define the size of a chunk in bytes.
148 # endif /* FRIBIDI_CHUNK_SIZE < 256 */
149 #endif /* FRIBIDI_CHUNK_SIZE */
150
151 /* FRIBIDI_BEGIN_STMT should be used at the beginning of your macro
152  * definitions that are to behave like simple statements.  Use
153  * FRIBIDI_END_STMT at the end of the macro after the semicolon or brace. */
154 #ifndef FRIBIDI_BEGIN_STMT
155 # define FRIBIDI_BEGIN_STMT do {
156 # define FRIBIDI_END_STMT } while (0)
157 #endif /* !FRIBIDI_BEGIN_STMT */
158
159 /* LIKEYLY and UNLIKELY are used to give a hint on branch prediction to the
160  * compiler. */
161 #ifndef LIKELY
162 # define LIKELY
163 # define UNLIKELY
164 #endif /* !LIKELY */
165
166 #ifndef FRIBIDI_EMPTY_STMT
167 # define FRIBIDI_EMPTY_STMT FRIBIDI_BEGIN_STMT (void) 0; FRIBIDI_END_STMT
168 #endif /* !FRIBIDI_EMPTY_STMT */
169
170 #if HAVE_STRINGIZE+0
171 # define STRINGIZE(symbol) #symbol
172 #else /* !HAVE_STRINGIZE */
173 # define STRINGIZE(symbol) (no stringize operator available)
174 #endif /* !HAVE_STRINGIZE */
175
176 /* As per recommendation of GNU Coding Standards. */
177 #ifndef _GNU_SOURCE
178 # define _GNU_SOURCE
179 #endif /* !_GNU_SOURCE */
180
181 /* We respect our own rules. */
182 #define FRIBIDI_NO_DEPRECATED
183
184
185 #include "debug.h"
186
187 #endif /* !_COMMON_H */
188 /* Editor directions:
189  * vim:textwidth=78:tabstop=8:shiftwidth=2:autoindent:cindent
190  */