6 /* Copyright (C) 1995,1996,2000,2001, 2002, 2006, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 3 of
11 * the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 /**********************************************************************
27 This file is Guile's central private header.
29 When included by other files, this file should preceed any include
30 other than __scm.h. See __scm.h for details regarding the purpose of
31 and differences between _scm.h and __scm.h.
32 **********************************************************************/
34 #if defined(__ia64) && !defined(__ia64__)
42 /* The size of `scm_t_bits'. */
43 #define SIZEOF_SCM_T_BITS SIZEOF_VOID_P
45 /* Undefine HAVE_STRUCT_TIMESPEC, because the libguile C code doesn't
46 need it anymore, and because on MinGW:
48 - the definition of struct timespec is provided (if at all) by
51 - pthread.h will _not_ define struct timespec if
52 HAVE_STRUCT_TIMESPEC is 1, because then it thinks that it doesn't
55 The libguile C code doesn't need HAVE_STRUCT_TIMESPEC anymore,
56 because the value of HAVE_STRUCT_TIMESPEC has already been
57 incorporated in how scm_t_timespec is defined (in scmconfig.h), and
58 the rest of the libguile C code now just uses scm_t_timespec.
60 #ifdef HAVE_STRUCT_TIMESPEC
61 #undef HAVE_STRUCT_TIMESPEC
67 #include "libguile/__scm.h"
69 /* Include headers for those files central to the implementation. The
70 rest should be explicitly #included in the C files themselves. */
71 #include "libguile/error.h" /* Everyone signals errors. */
72 #include "libguile/print.h" /* Everyone needs to print. */
73 #include "libguile/pairs.h" /* Everyone conses. */
74 #include "libguile/list.h" /* Everyone makes lists. */
75 #include "libguile/gc.h" /* Everyone allocates. */
76 #include "libguile/gsubr.h" /* Everyone defines global functions. */
77 #include "libguile/procs.h" /* Same. */
78 #include "libguile/numbers.h" /* Everyone deals with fixnums. */
79 #include "libguile/symbols.h" /* For length, chars, values, miscellany. */
80 #include "libguile/boolean.h" /* Everyone wonders about the truth. */
81 #include "libguile/threads.h" /* You are not alone. */
82 #include "libguile/snarf.h" /* Everyone snarfs. */
83 #include "libguile/foreign.h" /* Snarfing needs the foreign data structures. */
84 #include "libguile/programs.h" /* ... and program.h. */
85 #include "libguile/variable.h"
86 #include "libguile/modules.h"
87 #include "libguile/inline.h"
88 #include "libguile/strings.h"
90 /* ASYNC_TICK after finding EINTR in order to handle pending signals, if
91 any. See comment in scm_syserror. */
96 # define SCM_SYSCALL(line) \
101 if (EVMSERR==errno && (vaxc$errno>>3)==(SS$_CONTROLC>>3)) \
108 # endif /* ndef __GNUC__ */
110 #endif /* ndef SCM_SYSCALL */
115 # define SCM_SYSCALL(line) \
120 if (errno == EINTR) \
127 # endif /* (EINTR > 0) */
128 # endif /* def EINTR */
129 #endif /* ndef SCM_SYSCALL */
132 # define SCM_SYSCALL(line) line;
133 #endif /* ndef SCM_SYSCALL */
138 #define min(A, B) ((A) <= (B) ? (A) : (B))
141 #define max(A, B) ((A) >= (B) ? (A) : (B))
144 /* Return the first integer greater than or equal to LEN such that
145 LEN % ALIGN == 0. Return LEN if ALIGN is zero. */
146 #define ROUND_UP(len, align) \
147 ((align) ? (((len) - 1UL) | ((align) - 1UL)) + 1UL : (len))
150 #if defined GUILE_USE_64_CALLS && GUILE_USE_64_CALLS && defined(HAVE_STAT64)
151 #define CHOOSE_LARGEFILE(foo,foo64) foo64
153 #define CHOOSE_LARGEFILE(foo,foo64) foo
156 /* These names are a bit long, but they make it clear what they represent. */
157 #if SCM_HAVE_STRUCT_DIRENT64 == 1
158 # define dirent_or_dirent64 CHOOSE_LARGEFILE(dirent,dirent64)
160 # define dirent_or_dirent64 dirent
162 #define fstat_or_fstat64 CHOOSE_LARGEFILE(fstat,fstat64)
163 #define ftruncate_or_ftruncate64 CHOOSE_LARGEFILE(ftruncate,ftruncate64)
164 #define lseek_or_lseek64 CHOOSE_LARGEFILE(lseek,lseek64)
165 #define lstat_or_lstat64 CHOOSE_LARGEFILE(lstat,lstat64)
166 #define off_t_or_off64_t CHOOSE_LARGEFILE(off_t,off64_t)
167 #define open_or_open64 CHOOSE_LARGEFILE(open,open64)
168 #define readdir_or_readdir64 CHOOSE_LARGEFILE(readdir,readdir64)
169 #if SCM_HAVE_READDIR64_R == 1
170 # define readdir_r_or_readdir64_r CHOOSE_LARGEFILE(readdir_r,readdir64_r)
172 # define readdir_r_or_readdir64_r readdir_r
174 #define stat_or_stat64 CHOOSE_LARGEFILE(stat,stat64)
175 #define truncate_or_truncate64 CHOOSE_LARGEFILE(truncate,truncate64)
176 #define scm_from_off_t_or_off64_t CHOOSE_LARGEFILE(scm_from_off_t,scm_from_int64)
177 #define scm_from_ino_t_or_ino64_t CHOOSE_LARGEFILE(scm_from_ulong,scm_from_uint64)
178 #define scm_from_blkcnt_t_or_blkcnt64_t CHOOSE_LARGEFILE(scm_from_ulong,scm_from_uint64)
179 #define scm_to_off_t_or_off64_t CHOOSE_LARGEFILE(scm_to_off_t,scm_to_int64)
181 #if SIZEOF_OFF_T == 4
182 # define scm_to_off_t scm_to_int32
183 # define scm_from_off_t scm_from_int32
184 #elif SIZEOF_OFF_T == 8
185 # define scm_to_off_t scm_to_int64
186 # define scm_from_off_t scm_from_int64
188 # error sizeof(off_t) is not 4 or 8.
190 #define scm_to_off64_t scm_to_int64
191 #define scm_from_off64_t scm_from_int64
197 /* VMS: Implement SCM_I_SETJMP in terms of setjump. */
198 extern int setjump(scm_i_jmp_buf env
);
199 extern int longjump(scm_i_jmp_buf env
, int ret
);
200 #define SCM_I_SETJMP setjump
201 #define SCM_I_LONGJMP longjump
203 #elif defined (_CRAY1)
204 /* Cray: Implement SCM_I_SETJMP in terms of setjump. */
205 extern int setjump(scm_i_jmp_buf env
);
206 extern int longjump(scm_i_jmp_buf env
, int ret
);
207 #define SCM_I_SETJMP setjump
208 #define SCM_I_LONGJMP longjump
210 #elif defined (__ia64__)
211 /* IA64: Implement SCM_I_SETJMP in terms of getcontext. */
212 # define SCM_I_SETJMP(JB) \
214 getcontext (&((JB).ctx)), \
215 ((JB).fresh ? ((JB).fresh = 0, 0) : 1) )
216 # define SCM_I_LONGJMP(JB,VAL) scm_ia64_longjmp (&(JB), VAL)
217 void scm_ia64_longjmp (scm_i_jmp_buf
*, int);
220 /* All other systems just use setjmp and longjmp. */
222 #define SCM_I_SETJMP setjmp
223 #define SCM_I_LONGJMP longjmp
228 #define SCM_ASYNC_TICK \
231 if (SCM_UNLIKELY (SCM_I_CURRENT_THREAD->pending_asyncs)) \
236 #define SCM_ASYNC_TICK_WITH_CODE(thr, stmt) \
239 if (SCM_UNLIKELY (thr->pending_asyncs)) \
250 /* The endianness marker in objcode. */
251 #ifdef WORDS_BIGENDIAN
252 # define SCM_OBJCODE_ENDIANNESS "BE"
254 # define SCM_OBJCODE_ENDIANNESS "LE"
257 #define _SCM_CPP_STRINGIFY(x) # x
258 #define SCM_CPP_STRINGIFY(x) _SCM_CPP_STRINGIFY (x)
260 /* The word size marker in objcode. */
261 #define SCM_OBJCODE_WORD_SIZE SCM_CPP_STRINGIFY (SIZEOF_VOID_P)
263 /* Major and minor versions must be single characters. */
264 #define SCM_OBJCODE_MAJOR_VERSION 2
265 #define SCM_OBJCODE_MINOR_VERSION 0
266 #define SCM_OBJCODE_MAJOR_VERSION_STRING \
267 SCM_CPP_STRINGIFY(SCM_OBJCODE_MAJOR_VERSION)
268 #define SCM_OBJCODE_MINOR_VERSION_STRING \
269 SCM_CPP_STRINGIFY(SCM_OBJCODE_MINOR_VERSION)
270 #define SCM_OBJCODE_VERSION_STRING \
271 SCM_OBJCODE_MAJOR_VERSION_STRING "." SCM_OBJCODE_MINOR_VERSION_STRING
272 #define SCM_OBJCODE_MACHINE_VERSION_STRING \
273 SCM_OBJCODE_ENDIANNESS "-" SCM_OBJCODE_WORD_SIZE "-" SCM_OBJCODE_VERSION_STRING
275 /* The objcode magic header. */
276 #define SCM_OBJCODE_COOKIE \
277 "GOOF----" SCM_OBJCODE_MACHINE_VERSION_STRING
278 #define SCM_OBJCODE_ENDIANNESS_OFFSET 8
279 #define SCM_OBJCODE_WORD_SIZE_OFFSET 11
282 #endif /* SCM__SCM_H */