inline.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef SCM_INLINE_H
  2. #define SCM_INLINE_H
  3. /* Copyright 2001-2004,2006,2008-2013,2018
  4. Free Software Foundation, Inc.
  5. This file is part of Guile.
  6. Guile is free software: you can redistribute it and/or modify it
  7. under the terms of the GNU Lesser General Public License as published
  8. by the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Guile is distributed in the hope that it will be useful, but WITHOUT
  11. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  13. License for more details.
  14. You should have received a copy of the GNU Lesser General Public
  15. License along with Guile. If not, see
  16. <https://www.gnu.org/licenses/>. */
  17. /* This file is for inline functions. On platforms that don't support
  18. inlining functions, they are turned into ordinary functions. On
  19. platforms that do support inline functions, the definitions are still
  20. compiled into the library, once, in inline.c. */
  21. #include "libguile/scm.h"
  22. /* Define SCM_C_INLINE_KEYWORD so that it can be used as a replacement
  23. for the "inline" keyword, expanding to nothing when "inline" is not
  24. available.
  25. */
  26. #ifdef SCM_C_INLINE
  27. #define SCM_C_INLINE_KEYWORD SCM_C_INLINE
  28. #else
  29. #define SCM_C_INLINE_KEYWORD
  30. #endif
  31. /* We would like gnu89 extern inline semantics, not C99 extern inline
  32. semantics, so that we can be sure to avoid reifying definitions of
  33. inline functions in all compilation units, which is a possibility at
  34. low optimization levels, or if a user takes the address of an inline
  35. function.
  36. Hence the `__gnu_inline__' attribute, in accordance with:
  37. http://gcc.gnu.org/gcc-4.3/porting_to.html .
  38. With GCC 4.2, `__GNUC_STDC_INLINE__' is never defined (because C99 inline
  39. semantics are not supported), but a warning is issued in C99 mode if
  40. `__gnu_inline__' is not used.
  41. Apple's GCC build >5400 (since Xcode 3.0) doesn't support GNU inline in
  42. C99 mode and doesn't define `__GNUC_STDC_INLINE__'. Fall back to "static
  43. inline" in that case. */
  44. # if (defined __GNUC__) && (!(((defined __APPLE_CC__) && (__APPLE_CC__ > 5400)) && __STDC_VERSION__ >= 199901L))
  45. # if (defined __GNUC_STDC_INLINE__) || (__GNUC__ == 4 && __GNUC_MINOR__ == 2)
  46. # define SCM_C_EXTERN_INLINE \
  47. extern __inline__ __attribute__ ((__gnu_inline__))
  48. # else
  49. # define SCM_C_EXTERN_INLINE extern __inline__
  50. # endif
  51. # endif
  52. /* SCM_INLINE is a macro prepended to all public inline function
  53. declarations. Implementations of those functions should also be in
  54. the header file, prefixed by SCM_INLINE_IMPLEMENTATION, and protected
  55. by SCM_CAN_INLINE. Non-inline definitions will be reified into
  56. inline.c. See strings.h for an example usage, for scm_is_string. */
  57. #if defined SCM_IMPLEMENT_INLINES
  58. /* Reifying functions to a file, whether or not inlining is available. */
  59. # define SCM_CAN_INLINE 0
  60. # define SCM_INLINE SCM_API
  61. # define SCM_INLINE_IMPLEMENTATION
  62. #elif defined SCM_C_INLINE
  63. /* Declarations when inlining is available. */
  64. # define SCM_CAN_INLINE 1
  65. # ifdef SCM_C_EXTERN_INLINE
  66. # define SCM_INLINE SCM_C_EXTERN_INLINE
  67. # else
  68. /* Fall back to static inline if GNU "extern inline" is unavailable. */
  69. # define SCM_INLINE static SCM_C_INLINE
  70. # endif
  71. # define SCM_INLINE_IMPLEMENTATION SCM_INLINE
  72. #else
  73. /* Declarations when inlining is not available. */
  74. # define SCM_CAN_INLINE 0
  75. # define SCM_INLINE SCM_API
  76. /* Don't define SCM_INLINE_IMPLEMENTATION; it should never be seen in
  77. this case. */
  78. #endif
  79. #endif /* SCM_INLINE_H */