discouraged.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /* This file contains definitions for discouraged features. When you
  2. discourage something, move it here when that is feasible.
  3. */
  4. /* Copyright (C) 2003, 2004, 2006, 2008 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
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but 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 02110-1301 USA
  19. */
  20. #ifdef HAVE_CONFIG_H
  21. # include <config.h>
  22. #endif
  23. #include <libguile.h>
  24. #if (SCM_ENABLE_DISCOURAGED == 1)
  25. SCM
  26. scm_short2num (short x)
  27. {
  28. return scm_from_short (x);
  29. }
  30. SCM
  31. scm_ushort2num (unsigned short x)
  32. {
  33. return scm_from_ushort (x);
  34. }
  35. SCM
  36. scm_int2num (int x)
  37. {
  38. return scm_from_int (x);
  39. }
  40. SCM
  41. scm_uint2num (unsigned int x)
  42. {
  43. return scm_from_uint (x);
  44. }
  45. SCM
  46. scm_long2num (long x)
  47. {
  48. return scm_from_long (x);
  49. }
  50. SCM
  51. scm_ulong2num (unsigned long x)
  52. {
  53. return scm_from_ulong (x);
  54. }
  55. SCM
  56. scm_size2num (size_t x)
  57. {
  58. return scm_from_size_t (x);
  59. }
  60. SCM
  61. scm_ptrdiff2num (ptrdiff_t x)
  62. {
  63. return scm_from_ssize_t (x);
  64. }
  65. short
  66. scm_num2short (SCM x, unsigned long pos, const char *s_caller)
  67. {
  68. return scm_to_short (x);
  69. }
  70. unsigned short
  71. scm_num2ushort (SCM x, unsigned long pos, const char *s_caller)
  72. {
  73. return scm_to_ushort (x);
  74. }
  75. int
  76. scm_num2int (SCM x, unsigned long pos, const char *s_caller)
  77. {
  78. return scm_to_int (x);
  79. }
  80. unsigned int
  81. scm_num2uint (SCM x, unsigned long pos, const char *s_caller)
  82. {
  83. return scm_to_uint (x);
  84. }
  85. long
  86. scm_num2long (SCM x, unsigned long pos, const char *s_caller)
  87. {
  88. return scm_to_long (x);
  89. }
  90. unsigned long
  91. scm_num2ulong (SCM x, unsigned long pos, const char *s_caller)
  92. {
  93. return scm_to_ulong (x);
  94. }
  95. size_t
  96. scm_num2size (SCM x, unsigned long pos, const char *s_caller)
  97. {
  98. return scm_to_size_t (x);
  99. }
  100. ptrdiff_t
  101. scm_num2ptrdiff (SCM x, unsigned long pos, const char *s_caller)
  102. {
  103. return scm_to_ssize_t (x);
  104. }
  105. #if SCM_SIZEOF_LONG_LONG != 0
  106. SCM
  107. scm_long_long2num (long long x)
  108. {
  109. return scm_from_long_long (x);
  110. }
  111. SCM
  112. scm_ulong_long2num (unsigned long long x)
  113. {
  114. return scm_from_ulong_long (x);
  115. }
  116. long long
  117. scm_num2long_long (SCM x, unsigned long pos, const char *s_caller)
  118. {
  119. return scm_to_long_long (x);
  120. }
  121. unsigned long long
  122. scm_num2ulong_long (SCM x, unsigned long pos, const char *s_caller)
  123. {
  124. return scm_to_ulong_long (x);
  125. }
  126. #endif
  127. SCM
  128. scm_make_real (double x)
  129. {
  130. return scm_from_double (x);
  131. }
  132. double
  133. scm_num2dbl (SCM a, const char *why)
  134. {
  135. return scm_to_double (a);
  136. }
  137. SCM
  138. scm_float2num (float n)
  139. {
  140. return scm_from_double ((double) n);
  141. }
  142. SCM
  143. scm_double2num (double n)
  144. {
  145. return scm_from_double (n);
  146. }
  147. SCM
  148. scm_make_complex (double x, double y)
  149. {
  150. return scm_c_make_rectangular (x, y);
  151. }
  152. SCM
  153. scm_mem2symbol (const char *mem, size_t len)
  154. {
  155. return scm_from_locale_symboln (mem, len);
  156. }
  157. SCM
  158. scm_mem2uninterned_symbol (const char *mem, size_t len)
  159. {
  160. return scm_make_symbol (scm_from_locale_stringn (mem, len));
  161. }
  162. SCM
  163. scm_str2symbol (const char *str)
  164. {
  165. return scm_from_locale_symbol (str);
  166. }
  167. /* This function must only be applied to memory obtained via malloc,
  168. since the GC is going to apply `free' to it when the string is
  169. dropped.
  170. Also, s[len] must be `\0', since we promise that strings are
  171. null-terminated. Perhaps we could handle non-null-terminated
  172. strings by claiming they're shared substrings of a string we just
  173. made up. */
  174. SCM
  175. scm_take_str (char *s, size_t len)
  176. {
  177. SCM answer = scm_from_locale_stringn (s, len);
  178. free (s);
  179. return answer;
  180. }
  181. /* `s' must be a malloc'd string. See scm_take_str. */
  182. SCM
  183. scm_take0str (char *s)
  184. {
  185. return scm_take_locale_string (s);
  186. }
  187. SCM
  188. scm_mem2string (const char *src, size_t len)
  189. {
  190. return scm_from_locale_stringn (src, len);
  191. }
  192. SCM
  193. scm_str2string (const char *src)
  194. {
  195. return scm_from_locale_string (src);
  196. }
  197. SCM
  198. scm_makfrom0str (const char *src)
  199. {
  200. if (!src) return SCM_BOOL_F;
  201. return scm_from_locale_string (src);
  202. }
  203. SCM
  204. scm_makfrom0str_opt (const char *src)
  205. {
  206. return scm_makfrom0str (src);
  207. }
  208. SCM
  209. scm_allocate_string (size_t len)
  210. {
  211. return scm_i_make_string (len, NULL);
  212. }
  213. SCM_DEFINE (scm_make_keyword_from_dash_symbol, "make-keyword-from-dash-symbol", 1, 0, 0,
  214. (SCM symbol),
  215. "Make a keyword object from a @var{symbol} that starts with a dash.")
  216. #define FUNC_NAME s_scm_make_keyword_from_dash_symbol
  217. {
  218. SCM dash_string, non_dash_symbol;
  219. SCM_ASSERT (scm_is_symbol (symbol)
  220. && ('-' == scm_i_symbol_chars(symbol)[0]),
  221. symbol, SCM_ARG1, FUNC_NAME);
  222. dash_string = scm_symbol_to_string (symbol);
  223. non_dash_symbol =
  224. scm_string_to_symbol (scm_c_substring (dash_string,
  225. 1,
  226. scm_c_string_length (dash_string)));
  227. return scm_symbol_to_keyword (non_dash_symbol);
  228. }
  229. #undef FUNC_NAME
  230. SCM_DEFINE (scm_keyword_dash_symbol, "keyword-dash-symbol", 1, 0, 0,
  231. (SCM keyword),
  232. "Return the dash symbol for @var{keyword}.\n"
  233. "This is the inverse of @code{make-keyword-from-dash-symbol}.")
  234. #define FUNC_NAME s_scm_keyword_dash_symbol
  235. {
  236. SCM symbol = scm_keyword_to_symbol (keyword);
  237. SCM parts = scm_list_2 (scm_from_locale_string ("-"),
  238. scm_symbol_to_string (symbol));
  239. return scm_string_to_symbol (scm_string_append (parts));
  240. }
  241. #undef FUNC_NAME
  242. SCM
  243. scm_c_make_keyword (const char *s)
  244. {
  245. return scm_from_locale_keyword (s);
  246. }
  247. void
  248. scm_i_init_discouraged (void)
  249. {
  250. #include "libguile/discouraged.x"
  251. }
  252. #endif