deprecated.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  1. /* Copyright 2003-2004,2006,2008-2018,2020,2021,2022
  2. Free Software Foundation, Inc.
  3. This file is part of Guile.
  4. Guile is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Lesser General Public License as published
  6. by the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. Guile is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  11. License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with Guile. If not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #ifdef HAVE_CONFIG_H
  16. # include <config.h>
  17. #endif
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include <unistd.h>
  21. #define SCM_BUILDING_DEPRECATED_CODE
  22. #include "alist.h"
  23. #include "array-handle.h"
  24. #include "arrays.h"
  25. #include "boolean.h"
  26. #include "bitvectors.h"
  27. #include "deprecation.h"
  28. #include "dynl.h"
  29. #include "eval.h"
  30. #include "foreign.h"
  31. #include "finalizers.h"
  32. #include "generalized-vectors.h"
  33. #include "gc.h"
  34. #include "gsubr.h"
  35. #include "modules.h"
  36. #include "objprop.h"
  37. #include "procprop.h"
  38. #include "srcprop.h"
  39. #include "srfi-4.h"
  40. #include "strings.h"
  41. #include "symbols.h"
  42. #include "uniform.h"
  43. #include "vectors.h"
  44. #include "deprecated.h"
  45. #if (SCM_ENABLE_DEPRECATED == 1)
  46. #ifndef MAXPATHLEN
  47. #define MAXPATHLEN 80
  48. #endif /* ndef MAXPATHLEN */
  49. #ifndef X_OK
  50. #define X_OK 1
  51. #endif /* ndef X_OK */
  52. char *
  53. scm_find_executable (const char *name)
  54. {
  55. char tbuf[MAXPATHLEN];
  56. int i = 0, c;
  57. FILE *f;
  58. scm_c_issue_deprecation_warning ("scm_find_executable is deprecated.");
  59. /* fprintf(stderr, "s_f_e checking access %s ->%d\n", name, access(name, X_OK)); fflush(stderr); */
  60. if (access (name, X_OK))
  61. return 0L;
  62. f = fopen (name, "r");
  63. if (!f)
  64. return 0L;
  65. if ((fgetc (f) == '#') && (fgetc (f) == '!'))
  66. {
  67. while (1)
  68. switch (c = fgetc (f))
  69. {
  70. case /*WHITE_SPACES */ ' ':
  71. case '\t':
  72. case '\r':
  73. case '\f':
  74. case EOF:
  75. tbuf[i] = 0;
  76. fclose (f);
  77. return strdup (tbuf);
  78. default:
  79. tbuf[i++] = c;
  80. break;
  81. }
  82. }
  83. fclose (f);
  84. return strdup (name);
  85. }
  86. int
  87. scm_is_simple_vector (SCM obj)
  88. {
  89. scm_c_issue_deprecation_warning
  90. ("scm_is_simple_vector is deprecated. Use scm_is_vector instead.");
  91. return SCM_I_IS_VECTOR (obj);
  92. }
  93. SCM
  94. scm_bitvector_p (SCM vec)
  95. {
  96. scm_c_issue_deprecation_warning
  97. ("scm_bitvector_p is deprecated. Use scm_is_bitvector instead.");
  98. return scm_from_bool (scm_is_bitvector (vec));
  99. }
  100. SCM
  101. scm_bitvector (SCM list)
  102. {
  103. scm_c_issue_deprecation_warning
  104. ("scm_bitvector is deprecated. Use scm_list_to_bitvector instead.");
  105. return scm_list_to_bitvector (list);
  106. }
  107. SCM
  108. scm_make_bitvector (SCM len, SCM fill)
  109. {
  110. scm_c_issue_deprecation_warning
  111. ("scm_make_bitvector is deprecated. Use scm_c_make_bitvector instead.");
  112. return scm_c_make_bitvector (scm_to_size_t (len), fill);
  113. }
  114. SCM
  115. scm_bitvector_length (SCM vec)
  116. {
  117. scm_c_issue_deprecation_warning
  118. ("scm_bitvector_length is deprecated. Use scm_c_bitvector_length "
  119. "instead.");
  120. return scm_from_size_t (scm_c_bitvector_length (vec));
  121. }
  122. SCM
  123. scm_c_bitvector_ref (SCM vec, size_t idx)
  124. {
  125. scm_c_issue_deprecation_warning
  126. ("bitvector-ref is deprecated. Use bitvector-bit-set? instead.");
  127. if (scm_is_bitvector (vec))
  128. return scm_from_bool (scm_c_bitvector_bit_is_set (vec, idx));
  129. SCM res;
  130. scm_t_array_handle handle;
  131. size_t len, off;
  132. ssize_t inc;
  133. const uint32_t *bits =
  134. scm_bitvector_elements (vec, &handle, &off, &len, &inc);
  135. if (idx >= len)
  136. scm_out_of_range (NULL, scm_from_size_t (idx));
  137. idx = idx*inc + off;
  138. res = scm_from_bool (bits[idx/32] & (1L << (idx%32)));
  139. scm_array_handle_release (&handle);
  140. return res;
  141. }
  142. SCM_DEFINE (scm_bitvector_ref, "bitvector-ref", 2, 0, 0,
  143. (SCM vec, SCM idx),
  144. "Return the element at index @var{idx} of the bitvector\n"
  145. "@var{vec}.")
  146. #define FUNC_NAME s_scm_bitvector_ref
  147. {
  148. return scm_c_bitvector_ref (vec, scm_to_size_t (idx));
  149. }
  150. #undef FUNC_NAME
  151. void
  152. scm_c_bitvector_set_x (SCM vec, size_t idx, SCM val)
  153. {
  154. scm_c_issue_deprecation_warning
  155. ("bitvector-set! is deprecated. Use bitvector-set-bit! or "
  156. "bitvector-clear-bit! instead.");
  157. if (scm_is_bitvector (vec))
  158. {
  159. if (scm_is_true (val))
  160. scm_c_bitvector_set_bit_x (vec, idx);
  161. else
  162. scm_c_bitvector_clear_bit_x (vec, idx);
  163. }
  164. else
  165. {
  166. scm_t_array_handle handle;
  167. uint32_t *bits, mask;
  168. size_t len, off;
  169. ssize_t inc;
  170. bits = scm_bitvector_writable_elements (vec, &handle, &off, &len, &inc);
  171. if (idx >= len)
  172. scm_out_of_range (NULL, scm_from_size_t (idx));
  173. idx = idx*inc + off;
  174. mask = 1L << (idx%32);
  175. if (scm_is_true (val))
  176. bits[idx/32] |= mask;
  177. else
  178. bits[idx/32] &= ~mask;
  179. scm_array_handle_release (&handle);
  180. }
  181. }
  182. SCM_DEFINE (scm_bitvector_set_x, "bitvector-set!", 3, 0, 0,
  183. (SCM vec, SCM idx, SCM val),
  184. "Set the element at index @var{idx} of the bitvector\n"
  185. "@var{vec} when @var{val} is true, else clear it.")
  186. #define FUNC_NAME s_scm_bitvector_set_x
  187. {
  188. scm_c_bitvector_set_x (vec, scm_to_size_t (idx), val);
  189. return SCM_UNSPECIFIED;
  190. }
  191. #undef FUNC_NAME
  192. SCM_DEFINE (scm_bitvector_fill_x, "bitvector-fill!", 2, 0, 0,
  193. (SCM vec, SCM val),
  194. "Set all elements of the bitvector\n"
  195. "@var{vec} when @var{val} is true, else clear them.")
  196. #define FUNC_NAME s_scm_bitvector_fill_x
  197. {
  198. scm_c_issue_deprecation_warning
  199. ("bitvector-fill! is deprecated. Use bitvector-set-all-bits! or "
  200. "bitvector-clear-all-bits! instead.");
  201. if (scm_is_bitvector (vec))
  202. {
  203. if (scm_is_true (val))
  204. scm_c_bitvector_set_all_bits_x (vec);
  205. else
  206. scm_c_bitvector_clear_all_bits_x (vec);
  207. return SCM_UNSPECIFIED;
  208. }
  209. scm_t_array_handle handle;
  210. size_t off, len;
  211. ssize_t inc;
  212. scm_bitvector_writable_elements (vec, &handle, &off, &len, &inc);
  213. size_t i;
  214. for (i = 0; i < len; i++)
  215. scm_array_handle_set (&handle, i*inc, val);
  216. scm_array_handle_release (&handle);
  217. return SCM_UNSPECIFIED;
  218. }
  219. #undef FUNC_NAME
  220. SCM_DEFINE (scm_bit_invert_x, "bit-invert!", 1, 0, 0,
  221. (SCM v),
  222. "Modify the bit vector @var{v} by replacing each element with\n"
  223. "its negation.")
  224. #define FUNC_NAME s_scm_bit_invert_x
  225. {
  226. scm_c_issue_deprecation_warning
  227. ("bit-invert! is deprecated. Use bitvector-flip-all-bits!, or "
  228. "scalar array accessors in a loop for generic arrays.");
  229. if (scm_is_bitvector (v))
  230. scm_c_bitvector_flip_all_bits_x (v);
  231. else
  232. {
  233. size_t off, len;
  234. ssize_t inc;
  235. scm_t_array_handle handle;
  236. scm_bitvector_writable_elements (v, &handle, &off, &len, &inc);
  237. for (size_t i = 0; i < len; i++)
  238. scm_array_handle_set (&handle, i*inc,
  239. scm_not (scm_array_handle_ref (&handle, i*inc)));
  240. scm_array_handle_release (&handle);
  241. }
  242. return SCM_UNSPECIFIED;
  243. }
  244. #undef FUNC_NAME
  245. SCM_DEFINE (scm_bit_count, "bit-count", 2, 0, 0,
  246. (SCM b, SCM bitvector),
  247. "Return the number of occurrences of the boolean @var{b} in\n"
  248. "@var{bitvector}.")
  249. #define FUNC_NAME s_scm_bit_count
  250. {
  251. int bit = scm_to_bool (b);
  252. size_t count = 0, len;
  253. scm_c_issue_deprecation_warning
  254. ("bit-count is deprecated. Use bitvector-count, or a loop over array-ref "
  255. "if array support is needed.");
  256. if (scm_is_bitvector (bitvector))
  257. {
  258. len = scm_to_size_t (scm_bitvector_length (bitvector));
  259. count = scm_c_bitvector_count (bitvector);
  260. }
  261. else
  262. {
  263. scm_t_array_handle handle;
  264. size_t off;
  265. ssize_t inc;
  266. scm_bitvector_elements (bitvector, &handle, &off, &len, &inc);
  267. for (size_t i = 0; i < len; i++)
  268. if (scm_is_true (scm_array_handle_ref (&handle, i*inc)))
  269. count++;
  270. scm_array_handle_release (&handle);
  271. }
  272. return scm_from_size_t (bit ? count : len-count);
  273. }
  274. #undef FUNC_NAME
  275. SCM_DEFINE (scm_bit_count_star, "bit-count*", 3, 0, 0,
  276. (SCM v, SCM kv, SCM obj),
  277. "Return a count of how many entries in bit vector @var{v} are\n"
  278. "equal to @var{obj}, with @var{kv} selecting the entries to\n"
  279. "consider.\n"
  280. "\n"
  281. "If @var{kv} is a bit vector, then those entries where it has\n"
  282. "@code{#t} are the ones in @var{v} which are considered.\n"
  283. "@var{kv} and @var{v} must be the same length.\n"
  284. "\n"
  285. "If @var{kv} is a u32vector, then it contains\n"
  286. "the indexes in @var{v} to consider.\n"
  287. "\n"
  288. "For example,\n"
  289. "\n"
  290. "@example\n"
  291. "(bit-count* #*01110111 #*11001101 #t) @result{} 3\n"
  292. "(bit-count* #*01110111 #u32(7 0 4) #f) @result{} 2\n"
  293. "@end example")
  294. #define FUNC_NAME s_scm_bit_count_star
  295. {
  296. size_t count = 0;
  297. scm_c_issue_deprecation_warning
  298. ("bit-count* is deprecated. Use bitvector-count-bits instead, and in the "
  299. "case of counting false bits, subtract from a bitvector-count on the "
  300. "selection bitvector.");
  301. /* Validate that OBJ is a boolean so this is done even if we don't
  302. need BIT.
  303. */
  304. int bit = scm_to_bool (obj);
  305. if (scm_is_bitvector (v) && scm_is_bitvector (kv))
  306. {
  307. count = scm_c_bitvector_count_bits (v, kv);
  308. if (bit == 0)
  309. count = scm_c_bitvector_count (kv) - count;
  310. }
  311. else
  312. {
  313. scm_t_array_handle v_handle;
  314. size_t v_off, v_len;
  315. ssize_t v_inc;
  316. scm_bitvector_elements (v, &v_handle, &v_off, &v_len, &v_inc);
  317. if (scm_is_bitvector (kv))
  318. {
  319. size_t kv_len = scm_c_bitvector_length (kv);
  320. for (size_t i = 0; i < kv_len; i++)
  321. if (scm_c_bitvector_bit_is_set (kv, i))
  322. {
  323. SCM elt = scm_array_handle_ref (&v_handle, i*v_inc);
  324. if ((bit && scm_is_true (elt)) || (!bit && scm_is_false (elt)))
  325. count++;
  326. }
  327. }
  328. else if (scm_is_true (scm_u32vector_p (kv)))
  329. {
  330. scm_t_array_handle kv_handle;
  331. size_t i, kv_len;
  332. ssize_t kv_inc;
  333. const uint32_t *kv_elts;
  334. kv_elts = scm_u32vector_elements (kv, &kv_handle, &kv_len, &kv_inc);
  335. for (i = 0; i < kv_len; i++, kv_elts += kv_inc)
  336. {
  337. SCM elt = scm_array_handle_ref (&v_handle, (*kv_elts)*v_inc);
  338. if ((bit && scm_is_true (elt)) || (!bit && scm_is_false (elt)))
  339. count++;
  340. }
  341. scm_array_handle_release (&kv_handle);
  342. }
  343. else
  344. scm_wrong_type_arg_msg (NULL, 0, kv, "bitvector or u32vector");
  345. scm_array_handle_release (&v_handle);
  346. }
  347. return scm_from_size_t (count);
  348. }
  349. #undef FUNC_NAME
  350. SCM_DEFINE (scm_bit_position, "bit-position", 3, 0, 0,
  351. (SCM item, SCM v, SCM k),
  352. "Return the index of the first occurrence of @var{item} in bit\n"
  353. "vector @var{v}, starting from @var{k}. If there is no\n"
  354. "@var{item} entry between @var{k} and the end of\n"
  355. "@var{v}, then return @code{#f}. For example,\n"
  356. "\n"
  357. "@example\n"
  358. "(bit-position #t #*000101 0) @result{} 3\n"
  359. "(bit-position #f #*0001111 3) @result{} #f\n"
  360. "@end example")
  361. #define FUNC_NAME s_scm_bit_position
  362. {
  363. scm_c_issue_deprecation_warning
  364. ("bit-position is deprecated. Use bitvector-position, or "
  365. "array-ref in a loop if you need generic arrays instead.");
  366. if (scm_is_bitvector (v))
  367. return scm_bitvector_position (v, item, k);
  368. scm_t_array_handle handle;
  369. size_t off, len;
  370. ssize_t inc;
  371. scm_bitvector_elements (v, &handle, &off, &len, &inc);
  372. int bit = scm_to_bool (item);
  373. size_t first_bit = scm_to_unsigned_integer (k, 0, len);
  374. SCM res = SCM_BOOL_F;
  375. for (size_t i = first_bit; i < len; i++)
  376. {
  377. SCM elt = scm_array_handle_ref (&handle, i*inc);
  378. if ((bit && scm_is_true (elt)) || (!bit && scm_is_false (elt)))
  379. {
  380. res = scm_from_size_t (i);
  381. break;
  382. }
  383. }
  384. scm_array_handle_release (&handle);
  385. return res;
  386. }
  387. #undef FUNC_NAME
  388. SCM_DEFINE (scm_bit_set_star_x, "bit-set*!", 3, 0, 0,
  389. (SCM v, SCM kv, SCM obj),
  390. "Set entries of bit vector @var{v} to @var{obj}, with @var{kv}\n"
  391. "selecting the entries to change. The return value is\n"
  392. "unspecified.\n"
  393. "\n"
  394. "If @var{kv} is a bit vector, then those entries where it has\n"
  395. "@code{#t} are the ones in @var{v} which are set to @var{obj}.\n"
  396. "@var{v} must be at least as long as @var{kv}. When @var{obj}\n"
  397. "is @code{#t} it's like @var{kv} is OR'ed into @var{v}. Or when\n"
  398. "@var{obj} is @code{#f} it can be seen as an ANDNOT.\n"
  399. "\n"
  400. "@example\n"
  401. "(define bv #*01000010)\n"
  402. "(bit-set*! bv #*10010001 #t)\n"
  403. "bv\n"
  404. "@result{} #*11010011\n"
  405. "@end example\n"
  406. "\n"
  407. "If @var{kv} is a u32vector, then its elements are\n"
  408. "indices into @var{v} which are set to @var{obj}.\n"
  409. "\n"
  410. "@example\n"
  411. "(define bv #*01000010)\n"
  412. "(bit-set*! bv #u32(5 2 7) #t)\n"
  413. "bv\n"
  414. "@result{} #*01100111\n"
  415. "@end example")
  416. #define FUNC_NAME s_scm_bit_set_star_x
  417. {
  418. scm_c_issue_deprecation_warning
  419. ("bit-set*! is deprecated. Use bitvector-set-bits! or "
  420. "bitvector-clear-bits! on bitvectors, or array-set! in a loop "
  421. "if you need to work on generic arrays.");
  422. int bit = scm_to_bool (obj);
  423. if (scm_is_bitvector (v) && scm_is_bitvector (kv))
  424. {
  425. if (bit)
  426. scm_c_bitvector_set_bits_x (v, kv);
  427. else
  428. scm_c_bitvector_clear_bits_x (v, kv);
  429. return SCM_UNSPECIFIED;
  430. }
  431. scm_t_array_handle v_handle;
  432. size_t v_off, v_len;
  433. ssize_t v_inc;
  434. scm_bitvector_writable_elements (v, &v_handle, &v_off, &v_len, &v_inc);
  435. if (scm_is_bitvector (kv))
  436. {
  437. size_t kv_len = scm_c_bitvector_length (kv);
  438. if (v_len < kv_len)
  439. scm_misc_error (NULL,
  440. "selection bitvector longer than target bitvector",
  441. SCM_EOL);
  442. for (size_t i = 0; i < kv_len; i++)
  443. if (scm_is_true (scm_c_bitvector_ref (kv, i)))
  444. scm_array_handle_set (&v_handle, i*v_inc, obj);
  445. }
  446. else if (scm_is_true (scm_u32vector_p (kv)))
  447. {
  448. scm_t_array_handle kv_handle;
  449. size_t kv_len;
  450. ssize_t kv_inc;
  451. const uint32_t *kv_elts;
  452. kv_elts = scm_u32vector_elements (kv, &kv_handle, &kv_len, &kv_inc);
  453. for (size_t i = 0; i < kv_len; i++, kv_elts += kv_inc)
  454. scm_array_handle_set (&v_handle, (*kv_elts)*v_inc, obj);
  455. scm_array_handle_release (&kv_handle);
  456. }
  457. else
  458. scm_wrong_type_arg_msg (NULL, 0, kv, "bitvector or u32vector");
  459. scm_array_handle_release (&v_handle);
  460. return SCM_UNSPECIFIED;
  461. }
  462. #undef FUNC_NAME
  463. SCM
  464. scm_istr2bve (SCM str)
  465. {
  466. scm_t_array_handle handle;
  467. size_t len = scm_i_string_length (str);
  468. SCM vec = scm_c_make_bitvector (len, SCM_UNDEFINED);
  469. SCM res = vec;
  470. uint32_t mask;
  471. size_t k, j;
  472. const char *c_str;
  473. uint32_t *data;
  474. scm_c_issue_deprecation_warning
  475. ("scm_istr2bve is deprecated. "
  476. "Read from a string instead, prefixed with `#*'.");
  477. data = scm_bitvector_writable_elements (vec, &handle, NULL, NULL, NULL);
  478. c_str = scm_i_string_chars (str);
  479. for (k = 0; k < (len + 31) / 32; k++)
  480. {
  481. data[k] = 0L;
  482. j = len - k * 32;
  483. if (j > 32)
  484. j = 32;
  485. for (mask = 1L; j--; mask <<= 1)
  486. switch (*c_str++)
  487. {
  488. case '0':
  489. break;
  490. case '1':
  491. data[k] |= mask;
  492. break;
  493. default:
  494. res = SCM_BOOL_F;
  495. goto exit;
  496. }
  497. }
  498. exit:
  499. scm_array_handle_release (&handle);
  500. scm_remember_upto_here_1 (str);
  501. return res;
  502. }
  503. SCM
  504. scm_from_contiguous_typed_array (SCM type, SCM bounds, const void *bytes,
  505. size_t byte_len)
  506. #define FUNC_NAME "scm_from_contiguous_typed_array"
  507. {
  508. size_t k, rlen = 1;
  509. scm_t_array_dim *s;
  510. SCM ra;
  511. scm_t_array_handle h;
  512. void *elts;
  513. size_t sz;
  514. scm_c_issue_deprecation_warning
  515. ("scm_from_contiguous_typed_array is deprecated. "
  516. "Instead, use scm_make_typed_array() and the array handle functions "
  517. "to copy data to the new array.");
  518. ra = scm_i_shap2ra (bounds);
  519. s = SCM_I_ARRAY_DIMS (ra);
  520. k = SCM_I_ARRAY_NDIM (ra);
  521. while (k--)
  522. {
  523. s[k].inc = rlen;
  524. SCM_ASSERT_RANGE (1, bounds, s[k].lbnd <= s[k].ubnd + 1);
  525. rlen = (s[k].ubnd - s[k].lbnd + 1) * s[k].inc;
  526. }
  527. SCM_I_ARRAY_SET_V (ra, scm_make_generalized_vector (type, scm_from_size_t (rlen), SCM_UNDEFINED));
  528. scm_array_get_handle (ra, &h);
  529. elts = h.writable_elements;
  530. sz = scm_array_handle_uniform_element_bit_size (&h);
  531. scm_array_handle_release (&h);
  532. if (sz >= 8 && ((sz % 8) == 0))
  533. {
  534. if (byte_len % (sz / 8))
  535. SCM_MISC_ERROR ("byte length not a multiple of the unit size", SCM_EOL);
  536. if (byte_len / (sz / 8) != rlen)
  537. SCM_MISC_ERROR ("byte length and dimensions do not match", SCM_EOL);
  538. }
  539. else if (sz < 8)
  540. {
  541. /* Elements of sub-byte size (bitvectors) are addressed in 32-bit
  542. units. */
  543. if (byte_len != ((rlen * sz + 31) / 32) * 4)
  544. SCM_MISC_ERROR ("byte length and dimensions do not match", SCM_EOL);
  545. }
  546. else
  547. /* an internal guile error, really */
  548. SCM_MISC_ERROR ("uniform elements larger than 8 bits must fill whole bytes", SCM_EOL);
  549. memcpy (elts, bytes, byte_len);
  550. if (1 == SCM_I_ARRAY_NDIM (ra) && 0 == SCM_I_ARRAY_BASE (ra))
  551. if (0 == s->lbnd)
  552. return SCM_I_ARRAY_V (ra);
  553. return ra;
  554. }
  555. #undef FUNC_NAME
  556. SCM_GLOBAL_SYMBOL (scm_sym_copy, "copy");
  557. SCM
  558. scm_make_srcprops (long line, int col, SCM filename, SCM copy, SCM alist)
  559. {
  560. scm_c_issue_deprecation_warning
  561. ("scm_make_srcprops is deprecated; use set-source-properties! instead");
  562. alist = SCM_UNBNDP (copy) ? alist : scm_acons (scm_sym_copy, copy, alist);
  563. return scm_i_make_srcprops (scm_from_long (line), scm_from_int (col),
  564. filename, alist);
  565. }
  566. SCM
  567. scm_copy_tree (SCM obj)
  568. {
  569. scm_c_issue_deprecation_warning
  570. ("scm_copy_tree is deprecated; use copy-tree from (ice-9 copy-tree) "
  571. "instead.");
  572. return scm_call_1 (scm_c_public_ref ("ice-9 copy-tree", "copy-tree"), obj);
  573. }
  574. /* Symbol properties. */
  575. SCM_SYMBOL (symbol_function_slot, "symbol-function-slot");
  576. SCM_SYMBOL (symbol_property_slot, "symbol-property-slot");
  577. SCM_DEFINE (scm_symbol_fref, "symbol-fref", 1, 0, 0,
  578. (SCM s),
  579. "Return the contents of the symbol @var{s}'s @dfn{function slot}.")
  580. #define FUNC_NAME s_scm_symbol_fref
  581. {
  582. SCM_VALIDATE_SYMBOL (1, s);
  583. return scm_object_property (s, symbol_function_slot);
  584. }
  585. #undef FUNC_NAME
  586. SCM_DEFINE (scm_symbol_pref, "symbol-pref", 1, 0, 0,
  587. (SCM s),
  588. "Return the @dfn{property list} currently associated with the\n"
  589. "symbol @var{s}.")
  590. #define FUNC_NAME s_scm_symbol_pref
  591. {
  592. SCM result;
  593. SCM_VALIDATE_SYMBOL (1, s);
  594. result = scm_object_property (s, symbol_property_slot);
  595. return scm_is_false (result) ? SCM_EOL : result;
  596. }
  597. #undef FUNC_NAME
  598. SCM_DEFINE (scm_symbol_fset_x, "symbol-fset!", 2, 0, 0,
  599. (SCM s, SCM val),
  600. "Change the binding of the symbol @var{s}'s function slot.")
  601. #define FUNC_NAME s_scm_symbol_fset_x
  602. {
  603. SCM_VALIDATE_SYMBOL (1, s);
  604. return scm_set_object_property_x (s, symbol_function_slot, val);
  605. }
  606. #undef FUNC_NAME
  607. SCM_DEFINE (scm_symbol_pset_x, "symbol-pset!", 2, 0, 0,
  608. (SCM s, SCM val),
  609. "Change the binding of the symbol @var{s}'s property slot.")
  610. #define FUNC_NAME s_scm_symbol_pset_x
  611. {
  612. SCM_VALIDATE_SYMBOL (1, s);
  613. return scm_set_object_property_x (s, symbol_property_slot, val);
  614. }
  615. #undef FUNC_NAME
  616. SCM_DEFINE (scm_dynamic_unlink, "dynamic-unlink", 1, 0, 0, (SCM obj), "")
  617. #define FUNC_NAME s_scm_dynamic_unlink
  618. {
  619. scm_c_issue_deprecation_warning
  620. ("scm_dynamic_unlink has no effect and is deprecated. Unloading "
  621. "shared libraries is no longer supported.");
  622. return SCM_UNSPECIFIED;
  623. }
  624. #undef FUNC_NAME
  625. static void
  626. finalize_bignum (void *ptr, void *data)
  627. {
  628. SCM bignum;
  629. bignum = SCM_PACK_POINTER (ptr);
  630. mpz_clear (SCM_I_BIG_MPZ (bignum));
  631. }
  632. static SCM
  633. make_bignum (void)
  634. {
  635. scm_t_bits *p;
  636. /* Allocate one word for the type tag and enough room for an `mpz_t'. */
  637. p = scm_gc_malloc_pointerless (sizeof (scm_t_bits) + sizeof (mpz_t),
  638. "bignum");
  639. p[0] = scm_tc16_big;
  640. scm_i_set_finalizer (p, finalize_bignum, NULL);
  641. return SCM_PACK (p);
  642. }
  643. /* scm_i_big2dbl() rounds to the closest representable double,
  644. in accordance with R5RS exact->inexact. */
  645. double
  646. scm_i_big2dbl (SCM b)
  647. {
  648. scm_c_issue_deprecation_warning
  649. ("scm_i_big2dbl is deprecated. Use scm_to_double instead.");
  650. return scm_to_double (b);
  651. }
  652. SCM
  653. scm_i_long2big (long x)
  654. {
  655. scm_c_issue_deprecation_warning
  656. ("scm_i_long2big is deprecated. Use scm_from_long instead.");
  657. /* Return a newly created bignum initialized to X. */
  658. SCM z = make_bignum ();
  659. mpz_init_set_si (SCM_I_BIG_MPZ (z), x);
  660. return z;
  661. }
  662. SCM
  663. scm_i_ulong2big (unsigned long x)
  664. {
  665. scm_c_issue_deprecation_warning
  666. ("scm_i_ulong2big is deprecated. Use scm_from_ulong instead.");
  667. /* Return a newly created bignum initialized to X. */
  668. SCM z = make_bignum ();
  669. mpz_init_set_ui (SCM_I_BIG_MPZ (z), x);
  670. return z;
  671. }
  672. SCM
  673. scm_i_clonebig (SCM src_big, int same_sign_p)
  674. {
  675. scm_c_issue_deprecation_warning
  676. ("scm_i_clonebig is deprecated. Use scm_to_mpz/scm_from_mpz instead.");
  677. /* Copy src_big's value, negate it if same_sign_p is false, and return. */
  678. SCM z = make_bignum ();
  679. scm_to_mpz (src_big, SCM_I_BIG_MPZ (z));
  680. if (!same_sign_p)
  681. mpz_neg (SCM_I_BIG_MPZ (z), SCM_I_BIG_MPZ (z));
  682. return z;
  683. }
  684. SCM
  685. scm_i_normbig (SCM b)
  686. {
  687. scm_c_issue_deprecation_warning
  688. ("scm_i_normbig is deprecated. Direct bignum bit manipulation is not "
  689. "supported.");
  690. /* convert a big back to a fixnum if it'll fit */
  691. /* presume b is a bignum */
  692. if (mpz_fits_slong_p (SCM_I_BIG_MPZ (b)))
  693. {
  694. scm_t_inum val = mpz_get_si (SCM_I_BIG_MPZ (b));
  695. if (SCM_FIXABLE (val))
  696. b = SCM_I_MAKINUM (val);
  697. }
  698. return b;
  699. }
  700. int scm_install_gmp_memory_functions;
  701. void
  702. scm_i_init_deprecated ()
  703. {
  704. #include "deprecated.x"
  705. }
  706. #endif /* SCM_ENABLE_DEPRECATD == 1 */