provide missing prototypes
[bpt/guile.git] / libguile / deprecated.c
CommitLineData
19e2247d
MV
1/* This file contains definitions for deprecated features. When you
2 deprecate something, move it here when that is feasible.
3*/
4
54cd7150 5/* Copyright (C) 2003, 2004, 2006, 2008, 2009, 2010 Free Software Foundation, Inc.
19e2247d 6 *
73be1d9e 7 * This library is free software; you can redistribute it and/or
53befeb7
NJ
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.
19e2247d 11 *
53befeb7
NJ
12 * This library is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
73be1d9e
MV
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
19e2247d 16 *
73be1d9e
MV
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
53befeb7
NJ
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301 USA
73be1d9e 21 */
19e2247d 22
dbb605f5
LC
23#ifdef HAVE_CONFIG_H
24# include <config.h>
25#endif
26
0eb934f1
LC
27#define SCM_BUILDING_DEPRECATED_CODE
28
19e2247d 29#include "libguile/_scm.h"
4e047c3e 30#include "libguile/async.h"
a2689737
AW
31#include "libguile/arrays.h"
32#include "libguile/array-map.h"
33#include "libguile/generalized-arrays.h"
34#include "libguile/bytevectors.h"
35#include "libguile/bitvectors.h"
19e2247d 36#include "libguile/deprecated.h"
db74ed03 37#include "libguile/discouraged.h"
55d30fac 38#include "libguile/deprecation.h"
19e2247d
MV
39#include "libguile/snarf.h"
40#include "libguile/validate.h"
41#include "libguile/strings.h"
c44ca4fe 42#include "libguile/srfi-13.h"
a0454d72
MV
43#include "libguile/modules.h"
44#include "libguile/eval.h"
45#include "libguile/smob.h"
46#include "libguile/procprop.h"
47#include "libguile/vectors.h"
48#include "libguile/hashtab.h"
49#include "libguile/struct.h"
50#include "libguile/variable.h"
51#include "libguile/fluids.h"
52#include "libguile/ports.h"
965445d4
MV
53#include "libguile/eq.h"
54#include "libguile/read.h"
a2689737 55#include "libguile/r6rs-ports.h"
4abecea8
MV
56#include "libguile/strports.h"
57#include "libguile/smob.h"
cc5c1b66 58#include "libguile/alist.h"
db74ed03 59#include "libguile/keywords.h"
3452e666 60#include "libguile/socket.h"
9de87eea 61#include "libguile/feature.h"
a2689737 62#include "libguile/uniform.h"
19e2247d 63
ad79736c 64#include <math.h>
55d30fac
MV
65#include <stdio.h>
66#include <string.h>
67
3452e666
LC
68#include <arpa/inet.h>
69
19e2247d
MV
70#if (SCM_ENABLE_DEPRECATED == 1)
71
7e6e6b37
DH
72/* From print.c: Internal symbol names of isyms. Deprecated in guile 1.7.0 on
73 * 2004-04-22. */
74char *scm_isymnames[] =
75{
76 "#@<deprecated>"
77};
78
79
19e2247d
MV
80SCM_REGISTER_PROC(s_substring_move_left_x, "substring-move-left!", 5, 0, 0, scm_substring_move_x);
81
82SCM_REGISTER_PROC(s_substring_move_right_x, "substring-move-right!", 5, 0, 0, scm_substring_move_x);
83
55d30fac
MV
84SCM
85scm_wta (SCM arg, const char *pos, const char *s_subr)
86{
87 if (!s_subr || !*s_subr)
88 s_subr = NULL;
89 if ((~0x1fL) & (long) pos)
90 {
91 /* error string supplied. */
92 scm_misc_error (s_subr, pos, scm_list_1 (arg));
93 }
94 else
95 {
96 /* numerical error code. */
97 scm_t_bits error = (scm_t_bits) pos;
98
99 switch (error)
100 {
101 case SCM_ARGn:
102 scm_wrong_type_arg (s_subr, 0, arg);
103 case SCM_ARG1:
104 scm_wrong_type_arg (s_subr, 1, arg);
105 case SCM_ARG2:
106 scm_wrong_type_arg (s_subr, 2, arg);
107 case SCM_ARG3:
108 scm_wrong_type_arg (s_subr, 3, arg);
109 case SCM_ARG4:
110 scm_wrong_type_arg (s_subr, 4, arg);
111 case SCM_ARG5:
112 scm_wrong_type_arg (s_subr, 5, arg);
113 case SCM_ARG6:
114 scm_wrong_type_arg (s_subr, 6, arg);
115 case SCM_ARG7:
116 scm_wrong_type_arg (s_subr, 7, arg);
117 case SCM_WNA:
118 scm_wrong_num_args (arg);
119 case SCM_OUTOFRANGE:
120 scm_out_of_range (s_subr, arg);
121 case SCM_NALLOC:
122 scm_memory_error (s_subr);
123 default:
124 /* this shouldn't happen. */
125 scm_misc_error (s_subr, "Unknown error", SCM_EOL);
126 }
127 }
128 return SCM_UNSPECIFIED;
129}
130
131/* Module registry
132 */
133
134/* We can't use SCM objects here. One should be able to call
135 SCM_REGISTER_MODULE from a C++ constructor for a static
136 object. This happens before main and thus before libguile is
137 initialized. */
138
139struct moddata {
140 struct moddata *link;
141 char *module_name;
142 void *init_func;
143};
144
145static struct moddata *registered_mods = NULL;
146
147void
148scm_register_module_xxx (char *module_name, void *init_func)
149{
150 struct moddata *md;
151
152 scm_c_issue_deprecation_warning
153 ("`scm_register_module_xxx' is deprecated. Use extensions instead.");
154
155 /* XXX - should we (and can we) DEFER_INTS here? */
156
157 for (md = registered_mods; md; md = md->link)
158 if (!strcmp (md->module_name, module_name))
159 {
160 md->init_func = init_func;
161 return;
162 }
163
164 md = (struct moddata *) malloc (sizeof (struct moddata));
165 if (md == NULL)
166 {
167 fprintf (stderr,
168 "guile: can't register module (%s): not enough memory",
169 module_name);
170 return;
171 }
172
173 md->module_name = module_name;
174 md->init_func = init_func;
175 md->link = registered_mods;
176 registered_mods = md;
177}
178
179SCM_DEFINE (scm_registered_modules, "c-registered-modules", 0, 0, 0,
180 (),
181 "Return a list of the object code modules that have been imported into\n"
182 "the current Guile process. Each element of the list is a pair whose\n"
183 "car is the name of the module, and whose cdr is the function handle\n"
184 "for that module's initializer function. The name is the string that\n"
185 "has been passed to scm_register_module_xxx.")
186#define FUNC_NAME s_scm_registered_modules
187{
188 SCM res;
189 struct moddata *md;
190
191 res = SCM_EOL;
192 for (md = registered_mods; md; md = md->link)
3ee86942 193 res = scm_cons (scm_cons (scm_from_locale_string (md->module_name),
c71b0706 194 scm_from_ulong ((unsigned long) md->init_func)),
55d30fac
MV
195 res);
196 return res;
197}
198#undef FUNC_NAME
199
200SCM_DEFINE (scm_clear_registered_modules, "c-clear-registered-modules", 0, 0, 0,
201 (),
202 "Destroy the list of modules registered with the current Guile process.\n"
203 "The return value is unspecified. @strong{Warning:} this function does\n"
204 "not actually unlink or deallocate these modules, but only destroys the\n"
205 "records of which modules have been loaded. It should therefore be used\n"
206 "only by module bookkeeping operations.")
207#define FUNC_NAME s_scm_clear_registered_modules
208{
209 struct moddata *md1, *md2;
210
9de87eea 211 SCM_CRITICAL_SECTION_START;
55d30fac
MV
212
213 for (md1 = registered_mods; md1; md1 = md2)
214 {
215 md2 = md1->link;
216 free (md1);
217 }
218 registered_mods = NULL;
219
9de87eea 220 SCM_CRITICAL_SECTION_END;
55d30fac
MV
221 return SCM_UNSPECIFIED;
222}
223#undef FUNC_NAME
224
a0454d72
MV
225void
226scm_remember (SCM *ptr)
227{
228 scm_c_issue_deprecation_warning ("`scm_remember' is deprecated. "
229 "Use the `scm_remember_upto_here*' family of functions instead.");
230}
231
232SCM
233scm_protect_object (SCM obj)
234{
235 scm_c_issue_deprecation_warning ("`scm_protect_object' is deprecated. "
236 "Use `scm_gc_protect_object' instead.");
237 return scm_gc_protect_object (obj);
238}
239
240SCM
241scm_unprotect_object (SCM obj)
242{
243 scm_c_issue_deprecation_warning ("`scm_unprotect_object' is deprecated. "
244 "Use `scm_gc_unprotect_object' instead.");
245 return scm_gc_unprotect_object (obj);
246}
247
248SCM_SYMBOL (scm_sym_app, "app");
249SCM_SYMBOL (scm_sym_modules, "modules");
250static SCM module_prefix = SCM_BOOL_F;
251static SCM make_modules_in_var;
252static SCM beautify_user_module_x_var;
253static SCM try_module_autoload_var;
254
255static void
256init_module_stuff ()
257{
a0454d72
MV
258 if (module_prefix == SCM_BOOL_F)
259 {
f39448c5
AW
260 module_prefix = scm_list_2 (scm_sym_app, scm_sym_modules);
261 make_modules_in_var = scm_c_lookup ("make-modules-in");
a0454d72 262 beautify_user_module_x_var =
f39448c5
AW
263 scm_c_lookup ("beautify-user-module!");
264 try_module_autoload_var = scm_c_lookup ("try-module-autoload");
a0454d72
MV
265 }
266}
267
a0454d72
MV
268static SCM
269scm_module_full_name (SCM name)
270{
271 init_module_stuff ();
bc36d050 272 if (scm_is_eq (SCM_CAR (name), scm_sym_app))
a0454d72
MV
273 return name;
274 else
275 return scm_append (scm_list_2 (module_prefix, name));
276}
277
278SCM
279scm_make_module (SCM name)
280{
281 init_module_stuff ();
282 scm_c_issue_deprecation_warning ("`scm_make_module' is deprecated. "
283 "Use `scm_c_define_module instead.");
284
285 return scm_call_2 (SCM_VARIABLE_REF (make_modules_in_var),
286 scm_the_root_module (),
287 scm_module_full_name (name));
288}
289
290SCM
291scm_ensure_user_module (SCM module)
292{
293 init_module_stuff ();
294 scm_c_issue_deprecation_warning ("`scm_ensure_user_module' is deprecated. "
295 "Use `scm_c_define_module instead.");
296
297 scm_call_1 (SCM_VARIABLE_REF (beautify_user_module_x_var), module);
298 return SCM_UNSPECIFIED;
299}
300
301SCM
302scm_load_scheme_module (SCM name)
303{
304 init_module_stuff ();
305 scm_c_issue_deprecation_warning ("`scm_load_scheme_module' is deprecated. "
306 "Use `scm_c_resolve_module instead.");
307
308 return scm_call_1 (SCM_VARIABLE_REF (try_module_autoload_var), name);
309}
310
311/* This is implemented in C solely for SCM_COERCE_OUTPORT ... */
312
313static void
314maybe_close_port (void *data, SCM port)
315{
6eadcdab 316 SCM except_set = (SCM) data;
a0454d72 317
6eadcdab 318 while (!scm_is_null (except_set))
a0454d72 319 {
6eadcdab 320 SCM p = SCM_COERCE_OUTPORT (SCM_CAR (except_set));
bc36d050 321 if (scm_is_eq (p, port))
a0454d72 322 return;
6eadcdab 323 except_set = SCM_CDR (except_set);
a0454d72
MV
324 }
325
326 scm_close_port (port);
327}
328
329SCM_DEFINE (scm_close_all_ports_except, "close-all-ports-except", 0, 0, 1,
330 (SCM ports),
331 "[DEPRECATED] Close all open file ports used by the interpreter\n"
332 "except for those supplied as arguments. This procedure\n"
333 "was intended to be used before an exec call to close file descriptors\n"
334 "which are not needed in the new process. However it has the\n"
335 "undesirable side effect of flushing buffers, so it's deprecated.\n"
336 "Use port-for-each instead.")
337#define FUNC_NAME s_scm_close_all_ports_except
338{
339 SCM p;
340 SCM_VALIDATE_REST_ARGUMENT (ports);
341
d2e53ed6 342 for (p = ports; !scm_is_null (p); p = SCM_CDR (p))
a0454d72
MV
343 SCM_VALIDATE_OPPORT (SCM_ARG1, SCM_COERCE_OUTPORT (SCM_CAR (p)));
344
345 scm_c_port_for_each (maybe_close_port, ports);
346
347 return SCM_UNSPECIFIED;
348}
349#undef FUNC_NAME
55d30fac 350
965445d4
MV
351SCM_DEFINE (scm_variable_set_name_hint, "variable-set-name-hint!", 2, 0, 0,
352 (SCM var, SCM hint),
353 "Do not use this function.")
354#define FUNC_NAME s_scm_variable_set_name_hint
355{
356 SCM_VALIDATE_VARIABLE (1, var);
357 SCM_VALIDATE_SYMBOL (2, hint);
358 scm_c_issue_deprecation_warning
359 ("'variable-set-name-hint!' is deprecated. Do not use it.");
360 return SCM_UNSPECIFIED;
361}
362#undef FUNC_NAME
363
364SCM_DEFINE (scm_builtin_variable, "builtin-variable", 1, 0, 0,
365 (SCM name),
366 "Do not use this function.")
367#define FUNC_NAME s_scm_builtin_variable
368{
369 SCM_VALIDATE_SYMBOL (1,name);
370 scm_c_issue_deprecation_warning ("`builtin-variable' is deprecated. "
371 "Use module system operations instead.");
372 return scm_sym2var (name, SCM_BOOL_F, SCM_BOOL_T);
373}
374#undef FUNC_NAME
375
376SCM
377scm_makstr (size_t len, int dummy)
378{
379 scm_c_issue_deprecation_warning
3ee86942
MV
380 ("'scm_makstr' is deprecated. Use 'scm_c_make_string' instead.");
381 return scm_c_make_string (len, SCM_UNDEFINED);
965445d4
MV
382}
383
384SCM
385scm_makfromstr (const char *src, size_t len, int dummy SCM_UNUSED)
386{
387 scm_c_issue_deprecation_warning ("`scm_makfromstr' is deprecated. "
3ee86942 388 "Use `scm_from_locale_stringn' instead.");
965445d4 389
3ee86942 390 return scm_from_locale_stringn (src, len);
965445d4
MV
391}
392
393SCM
394scm_internal_with_fluids (SCM fluids, SCM values, SCM (*cproc) (), void *cdata)
395{
396 scm_c_issue_deprecation_warning ("`scm_internal_with_fluids' is deprecated. "
397 "Use `scm_c_with_fluids' instead.");
398
399 return scm_c_with_fluids (fluids, values, cproc, cdata);
400}
401
402SCM
403scm_make_gsubr (const char *name, int req, int opt, int rst, SCM (*fcn)())
404{
405 scm_c_issue_deprecation_warning
406 ("`scm_make_gsubr' is deprecated. Use `scm_c_define_gsubr' instead.");
407
408 return scm_c_define_gsubr (name, req, opt, rst, fcn);
409}
410
411SCM
412scm_make_gsubr_with_generic (const char *name,
413 int req, int opt, int rst,
414 SCM (*fcn)(), SCM *gf)
415{
416 scm_c_issue_deprecation_warning
417 ("`scm_make_gsubr_with_generic' is deprecated. "
418 "Use `scm_c_define_gsubr_with_generic' instead.");
419
420 return scm_c_define_gsubr_with_generic (name, req, opt, rst, fcn, gf);
421}
422
423SCM
424scm_create_hook (const char *name, int n_args)
425{
426 scm_c_issue_deprecation_warning
427 ("'scm_create_hook' is deprecated. "
428 "Use 'scm_make_hook' and 'scm_c_define' instead.");
429 {
7888309b 430 SCM hook = scm_make_hook (scm_from_int (n_args));
965445d4 431 scm_c_define (name, hook);
838aa000 432 return hook;
965445d4
MV
433 }
434}
435
436SCM_DEFINE (scm_sloppy_memq, "sloppy-memq", 2, 0, 0,
437 (SCM x, SCM lst),
438 "This procedure behaves like @code{memq}, but does no type or error checking.\n"
439 "Its use is recommended only in writing Guile internals,\n"
440 "not for high-level Scheme programs.")
441#define FUNC_NAME s_scm_sloppy_memq
442{
443 scm_c_issue_deprecation_warning
444 ("'sloppy-memq' is deprecated. Use 'memq' instead.");
445
d2e53ed6 446 for(; scm_is_pair (lst); lst = SCM_CDR(lst))
965445d4 447 {
bc36d050 448 if (scm_is_eq (SCM_CAR (lst), x))
965445d4
MV
449 return lst;
450 }
451 return lst;
452}
453#undef FUNC_NAME
454
455
456SCM_DEFINE (scm_sloppy_memv, "sloppy-memv", 2, 0, 0,
457 (SCM x, SCM lst),
458 "This procedure behaves like @code{memv}, but does no type or error checking.\n"
459 "Its use is recommended only in writing Guile internals,\n"
460 "not for high-level Scheme programs.")
461#define FUNC_NAME s_scm_sloppy_memv
462{
463 scm_c_issue_deprecation_warning
464 ("'sloppy-memv' is deprecated. Use 'memv' instead.");
465
d2e53ed6 466 for(; scm_is_pair (lst); lst = SCM_CDR(lst))
965445d4 467 {
7888309b 468 if (! scm_is_false (scm_eqv_p (SCM_CAR (lst), x)))
965445d4
MV
469 return lst;
470 }
471 return lst;
472}
473#undef FUNC_NAME
474
475
476SCM_DEFINE (scm_sloppy_member, "sloppy-member", 2, 0, 0,
477 (SCM x, SCM lst),
478 "This procedure behaves like @code{member}, but does no type or error checking.\n"
479 "Its use is recommended only in writing Guile internals,\n"
480 "not for high-level Scheme programs.")
481#define FUNC_NAME s_scm_sloppy_member
482{
483 scm_c_issue_deprecation_warning
484 ("'sloppy-member' is deprecated. Use 'member' instead.");
485
d2e53ed6 486 for(; scm_is_pair (lst); lst = SCM_CDR(lst))
965445d4 487 {
7888309b 488 if (! scm_is_false (scm_equal_p (SCM_CAR (lst), x)))
965445d4
MV
489 return lst;
490 }
491 return lst;
492}
493#undef FUNC_NAME
494
495SCM_SYMBOL (scm_end_of_file_key, "end-of-file");
496
497SCM_DEFINE (scm_read_and_eval_x, "read-and-eval!", 0, 1, 0,
498 (SCM port),
499 "Read a form from @var{port} (standard input by default), and evaluate it\n"
500 "(memoizing it in the process) in the top-level environment. If no data\n"
501 "is left to be read from @var{port}, an @code{end-of-file} error is\n"
502 "signalled.")
503#define FUNC_NAME s_scm_read_and_eval_x
504{
f8ba2197
DH
505 SCM form;
506
965445d4
MV
507 scm_c_issue_deprecation_warning
508 ("'read-and-eval!' is deprecated. Use 'read' and 'eval' instead.");
509
f8ba2197 510 form = scm_read (port);
965445d4
MV
511 if (SCM_EOF_OBJECT_P (form))
512 scm_ithrow (scm_end_of_file_key, SCM_EOL, 1);
513 return scm_eval_x (form, scm_current_module ());
514}
515#undef FUNC_NAME
516
4abecea8
MV
517/* Call thunk(closure) underneath a top-level error handler.
518 * If an error occurs, pass the exitval through err_filter and return it.
519 * If no error occurs, return the value of thunk.
520 */
521
522#ifdef _UNICOS
523typedef int setjmp_type;
524#else
525typedef long setjmp_type;
526#endif
527
528struct cce_handler_data {
529 SCM (*err_filter) ();
530 void *closure;
531};
532
533static SCM
534invoke_err_filter (void *d, SCM tag, SCM args)
535{
536 struct cce_handler_data *data = (struct cce_handler_data *)d;
537 return data->err_filter (SCM_BOOL_F, data->closure);
538}
539
540SCM
541scm_call_catching_errors (SCM (*thunk)(), SCM (*err_filter)(), void *closure)
542{
543 scm_c_issue_deprecation_warning
544 ("'scm_call_catching_errors' is deprecated. "
545 "Use 'scm_internal_catch' instead.");
546
547 {
548 struct cce_handler_data data;
549 data.err_filter = err_filter;
550 data.closure = closure;
551 return scm_internal_catch (SCM_BOOL_T,
552 (scm_t_catch_body)thunk, closure,
553 (scm_t_catch_handler)invoke_err_filter, &data);
554 }
555}
556
557long
558scm_make_smob_type_mfpe (char *name, size_t size,
559 SCM (*mark) (SCM),
560 size_t (*free) (SCM),
561 int (*print) (SCM, SCM, scm_print_state *),
562 SCM (*equalp) (SCM, SCM))
563{
564 scm_c_issue_deprecation_warning
565 ("'scm_make_smob_type_mfpe' is deprecated. "
566 "Use 'scm_make_smob_type' plus 'scm_set_smob_*' instead.");
567
568 {
569 long answer = scm_make_smob_type (name, size);
570 scm_set_smob_mfpe (answer, mark, free, print, equalp);
571 return answer;
572 }
573}
574
575void
576scm_set_smob_mfpe (long tc,
577 SCM (*mark) (SCM),
578 size_t (*free) (SCM),
579 int (*print) (SCM, SCM, scm_print_state *),
580 SCM (*equalp) (SCM, SCM))
581{
582 scm_c_issue_deprecation_warning
583 ("'scm_set_smob_mfpe' is deprecated. "
584 "Use 'scm_set_smob_mark' instead, for example.");
585
586 if (mark) scm_set_smob_mark (tc, mark);
587 if (free) scm_set_smob_free (tc, free);
588 if (print) scm_set_smob_print (tc, print);
589 if (equalp) scm_set_smob_equalp (tc, equalp);
590}
591
3051344b
LC
592size_t
593scm_smob_free (SCM obj)
594{
595 long n = SCM_SMOBNUM (obj);
596
597 scm_c_issue_deprecation_warning
598 ("`scm_smob_free' is deprecated. "
599 "It is no longer needed.");
600
601 if (scm_smobs[n].size > 0)
4dc2165b 602 scm_gc_free ((void *) SCM_SMOB_DATA_1 (obj),
3051344b
LC
603 scm_smobs[n].size, SCM_SMOBNAME (n));
604 return 0;
605}
606
4abecea8
MV
607SCM
608scm_read_0str (char *expr)
609{
610 scm_c_issue_deprecation_warning
611 ("scm_read_0str is deprecated. Use scm_c_read_string instead.");
612
613 return scm_c_read_string (expr);
614}
615
616SCM
617scm_eval_0str (const char *expr)
618{
619 scm_c_issue_deprecation_warning
620 ("scm_eval_0str is deprecated. Use scm_c_eval_string instead.");
621
622 return scm_c_eval_string (expr);
623}
624
625SCM
626scm_strprint_obj (SCM obj)
627{
628 scm_c_issue_deprecation_warning
629 ("scm_strprint_obj is deprecated. Use scm_object_to_string instead.");
630 return scm_object_to_string (obj, SCM_UNDEFINED);
631}
632
a725fa95
MV
633char *
634scm_i_object_chars (SCM obj)
635{
636 scm_c_issue_deprecation_warning
637 ("SCM_CHARS is deprecated. See the manual for alternatives.");
638 if (SCM_STRINGP (obj))
639 return SCM_STRING_CHARS (obj);
640 if (SCM_SYMBOLP (obj))
641 return SCM_SYMBOL_CHARS (obj);
642 abort ();
643}
644
645long
646scm_i_object_length (SCM obj)
647{
648 scm_c_issue_deprecation_warning
649 ("SCM_LENGTH is deprecated. "
650 "Use scm_c_string_length instead, for example, or see the manual.");
651 if (SCM_STRINGP (obj))
652 return SCM_STRING_LENGTH (obj);
653 if (SCM_SYMBOLP (obj))
654 return SCM_SYMBOL_LENGTH (obj);
655 if (SCM_VECTORP (obj))
656 return SCM_VECTOR_LENGTH (obj);
657 abort ();
658}
659
cc5c1b66
MV
660SCM
661scm_sym2ovcell_soft (SCM sym, SCM obarray)
662{
663 SCM lsym, z;
3ee86942 664 size_t hash = scm_i_symbol_hash (sym) % SCM_VECTOR_LENGTH (obarray);
cc5c1b66
MV
665
666 scm_c_issue_deprecation_warning ("`scm_sym2ovcell_soft' is deprecated. "
667 "Use hashtables instead.");
668
9de87eea 669 SCM_CRITICAL_SECTION_START;
cc5c1b66
MV
670 for (lsym = SCM_VECTOR_REF (obarray, hash);
671 SCM_NIMP (lsym);
672 lsym = SCM_CDR (lsym))
673 {
674 z = SCM_CAR (lsym);
bc36d050 675 if (scm_is_eq (SCM_CAR (z), sym))
cc5c1b66 676 {
9de87eea 677 SCM_CRITICAL_SECTION_END;
cc5c1b66
MV
678 return z;
679 }
680 }
9de87eea 681 SCM_CRITICAL_SECTION_END;
cc5c1b66
MV
682 return SCM_BOOL_F;
683}
684
685
686SCM
687scm_sym2ovcell (SCM sym, SCM obarray)
688#define FUNC_NAME "scm_sym2ovcell"
689{
690 SCM answer;
691
692 scm_c_issue_deprecation_warning ("`scm_sym2ovcell' is deprecated. "
693 "Use hashtables instead.");
694
695 answer = scm_sym2ovcell_soft (sym, obarray);
7888309b 696 if (scm_is_true (answer))
cc5c1b66
MV
697 return answer;
698 SCM_MISC_ERROR ("uninterned symbol: ~S", scm_list_1 (sym));
699 return SCM_UNSPECIFIED; /* not reached */
700}
701#undef FUNC_NAME
702
703
704/* Intern a symbol whose name is the LEN characters at NAME in OBARRAY.
705
706 OBARRAY should be a vector of lists, indexed by the name's hash
707 value, modulo OBARRAY's length. Each list has the form
708 ((SYMBOL . VALUE) ...), where SYMBOL is a symbol, and VALUE is the
709 value associated with that symbol (in the current module? in the
710 system module?)
711
712 To "intern" a symbol means: if OBARRAY already contains a symbol by
713 that name, return its (SYMBOL . VALUE) pair; otherwise, create a
714 new symbol, add the pair (SYMBOL . SCM_UNDEFINED) to the
715 appropriate list of the OBARRAY, and return the pair.
716
717 If softness is non-zero, don't create a symbol if it isn't already
718 in OBARRAY; instead, just return #f.
719
720 If OBARRAY is SCM_BOOL_F, create a symbol listed in no obarray and
721 return (SYMBOL . SCM_UNDEFINED). */
722
723
7f594642
MG
724static SCM
725intern_obarray_soft (SCM symbol, SCM obarray, unsigned int softness)
cc5c1b66 726{
3ee86942 727 size_t raw_hash = scm_i_symbol_hash (symbol);
cc5c1b66
MV
728 size_t hash;
729 SCM lsym;
730
7888309b 731 if (scm_is_false (obarray))
cc5c1b66
MV
732 {
733 if (softness)
734 return SCM_BOOL_F;
735 else
736 return scm_cons (symbol, SCM_UNDEFINED);
737 }
738
739 hash = raw_hash % SCM_VECTOR_LENGTH (obarray);
740
741 for (lsym = SCM_VECTOR_REF(obarray, hash);
742 SCM_NIMP (lsym); lsym = SCM_CDR (lsym))
743 {
744 SCM a = SCM_CAR (lsym);
745 SCM z = SCM_CAR (a);
bc36d050 746 if (scm_is_eq (z, symbol))
cc5c1b66
MV
747 return a;
748 }
749
750 if (softness)
751 {
752 return SCM_BOOL_F;
753 }
754 else
755 {
756 SCM cell = scm_cons (symbol, SCM_UNDEFINED);
757 SCM slot = SCM_VECTOR_REF (obarray, hash);
758
759 SCM_VECTOR_SET (obarray, hash, scm_cons (cell, slot));
760
761 return cell;
762 }
763}
764
765
7f594642
MG
766SCM
767scm_intern_obarray_soft (const char *name, size_t len, SCM obarray,
768 unsigned int softness)
769{
770 SCM symbol = scm_from_locale_symboln (name, len);
771
772 scm_c_issue_deprecation_warning ("`scm_intern_obarray_soft' is deprecated. "
773 "Use hashtables instead.");
774
775 return intern_obarray_soft (symbol, obarray, softness);
776}
777
cc5c1b66
MV
778SCM
779scm_intern_obarray (const char *name,size_t len,SCM obarray)
780{
781 scm_c_issue_deprecation_warning ("`scm_intern_obarray' is deprecated. "
782 "Use hashtables instead.");
783
784 return scm_intern_obarray_soft (name, len, obarray, 0);
785}
786
787/* Lookup the value of the symbol named by the nul-terminated string
788 NAME in the current module. */
789SCM
790scm_symbol_value0 (const char *name)
791{
792 scm_c_issue_deprecation_warning ("`scm_symbol_value0' is deprecated. "
793 "Use `scm_lookup' instead.");
794
795 return scm_variable_ref (scm_c_lookup (name));
796}
797
798SCM_DEFINE (scm_string_to_obarray_symbol, "string->obarray-symbol", 2, 1, 0,
799 (SCM o, SCM s, SCM softp),
800 "Intern a new symbol in @var{obarray}, a symbol table, with name\n"
801 "@var{string}.\n\n"
802 "If @var{obarray} is @code{#f}, use the default system symbol table. If\n"
803 "@var{obarray} is @code{#t}, the symbol should not be interned in any\n"
804 "symbol table; merely return the pair (@var{symbol}\n"
805 ". @var{#<undefined>}).\n\n"
806 "The @var{soft?} argument determines whether new symbol table entries\n"
807 "should be created when the specified symbol is not already present in\n"
808 "@var{obarray}. If @var{soft?} is specified and is a true value, then\n"
809 "new entries should not be added for symbols not already present in the\n"
810 "table; instead, simply return @code{#f}.")
811#define FUNC_NAME s_scm_string_to_obarray_symbol
812{
813 SCM vcell;
814 SCM answer;
815 int softness;
816
817 SCM_VALIDATE_STRING (2, s);
7888309b 818 SCM_ASSERT (scm_is_bool (o) || SCM_VECTORP (o), o, SCM_ARG1, FUNC_NAME);
cc5c1b66
MV
819
820 scm_c_issue_deprecation_warning ("`string->obarray-symbol' is deprecated. "
821 "Use hashtables instead.");
822
7888309b 823 softness = (!SCM_UNBNDP (softp) && scm_is_true(softp));
cc5c1b66 824 /* iron out some screwy calling conventions */
7888309b 825 if (scm_is_false (o))
cc5c1b66
MV
826 {
827 /* nothing interesting to do here. */
828 return scm_string_to_symbol (s);
829 }
bc36d050 830 else if (scm_is_eq (o, SCM_BOOL_T))
cc5c1b66
MV
831 o = SCM_BOOL_F;
832
7f594642 833 vcell = intern_obarray_soft (scm_string_to_symbol (s), o, softness);
7888309b 834 if (scm_is_false (vcell))
cc5c1b66
MV
835 return vcell;
836 answer = SCM_CAR (vcell);
837 return answer;
838}
839#undef FUNC_NAME
840
841SCM_DEFINE (scm_intern_symbol, "intern-symbol", 2, 0, 0,
842 (SCM o, SCM s),
843 "Add a new symbol to @var{obarray} with name @var{string}, bound to an\n"
844 "unspecified initial value. The symbol table is not modified if a symbol\n"
845 "with this name is already present.")
846#define FUNC_NAME s_scm_intern_symbol
847{
848 size_t hval;
849 SCM_VALIDATE_SYMBOL (2,s);
7888309b 850 if (scm_is_false (o))
cc5c1b66
MV
851 return SCM_UNSPECIFIED;
852
853 scm_c_issue_deprecation_warning ("`intern-symbol' is deprecated. "
854 "Use hashtables instead.");
855
856 SCM_VALIDATE_VECTOR (1,o);
3ee86942 857 hval = scm_i_symbol_hash (s) % SCM_VECTOR_LENGTH (o);
cc5c1b66 858 /* If the symbol is already interned, simply return. */
9de87eea 859 SCM_CRITICAL_SECTION_START;
cc5c1b66
MV
860 {
861 SCM lsym;
862 SCM sym;
863 for (lsym = SCM_VECTOR_REF (o, hval);
864 SCM_NIMP (lsym);
865 lsym = SCM_CDR (lsym))
866 {
867 sym = SCM_CAR (lsym);
bc36d050 868 if (scm_is_eq (SCM_CAR (sym), s))
cc5c1b66 869 {
9de87eea 870 SCM_CRITICAL_SECTION_END;
cc5c1b66
MV
871 return SCM_UNSPECIFIED;
872 }
873 }
874 SCM_VECTOR_SET (o, hval,
875 scm_acons (s, SCM_UNDEFINED,
876 SCM_VECTOR_REF (o, hval)));
877 }
9de87eea 878 SCM_CRITICAL_SECTION_END;
cc5c1b66
MV
879 return SCM_UNSPECIFIED;
880}
881#undef FUNC_NAME
882
883SCM_DEFINE (scm_unintern_symbol, "unintern-symbol", 2, 0, 0,
884 (SCM o, SCM s),
885 "Remove the symbol with name @var{string} from @var{obarray}. This\n"
886 "function returns @code{#t} if the symbol was present and @code{#f}\n"
887 "otherwise.")
888#define FUNC_NAME s_scm_unintern_symbol
889{
890 size_t hval;
891
892 scm_c_issue_deprecation_warning ("`unintern-symbol' is deprecated. "
893 "Use hashtables instead.");
894
895 SCM_VALIDATE_SYMBOL (2,s);
7888309b 896 if (scm_is_false (o))
cc5c1b66
MV
897 return SCM_BOOL_F;
898 SCM_VALIDATE_VECTOR (1,o);
3ee86942 899 hval = scm_i_symbol_hash (s) % SCM_VECTOR_LENGTH (o);
9de87eea 900 SCM_CRITICAL_SECTION_START;
cc5c1b66
MV
901 {
902 SCM lsym_follow;
903 SCM lsym;
904 SCM sym;
905 for (lsym = SCM_VECTOR_REF (o, hval), lsym_follow = SCM_BOOL_F;
906 SCM_NIMP (lsym);
907 lsym_follow = lsym, lsym = SCM_CDR (lsym))
908 {
909 sym = SCM_CAR (lsym);
bc36d050 910 if (scm_is_eq (SCM_CAR (sym), s))
cc5c1b66
MV
911 {
912 /* Found the symbol to unintern. */
7888309b 913 if (scm_is_false (lsym_follow))
cc5c1b66
MV
914 SCM_VECTOR_SET (o, hval, lsym);
915 else
916 SCM_SETCDR (lsym_follow, SCM_CDR(lsym));
9de87eea 917 SCM_CRITICAL_SECTION_END;
cc5c1b66
MV
918 return SCM_BOOL_T;
919 }
920 }
921 }
9de87eea 922 SCM_CRITICAL_SECTION_END;
cc5c1b66
MV
923 return SCM_BOOL_F;
924}
925#undef FUNC_NAME
926
927SCM_DEFINE (scm_symbol_binding, "symbol-binding", 2, 0, 0,
928 (SCM o, SCM s),
929 "Look up in @var{obarray} the symbol whose name is @var{string}, and\n"
930 "return the value to which it is bound. If @var{obarray} is @code{#f},\n"
931 "use the global symbol table. If @var{string} is not interned in\n"
932 "@var{obarray}, an error is signalled.")
933#define FUNC_NAME s_scm_symbol_binding
934{
935 SCM vcell;
936
937 scm_c_issue_deprecation_warning ("`symbol-binding' is deprecated. "
938 "Use hashtables instead.");
939
940 SCM_VALIDATE_SYMBOL (2,s);
7888309b 941 if (scm_is_false (o))
cc5c1b66
MV
942 return scm_variable_ref (scm_lookup (s));
943 SCM_VALIDATE_VECTOR (1,o);
944 vcell = scm_sym2ovcell (s, o);
945 return SCM_CDR(vcell);
946}
947#undef FUNC_NAME
948
949#if 0
950SCM_DEFINE (scm_symbol_interned_p, "symbol-interned?", 2, 0, 0,
951 (SCM o, SCM s),
952 "Return @code{#t} if @var{obarray} contains a symbol with name\n"
953 "@var{string}, and @code{#f} otherwise.")
954#define FUNC_NAME s_scm_symbol_interned_p
955{
956 SCM vcell;
957
958 scm_c_issue_deprecation_warning ("`symbol-interned?' is deprecated. "
959 "Use hashtables instead.");
960
961 SCM_VALIDATE_SYMBOL (2,s);
7888309b 962 if (scm_is_false (o))
cc5c1b66
MV
963 {
964 SCM var = scm_sym2var (s, SCM_BOOL_F, SCM_BOOL_F);
965 if (var != SCM_BOOL_F)
966 return SCM_BOOL_T;
967 return SCM_BOOL_F;
968 }
969 SCM_VALIDATE_VECTOR (1,o);
970 vcell = scm_sym2ovcell_soft (s, o);
971 return (SCM_NIMP(vcell)
972 ? SCM_BOOL_T
973 : SCM_BOOL_F);
974}
975#undef FUNC_NAME
976#endif
977
978SCM_DEFINE (scm_symbol_bound_p, "symbol-bound?", 2, 0, 0,
979 (SCM o, SCM s),
980 "Return @code{#t} if @var{obarray} contains a symbol with name\n"
981 "@var{string} bound to a defined value. This differs from\n"
982 "@var{symbol-interned?} in that the mere mention of a symbol\n"
983 "usually causes it to be interned; @code{symbol-bound?}\n"
984 "determines whether a symbol has been given any meaningful\n"
985 "value.")
986#define FUNC_NAME s_scm_symbol_bound_p
987{
988 SCM vcell;
989
990 scm_c_issue_deprecation_warning ("`symbol-bound?' is deprecated. "
991 "Use hashtables instead.");
992
993 SCM_VALIDATE_SYMBOL (2,s);
7888309b 994 if (scm_is_false (o))
cc5c1b66
MV
995 {
996 SCM var = scm_sym2var (s, SCM_BOOL_F, SCM_BOOL_F);
997 if (SCM_VARIABLEP(var) && !SCM_UNBNDP(SCM_VARIABLE_REF(var)))
998 return SCM_BOOL_T;
999 return SCM_BOOL_F;
1000 }
1001 SCM_VALIDATE_VECTOR (1,o);
1002 vcell = scm_sym2ovcell_soft (s, o);
7888309b 1003 return scm_from_bool (SCM_NIMP (vcell) && !SCM_UNBNDP (SCM_CDR (vcell)));
cc5c1b66
MV
1004}
1005#undef FUNC_NAME
1006
1007
1008SCM_DEFINE (scm_symbol_set_x, "symbol-set!", 3, 0, 0,
1009 (SCM o, SCM s, SCM v),
1010 "Find the symbol in @var{obarray} whose name is @var{string}, and rebind\n"
1011 "it to @var{value}. An error is signalled if @var{string} is not present\n"
1012 "in @var{obarray}.")
1013#define FUNC_NAME s_scm_symbol_set_x
1014{
1015 SCM vcell;
1016
1017 scm_c_issue_deprecation_warning ("`symbol-set!' is deprecated. "
1018 "Use the module system instead.");
1019
1020 SCM_VALIDATE_SYMBOL (2,s);
7888309b 1021 if (scm_is_false (o))
cc5c1b66
MV
1022 {
1023 scm_define (s, v);
1024 return SCM_UNSPECIFIED;
1025 }
1026 SCM_VALIDATE_VECTOR (1,o);
1027 vcell = scm_sym2ovcell (s, o);
1028 SCM_SETCDR (vcell, v);
1029 return SCM_UNSPECIFIED;
1030}
1031#undef FUNC_NAME
1032
1033#define MAX_PREFIX_LENGTH 30
1034
1035static int gentemp_counter;
1036
1037SCM_DEFINE (scm_gentemp, "gentemp", 0, 2, 0,
1038 (SCM prefix, SCM obarray),
1039 "Create a new symbol with a name unique in an obarray.\n"
1040 "The name is constructed from an optional string @var{prefix}\n"
1041 "and a counter value. The default prefix is @code{t}. The\n"
1042 "@var{obarray} is specified as a second optional argument.\n"
1043 "Default is the system obarray where all normal symbols are\n"
1044 "interned. The counter is increased by 1 at each\n"
1045 "call. There is no provision for resetting the counter.")
1046#define FUNC_NAME s_scm_gentemp
1047{
1048 char buf[MAX_PREFIX_LENGTH + SCM_INTBUFLEN];
1049 char *name = buf;
806f1ded
MG
1050 int n_digits;
1051 size_t len;
cc5c1b66
MV
1052
1053 scm_c_issue_deprecation_warning ("`gentemp' is deprecated. "
1054 "Use `gensym' instead.");
1055
1056 if (SCM_UNBNDP (prefix))
1057 {
1058 name[0] = 't';
1059 len = 1;
1060 }
1061 else
1062 {
1063 SCM_VALIDATE_STRING (1, prefix);
3ee86942 1064 len = scm_i_string_length (prefix);
806f1ded 1065 name = scm_to_locale_stringn (prefix, &len);
7f594642 1066 name = scm_realloc (name, len + SCM_INTBUFLEN);
cc5c1b66
MV
1067 }
1068
1069 if (SCM_UNBNDP (obarray))
1070 return scm_gensym (prefix);
1071 else
4057a3e0 1072 SCM_ASSERT ((scm_is_vector (obarray) || SCM_I_WVECTP (obarray)),
cc5c1b66
MV
1073 obarray,
1074 SCM_ARG2,
1075 FUNC_NAME);
1076 do
1077 n_digits = scm_iint2str (gentemp_counter++, 10, &name[len]);
7888309b 1078 while (scm_is_true (scm_intern_obarray_soft (name,
cc5c1b66
MV
1079 len + n_digits,
1080 obarray,
1081 1)));
1082 {
1083 SCM vcell = scm_intern_obarray_soft (name,
1084 len + n_digits,
1085 obarray,
1086 0);
1087 if (name != buf)
7f594642 1088 free (name);
cc5c1b66
MV
1089 return SCM_CAR (vcell);
1090 }
1091}
1092#undef FUNC_NAME
1093
7888309b 1094SCM
fe78c51a 1095scm_i_makinum (scm_t_signed_bits val)
7888309b
MV
1096{
1097 scm_c_issue_deprecation_warning
1098 ("SCM_MAKINUM is deprecated. Use scm_from_int or similar instead.");
3aa13a05
MV
1099 return SCM_I_MAKINUM (val);
1100}
1101
1102int
fe78c51a 1103scm_i_inump (SCM obj)
3aa13a05
MV
1104{
1105 scm_c_issue_deprecation_warning
1106 ("SCM_INUMP is deprecated. Use scm_is_integer or similar instead.");
1107 return SCM_I_INUMP (obj);
1108}
1109
1110scm_t_signed_bits
fe78c51a 1111scm_i_inum (SCM obj)
3aa13a05
MV
1112{
1113 scm_c_issue_deprecation_warning
1114 ("SCM_INUM is deprecated. Use scm_to_int or similar instead.");
1115 return scm_to_intmax (obj);
7888309b 1116}
7888309b 1117
c829a427
MV
1118char *
1119scm_c_string2str (SCM obj, char *str, size_t *lenp)
1120{
1121 scm_c_issue_deprecation_warning
1122 ("scm_c_string2str is deprecated. Use scm_to_locale_stringbuf or similar instead.");
1123
1124 if (str == NULL)
1125 {
1126 char *result = scm_to_locale_string (obj);
1127 if (lenp)
3ee86942 1128 *lenp = scm_i_string_length (obj);
c829a427
MV
1129 return result;
1130 }
1131 else
1132 {
1133 /* Pray that STR is large enough.
1134 */
1135 size_t len = scm_to_locale_stringbuf (obj, str, SCM_I_SIZE_MAX);
1136 str[len] = '\0';
1137 if (lenp)
1138 *lenp = len;
1139 return str;
1140 }
1141}
1142
1143char *
1144scm_c_substring2str (SCM obj, char *str, size_t start, size_t len)
1145{
1146 scm_c_issue_deprecation_warning
1147 ("scm_c_substring2str is deprecated. Use scm_substring plus scm_to_locale_stringbuf instead.");
1148
1149 if (start)
1150 obj = scm_substring (obj, scm_from_size_t (start), SCM_UNDEFINED);
1151
1152 scm_to_locale_stringbuf (obj, str, len);
1153 return str;
1154}
1155
3ee86942
MV
1156/* Converts the given Scheme symbol OBJ into a C string, containing a copy
1157 of OBJ's content with a trailing null byte. If LENP is non-NULL, set
1158 *LENP to the string's length.
1159
1160 When STR is non-NULL it receives the copy and is returned by the function,
1161 otherwise new memory is allocated and the caller is responsible for
1162 freeing it via free(). If out of memory, NULL is returned.
1163
1164 Note that Scheme symbols may contain arbitrary data, including null
1165 characters. This means that null termination is not a reliable way to
1166 determine the length of the returned value. However, the function always
1167 copies the complete contents of OBJ, and sets *LENP to the length of the
1168 scheme symbol (if LENP is non-null). */
1169char *
1170scm_c_symbol2str (SCM obj, char *str, size_t *lenp)
1171{
1172 return scm_c_string2str (scm_symbol_to_string (obj), str, lenp);
1173}
1174
3101f40f
MV
1175double
1176scm_truncate (double x)
1177{
1178 scm_c_issue_deprecation_warning
1179 ("scm_truncate is deprecated. Use scm_c_truncate instead.");
1180 return scm_c_truncate (x);
1181}
1182
1183double
1184scm_round (double x)
1185{
1186 scm_c_issue_deprecation_warning
1187 ("scm_round is deprecated. Use scm_c_round instead.");
1188 return scm_c_round (x);
1189}
1190
6fc4d012
AW
1191SCM
1192scm_sys_expt (SCM x, SCM y)
1193{
1194 scm_c_issue_deprecation_warning
1195 ("scm_sys_expt is deprecated. Use scm_expt instead.");
1196 return scm_expt (x, y);
1197}
1198
ad79736c
AW
1199double
1200scm_asinh (double x)
1201{
1202 scm_c_issue_deprecation_warning
1203 ("scm_asinh is deprecated. Use asinh instead.");
1204#if HAVE_ASINH
1205 return asinh (x);
1206#else
1207 return log (x + sqrt (x * x + 1));
1208#endif
1209}
1210
1211double
1212scm_acosh (double x)
1213{
1214 scm_c_issue_deprecation_warning
1215 ("scm_acosh is deprecated. Use acosh instead.");
1216#if HAVE_ACOSH
1217 return acosh (x);
1218#else
1219 return log (x + sqrt (x * x - 1));
1220#endif
1221}
1222
1223double
1224scm_atanh (double x)
1225{
1226 scm_c_issue_deprecation_warning
1227 ("scm_atanh is deprecated. Use atanh instead.");
1228#if HAVE_ATANH
1229 return atanh (x);
1230#else
1231 return 0.5 * log ((1 + x) / (1 - x));
1232#endif
1233}
1234
1235SCM
1236scm_sys_atan2 (SCM z1, SCM z2)
1237{
1238 scm_c_issue_deprecation_warning
1239 ("scm_sys_atan2 is deprecated. Use scm_atan instead.");
1240 return scm_atan (z1, z2);
1241}
1242
3ee86942 1243char *
fe78c51a 1244scm_i_deprecated_symbol_chars (SCM sym)
3ee86942
MV
1245{
1246 scm_c_issue_deprecation_warning
1247 ("SCM_SYMBOL_CHARS is deprecated. Use scm_symbol_to_string.");
1248
ba16a103 1249 return (char *)scm_i_symbol_chars (sym);
3ee86942
MV
1250}
1251
1252size_t
fe78c51a 1253scm_i_deprecated_symbol_length (SCM sym)
3ee86942
MV
1254{
1255 scm_c_issue_deprecation_warning
1256 ("SCM_SYMBOL_LENGTH is deprecated. Use scm_symbol_to_string.");
ba16a103 1257 return scm_i_symbol_length (sym);
3ee86942
MV
1258}
1259
265a7997 1260int
fe78c51a 1261scm_i_keywordp (SCM obj)
265a7997
MV
1262{
1263 scm_c_issue_deprecation_warning
1264 ("SCM_KEYWORDP is deprecated. Use scm_is_keyword instead.");
1265 return scm_is_keyword (obj);
1266}
1267
1268SCM
fe78c51a 1269scm_i_keywordsym (SCM keyword)
265a7997
MV
1270{
1271 scm_c_issue_deprecation_warning
1272 ("SCM_KEYWORDSYM is deprecated. See scm_keyword_to_symbol instead.");
1273 return scm_keyword_dash_symbol (keyword);
1274}
1275
354116f7 1276int
fe78c51a 1277scm_i_vectorp (SCM x)
354116f7
MV
1278{
1279 scm_c_issue_deprecation_warning
1280 ("SCM_VECTORP is deprecated. Use scm_is_vector instead.");
1281 return SCM_I_IS_VECTOR (x);
1282}
1283
1284unsigned long
fe78c51a 1285scm_i_vector_length (SCM x)
354116f7
MV
1286{
1287 scm_c_issue_deprecation_warning
1288 ("SCM_VECTOR_LENGTH is deprecated. Use scm_c_vector_length instead.");
1289 return SCM_I_VECTOR_LENGTH (x);
1290}
1291
1292const SCM *
fe78c51a 1293scm_i_velts (SCM x)
354116f7
MV
1294{
1295 scm_c_issue_deprecation_warning
1296 ("SCM_VELTS is deprecated. Use scm_vector_elements instead.");
1297 return SCM_I_VECTOR_ELTS (x);
1298}
1299
1300SCM *
fe78c51a 1301scm_i_writable_velts (SCM x)
354116f7
MV
1302{
1303 scm_c_issue_deprecation_warning
1304 ("SCM_WRITABLE_VELTS is deprecated. "
1305 "Use scm_vector_writable_elements instead.");
1306 return SCM_I_VECTOR_WELTS (x);
1307}
1308
1309SCM
fe78c51a 1310scm_i_vector_ref (SCM x, size_t idx)
354116f7
MV
1311{
1312 scm_c_issue_deprecation_warning
1313 ("SCM_VECTOR_REF is deprecated. "
1314 "Use scm_c_vector_ref or scm_vector_elements instead.");
1315 return scm_c_vector_ref (x, idx);
1316}
1317
1318void
fe78c51a 1319scm_i_vector_set (SCM x, size_t idx, SCM val)
354116f7
MV
1320{
1321 scm_c_issue_deprecation_warning
1322 ("SCM_VECTOR_SET is deprecated. "
1323 "Use scm_c_vector_set_x or scm_vector_writable_elements instead.");
1324 scm_c_vector_set_x (x, idx, val);
1325}
1326
1327SCM
1328scm_vector_equal_p (SCM x, SCM y)
1329{
1330 scm_c_issue_deprecation_warning
1331 ("scm_vector_euqal_p is deprecated. "
1332 "Use scm_equal_p instead.");
1333 return scm_equal_p (x, y);
1334}
1335
a2689737
AW
1336SCM_DEFINE (scm_uniform_vector_read_x, "uniform-vector-read!", 1, 3, 0,
1337 (SCM uvec, SCM port_or_fd, SCM start, SCM end),
1338 "Fill the elements of @var{uvec} by reading\n"
1339 "raw bytes from @var{port-or-fdes}, using host byte order.\n\n"
1340 "The optional arguments @var{start} (inclusive) and @var{end}\n"
1341 "(exclusive) allow a specified region to be read,\n"
1342 "leaving the remainder of the vector unchanged.\n\n"
1343 "When @var{port-or-fdes} is a port, all specified elements\n"
1344 "of @var{uvec} are attempted to be read, potentially blocking\n"
1345 "while waiting formore input or end-of-file.\n"
1346 "When @var{port-or-fd} is an integer, a single call to\n"
1347 "read(2) is made.\n\n"
1348 "An error is signalled when the last element has only\n"
1349 "been partially filled before reaching end-of-file or in\n"
1350 "the single call to read(2).\n\n"
1351 "@code{uniform-vector-read!} returns the number of elements\n"
1352 "read.\n\n"
1353 "@var{port-or-fdes} may be omitted, in which case it defaults\n"
1354 "to the value returned by @code{(current-input-port)}.")
1355#define FUNC_NAME s_scm_uniform_vector_read_x
1356{
1357 size_t width;
1358 SCM_VALIDATE_BYTEVECTOR (SCM_ARG1, uvec);
1f366ef7 1359
a2689737
AW
1360 scm_c_issue_deprecation_warning
1361 ("`uniform-vector-read!' is deprecated. Use `get-bytevector-n!' from\n"
1362 "`(rnrs io ports)' instead.");
1f366ef7 1363
a2689737 1364 width = scm_to_size_t (scm_uniform_vector_element_size (uvec));
1f366ef7 1365
a2689737
AW
1366 return scm_get_bytevector_n_x (port_or_fd, uvec,
1367 scm_from_size_t (scm_to_size_t (start)*width),
1368 scm_from_size_t ((scm_to_size_t (end)
1369 - scm_to_size_t (start))
1370 * width));
1f366ef7 1371}
a2689737 1372#undef FUNC_NAME
1f366ef7 1373
a2689737
AW
1374SCM_DEFINE (scm_uniform_vector_write, "uniform-vector-write", 1, 3, 0,
1375 (SCM uvec, SCM port_or_fd, SCM start, SCM end),
1376 "Write the elements of @var{uvec} as raw bytes to\n"
1377 "@var{port-or-fdes}, in the host byte order.\n\n"
1378 "The optional arguments @var{start} (inclusive)\n"
1379 "and @var{end} (exclusive) allow\n"
1380 "a specified region to be written.\n\n"
1381 "When @var{port-or-fdes} is a port, all specified elements\n"
1382 "of @var{uvec} are attempted to be written, potentially blocking\n"
1383 "while waiting for more room.\n"
1384 "When @var{port-or-fd} is an integer, a single call to\n"
1385 "write(2) is made.\n\n"
1386 "An error is signalled when the last element has only\n"
1387 "been partially written in the single call to write(2).\n\n"
1388 "The number of objects actually written is returned.\n"
1389 "@var{port-or-fdes} may be\n"
1390 "omitted, in which case it defaults to the value returned by\n"
1391 "@code{(current-output-port)}.")
1392#define FUNC_NAME s_scm_uniform_vector_write
1393{
1394 size_t width;
1395 SCM_VALIDATE_BYTEVECTOR (SCM_ARG1, uvec);
1396 port_or_fd = SCM_COERCE_OUTPORT (port_or_fd);
1397
1398 scm_c_issue_deprecation_warning
1399 ("`uniform-vector-write' is deprecated. Use `put-bytevector' from\n"
1400 "`(rnrs io ports)' instead.");
1401
1402 width = scm_to_size_t (scm_uniform_vector_element_size (uvec));
1403
1404 return scm_put_bytevector (port_or_fd, uvec,
1405 scm_from_size_t (scm_to_size_t (start)*width),
1406 scm_from_size_t ((scm_to_size_t (end)
1407 - scm_to_size_t (start))
1408 * width));
1f366ef7 1409}
a2689737 1410#undef FUNC_NAME
1f366ef7 1411
a2689737
AW
1412static SCM
1413scm_ra2contig (SCM ra, int copy)
1414{
1415 SCM ret;
1416 long inc = 1;
1417 size_t k, len = 1;
1418 for (k = SCM_I_ARRAY_NDIM (ra); k--;)
1419 len *= SCM_I_ARRAY_DIMS (ra)[k].ubnd - SCM_I_ARRAY_DIMS (ra)[k].lbnd + 1;
1420 k = SCM_I_ARRAY_NDIM (ra);
1421 if (SCM_I_ARRAY_CONTP (ra) && ((0 == k) || (1 == SCM_I_ARRAY_DIMS (ra)[k - 1].inc)))
1422 {
1423 if (!scm_is_bitvector (SCM_I_ARRAY_V (ra)))
1424 return ra;
1425 if ((len == scm_c_bitvector_length (SCM_I_ARRAY_V (ra)) &&
1426 0 == SCM_I_ARRAY_BASE (ra) % SCM_LONG_BIT &&
1427 0 == len % SCM_LONG_BIT))
1428 return ra;
1429 }
1430 ret = scm_i_make_array (k);
1431 SCM_I_ARRAY_BASE (ret) = 0;
1432 while (k--)
1433 {
1434 SCM_I_ARRAY_DIMS (ret)[k].lbnd = SCM_I_ARRAY_DIMS (ra)[k].lbnd;
1435 SCM_I_ARRAY_DIMS (ret)[k].ubnd = SCM_I_ARRAY_DIMS (ra)[k].ubnd;
1436 SCM_I_ARRAY_DIMS (ret)[k].inc = inc;
1437 inc *= SCM_I_ARRAY_DIMS (ra)[k].ubnd - SCM_I_ARRAY_DIMS (ra)[k].lbnd + 1;
1438 }
1439 SCM_I_ARRAY_V (ret) =
1440 scm_make_generalized_vector (scm_array_type (ra), scm_from_size_t (inc),
1441 SCM_UNDEFINED);
1442 if (copy)
1443 scm_array_copy_x (ra, ret);
1444 return ret;
1445}
1446
1447SCM_DEFINE (scm_uniform_array_read_x, "uniform-array-read!", 1, 3, 0,
1448 (SCM ura, SCM port_or_fd, SCM start, SCM end),
1449 "@deffnx {Scheme Procedure} uniform-vector-read! uve [port-or-fdes] [start] [end]\n"
1450 "Attempt to read all elements of @var{ura}, in lexicographic order, as\n"
1451 "binary objects from @var{port-or-fdes}.\n"
1452 "If an end of file is encountered,\n"
1453 "the objects up to that point are put into @var{ura}\n"
1454 "(starting at the beginning) and the remainder of the array is\n"
1455 "unchanged.\n\n"
1456 "The optional arguments @var{start} and @var{end} allow\n"
1457 "a specified region of a vector (or linearized array) to be read,\n"
1458 "leaving the remainder of the vector unchanged.\n\n"
1459 "@code{uniform-array-read!} returns the number of objects read.\n"
1460 "@var{port-or-fdes} may be omitted, in which case it defaults to the value\n"
1461 "returned by @code{(current-input-port)}.")
1462#define FUNC_NAME s_scm_uniform_array_read_x
1463{
1464 if (SCM_UNBNDP (port_or_fd))
1465 port_or_fd = scm_current_input_port ();
1466
1467 if (scm_is_uniform_vector (ura))
1468 {
1469 return scm_uniform_vector_read_x (ura, port_or_fd, start, end);
1470 }
1471 else if (SCM_I_ARRAYP (ura))
1472 {
1473 size_t base, vlen, cstart, cend;
1474 SCM cra, ans;
1475
1476 cra = scm_ra2contig (ura, 0);
1477 base = SCM_I_ARRAY_BASE (cra);
1478 vlen = SCM_I_ARRAY_DIMS (cra)->inc *
1479 (SCM_I_ARRAY_DIMS (cra)->ubnd - SCM_I_ARRAY_DIMS (cra)->lbnd + 1);
1480
1481 cstart = 0;
1482 cend = vlen;
1483 if (!SCM_UNBNDP (start))
1484 {
1485 cstart = scm_to_unsigned_integer (start, 0, vlen);
1486 if (!SCM_UNBNDP (end))
1487 cend = scm_to_unsigned_integer (end, cstart, vlen);
1488 }
1489
1490 ans = scm_uniform_vector_read_x (SCM_I_ARRAY_V (cra), port_or_fd,
1491 scm_from_size_t (base + cstart),
1492 scm_from_size_t (base + cend));
1493
1494 if (!scm_is_eq (cra, ura))
1495 scm_array_copy_x (cra, ura);
1496 return ans;
1497 }
1498 else
1499 scm_wrong_type_arg_msg (NULL, 0, ura, "array");
1f366ef7 1500}
a2689737 1501#undef FUNC_NAME
1f366ef7 1502
a2689737
AW
1503SCM_DEFINE (scm_uniform_array_write, "uniform-array-write", 1, 3, 0,
1504 (SCM ura, SCM port_or_fd, SCM start, SCM end),
1505 "Writes all elements of @var{ura} as binary objects to\n"
1506 "@var{port-or-fdes}.\n\n"
1507 "The optional arguments @var{start}\n"
1508 "and @var{end} allow\n"
1509 "a specified region of a vector (or linearized array) to be written.\n\n"
1510 "The number of objects actually written is returned.\n"
1511 "@var{port-or-fdes} may be\n"
1512 "omitted, in which case it defaults to the value returned by\n"
1513 "@code{(current-output-port)}.")
1514#define FUNC_NAME s_scm_uniform_array_write
1515{
1516 if (SCM_UNBNDP (port_or_fd))
1517 port_or_fd = scm_current_output_port ();
1518
1519 if (scm_is_uniform_vector (ura))
1520 {
1521 return scm_uniform_vector_write (ura, port_or_fd, start, end);
1522 }
1523 else if (SCM_I_ARRAYP (ura))
1524 {
1525 size_t base, vlen, cstart, cend;
1526 SCM cra, ans;
1527
1528 cra = scm_ra2contig (ura, 1);
1529 base = SCM_I_ARRAY_BASE (cra);
1530 vlen = SCM_I_ARRAY_DIMS (cra)->inc *
1531 (SCM_I_ARRAY_DIMS (cra)->ubnd - SCM_I_ARRAY_DIMS (cra)->lbnd + 1);
1532
1533 cstart = 0;
1534 cend = vlen;
1535 if (!SCM_UNBNDP (start))
1536 {
1537 cstart = scm_to_unsigned_integer (start, 0, vlen);
1538 if (!SCM_UNBNDP (end))
1539 cend = scm_to_unsigned_integer (end, cstart, vlen);
1540 }
1541
1542 ans = scm_uniform_vector_write (SCM_I_ARRAY_V (cra), port_or_fd,
1543 scm_from_size_t (base + cstart),
1544 scm_from_size_t (base + cend));
1545
1546 return ans;
1547 }
1548 else
1549 scm_wrong_type_arg_msg (NULL, 0, ura, "array");
1f366ef7 1550}
a2689737 1551#undef FUNC_NAME
1f366ef7 1552
9de87eea
MV
1553SCM
1554scm_i_cur_inp (void)
1555{
1556 scm_c_issue_deprecation_warning
1557 ("scm_cur_inp is deprecated. Use scm_current_input_port instead.");
1558 return scm_current_input_port ();
1559}
1560
1561SCM
1562scm_i_cur_outp (void)
1563{
1564 scm_c_issue_deprecation_warning
1565 ("scm_cur_outp is deprecated. Use scm_current_output_port instead.");
1566 return scm_current_output_port ();
1567}
1568
1569SCM
1570scm_i_cur_errp (void)
1571{
1572 scm_c_issue_deprecation_warning
1573 ("scm_cur_errp is deprecated. Use scm_current_error_port instead.");
1574 return scm_current_error_port ();
1575}
1576
1577SCM
1578scm_i_cur_loadp (void)
1579{
1580 scm_c_issue_deprecation_warning
1581 ("scm_cur_loadp is deprecated. Use scm_current_load_port instead.");
1582 return scm_current_load_port ();
1583}
1584
1585SCM
1586scm_i_progargs (void)
1587{
1588 scm_c_issue_deprecation_warning
1589 ("scm_progargs is deprecated. Use scm_program_arguments instead.");
1590 return scm_program_arguments ();
1591}
1592
1593SCM
1594scm_i_deprecated_dynwinds (void)
1595{
1596 scm_c_issue_deprecation_warning
1597 ("scm_dynwinds is deprecated. Do not use it.");
1598 return scm_i_dynwinds ();
1599}
1600
9de87eea
MV
1601SCM_STACKITEM *
1602scm_i_stack_base (void)
1603{
1604 scm_c_issue_deprecation_warning
1605 ("scm_stack_base is deprecated. Do not use it.");
1606 return SCM_I_CURRENT_THREAD->base;
1607}
1608
1609int
1610scm_i_fluidp (SCM x)
1611{
1612 scm_c_issue_deprecation_warning
1613 ("SCM_FLUIDP is deprecated. Use scm_is_fluid instead.");
1614 return scm_is_fluid (x);
1615}
1616
3452e666
LC
1617\f
1618/* Networking. */
1619
1040b205
LC
1620#ifdef HAVE_NETWORKING
1621
1622SCM_DEFINE (scm_inet_aton, "inet-aton", 1, 0, 0,
3452e666
LC
1623 (SCM address),
1624 "Convert an IPv4 Internet address from printable string\n"
1625 "(dotted decimal notation) to an integer. E.g.,\n\n"
1626 "@lisp\n"
1627 "(inet-aton \"127.0.0.1\") @result{} 2130706433\n"
1628 "@end lisp")
1629#define FUNC_NAME s_scm_inet_aton
1630{
1631 scm_c_issue_deprecation_warning
1632 ("`inet-aton' is deprecated. Use `inet-pton' instead.");
1633
1634 return scm_inet_pton (scm_from_int (AF_INET), address);
1635}
1636#undef FUNC_NAME
1637
1638
1040b205 1639SCM_DEFINE (scm_inet_ntoa, "inet-ntoa", 1, 0, 0,
3452e666
LC
1640 (SCM inetid),
1641 "Convert an IPv4 Internet address to a printable\n"
1642 "(dotted decimal notation) string. E.g.,\n\n"
1643 "@lisp\n"
1644 "(inet-ntoa 2130706433) @result{} \"127.0.0.1\"\n"
1645 "@end lisp")
1646#define FUNC_NAME s_scm_inet_ntoa
1647{
1648 scm_c_issue_deprecation_warning
1649 ("`inet-ntoa' is deprecated. Use `inet-ntop' instead.");
1650
1651 return scm_inet_ntop (scm_from_int (AF_INET), inetid);
1652}
1653#undef FUNC_NAME
1654
1040b205 1655#endif /* HAVE_NETWORKING */
3452e666
LC
1656
1657\f
9de87eea
MV
1658void
1659scm_i_defer_ints_etc ()
1660{
1661 scm_c_issue_deprecation_warning
2b829bbb 1662 ("SCM_DEFER_INTS etc are deprecated. "
9de87eea
MV
1663 "Use a mutex instead if appropriate.");
1664}
1665
b8ec9dab
LC
1666int
1667scm_i_mask_ints (void)
1668{
1669 scm_c_issue_deprecation_warning ("`scm_mask_ints' is deprecated.");
1670 return (SCM_I_CURRENT_THREAD->block_asyncs != 0);
1671}
1672
1673\f
06c1d900
MV
1674SCM
1675scm_guard (SCM guardian, SCM obj, int throw_p)
1676{
1677 scm_c_issue_deprecation_warning
1678 ("scm_guard is deprecated. Use scm_call_1 instead.");
1679
1680 return scm_call_1 (guardian, obj);
1681}
1682
1683SCM
1684scm_get_one_zombie (SCM guardian)
1685{
1686 scm_c_issue_deprecation_warning
1687 ("scm_guard is deprecated. Use scm_call_0 instead.");
1688
1689 return scm_call_0 (guardian);
1690}
1691
1692SCM_DEFINE (scm_guardian_destroyed_p, "guardian-destroyed?", 1, 0, 0,
1693 (SCM guardian),
1694 "Return @code{#t} if @var{guardian} has been destroyed, otherwise @code{#f}.")
1695#define FUNC_NAME s_scm_guardian_destroyed_p
1696{
1697 scm_c_issue_deprecation_warning
1698 ("'guardian-destroyed?' is deprecated.");
1699 return SCM_BOOL_F;
1700}
1701#undef FUNC_NAME
1702
1703SCM_DEFINE (scm_guardian_greedy_p, "guardian-greedy?", 1, 0, 0,
1704 (SCM guardian),
1705 "Return @code{#t} if @var{guardian} is a greedy guardian, otherwise @code{#f}.")
1706#define FUNC_NAME s_scm_guardian_greedy_p
1707{
1708 scm_c_issue_deprecation_warning
1709 ("'guardian-greedy?' is deprecated.");
1710 return SCM_BOOL_F;
1711}
1712#undef FUNC_NAME
1713
1714SCM_DEFINE (scm_destroy_guardian_x, "destroy-guardian!", 1, 0, 0,
1715 (SCM guardian),
1716 "Destroys @var{guardian}, by making it impossible to put any more\n"
1717 "objects in it or get any objects from it. It also unguards any\n"
1718 "objects guarded by @var{guardian}.")
1719#define FUNC_NAME s_scm_destroy_guardian_x
1720{
1721 scm_c_issue_deprecation_warning
1722 ("'destroy-guardian!' is deprecated and ineffective.");
1723 return SCM_UNSPECIFIED;
1724}
1725#undef FUNC_NAME
1726
760fb97d
LC
1727\f
1728/* GC-related things. */
1729
1730unsigned long scm_mallocated, scm_mtrigger;
1731size_t scm_max_segment_size;
1732
1733#if defined (GUILE_DEBUG) || defined (GUILE_DEBUG_FREELIST)
1734SCM
1735scm_map_free_list (void)
1736{
1737 return SCM_EOL;
1738}
1739#endif
1740
1741#if defined (GUILE_DEBUG_FREELIST)
1742SCM
1743scm_gc_set_debug_check_freelist_x (SCM flag)
1744{
1745 return SCM_UNSPECIFIED;
1746}
1747#endif
1748
1749\f
a3e92377
AW
1750/* Trampolines
1751 *
1752 * Trampolines were an intent to speed up calling the same Scheme procedure many
1753 * times from C.
1754 *
1755 * However, this was the wrong thing to optimize; if you really know what you're
1756 * calling, call its function directly, otherwise you're in Scheme-land, and we
1757 * have many better tricks there (inlining, for example, which can remove the
1758 * need for closures and free variables).
1759 *
1760 * Also, in the normal debugging case, trampolines were being computed but not
1761 * used. Silliness.
1762 */
1763
1764scm_t_trampoline_0
1765scm_trampoline_0 (SCM proc)
1766{
1767 scm_c_issue_deprecation_warning
1768 ("`scm_trampoline_0' is deprecated. Just use `scm_call_0' instead.");
1769 return scm_call_0;
1770}
1771
1772scm_t_trampoline_1
1773scm_trampoline_1 (SCM proc)
1774{
1775 scm_c_issue_deprecation_warning
1776 ("`scm_trampoline_1' is deprecated. Just use `scm_call_1' instead.");
1777 return scm_call_1;
1778}
1779
1780scm_t_trampoline_2
1781scm_trampoline_2 (SCM proc)
1782{
1783 scm_c_issue_deprecation_warning
1784 ("`scm_trampoline_2' is deprecated. Just use `scm_call_2' instead.");
1785 return scm_call_2;
1786}
1787
1788\f
19e2247d
MV
1789void
1790scm_i_init_deprecated ()
1791{
1792#include "libguile/deprecated.x"
1793}
1794
1795#endif