_scm.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /* classes: h_files */
  2. #ifndef SCM__SCM_H
  3. #define SCM__SCM_H
  4. /* Copyright (C) 1995,1996,2000,2001, 2002, 2006, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public License
  8. * as published by the Free Software Foundation; either version 3 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19. * 02110-1301 USA
  20. */
  21. /**********************************************************************
  22. This file is Guile's central private header.
  23. When included by other files, this file should preceed any include
  24. other than __scm.h. See __scm.h for details regarding the purpose of
  25. and differences between _scm.h and __scm.h.
  26. **********************************************************************/
  27. #if defined(__ia64) && !defined(__ia64__)
  28. # define __ia64__
  29. #endif
  30. #if HAVE_CONFIG_H
  31. # include <config.h>
  32. #endif
  33. /* The size of `scm_t_bits'. */
  34. #define SIZEOF_SCM_T_BITS SIZEOF_VOID_P
  35. /* Undefine HAVE_STRUCT_TIMESPEC, because the libguile C code doesn't
  36. need it anymore, and because on MinGW:
  37. - the definition of struct timespec is provided (if at all) by
  38. pthread.h
  39. - pthread.h will _not_ define struct timespec if
  40. HAVE_STRUCT_TIMESPEC is 1, because then it thinks that it doesn't
  41. need to.
  42. The libguile C code doesn't need HAVE_STRUCT_TIMESPEC anymore,
  43. because the value of HAVE_STRUCT_TIMESPEC has already been
  44. incorporated in how scm_t_timespec is defined (in scmconfig.h), and
  45. the rest of the libguile C code now just uses scm_t_timespec.
  46. */
  47. #ifdef HAVE_STRUCT_TIMESPEC
  48. #undef HAVE_STRUCT_TIMESPEC
  49. #endif
  50. #include <errno.h>
  51. #include <verify.h>
  52. #include <alignof.h>
  53. #include "libguile/__scm.h"
  54. /* Include headers for those files central to the implementation. The
  55. rest should be explicitly #included in the C files themselves. */
  56. #include "libguile/error.h" /* Everyone signals errors. */
  57. #include "libguile/print.h" /* Everyone needs to print. */
  58. #include "libguile/pairs.h" /* Everyone conses. */
  59. #include "libguile/list.h" /* Everyone makes lists. */
  60. #include "libguile/gc.h" /* Everyone allocates. */
  61. #include "libguile/gsubr.h" /* Everyone defines global functions. */
  62. #include "libguile/procs.h" /* Same. */
  63. #include "libguile/numbers.h" /* Everyone deals with fixnums. */
  64. #include "libguile/symbols.h" /* For length, chars, values, miscellany. */
  65. #include "libguile/boolean.h" /* Everyone wonders about the truth. */
  66. #include "libguile/threads.h" /* You are not alone. */
  67. #include "libguile/snarf.h" /* Everyone snarfs. */
  68. #include "libguile/foreign.h" /* Snarfing needs the foreign data structures. */
  69. #include "libguile/programs.h" /* ... and program.h. */
  70. #include "libguile/variable.h"
  71. #include "libguile/modules.h"
  72. #include "libguile/inline.h"
  73. #include "libguile/strings.h"
  74. /* ASYNC_TICK after finding EINTR in order to handle pending signals, if
  75. any. See comment in scm_syserror. */
  76. #ifndef SCM_SYSCALL
  77. #ifdef vms
  78. # ifndef __GNUC__
  79. # include <ssdef.h>
  80. # define SCM_SYSCALL(line) \
  81. do \
  82. { \
  83. errno = 0; \
  84. line; \
  85. if (EVMSERR==errno && (vaxc$errno>>3)==(SS$_CONTROLC>>3)) \
  86. { \
  87. SCM_ASYNC_TICK; \
  88. continue; \
  89. } \
  90. } \
  91. while(0)
  92. # endif /* ndef __GNUC__ */
  93. #endif /* def vms */
  94. #endif /* ndef SCM_SYSCALL */
  95. #ifndef SCM_SYSCALL
  96. # ifdef EINTR
  97. # if (EINTR > 0)
  98. # define SCM_SYSCALL(line) \
  99. do \
  100. { \
  101. errno = 0; \
  102. line; \
  103. if (errno == EINTR) \
  104. { \
  105. SCM_ASYNC_TICK; \
  106. continue; \
  107. } \
  108. } \
  109. while(0)
  110. # endif /* (EINTR > 0) */
  111. # endif /* def EINTR */
  112. #endif /* ndef SCM_SYSCALL */
  113. #ifndef SCM_SYSCALL
  114. # define SCM_SYSCALL(line) line;
  115. #endif /* ndef SCM_SYSCALL */
  116. #ifndef min
  117. #define min(A, B) ((A) <= (B) ? (A) : (B))
  118. #endif
  119. #ifndef max
  120. #define max(A, B) ((A) >= (B) ? (A) : (B))
  121. #endif
  122. /* Return the first integer greater than or equal to LEN such that
  123. LEN % ALIGN == 0. Return LEN if ALIGN is zero. */
  124. #define ROUND_UP(len, align) \
  125. ((align) ? (((len) - 1UL) | ((align) - 1UL)) + 1UL : (len))
  126. #if defined GUILE_USE_64_CALLS && GUILE_USE_64_CALLS && defined(HAVE_STAT64)
  127. #define CHOOSE_LARGEFILE(foo,foo64) foo64
  128. #else
  129. #define CHOOSE_LARGEFILE(foo,foo64) foo
  130. #endif
  131. /* These names are a bit long, but they make it clear what they represent. */
  132. #if SCM_HAVE_STRUCT_DIRENT64 == 1
  133. # define dirent_or_dirent64 CHOOSE_LARGEFILE(dirent,dirent64)
  134. #else
  135. # define dirent_or_dirent64 dirent
  136. #endif
  137. #define fstat_or_fstat64 CHOOSE_LARGEFILE(fstat,fstat64)
  138. #define ftruncate_or_ftruncate64 CHOOSE_LARGEFILE(ftruncate,ftruncate64)
  139. #define lseek_or_lseek64 CHOOSE_LARGEFILE(lseek,lseek64)
  140. #define lstat_or_lstat64 CHOOSE_LARGEFILE(lstat,lstat64)
  141. #define off_t_or_off64_t CHOOSE_LARGEFILE(off_t,off64_t)
  142. #define open_or_open64 CHOOSE_LARGEFILE(open,open64)
  143. #define readdir_or_readdir64 CHOOSE_LARGEFILE(readdir,readdir64)
  144. #if SCM_HAVE_READDIR64_R == 1
  145. # define readdir_r_or_readdir64_r CHOOSE_LARGEFILE(readdir_r,readdir64_r)
  146. #else
  147. # define readdir_r_or_readdir64_r readdir_r
  148. #endif
  149. #define stat_or_stat64 CHOOSE_LARGEFILE(stat,stat64)
  150. #define truncate_or_truncate64 CHOOSE_LARGEFILE(truncate,truncate64)
  151. #define scm_from_off_t_or_off64_t CHOOSE_LARGEFILE(scm_from_off_t,scm_from_int64)
  152. #define scm_from_ino_t_or_ino64_t CHOOSE_LARGEFILE(scm_from_ulong,scm_from_uint64)
  153. #define scm_from_blkcnt_t_or_blkcnt64_t CHOOSE_LARGEFILE(scm_from_ulong,scm_from_uint64)
  154. #define scm_to_off_t_or_off64_t CHOOSE_LARGEFILE(scm_to_off_t,scm_to_int64)
  155. #if SIZEOF_OFF_T == 4
  156. # define scm_to_off_t scm_to_int32
  157. # define scm_from_off_t scm_from_int32
  158. #elif SIZEOF_OFF_T == 8
  159. # define scm_to_off_t scm_to_int64
  160. # define scm_from_off_t scm_from_int64
  161. #else
  162. # error sizeof(off_t) is not 4 or 8.
  163. #endif
  164. #define scm_to_off64_t scm_to_int64
  165. #define scm_from_off64_t scm_from_int64
  166. #if defined (vms)
  167. /* VMS: Implement SCM_I_SETJMP in terms of setjump. */
  168. extern int setjump(scm_i_jmp_buf env);
  169. extern int longjump(scm_i_jmp_buf env, int ret);
  170. #define SCM_I_SETJMP setjump
  171. #define SCM_I_LONGJMP longjump
  172. #elif defined (_CRAY1)
  173. /* Cray: Implement SCM_I_SETJMP in terms of setjump. */
  174. extern int setjump(scm_i_jmp_buf env);
  175. extern int longjump(scm_i_jmp_buf env, int ret);
  176. #define SCM_I_SETJMP setjump
  177. #define SCM_I_LONGJMP longjump
  178. #elif defined (__ia64__)
  179. /* IA64: Implement SCM_I_SETJMP in terms of getcontext. */
  180. # define SCM_I_SETJMP(JB) \
  181. ( (JB).fresh = 1, \
  182. getcontext (&((JB).ctx)), \
  183. ((JB).fresh ? ((JB).fresh = 0, 0) : 1) )
  184. # define SCM_I_LONGJMP(JB,VAL) scm_ia64_longjmp (&(JB), VAL)
  185. void scm_ia64_longjmp (scm_i_jmp_buf *, int);
  186. #else
  187. /* All other systems just use setjmp and longjmp. */
  188. #define SCM_I_SETJMP setjmp
  189. #define SCM_I_LONGJMP longjmp
  190. #endif
  191. #define SCM_ASYNC_TICK \
  192. do \
  193. { \
  194. if (SCM_UNLIKELY (SCM_I_CURRENT_THREAD->pending_asyncs)) \
  195. scm_async_tick (); \
  196. } \
  197. while (0)
  198. #define SCM_ASYNC_TICK_WITH_CODE(thr, stmt) \
  199. do \
  200. { \
  201. if (SCM_UNLIKELY (thr->pending_asyncs)) \
  202. { \
  203. stmt; \
  204. scm_async_tick (); \
  205. } \
  206. } \
  207. while (0)
  208. /* The endianness marker in objcode. */
  209. #ifdef WORDS_BIGENDIAN
  210. # define SCM_OBJCODE_ENDIANNESS "BE"
  211. #else
  212. # define SCM_OBJCODE_ENDIANNESS "LE"
  213. #endif
  214. #define _SCM_CPP_STRINGIFY(x) # x
  215. #define SCM_CPP_STRINGIFY(x) _SCM_CPP_STRINGIFY (x)
  216. /* The word size marker in objcode. */
  217. #define SCM_OBJCODE_WORD_SIZE SCM_CPP_STRINGIFY (SIZEOF_VOID_P)
  218. /* Major and minor versions must be single characters. */
  219. #define SCM_OBJCODE_MAJOR_VERSION 3
  220. #define SCM_OBJCODE_MINOR_VERSION 0
  221. #define SCM_OBJCODE_MAJOR_VERSION_STRING \
  222. SCM_CPP_STRINGIFY(SCM_OBJCODE_MAJOR_VERSION)
  223. #define SCM_OBJCODE_MINOR_VERSION_STRING \
  224. SCM_CPP_STRINGIFY(SCM_OBJCODE_MINOR_VERSION)
  225. #define SCM_OBJCODE_VERSION_STRING \
  226. SCM_OBJCODE_MAJOR_VERSION_STRING "." SCM_OBJCODE_MINOR_VERSION_STRING
  227. #define SCM_OBJCODE_MACHINE_VERSION_STRING \
  228. SCM_OBJCODE_ENDIANNESS "-" SCM_OBJCODE_WORD_SIZE "-" SCM_OBJCODE_VERSION_STRING
  229. /* The objcode magic header. */
  230. #define SCM_OBJCODE_COOKIE \
  231. "GOOF----" SCM_OBJCODE_MACHINE_VERSION_STRING
  232. #define SCM_OBJCODE_ENDIANNESS_OFFSET 8
  233. #define SCM_OBJCODE_WORD_SIZE_OFFSET 11
  234. #endif /* SCM__SCM_H */
  235. /*
  236. Local Variables:
  237. c-file-style: "gnu"
  238. End:
  239. */