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