_scm.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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,
  5. * 2011, 2013, 2014 Free Software Foundation, Inc.
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public License
  9. * as published by the Free Software Foundation; either version 3 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. */
  22. /**********************************************************************
  23. This file is Guile's central private header.
  24. When included by other files, this file should preceed any include
  25. other than __scm.h. See __scm.h for details regarding the purpose of
  26. and differences between _scm.h and __scm.h.
  27. **********************************************************************/
  28. #if defined(__ia64) && !defined(__ia64__)
  29. # define __ia64__
  30. #endif
  31. #if HAVE_CONFIG_H
  32. # include <config.h>
  33. #endif
  34. /* The size of `scm_t_bits'. */
  35. #define SIZEOF_SCM_T_BITS SIZEOF_VOID_P
  36. /* Undefine HAVE_STRUCT_TIMESPEC, because the libguile C code doesn't
  37. need it anymore, and because on MinGW:
  38. - the definition of struct timespec is provided (if at all) by
  39. pthread.h
  40. - pthread.h will _not_ define struct timespec if
  41. HAVE_STRUCT_TIMESPEC is 1, because then it thinks that it doesn't
  42. need to.
  43. The libguile C code doesn't need HAVE_STRUCT_TIMESPEC anymore,
  44. because the value of HAVE_STRUCT_TIMESPEC has already been
  45. incorporated in how scm_t_timespec is defined (in scmconfig.h), and
  46. the rest of the libguile C code now just uses scm_t_timespec.
  47. */
  48. #ifdef HAVE_STRUCT_TIMESPEC
  49. #undef HAVE_STRUCT_TIMESPEC
  50. #endif
  51. #include <errno.h>
  52. #include <verify.h>
  53. #include <alignof.h>
  54. #include "libguile/__scm.h"
  55. /* Include headers for those files central to the implementation. The
  56. rest should be explicitly #included in the C files themselves. */
  57. #include "libguile/error.h" /* Everyone signals errors. */
  58. #include "libguile/print.h" /* Everyone needs to print. */
  59. #include "libguile/pairs.h" /* Everyone conses. */
  60. #include "libguile/list.h" /* Everyone makes lists. */
  61. #include "libguile/gc.h" /* Everyone allocates. */
  62. #include "libguile/gsubr.h" /* Everyone defines global functions. */
  63. #include "libguile/procs.h" /* Same. */
  64. #include "libguile/numbers.h" /* Everyone deals with fixnums. */
  65. #include "libguile/symbols.h" /* For length, chars, values, miscellany. */
  66. #include "libguile/boolean.h" /* Everyone wonders about the truth. */
  67. #include "libguile/threads.h" /* You are not alone. */
  68. #include "libguile/snarf.h" /* Everyone snarfs. */
  69. #include "libguile/foreign.h" /* Snarfing needs the foreign data structures. */
  70. #include "libguile/programs.h" /* ... and program.h. */
  71. #include "libguile/variable.h"
  72. #include "libguile/modules.h"
  73. #include "libguile/inline.h"
  74. #include "libguile/strings.h"
  75. /* ASYNC_TICK after finding EINTR in order to handle pending signals, if
  76. any. See comment in scm_syserror. */
  77. #ifndef SCM_SYSCALL
  78. #ifdef vms
  79. # ifndef __GNUC__
  80. # include <ssdef.h>
  81. # define SCM_SYSCALL(line) \
  82. do \
  83. { \
  84. errno = 0; \
  85. line; \
  86. if (EVMSERR == errno && (vaxc$errno>>3)==(SS$_CONTROLC>>3)) \
  87. SCM_ASYNC_TICK; \
  88. else \
  89. break; \
  90. } \
  91. while (1)
  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. errno = EINTR; \
  107. } \
  108. } \
  109. while (errno == EINTR)
  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_WITH_GUARD_CODE(thr, pre, post) \
  192. do \
  193. { \
  194. if (SCM_UNLIKELY (thr->pending_asyncs)) \
  195. { \
  196. pre; \
  197. scm_async_tick (); \
  198. post; \
  199. } \
  200. } \
  201. while (0)
  202. #define SCM_ASYNC_TICK_WITH_CODE(thr, stmt) \
  203. SCM_ASYNC_TICK_WITH_GUARD_CODE (thr, stmt, (void) 0)
  204. #define SCM_ASYNC_TICK \
  205. SCM_ASYNC_TICK_WITH_CODE (SCM_I_CURRENT_THREAD, (void) 0)
  206. #if (defined __GNUC__)
  207. # define SCM_NOINLINE __attribute__ ((__noinline__))
  208. #else
  209. # define SCM_NOINLINE /* noinline */
  210. #endif
  211. /* The endianness marker in objcode. */
  212. #ifdef WORDS_BIGENDIAN
  213. # define SCM_OBJCODE_ENDIANNESS "BE"
  214. #else
  215. # define SCM_OBJCODE_ENDIANNESS "LE"
  216. #endif
  217. #define _SCM_CPP_STRINGIFY(x) # x
  218. #define SCM_CPP_STRINGIFY(x) _SCM_CPP_STRINGIFY (x)
  219. /* The word size marker in objcode. */
  220. #define SCM_OBJCODE_WORD_SIZE SCM_CPP_STRINGIFY (SIZEOF_VOID_P)
  221. /* Major and minor versions must be single characters. */
  222. #define SCM_OBJCODE_MAJOR_VERSION 3
  223. #define SCM_OBJCODE_MINOR_VERSION 7
  224. #define SCM_OBJCODE_MAJOR_VERSION_STRING \
  225. SCM_CPP_STRINGIFY(SCM_OBJCODE_MAJOR_VERSION)
  226. #define SCM_OBJCODE_MINOR_VERSION_STRING \
  227. SCM_CPP_STRINGIFY(SCM_OBJCODE_MINOR_VERSION)
  228. #define SCM_OBJCODE_VERSION_STRING \
  229. SCM_OBJCODE_MAJOR_VERSION_STRING "." SCM_OBJCODE_MINOR_VERSION_STRING
  230. #define SCM_OBJCODE_MACHINE_VERSION_STRING \
  231. SCM_OBJCODE_ENDIANNESS "-" SCM_OBJCODE_WORD_SIZE "-" SCM_OBJCODE_VERSION_STRING
  232. #endif /* SCM__SCM_H */
  233. /*
  234. Local Variables:
  235. c-file-style: "gnu"
  236. End:
  237. */