Subversion Repositories Kolibri OS

Rev

Rev 1892 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1892 serge 1
/* cairo - a vector graphics library with display and print output
2
 *
3
 * Copyright © 2002 University of Southern California
4
 * Copyright © 2005 Red Hat, Inc.
5
 *
6
 * This library is free software; you can redistribute it and/or
7
 * modify it either under the terms of the GNU Lesser General Public
8
 * License version 2.1 as published by the Free Software Foundation
9
 * (the "LGPL") or, at your option, under the terms of the Mozilla
10
 * Public License Version 1.1 (the "MPL"). If you do not alter this
11
 * notice, a recipient may use your version of this file under either
12
 * the MPL or the LGPL.
13
 *
14
 * You should have received a copy of the LGPL along with this library
15
 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
16
 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
17
 * You should have received a copy of the MPL along with this library
18
 * in the file COPYING-MPL-1.1
19
 *
20
 * The contents of this file are subject to the Mozilla Public License
21
 * Version 1.1 (the "License"); you may not use this file except in
22
 * compliance with the License. You may obtain a copy of the License at
23
 * http://www.mozilla.org/MPL/
24
 *
25
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
26
 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
27
 * the specific language governing rights and limitations.
28
 *
29
 * The Original Code is the cairo graphics library.
30
 *
31
 * The Initial Developer of the Original Code is University of Southern
32
 * California.
33
 *
34
 * Contributor(s):
35
 *	Carl D. Worth 
36
 */
37
 
38
#ifndef CAIRO_COMPILER_PRIVATE_H
39
#define CAIRO_COMPILER_PRIVATE_H
40
 
41
#include "cairo.h"
42
 
43
#if HAVE_CONFIG_H
44
#include "config.h"
45
#endif
46
 
47
/* Size in bytes of buffer to use off the stack per functions.
48
 * Mostly used by text functions.  For larger allocations, they'll
49
 * malloc(). */
50
#ifndef CAIRO_STACK_BUFFER_SIZE
51
#define CAIRO_STACK_BUFFER_SIZE (512 * sizeof (int))
52
#endif
53
 
54
#define CAIRO_STACK_ARRAY_LENGTH(T) (CAIRO_STACK_BUFFER_SIZE / sizeof(T))
55
 
56
/*
57
 * The goal of this block is to define the following macros for
58
 * providing faster linkage to functions in the public API for calls
59
 * from within cairo.
60
 *
61
 * slim_hidden_proto(f)
62
 * slim_hidden_proto_no_warn(f)
63
 *
64
 *   Declares `f' as a library internal function and hides the
65
 *   function from the global symbol table.  This macro must be
66
 *   expanded after `f' has been declared with a prototype but before
67
 *   any calls to the function are seen by the compiler.  The no_warn
68
 *   variant inhibits warnings about the return value being unused at
69
 *   call sites.  The macro works by renaming `f' to an internal name
70
 *   in the symbol table and hiding that.  As far as cairo internal
71
 *   calls are concerned they're calling a library internal function
72
 *   and thus don't need to bounce via the PLT.
73
 *
74
 * slim_hidden_def(f)
75
 *
76
 *   Exports `f' back to the global symbol table.  This macro must be
77
 *   expanded right after the function definition and only for symbols
78
 *   hidden previously with slim_hidden_proto().  The macro works by
79
 *   adding a global entry to the symbol table which points at the
80
 *   internal name of `f' created by slim_hidden_proto().
81
 *
82
 * Functions in the public API which aren't called by the library
83
 * don't need to be hidden and re-exported using the slim hidden
84
 * macros.
85
 */
86
#if __GNUC__ >= 3 && defined(__ELF__) && !defined(__sun)
87
# define slim_hidden_proto(name)		slim_hidden_proto1(name, slim_hidden_int_name(name)) cairo_private
88
# define slim_hidden_proto_no_warn(name)	slim_hidden_proto1(name, slim_hidden_int_name(name)) cairo_private_no_warn
89
# define slim_hidden_def(name)			slim_hidden_def1(name, slim_hidden_int_name(name))
90
# define slim_hidden_int_name(name) INT_##name
91
# define slim_hidden_proto1(name, internal)				\
92
  extern __typeof (name) name						\
93
	__asm__ (slim_hidden_asmname (internal))
94
# define slim_hidden_def1(name, internal)				\
95
  extern __typeof (name) EXT_##name __asm__(slim_hidden_asmname(name))	\
96
	__attribute__((__alias__(slim_hidden_asmname(internal))))
97
# define slim_hidden_ulp		slim_hidden_ulp1(__USER_LABEL_PREFIX__)
98
# define slim_hidden_ulp1(x)		slim_hidden_ulp2(x)
99
# define slim_hidden_ulp2(x)		#x
100
# define slim_hidden_asmname(name)	slim_hidden_asmname1(name)
101
# define slim_hidden_asmname1(name)	slim_hidden_ulp #name
102
#else
103
# define slim_hidden_proto(name)		int _cairo_dummy_prototype(void)
104
# define slim_hidden_proto_no_warn(name)	int _cairo_dummy_prototype(void)
105
# define slim_hidden_def(name)			int _cairo_dummy_prototype(void)
106
#endif
107
 
108
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
109
#define CAIRO_PRINTF_FORMAT(fmt_index, va_index) \
110
	__attribute__((__format__(__printf__, fmt_index, va_index)))
111
#else
112
#define CAIRO_PRINTF_FORMAT(fmt_index, va_index)
113
#endif
114
 
115
/* slim_internal.h */
116
#define CAIRO_HAS_HIDDEN_SYMBOLS 1
3959 Serge 117
#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && \
118
    (defined(__ELF__) || defined(__APPLE__)) &&			\
119
    !defined(__sun)
1892 serge 120
#define cairo_private_no_warn	__attribute__((__visibility__("hidden")))
121
#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
122
#define cairo_private_no_warn	__hidden
123
#else /* not gcc >= 3.3 and not Sun Studio >= 8 */
124
#define cairo_private_no_warn
125
#undef CAIRO_HAS_HIDDEN_SYMBOLS
126
#endif
127
 
128
#ifndef WARN_UNUSED_RESULT
129
#define WARN_UNUSED_RESULT
130
#endif
131
/* Add attribute(warn_unused_result) if supported */
132
#define cairo_warn	    WARN_UNUSED_RESULT
133
#define cairo_private	    cairo_private_no_warn cairo_warn
134
 
135
/* This macro allow us to deprecate a function by providing an alias
136
   for the old function name to the new function name. With this
137
   macro, binary compatibility is preserved. The macro only works on
138
   some platforms --- tough.
139
 
140
   Meanwhile, new definitions in the public header file break the
141
   source code so that it will no longer link against the old
142
   symbols. Instead it will give a descriptive error message
143
   indicating that the old function has been deprecated by the new
144
   function.
145
*/
146
#if __GNUC__ >= 2 && defined(__ELF__)
147
# define CAIRO_FUNCTION_ALIAS(old, new)		\
148
	extern __typeof (new) old		\
149
	__asm__ ("" #old)			\
150
	__attribute__((__alias__("" #new)))
151
#else
152
# define CAIRO_FUNCTION_ALIAS(old, new)
153
#endif
154
 
155
/*
156
 * Cairo uses the following function attributes in order to improve the
157
 * generated code (effectively by manual inter-procedural analysis).
158
 *
159
 *   'cairo_pure': The function is only allowed to read from its arguments
160
 *                 and global memory (i.e. following a pointer argument or
161
 *                 accessing a shared variable). The return value should
162
 *                 only depend on its arguments, and for an identical set of
163
 *                 arguments should return the same value.
164
 *
165
 *   'cairo_const': The function is only allowed to read from its arguments.
166
 *                  It is not allowed to access global memory. The return
167
 *                  value should only depend its arguments, and for an
168
 *                  identical set of arguments should return the same value.
169
 *                  This is currently the most strict function attribute.
170
 *
171
 * Both these function attributes allow gcc to perform CSE and
172
 * constant-folding, with 'cairo_const 'also guaranteeing that pointer contents
173
 * do not change across the function call.
174
 */
175
#if __GNUC__ >= 3
176
#define cairo_pure __attribute__((pure))
177
#define cairo_const __attribute__((const))
178
#define cairo_always_inline inline __attribute__((always_inline))
179
#else
180
#define cairo_pure
181
#define cairo_const
182
#define cairo_always_inline inline
183
#endif
184
 
185
#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
3959 Serge 186
#define likely(expr) (__builtin_expect (!!(expr), 1))
187
#define unlikely(expr) (__builtin_expect (!!(expr), 0))
1892 serge 188
#else
189
#define likely(expr) (expr)
190
#define unlikely(expr) (expr)
191
#endif
192
 
193
#ifndef __GNUC__
194
#undef __attribute__
195
#define __attribute__(x)
196
#endif
197
 
198
#if (defined(__WIN32__) && !defined(__WINE__)) || defined(_MSC_VER)
3959 Serge 199
#define access _access
200
#define fdopen _fdopen
201
#define hypot _hypot
202
#define pclose _pclose
203
#define popen _popen
1892 serge 204
#define snprintf _snprintf
3959 Serge 205
#define strdup _strdup
206
#define unlink _unlink
207
#define vsnprintf _vsnprintf
1892 serge 208
#endif
209
 
210
#ifdef _MSC_VER
3959 Serge 211
#ifndef __cplusplus
1892 serge 212
#undef inline
213
#define inline __inline
214
#endif
3959 Serge 215
#endif
1892 serge 216
 
217
#if defined(_MSC_VER) && defined(_M_IX86)
218
/* When compiling with /Gy and /OPT:ICF identical functions will be folded in together.
219
   The CAIRO_ENSURE_UNIQUE macro ensures that a function is always unique and
220
   will never be folded into another one. Something like this might eventually
221
   be needed for GCC but it seems fine for now. */
222
#define CAIRO_ENSURE_UNIQUE                       \
223
    do {                                          \
224
	char func[] = __FUNCTION__;               \
225
	char file[] = __FILE__;                   \
226
	__asm {                                   \
227
	    __asm jmp __internal_skip_line_no     \
228
	    __asm _emit (__LINE__ & 0xff)         \
229
	    __asm _emit ((__LINE__>>8) & 0xff)    \
230
	    __asm _emit ((__LINE__>>16) & 0xff)   \
231
	    __asm _emit ((__LINE__>>24) & 0xff)   \
232
	    __asm lea eax, func                   \
233
	    __asm lea eax, file                   \
234
	    __asm __internal_skip_line_no:        \
235
	};                                        \
236
    } while (0)
237
#else
238
#define CAIRO_ENSURE_UNIQUE    do { } while (0)
239
#endif
240
 
241
#ifdef __STRICT_ANSI__
242
#undef inline
243
#define inline __inline__
244
#endif
245
 
246
#endif