2 * common.h - common include for library sources
5 * Behdad Esfahbod, 2004
7 * Copyright (C) 2004 Sharif FarsiWeb, Inc.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this library, in a file named COPYING; if not, write to the
21 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA
24 * For licensing issues, contact <fribidi.license@gmail.com>.
33 #include <fribidi-common.h>
39 # define true (!false)
45 # else /* !__cplusplus */
46 # define NULL ((void*) 0)
47 # endif /* !__cplusplus */
50 /* fribidi_malloc and fribidi_free should be used instead of malloc and free.
51 * No need to include any headers. */
52 #ifndef fribidi_malloc
54 # ifndef __FRIBIDI_DOC
56 # endif /* __FRIBIDI_DOC */
57 # define fribidi_malloc malloc
58 # else /* !HAVE_STDLIB_H */
59 # define fribidi_malloc (void *) malloc
60 # endif /* !HAVE_STDLIB_H */
61 # define fribidi_free free
62 #else /* fribidi_malloc */
64 # error "You should define fribidi_free too when you define fribidi_malloc."
65 # endif /* !fribidi_free */
66 #endif /* fribidi_malloc */
69 # if !STDC_HEADERS && HAVE_MEMORY_H
78 /* FRIBIDI_BEGIN_STMT should be used at the beginning of your macro
79 * definitions that are to behave like simple statements. Use
80 * FRIBIDI_END_STMT at the end of the macro after the semicolon or brace. */
81 #ifndef FRIBIDI_BEGIN_STMT
82 # define FRIBIDI_BEGIN_STMT do {
83 # define FRIBIDI_END_STMT } while (0)
84 #endif /* !FRIBIDI_BEGIN_STMT */
86 /* LIKEYLY and UNLIKELY are used to give a hint on branch prediction to the
89 # if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
90 # define FRIBIDI_BOOLEAN_EXPR(expr) \
92 int fribidi_bool_var; \
94 fribidi_bool_var = 1; \
96 fribidi_bool_var = 0; \
99 # define LIKELY(expr) (__builtin_expect (FRIBIDI_BOOLEAN_EXPR(expr), 1))
100 # define UNLIKELY(expr) (__builtin_expect (FRIBIDI_BOOLEAN_EXPR(expr), 0))
107 #ifndef FRIBIDI_EMPTY_STMT
108 # define FRIBIDI_EMPTY_STMT FRIBIDI_BEGIN_STMT (void) 0; FRIBIDI_END_STMT
109 #endif /* !FRIBIDI_EMPTY_STMT */
111 #ifdef HAVE_STRINGIZE
112 # define STRINGIZE(symbol) #symbol
113 #else /* !HAVE_STRINGIZE */
114 # error "No stringize operator available?"
115 #endif /* !HAVE_STRINGIZE */
117 /* As per recommendation of GNU Coding Standards. */
120 #endif /* !_GNU_SOURCE */
122 /* We respect our own rules. */
123 #ifndef FRIBIDI_NO_DEPRECATED
124 # define FRIBIDI_NO_DEPRECATED
125 #endif /* !FRIBIDI_NO_DEPRECATED */
130 #endif /* !_COMMON_H */
131 /* Editor directions:
132 * vim:textwidth=78:tabstop=8:shiftwidth=2:autoindent:cindent