(SCM_BITVEC_REF, SCM_BITVEC_SET, SCM_BITVEC_CLR): Removed.
[bpt/guile.git] / libguile / deprecated.c
1 /* This file contains definitions for deprecated features. When you
2 deprecate something, move it here when that is feasible.
3 */
4
5 /* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22 #include "libguile/_scm.h"
23 #include "libguile/deprecated.h"
24 #include "libguile/discouraged.h"
25 #include "libguile/deprecation.h"
26 #include "libguile/snarf.h"
27 #include "libguile/validate.h"
28 #include "libguile/strings.h"
29 #include "libguile/srfi-13.h"
30 #include "libguile/modules.h"
31 #include "libguile/eval.h"
32 #include "libguile/smob.h"
33 #include "libguile/procprop.h"
34 #include "libguile/vectors.h"
35 #include "libguile/hashtab.h"
36 #include "libguile/struct.h"
37 #include "libguile/variable.h"
38 #include "libguile/fluids.h"
39 #include "libguile/ports.h"
40 #include "libguile/eq.h"
41 #include "libguile/read.h"
42 #include "libguile/strports.h"
43 #include "libguile/smob.h"
44 #include "libguile/alist.h"
45 #include "libguile/keywords.h"
46
47 #include <stdio.h>
48 #include <string.h>
49
50 #if (SCM_ENABLE_DEPRECATED == 1)
51
52 /* From print.c: Internal symbol names of isyms. Deprecated in guile 1.7.0 on
53 * 2004-04-22. */
54 char *scm_isymnames[] =
55 {
56 "#@<deprecated>"
57 };
58
59
60 /* From eval.c: Error messages of the evaluator. These were deprecated in
61 * guile 1.7.0 on 2003-06-02. */
62 const char scm_s_expression[] = "missing or extra expression";
63 const char scm_s_test[] = "bad test";
64 const char scm_s_body[] = "bad body";
65 const char scm_s_bindings[] = "bad bindings";
66 const char scm_s_variable[] = "bad variable";
67 const char scm_s_clauses[] = "bad or missing clauses";
68 const char scm_s_formals[] = "bad formals";
69
70
71 SCM_REGISTER_PROC(s_substring_move_left_x, "substring-move-left!", 5, 0, 0, scm_substring_move_x);
72
73 SCM_REGISTER_PROC(s_substring_move_right_x, "substring-move-right!", 5, 0, 0, scm_substring_move_x);
74
75 SCM
76 scm_wta (SCM arg, const char *pos, const char *s_subr)
77 {
78 if (!s_subr || !*s_subr)
79 s_subr = NULL;
80 if ((~0x1fL) & (long) pos)
81 {
82 /* error string supplied. */
83 scm_misc_error (s_subr, pos, scm_list_1 (arg));
84 }
85 else
86 {
87 /* numerical error code. */
88 scm_t_bits error = (scm_t_bits) pos;
89
90 switch (error)
91 {
92 case SCM_ARGn:
93 scm_wrong_type_arg (s_subr, 0, arg);
94 case SCM_ARG1:
95 scm_wrong_type_arg (s_subr, 1, arg);
96 case SCM_ARG2:
97 scm_wrong_type_arg (s_subr, 2, arg);
98 case SCM_ARG3:
99 scm_wrong_type_arg (s_subr, 3, arg);
100 case SCM_ARG4:
101 scm_wrong_type_arg (s_subr, 4, arg);
102 case SCM_ARG5:
103 scm_wrong_type_arg (s_subr, 5, arg);
104 case SCM_ARG6:
105 scm_wrong_type_arg (s_subr, 6, arg);
106 case SCM_ARG7:
107 scm_wrong_type_arg (s_subr, 7, arg);
108 case SCM_WNA:
109 scm_wrong_num_args (arg);
110 case SCM_OUTOFRANGE:
111 scm_out_of_range (s_subr, arg);
112 case SCM_NALLOC:
113 scm_memory_error (s_subr);
114 default:
115 /* this shouldn't happen. */
116 scm_misc_error (s_subr, "Unknown error", SCM_EOL);
117 }
118 }
119 return SCM_UNSPECIFIED;
120 }
121
122 /* Module registry
123 */
124
125 /* We can't use SCM objects here. One should be able to call
126 SCM_REGISTER_MODULE from a C++ constructor for a static
127 object. This happens before main and thus before libguile is
128 initialized. */
129
130 struct moddata {
131 struct moddata *link;
132 char *module_name;
133 void *init_func;
134 };
135
136 static struct moddata *registered_mods = NULL;
137
138 void
139 scm_register_module_xxx (char *module_name, void *init_func)
140 {
141 struct moddata *md;
142
143 scm_c_issue_deprecation_warning
144 ("`scm_register_module_xxx' is deprecated. Use extensions instead.");
145
146 /* XXX - should we (and can we) DEFER_INTS here? */
147
148 for (md = registered_mods; md; md = md->link)
149 if (!strcmp (md->module_name, module_name))
150 {
151 md->init_func = init_func;
152 return;
153 }
154
155 md = (struct moddata *) malloc (sizeof (struct moddata));
156 if (md == NULL)
157 {
158 fprintf (stderr,
159 "guile: can't register module (%s): not enough memory",
160 module_name);
161 return;
162 }
163
164 md->module_name = module_name;
165 md->init_func = init_func;
166 md->link = registered_mods;
167 registered_mods = md;
168 }
169
170 SCM_DEFINE (scm_registered_modules, "c-registered-modules", 0, 0, 0,
171 (),
172 "Return a list of the object code modules that have been imported into\n"
173 "the current Guile process. Each element of the list is a pair whose\n"
174 "car is the name of the module, and whose cdr is the function handle\n"
175 "for that module's initializer function. The name is the string that\n"
176 "has been passed to scm_register_module_xxx.")
177 #define FUNC_NAME s_scm_registered_modules
178 {
179 SCM res;
180 struct moddata *md;
181
182 res = SCM_EOL;
183 for (md = registered_mods; md; md = md->link)
184 res = scm_cons (scm_cons (scm_from_locale_string (md->module_name),
185 scm_from_ulong ((unsigned long) md->init_func)),
186 res);
187 return res;
188 }
189 #undef FUNC_NAME
190
191 SCM_DEFINE (scm_clear_registered_modules, "c-clear-registered-modules", 0, 0, 0,
192 (),
193 "Destroy the list of modules registered with the current Guile process.\n"
194 "The return value is unspecified. @strong{Warning:} this function does\n"
195 "not actually unlink or deallocate these modules, but only destroys the\n"
196 "records of which modules have been loaded. It should therefore be used\n"
197 "only by module bookkeeping operations.")
198 #define FUNC_NAME s_scm_clear_registered_modules
199 {
200 struct moddata *md1, *md2;
201
202 SCM_DEFER_INTS;
203
204 for (md1 = registered_mods; md1; md1 = md2)
205 {
206 md2 = md1->link;
207 free (md1);
208 }
209 registered_mods = NULL;
210
211 SCM_ALLOW_INTS;
212 return SCM_UNSPECIFIED;
213 }
214 #undef FUNC_NAME
215
216 void
217 scm_remember (SCM *ptr)
218 {
219 scm_c_issue_deprecation_warning ("`scm_remember' is deprecated. "
220 "Use the `scm_remember_upto_here*' family of functions instead.");
221 }
222
223 SCM
224 scm_protect_object (SCM obj)
225 {
226 scm_c_issue_deprecation_warning ("`scm_protect_object' is deprecated. "
227 "Use `scm_gc_protect_object' instead.");
228 return scm_gc_protect_object (obj);
229 }
230
231 SCM
232 scm_unprotect_object (SCM obj)
233 {
234 scm_c_issue_deprecation_warning ("`scm_unprotect_object' is deprecated. "
235 "Use `scm_gc_unprotect_object' instead.");
236 return scm_gc_unprotect_object (obj);
237 }
238
239 SCM_SYMBOL (scm_sym_app, "app");
240 SCM_SYMBOL (scm_sym_modules, "modules");
241 static SCM module_prefix = SCM_BOOL_F;
242 static SCM make_modules_in_var;
243 static SCM beautify_user_module_x_var;
244 static SCM try_module_autoload_var;
245
246 static void
247 init_module_stuff ()
248 {
249 #define PERM(x) scm_permanent_object(x)
250
251 if (module_prefix == SCM_BOOL_F)
252 {
253 module_prefix = PERM (scm_list_2 (scm_sym_app, scm_sym_modules));
254 make_modules_in_var = PERM (scm_c_lookup ("make-modules-in"));
255 beautify_user_module_x_var =
256 PERM (scm_c_lookup ("beautify-user-module!"));
257 try_module_autoload_var = PERM (scm_c_lookup ("try-module-autoload"));
258 }
259 }
260
261 SCM
262 scm_the_root_module ()
263 {
264 init_module_stuff ();
265 scm_c_issue_deprecation_warning ("`scm_the_root_module' is deprecated. "
266 "Use `scm_c_resolve_module (\"guile\")' "
267 "instead.");
268
269 return scm_c_resolve_module ("guile");
270 }
271
272 static SCM
273 scm_module_full_name (SCM name)
274 {
275 init_module_stuff ();
276 if (scm_is_eq (SCM_CAR (name), scm_sym_app))
277 return name;
278 else
279 return scm_append (scm_list_2 (module_prefix, name));
280 }
281
282 SCM
283 scm_make_module (SCM name)
284 {
285 init_module_stuff ();
286 scm_c_issue_deprecation_warning ("`scm_make_module' is deprecated. "
287 "Use `scm_c_define_module instead.");
288
289 return scm_call_2 (SCM_VARIABLE_REF (make_modules_in_var),
290 scm_the_root_module (),
291 scm_module_full_name (name));
292 }
293
294 SCM
295 scm_ensure_user_module (SCM module)
296 {
297 init_module_stuff ();
298 scm_c_issue_deprecation_warning ("`scm_ensure_user_module' is deprecated. "
299 "Use `scm_c_define_module instead.");
300
301 scm_call_1 (SCM_VARIABLE_REF (beautify_user_module_x_var), module);
302 return SCM_UNSPECIFIED;
303 }
304
305 SCM
306 scm_load_scheme_module (SCM name)
307 {
308 init_module_stuff ();
309 scm_c_issue_deprecation_warning ("`scm_load_scheme_module' is deprecated. "
310 "Use `scm_c_resolve_module instead.");
311
312 return scm_call_1 (SCM_VARIABLE_REF (try_module_autoload_var), name);
313 }
314
315 /* This is implemented in C solely for SCM_COERCE_OUTPORT ... */
316
317 static void
318 maybe_close_port (void *data, SCM port)
319 {
320 SCM except = (SCM)data;
321
322 while (!scm_is_null (except))
323 {
324 SCM p = SCM_COERCE_OUTPORT (SCM_CAR (except));
325 if (scm_is_eq (p, port))
326 return;
327 except = SCM_CDR (except);
328 }
329
330 scm_close_port (port);
331 }
332
333 SCM_DEFINE (scm_close_all_ports_except, "close-all-ports-except", 0, 0, 1,
334 (SCM ports),
335 "[DEPRECATED] Close all open file ports used by the interpreter\n"
336 "except for those supplied as arguments. This procedure\n"
337 "was intended to be used before an exec call to close file descriptors\n"
338 "which are not needed in the new process. However it has the\n"
339 "undesirable side effect of flushing buffers, so it's deprecated.\n"
340 "Use port-for-each instead.")
341 #define FUNC_NAME s_scm_close_all_ports_except
342 {
343 SCM p;
344 SCM_VALIDATE_REST_ARGUMENT (ports);
345
346 for (p = ports; !scm_is_null (p); p = SCM_CDR (p))
347 SCM_VALIDATE_OPPORT (SCM_ARG1, SCM_COERCE_OUTPORT (SCM_CAR (p)));
348
349 scm_c_port_for_each (maybe_close_port, ports);
350
351 return SCM_UNSPECIFIED;
352 }
353 #undef FUNC_NAME
354
355 SCM_DEFINE (scm_variable_set_name_hint, "variable-set-name-hint!", 2, 0, 0,
356 (SCM var, SCM hint),
357 "Do not use this function.")
358 #define FUNC_NAME s_scm_variable_set_name_hint
359 {
360 SCM_VALIDATE_VARIABLE (1, var);
361 SCM_VALIDATE_SYMBOL (2, hint);
362 scm_c_issue_deprecation_warning
363 ("'variable-set-name-hint!' is deprecated. Do not use it.");
364 return SCM_UNSPECIFIED;
365 }
366 #undef FUNC_NAME
367
368 SCM_DEFINE (scm_builtin_variable, "builtin-variable", 1, 0, 0,
369 (SCM name),
370 "Do not use this function.")
371 #define FUNC_NAME s_scm_builtin_variable
372 {
373 SCM_VALIDATE_SYMBOL (1,name);
374 scm_c_issue_deprecation_warning ("`builtin-variable' is deprecated. "
375 "Use module system operations instead.");
376 return scm_sym2var (name, SCM_BOOL_F, SCM_BOOL_T);
377 }
378 #undef FUNC_NAME
379
380 SCM
381 scm_makstr (size_t len, int dummy)
382 {
383 scm_c_issue_deprecation_warning
384 ("'scm_makstr' is deprecated. Use 'scm_c_make_string' instead.");
385 return scm_c_make_string (len, SCM_UNDEFINED);
386 }
387
388 SCM
389 scm_makfromstr (const char *src, size_t len, int dummy SCM_UNUSED)
390 {
391 scm_c_issue_deprecation_warning ("`scm_makfromstr' is deprecated. "
392 "Use `scm_from_locale_stringn' instead.");
393
394 return scm_from_locale_stringn (src, len);
395 }
396
397 SCM
398 scm_internal_with_fluids (SCM fluids, SCM values, SCM (*cproc) (), void *cdata)
399 {
400 scm_c_issue_deprecation_warning ("`scm_internal_with_fluids' is deprecated. "
401 "Use `scm_c_with_fluids' instead.");
402
403 return scm_c_with_fluids (fluids, values, cproc, cdata);
404 }
405
406 SCM
407 scm_make_gsubr (const char *name, int req, int opt, int rst, SCM (*fcn)())
408 {
409 scm_c_issue_deprecation_warning
410 ("`scm_make_gsubr' is deprecated. Use `scm_c_define_gsubr' instead.");
411
412 return scm_c_define_gsubr (name, req, opt, rst, fcn);
413 }
414
415 SCM
416 scm_make_gsubr_with_generic (const char *name,
417 int req, int opt, int rst,
418 SCM (*fcn)(), SCM *gf)
419 {
420 scm_c_issue_deprecation_warning
421 ("`scm_make_gsubr_with_generic' is deprecated. "
422 "Use `scm_c_define_gsubr_with_generic' instead.");
423
424 return scm_c_define_gsubr_with_generic (name, req, opt, rst, fcn, gf);
425 }
426
427 SCM
428 scm_create_hook (const char *name, int n_args)
429 {
430 scm_c_issue_deprecation_warning
431 ("'scm_create_hook' is deprecated. "
432 "Use 'scm_make_hook' and 'scm_c_define' instead.");
433 {
434 SCM hook = scm_make_hook (scm_from_int (n_args));
435 scm_c_define (name, hook);
436 return scm_permanent_object (hook);
437 }
438 }
439
440 SCM_DEFINE (scm_sloppy_memq, "sloppy-memq", 2, 0, 0,
441 (SCM x, SCM lst),
442 "This procedure behaves like @code{memq}, but does no type or error checking.\n"
443 "Its use is recommended only in writing Guile internals,\n"
444 "not for high-level Scheme programs.")
445 #define FUNC_NAME s_scm_sloppy_memq
446 {
447 scm_c_issue_deprecation_warning
448 ("'sloppy-memq' is deprecated. Use 'memq' instead.");
449
450 for(; scm_is_pair (lst); lst = SCM_CDR(lst))
451 {
452 if (scm_is_eq (SCM_CAR (lst), x))
453 return lst;
454 }
455 return lst;
456 }
457 #undef FUNC_NAME
458
459
460 SCM_DEFINE (scm_sloppy_memv, "sloppy-memv", 2, 0, 0,
461 (SCM x, SCM lst),
462 "This procedure behaves like @code{memv}, but does no type or error checking.\n"
463 "Its use is recommended only in writing Guile internals,\n"
464 "not for high-level Scheme programs.")
465 #define FUNC_NAME s_scm_sloppy_memv
466 {
467 scm_c_issue_deprecation_warning
468 ("'sloppy-memv' is deprecated. Use 'memv' instead.");
469
470 for(; scm_is_pair (lst); lst = SCM_CDR(lst))
471 {
472 if (! scm_is_false (scm_eqv_p (SCM_CAR (lst), x)))
473 return lst;
474 }
475 return lst;
476 }
477 #undef FUNC_NAME
478
479
480 SCM_DEFINE (scm_sloppy_member, "sloppy-member", 2, 0, 0,
481 (SCM x, SCM lst),
482 "This procedure behaves like @code{member}, but does no type or error checking.\n"
483 "Its use is recommended only in writing Guile internals,\n"
484 "not for high-level Scheme programs.")
485 #define FUNC_NAME s_scm_sloppy_member
486 {
487 scm_c_issue_deprecation_warning
488 ("'sloppy-member' is deprecated. Use 'member' instead.");
489
490 for(; scm_is_pair (lst); lst = SCM_CDR(lst))
491 {
492 if (! scm_is_false (scm_equal_p (SCM_CAR (lst), x)))
493 return lst;
494 }
495 return lst;
496 }
497 #undef FUNC_NAME
498
499 SCM_SYMBOL (scm_end_of_file_key, "end-of-file");
500
501 SCM_DEFINE (scm_read_and_eval_x, "read-and-eval!", 0, 1, 0,
502 (SCM port),
503 "Read a form from @var{port} (standard input by default), and evaluate it\n"
504 "(memoizing it in the process) in the top-level environment. If no data\n"
505 "is left to be read from @var{port}, an @code{end-of-file} error is\n"
506 "signalled.")
507 #define FUNC_NAME s_scm_read_and_eval_x
508 {
509 SCM form;
510
511 scm_c_issue_deprecation_warning
512 ("'read-and-eval!' is deprecated. Use 'read' and 'eval' instead.");
513
514 form = scm_read (port);
515 if (SCM_EOF_OBJECT_P (form))
516 scm_ithrow (scm_end_of_file_key, SCM_EOL, 1);
517 return scm_eval_x (form, scm_current_module ());
518 }
519 #undef FUNC_NAME
520
521 SCM
522 scm_make_subr_opt (const char *name, int type, SCM (*fcn) (), int set)
523 {
524 scm_c_issue_deprecation_warning
525 ("`scm_make_subr_opt' is deprecated. Use `scm_c_make_subr' or "
526 "`scm_c_define_subr' instead.");
527
528 if (set)
529 return scm_c_define_subr (name, type, fcn);
530 else
531 return scm_c_make_subr (name, type, fcn);
532 }
533
534 SCM
535 scm_make_subr (const char *name, int type, SCM (*fcn) ())
536 {
537 scm_c_issue_deprecation_warning
538 ("`scm_make_subr' is deprecated. Use `scm_c_define_subr' instead.");
539
540 return scm_c_define_subr (name, type, fcn);
541 }
542
543 SCM
544 scm_make_subr_with_generic (const char *name, int type, SCM (*fcn) (), SCM *gf)
545 {
546 scm_c_issue_deprecation_warning
547 ("`scm_make_subr_with_generic' is deprecated. Use "
548 "`scm_c_define_subr_with_generic' instead.");
549
550 return scm_c_define_subr_with_generic (name, type, fcn, gf);
551 }
552
553 /* Call thunk(closure) underneath a top-level error handler.
554 * If an error occurs, pass the exitval through err_filter and return it.
555 * If no error occurs, return the value of thunk.
556 */
557
558 #ifdef _UNICOS
559 typedef int setjmp_type;
560 #else
561 typedef long setjmp_type;
562 #endif
563
564 struct cce_handler_data {
565 SCM (*err_filter) ();
566 void *closure;
567 };
568
569 static SCM
570 invoke_err_filter (void *d, SCM tag, SCM args)
571 {
572 struct cce_handler_data *data = (struct cce_handler_data *)d;
573 return data->err_filter (SCM_BOOL_F, data->closure);
574 }
575
576 SCM
577 scm_call_catching_errors (SCM (*thunk)(), SCM (*err_filter)(), void *closure)
578 {
579 scm_c_issue_deprecation_warning
580 ("'scm_call_catching_errors' is deprecated. "
581 "Use 'scm_internal_catch' instead.");
582
583 {
584 struct cce_handler_data data;
585 data.err_filter = err_filter;
586 data.closure = closure;
587 return scm_internal_catch (SCM_BOOL_T,
588 (scm_t_catch_body)thunk, closure,
589 (scm_t_catch_handler)invoke_err_filter, &data);
590 }
591 }
592
593 long
594 scm_make_smob_type_mfpe (char *name, size_t size,
595 SCM (*mark) (SCM),
596 size_t (*free) (SCM),
597 int (*print) (SCM, SCM, scm_print_state *),
598 SCM (*equalp) (SCM, SCM))
599 {
600 scm_c_issue_deprecation_warning
601 ("'scm_make_smob_type_mfpe' is deprecated. "
602 "Use 'scm_make_smob_type' plus 'scm_set_smob_*' instead.");
603
604 {
605 long answer = scm_make_smob_type (name, size);
606 scm_set_smob_mfpe (answer, mark, free, print, equalp);
607 return answer;
608 }
609 }
610
611 void
612 scm_set_smob_mfpe (long tc,
613 SCM (*mark) (SCM),
614 size_t (*free) (SCM),
615 int (*print) (SCM, SCM, scm_print_state *),
616 SCM (*equalp) (SCM, SCM))
617 {
618 scm_c_issue_deprecation_warning
619 ("'scm_set_smob_mfpe' is deprecated. "
620 "Use 'scm_set_smob_mark' instead, for example.");
621
622 if (mark) scm_set_smob_mark (tc, mark);
623 if (free) scm_set_smob_free (tc, free);
624 if (print) scm_set_smob_print (tc, print);
625 if (equalp) scm_set_smob_equalp (tc, equalp);
626 }
627
628 SCM
629 scm_read_0str (char *expr)
630 {
631 scm_c_issue_deprecation_warning
632 ("scm_read_0str is deprecated. Use scm_c_read_string instead.");
633
634 return scm_c_read_string (expr);
635 }
636
637 SCM
638 scm_eval_0str (const char *expr)
639 {
640 scm_c_issue_deprecation_warning
641 ("scm_eval_0str is deprecated. Use scm_c_eval_string instead.");
642
643 return scm_c_eval_string (expr);
644 }
645
646 SCM
647 scm_strprint_obj (SCM obj)
648 {
649 scm_c_issue_deprecation_warning
650 ("scm_strprint_obj is deprecated. Use scm_object_to_string instead.");
651 return scm_object_to_string (obj, SCM_UNDEFINED);
652 }
653
654 SCM
655 scm_sym2ovcell_soft (SCM sym, SCM obarray)
656 {
657 SCM lsym, z;
658 size_t hash = scm_i_symbol_hash (sym) % SCM_VECTOR_LENGTH (obarray);
659
660 scm_c_issue_deprecation_warning ("`scm_sym2ovcell_soft' is deprecated. "
661 "Use hashtables instead.");
662
663 SCM_REDEFER_INTS;
664 for (lsym = SCM_VECTOR_REF (obarray, hash);
665 SCM_NIMP (lsym);
666 lsym = SCM_CDR (lsym))
667 {
668 z = SCM_CAR (lsym);
669 if (scm_is_eq (SCM_CAR (z), sym))
670 {
671 SCM_REALLOW_INTS;
672 return z;
673 }
674 }
675 SCM_REALLOW_INTS;
676 return SCM_BOOL_F;
677 }
678
679
680 SCM
681 scm_sym2ovcell (SCM sym, SCM obarray)
682 #define FUNC_NAME "scm_sym2ovcell"
683 {
684 SCM answer;
685
686 scm_c_issue_deprecation_warning ("`scm_sym2ovcell' is deprecated. "
687 "Use hashtables instead.");
688
689 answer = scm_sym2ovcell_soft (sym, obarray);
690 if (scm_is_true (answer))
691 return answer;
692 SCM_MISC_ERROR ("uninterned symbol: ~S", scm_list_1 (sym));
693 return SCM_UNSPECIFIED; /* not reached */
694 }
695 #undef FUNC_NAME
696
697
698 /* Intern a symbol whose name is the LEN characters at NAME in OBARRAY.
699
700 OBARRAY should be a vector of lists, indexed by the name's hash
701 value, modulo OBARRAY's length. Each list has the form
702 ((SYMBOL . VALUE) ...), where SYMBOL is a symbol, and VALUE is the
703 value associated with that symbol (in the current module? in the
704 system module?)
705
706 To "intern" a symbol means: if OBARRAY already contains a symbol by
707 that name, return its (SYMBOL . VALUE) pair; otherwise, create a
708 new symbol, add the pair (SYMBOL . SCM_UNDEFINED) to the
709 appropriate list of the OBARRAY, and return the pair.
710
711 If softness is non-zero, don't create a symbol if it isn't already
712 in OBARRAY; instead, just return #f.
713
714 If OBARRAY is SCM_BOOL_F, create a symbol listed in no obarray and
715 return (SYMBOL . SCM_UNDEFINED). */
716
717
718 SCM
719 scm_intern_obarray_soft (const char *name,size_t len,SCM obarray,unsigned int softness)
720 {
721 SCM symbol = scm_from_locale_symboln (name, len);
722 size_t raw_hash = scm_i_symbol_hash (symbol);
723 size_t hash;
724 SCM lsym;
725
726 scm_c_issue_deprecation_warning ("`scm_intern_obarray_soft' is deprecated. "
727 "Use hashtables instead.");
728
729 if (scm_is_false (obarray))
730 {
731 if (softness)
732 return SCM_BOOL_F;
733 else
734 return scm_cons (symbol, SCM_UNDEFINED);
735 }
736
737 hash = raw_hash % SCM_VECTOR_LENGTH (obarray);
738
739 for (lsym = SCM_VECTOR_REF(obarray, hash);
740 SCM_NIMP (lsym); lsym = SCM_CDR (lsym))
741 {
742 SCM a = SCM_CAR (lsym);
743 SCM z = SCM_CAR (a);
744 if (scm_is_eq (z, symbol))
745 return a;
746 }
747
748 if (softness)
749 {
750 return SCM_BOOL_F;
751 }
752 else
753 {
754 SCM cell = scm_cons (symbol, SCM_UNDEFINED);
755 SCM slot = SCM_VECTOR_REF (obarray, hash);
756
757 SCM_VECTOR_SET (obarray, hash, scm_cons (cell, slot));
758
759 return cell;
760 }
761 }
762
763
764 SCM
765 scm_intern_obarray (const char *name,size_t len,SCM obarray)
766 {
767 scm_c_issue_deprecation_warning ("`scm_intern_obarray' is deprecated. "
768 "Use hashtables instead.");
769
770 return scm_intern_obarray_soft (name, len, obarray, 0);
771 }
772
773 /* Lookup the value of the symbol named by the nul-terminated string
774 NAME in the current module. */
775 SCM
776 scm_symbol_value0 (const char *name)
777 {
778 scm_c_issue_deprecation_warning ("`scm_symbol_value0' is deprecated. "
779 "Use `scm_lookup' instead.");
780
781 return scm_variable_ref (scm_c_lookup (name));
782 }
783
784 SCM_DEFINE (scm_string_to_obarray_symbol, "string->obarray-symbol", 2, 1, 0,
785 (SCM o, SCM s, SCM softp),
786 "Intern a new symbol in @var{obarray}, a symbol table, with name\n"
787 "@var{string}.\n\n"
788 "If @var{obarray} is @code{#f}, use the default system symbol table. If\n"
789 "@var{obarray} is @code{#t}, the symbol should not be interned in any\n"
790 "symbol table; merely return the pair (@var{symbol}\n"
791 ". @var{#<undefined>}).\n\n"
792 "The @var{soft?} argument determines whether new symbol table entries\n"
793 "should be created when the specified symbol is not already present in\n"
794 "@var{obarray}. If @var{soft?} is specified and is a true value, then\n"
795 "new entries should not be added for symbols not already present in the\n"
796 "table; instead, simply return @code{#f}.")
797 #define FUNC_NAME s_scm_string_to_obarray_symbol
798 {
799 SCM vcell;
800 SCM answer;
801 int softness;
802
803 SCM_VALIDATE_STRING (2, s);
804 SCM_ASSERT (scm_is_bool (o) || SCM_VECTORP (o), o, SCM_ARG1, FUNC_NAME);
805
806 scm_c_issue_deprecation_warning ("`string->obarray-symbol' is deprecated. "
807 "Use hashtables instead.");
808
809 softness = (!SCM_UNBNDP (softp) && scm_is_true(softp));
810 /* iron out some screwy calling conventions */
811 if (scm_is_false (o))
812 {
813 /* nothing interesting to do here. */
814 return scm_string_to_symbol (s);
815 }
816 else if (scm_is_eq (o, SCM_BOOL_T))
817 o = SCM_BOOL_F;
818
819 vcell = scm_intern_obarray_soft (scm_i_string_chars (s),
820 scm_i_string_length (s),
821 o,
822 softness);
823 if (scm_is_false (vcell))
824 return vcell;
825 answer = SCM_CAR (vcell);
826 return answer;
827 }
828 #undef FUNC_NAME
829
830 SCM_DEFINE (scm_intern_symbol, "intern-symbol", 2, 0, 0,
831 (SCM o, SCM s),
832 "Add a new symbol to @var{obarray} with name @var{string}, bound to an\n"
833 "unspecified initial value. The symbol table is not modified if a symbol\n"
834 "with this name is already present.")
835 #define FUNC_NAME s_scm_intern_symbol
836 {
837 size_t hval;
838 SCM_VALIDATE_SYMBOL (2,s);
839 if (scm_is_false (o))
840 return SCM_UNSPECIFIED;
841
842 scm_c_issue_deprecation_warning ("`intern-symbol' is deprecated. "
843 "Use hashtables instead.");
844
845 SCM_VALIDATE_VECTOR (1,o);
846 hval = scm_i_symbol_hash (s) % SCM_VECTOR_LENGTH (o);
847 /* If the symbol is already interned, simply return. */
848 SCM_REDEFER_INTS;
849 {
850 SCM lsym;
851 SCM sym;
852 for (lsym = SCM_VECTOR_REF (o, hval);
853 SCM_NIMP (lsym);
854 lsym = SCM_CDR (lsym))
855 {
856 sym = SCM_CAR (lsym);
857 if (scm_is_eq (SCM_CAR (sym), s))
858 {
859 SCM_REALLOW_INTS;
860 return SCM_UNSPECIFIED;
861 }
862 }
863 SCM_VECTOR_SET (o, hval,
864 scm_acons (s, SCM_UNDEFINED,
865 SCM_VECTOR_REF (o, hval)));
866 }
867 SCM_REALLOW_INTS;
868 return SCM_UNSPECIFIED;
869 }
870 #undef FUNC_NAME
871
872 SCM_DEFINE (scm_unintern_symbol, "unintern-symbol", 2, 0, 0,
873 (SCM o, SCM s),
874 "Remove the symbol with name @var{string} from @var{obarray}. This\n"
875 "function returns @code{#t} if the symbol was present and @code{#f}\n"
876 "otherwise.")
877 #define FUNC_NAME s_scm_unintern_symbol
878 {
879 size_t hval;
880
881 scm_c_issue_deprecation_warning ("`unintern-symbol' is deprecated. "
882 "Use hashtables instead.");
883
884 SCM_VALIDATE_SYMBOL (2,s);
885 if (scm_is_false (o))
886 return SCM_BOOL_F;
887 SCM_VALIDATE_VECTOR (1,o);
888 hval = scm_i_symbol_hash (s) % SCM_VECTOR_LENGTH (o);
889 SCM_DEFER_INTS;
890 {
891 SCM lsym_follow;
892 SCM lsym;
893 SCM sym;
894 for (lsym = SCM_VECTOR_REF (o, hval), lsym_follow = SCM_BOOL_F;
895 SCM_NIMP (lsym);
896 lsym_follow = lsym, lsym = SCM_CDR (lsym))
897 {
898 sym = SCM_CAR (lsym);
899 if (scm_is_eq (SCM_CAR (sym), s))
900 {
901 /* Found the symbol to unintern. */
902 if (scm_is_false (lsym_follow))
903 SCM_VECTOR_SET (o, hval, lsym);
904 else
905 SCM_SETCDR (lsym_follow, SCM_CDR(lsym));
906 SCM_ALLOW_INTS;
907 return SCM_BOOL_T;
908 }
909 }
910 }
911 SCM_ALLOW_INTS;
912 return SCM_BOOL_F;
913 }
914 #undef FUNC_NAME
915
916 SCM_DEFINE (scm_symbol_binding, "symbol-binding", 2, 0, 0,
917 (SCM o, SCM s),
918 "Look up in @var{obarray} the symbol whose name is @var{string}, and\n"
919 "return the value to which it is bound. If @var{obarray} is @code{#f},\n"
920 "use the global symbol table. If @var{string} is not interned in\n"
921 "@var{obarray}, an error is signalled.")
922 #define FUNC_NAME s_scm_symbol_binding
923 {
924 SCM vcell;
925
926 scm_c_issue_deprecation_warning ("`symbol-binding' is deprecated. "
927 "Use hashtables instead.");
928
929 SCM_VALIDATE_SYMBOL (2,s);
930 if (scm_is_false (o))
931 return scm_variable_ref (scm_lookup (s));
932 SCM_VALIDATE_VECTOR (1,o);
933 vcell = scm_sym2ovcell (s, o);
934 return SCM_CDR(vcell);
935 }
936 #undef FUNC_NAME
937
938 #if 0
939 SCM_DEFINE (scm_symbol_interned_p, "symbol-interned?", 2, 0, 0,
940 (SCM o, SCM s),
941 "Return @code{#t} if @var{obarray} contains a symbol with name\n"
942 "@var{string}, and @code{#f} otherwise.")
943 #define FUNC_NAME s_scm_symbol_interned_p
944 {
945 SCM vcell;
946
947 scm_c_issue_deprecation_warning ("`symbol-interned?' is deprecated. "
948 "Use hashtables instead.");
949
950 SCM_VALIDATE_SYMBOL (2,s);
951 if (scm_is_false (o))
952 {
953 SCM var = scm_sym2var (s, SCM_BOOL_F, SCM_BOOL_F);
954 if (var != SCM_BOOL_F)
955 return SCM_BOOL_T;
956 return SCM_BOOL_F;
957 }
958 SCM_VALIDATE_VECTOR (1,o);
959 vcell = scm_sym2ovcell_soft (s, o);
960 return (SCM_NIMP(vcell)
961 ? SCM_BOOL_T
962 : SCM_BOOL_F);
963 }
964 #undef FUNC_NAME
965 #endif
966
967 SCM_DEFINE (scm_symbol_bound_p, "symbol-bound?", 2, 0, 0,
968 (SCM o, SCM s),
969 "Return @code{#t} if @var{obarray} contains a symbol with name\n"
970 "@var{string} bound to a defined value. This differs from\n"
971 "@var{symbol-interned?} in that the mere mention of a symbol\n"
972 "usually causes it to be interned; @code{symbol-bound?}\n"
973 "determines whether a symbol has been given any meaningful\n"
974 "value.")
975 #define FUNC_NAME s_scm_symbol_bound_p
976 {
977 SCM vcell;
978
979 scm_c_issue_deprecation_warning ("`symbol-bound?' is deprecated. "
980 "Use hashtables instead.");
981
982 SCM_VALIDATE_SYMBOL (2,s);
983 if (scm_is_false (o))
984 {
985 SCM var = scm_sym2var (s, SCM_BOOL_F, SCM_BOOL_F);
986 if (SCM_VARIABLEP(var) && !SCM_UNBNDP(SCM_VARIABLE_REF(var)))
987 return SCM_BOOL_T;
988 return SCM_BOOL_F;
989 }
990 SCM_VALIDATE_VECTOR (1,o);
991 vcell = scm_sym2ovcell_soft (s, o);
992 return scm_from_bool (SCM_NIMP (vcell) && !SCM_UNBNDP (SCM_CDR (vcell)));
993 }
994 #undef FUNC_NAME
995
996
997 SCM_DEFINE (scm_symbol_set_x, "symbol-set!", 3, 0, 0,
998 (SCM o, SCM s, SCM v),
999 "Find the symbol in @var{obarray} whose name is @var{string}, and rebind\n"
1000 "it to @var{value}. An error is signalled if @var{string} is not present\n"
1001 "in @var{obarray}.")
1002 #define FUNC_NAME s_scm_symbol_set_x
1003 {
1004 SCM vcell;
1005
1006 scm_c_issue_deprecation_warning ("`symbol-set!' is deprecated. "
1007 "Use the module system instead.");
1008
1009 SCM_VALIDATE_SYMBOL (2,s);
1010 if (scm_is_false (o))
1011 {
1012 scm_define (s, v);
1013 return SCM_UNSPECIFIED;
1014 }
1015 SCM_VALIDATE_VECTOR (1,o);
1016 vcell = scm_sym2ovcell (s, o);
1017 SCM_SETCDR (vcell, v);
1018 return SCM_UNSPECIFIED;
1019 }
1020 #undef FUNC_NAME
1021
1022 #define MAX_PREFIX_LENGTH 30
1023
1024 static int gentemp_counter;
1025
1026 SCM_DEFINE (scm_gentemp, "gentemp", 0, 2, 0,
1027 (SCM prefix, SCM obarray),
1028 "Create a new symbol with a name unique in an obarray.\n"
1029 "The name is constructed from an optional string @var{prefix}\n"
1030 "and a counter value. The default prefix is @code{t}. The\n"
1031 "@var{obarray} is specified as a second optional argument.\n"
1032 "Default is the system obarray where all normal symbols are\n"
1033 "interned. The counter is increased by 1 at each\n"
1034 "call. There is no provision for resetting the counter.")
1035 #define FUNC_NAME s_scm_gentemp
1036 {
1037 char buf[MAX_PREFIX_LENGTH + SCM_INTBUFLEN];
1038 char *name = buf;
1039 int len, n_digits;
1040
1041 scm_c_issue_deprecation_warning ("`gentemp' is deprecated. "
1042 "Use `gensym' instead.");
1043
1044 if (SCM_UNBNDP (prefix))
1045 {
1046 name[0] = 't';
1047 len = 1;
1048 }
1049 else
1050 {
1051 SCM_VALIDATE_STRING (1, prefix);
1052 len = scm_i_string_length (prefix);
1053 if (len > MAX_PREFIX_LENGTH)
1054 name = SCM_MUST_MALLOC (MAX_PREFIX_LENGTH + SCM_INTBUFLEN);
1055 strncpy (name, scm_i_string_chars (prefix), len);
1056 }
1057
1058 if (SCM_UNBNDP (obarray))
1059 return scm_gensym (prefix);
1060 else
1061 SCM_ASSERT ((scm_is_vector (obarray) || SCM_I_WVECTP (obarray)),
1062 obarray,
1063 SCM_ARG2,
1064 FUNC_NAME);
1065 do
1066 n_digits = scm_iint2str (gentemp_counter++, 10, &name[len]);
1067 while (scm_is_true (scm_intern_obarray_soft (name,
1068 len + n_digits,
1069 obarray,
1070 1)));
1071 {
1072 SCM vcell = scm_intern_obarray_soft (name,
1073 len + n_digits,
1074 obarray,
1075 0);
1076 if (name != buf)
1077 scm_must_free (name);
1078 return SCM_CAR (vcell);
1079 }
1080 }
1081 #undef FUNC_NAME
1082
1083 SCM
1084 SCM_MAKINUM (scm_t_signed_bits val)
1085 {
1086 scm_c_issue_deprecation_warning
1087 ("SCM_MAKINUM is deprecated. Use scm_from_int or similar instead.");
1088 return SCM_I_MAKINUM (val);
1089 }
1090
1091 int
1092 SCM_INUMP (SCM obj)
1093 {
1094 scm_c_issue_deprecation_warning
1095 ("SCM_INUMP is deprecated. Use scm_is_integer or similar instead.");
1096 return SCM_I_INUMP (obj);
1097 }
1098
1099 scm_t_signed_bits
1100 SCM_INUM (SCM obj)
1101 {
1102 scm_c_issue_deprecation_warning
1103 ("SCM_INUM is deprecated. Use scm_to_int or similar instead.");
1104 return scm_to_intmax (obj);
1105 }
1106
1107 char *
1108 scm_c_string2str (SCM obj, char *str, size_t *lenp)
1109 {
1110 scm_c_issue_deprecation_warning
1111 ("scm_c_string2str is deprecated. Use scm_to_locale_stringbuf or similar instead.");
1112
1113 if (str == NULL)
1114 {
1115 char *result = scm_to_locale_string (obj);
1116 if (lenp)
1117 *lenp = scm_i_string_length (obj);
1118 return result;
1119 }
1120 else
1121 {
1122 /* Pray that STR is large enough.
1123 */
1124 size_t len = scm_to_locale_stringbuf (obj, str, SCM_I_SIZE_MAX);
1125 str[len] = '\0';
1126 if (lenp)
1127 *lenp = len;
1128 return str;
1129 }
1130 }
1131
1132 char *
1133 scm_c_substring2str (SCM obj, char *str, size_t start, size_t len)
1134 {
1135 scm_c_issue_deprecation_warning
1136 ("scm_c_substring2str is deprecated. Use scm_substring plus scm_to_locale_stringbuf instead.");
1137
1138 if (start)
1139 obj = scm_substring (obj, scm_from_size_t (start), SCM_UNDEFINED);
1140
1141 scm_to_locale_stringbuf (obj, str, len);
1142 return str;
1143 }
1144
1145 /* Converts the given Scheme symbol OBJ into a C string, containing a copy
1146 of OBJ's content with a trailing null byte. If LENP is non-NULL, set
1147 *LENP to the string's length.
1148
1149 When STR is non-NULL it receives the copy and is returned by the function,
1150 otherwise new memory is allocated and the caller is responsible for
1151 freeing it via free(). If out of memory, NULL is returned.
1152
1153 Note that Scheme symbols may contain arbitrary data, including null
1154 characters. This means that null termination is not a reliable way to
1155 determine the length of the returned value. However, the function always
1156 copies the complete contents of OBJ, and sets *LENP to the length of the
1157 scheme symbol (if LENP is non-null). */
1158 char *
1159 scm_c_symbol2str (SCM obj, char *str, size_t *lenp)
1160 {
1161 return scm_c_string2str (scm_symbol_to_string (obj), str, lenp);
1162 }
1163
1164 double
1165 scm_truncate (double x)
1166 {
1167 scm_c_issue_deprecation_warning
1168 ("scm_truncate is deprecated. Use scm_c_truncate instead.");
1169 return scm_c_truncate (x);
1170 }
1171
1172 double
1173 scm_round (double x)
1174 {
1175 scm_c_issue_deprecation_warning
1176 ("scm_round is deprecated. Use scm_c_round instead.");
1177 return scm_c_round (x);
1178 }
1179
1180 char *
1181 SCM_SYMBOL_CHARS (SCM sym)
1182 {
1183 scm_c_issue_deprecation_warning
1184 ("SCM_SYMBOL_CHARS is deprecated. Use scm_symbol_to_string.");
1185
1186 return (char *)scm_i_symbol_chars (sym);
1187 }
1188
1189 size_t
1190 SCM_SYMBOL_LENGTH (SCM sym)
1191 {
1192 scm_c_issue_deprecation_warning
1193 ("SCM_SYMBOL_LENGTH is deprecated. Use scm_symbol_to_string.");
1194 return scm_i_symbol_length (sym);
1195 }
1196
1197 int
1198 SCM_KEYWORDP (SCM obj)
1199 {
1200 scm_c_issue_deprecation_warning
1201 ("SCM_KEYWORDP is deprecated. Use scm_is_keyword instead.");
1202 return scm_is_keyword (obj);
1203 }
1204
1205 SCM
1206 SCM_KEYWORDSYM (SCM keyword)
1207 {
1208 scm_c_issue_deprecation_warning
1209 ("SCM_KEYWORDSYM is deprecated. See scm_keyword_to_symbol instead.");
1210 return scm_keyword_dash_symbol (keyword);
1211 }
1212
1213 int
1214 SCM_VECTORP (SCM x)
1215 {
1216 scm_c_issue_deprecation_warning
1217 ("SCM_VECTORP is deprecated. Use scm_is_vector instead.");
1218 return SCM_I_IS_VECTOR (x);
1219 }
1220
1221 unsigned long
1222 SCM_VECTOR_LENGTH (SCM x)
1223 {
1224 scm_c_issue_deprecation_warning
1225 ("SCM_VECTOR_LENGTH is deprecated. Use scm_c_vector_length instead.");
1226 return SCM_I_VECTOR_LENGTH (x);
1227 }
1228
1229 const SCM *
1230 SCM_VELTS (SCM x)
1231 {
1232 scm_c_issue_deprecation_warning
1233 ("SCM_VELTS is deprecated. Use scm_vector_elements instead.");
1234 return SCM_I_VECTOR_ELTS (x);
1235 }
1236
1237 SCM *
1238 SCM_WRITABLE_VELTS (SCM x)
1239 {
1240 scm_c_issue_deprecation_warning
1241 ("SCM_WRITABLE_VELTS is deprecated. "
1242 "Use scm_vector_writable_elements instead.");
1243 return SCM_I_VECTOR_WELTS (x);
1244 }
1245
1246 SCM
1247 SCM_VECTOR_REF (SCM x, size_t idx)
1248 {
1249 scm_c_issue_deprecation_warning
1250 ("SCM_VECTOR_REF is deprecated. "
1251 "Use scm_c_vector_ref or scm_vector_elements instead.");
1252 return scm_c_vector_ref (x, idx);
1253 }
1254
1255 void
1256 SCM_VECTOR_SET (SCM x, size_t idx, SCM val)
1257 {
1258 scm_c_issue_deprecation_warning
1259 ("SCM_VECTOR_SET is deprecated. "
1260 "Use scm_c_vector_set_x or scm_vector_writable_elements instead.");
1261 scm_c_vector_set_x (x, idx, val);
1262 }
1263
1264 SCM
1265 scm_vector_equal_p (SCM x, SCM y)
1266 {
1267 scm_c_issue_deprecation_warning
1268 ("scm_vector_euqal_p is deprecated. "
1269 "Use scm_equal_p instead.");
1270 return scm_equal_p (x, y);
1271 }
1272
1273 void
1274 scm_i_init_deprecated ()
1275 {
1276 #include "libguile/deprecated.x"
1277 }
1278
1279 #endif