*** empty log message ***
[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
5/* Copyright (C) 2003 Free Software Foundation, Inc.
6 *
73be1d9e
MV
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.
19e2247d 11 *
73be1d9e 12 * This library is distributed in the hope that it will be useful,
19e2247d 13 * but 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
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
19e2247d
MV
21
22#include "libguile/_scm.h"
23#include "libguile/deprecated.h"
55d30fac 24#include "libguile/deprecation.h"
19e2247d
MV
25#include "libguile/snarf.h"
26#include "libguile/validate.h"
27#include "libguile/strings.h"
28#include "libguile/strop.h"
a0454d72
MV
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"
965445d4
MV
39#include "libguile/eq.h"
40#include "libguile/read.h"
4abecea8
MV
41#include "libguile/strports.h"
42#include "libguile/smob.h"
19e2247d 43
55d30fac
MV
44#include <stdio.h>
45#include <string.h>
46
19e2247d
MV
47#if (SCM_ENABLE_DEPRECATED == 1)
48
49SCM_REGISTER_PROC(s_substring_move_left_x, "substring-move-left!", 5, 0, 0, scm_substring_move_x);
50
51SCM_REGISTER_PROC(s_substring_move_right_x, "substring-move-right!", 5, 0, 0, scm_substring_move_x);
52
55d30fac
MV
53SCM
54scm_wta (SCM arg, const char *pos, const char *s_subr)
55{
56 if (!s_subr || !*s_subr)
57 s_subr = NULL;
58 if ((~0x1fL) & (long) pos)
59 {
60 /* error string supplied. */
61 scm_misc_error (s_subr, pos, scm_list_1 (arg));
62 }
63 else
64 {
65 /* numerical error code. */
66 scm_t_bits error = (scm_t_bits) pos;
67
68 switch (error)
69 {
70 case SCM_ARGn:
71 scm_wrong_type_arg (s_subr, 0, arg);
72 case SCM_ARG1:
73 scm_wrong_type_arg (s_subr, 1, arg);
74 case SCM_ARG2:
75 scm_wrong_type_arg (s_subr, 2, arg);
76 case SCM_ARG3:
77 scm_wrong_type_arg (s_subr, 3, arg);
78 case SCM_ARG4:
79 scm_wrong_type_arg (s_subr, 4, arg);
80 case SCM_ARG5:
81 scm_wrong_type_arg (s_subr, 5, arg);
82 case SCM_ARG6:
83 scm_wrong_type_arg (s_subr, 6, arg);
84 case SCM_ARG7:
85 scm_wrong_type_arg (s_subr, 7, arg);
86 case SCM_WNA:
87 scm_wrong_num_args (arg);
88 case SCM_OUTOFRANGE:
89 scm_out_of_range (s_subr, arg);
90 case SCM_NALLOC:
91 scm_memory_error (s_subr);
92 default:
93 /* this shouldn't happen. */
94 scm_misc_error (s_subr, "Unknown error", SCM_EOL);
95 }
96 }
97 return SCM_UNSPECIFIED;
98}
99
100/* Module registry
101 */
102
103/* We can't use SCM objects here. One should be able to call
104 SCM_REGISTER_MODULE from a C++ constructor for a static
105 object. This happens before main and thus before libguile is
106 initialized. */
107
108struct moddata {
109 struct moddata *link;
110 char *module_name;
111 void *init_func;
112};
113
114static struct moddata *registered_mods = NULL;
115
116void
117scm_register_module_xxx (char *module_name, void *init_func)
118{
119 struct moddata *md;
120
121 scm_c_issue_deprecation_warning
122 ("`scm_register_module_xxx' is deprecated. Use extensions instead.");
123
124 /* XXX - should we (and can we) DEFER_INTS here? */
125
126 for (md = registered_mods; md; md = md->link)
127 if (!strcmp (md->module_name, module_name))
128 {
129 md->init_func = init_func;
130 return;
131 }
132
133 md = (struct moddata *) malloc (sizeof (struct moddata));
134 if (md == NULL)
135 {
136 fprintf (stderr,
137 "guile: can't register module (%s): not enough memory",
138 module_name);
139 return;
140 }
141
142 md->module_name = module_name;
143 md->init_func = init_func;
144 md->link = registered_mods;
145 registered_mods = md;
146}
147
148SCM_DEFINE (scm_registered_modules, "c-registered-modules", 0, 0, 0,
149 (),
150 "Return a list of the object code modules that have been imported into\n"
151 "the current Guile process. Each element of the list is a pair whose\n"
152 "car is the name of the module, and whose cdr is the function handle\n"
153 "for that module's initializer function. The name is the string that\n"
154 "has been passed to scm_register_module_xxx.")
155#define FUNC_NAME s_scm_registered_modules
156{
157 SCM res;
158 struct moddata *md;
159
160 res = SCM_EOL;
161 for (md = registered_mods; md; md = md->link)
162 res = scm_cons (scm_cons (scm_makfrom0str (md->module_name),
163 scm_ulong2num ((unsigned long) md->init_func)),
164 res);
165 return res;
166}
167#undef FUNC_NAME
168
169SCM_DEFINE (scm_clear_registered_modules, "c-clear-registered-modules", 0, 0, 0,
170 (),
171 "Destroy the list of modules registered with the current Guile process.\n"
172 "The return value is unspecified. @strong{Warning:} this function does\n"
173 "not actually unlink or deallocate these modules, but only destroys the\n"
174 "records of which modules have been loaded. It should therefore be used\n"
175 "only by module bookkeeping operations.")
176#define FUNC_NAME s_scm_clear_registered_modules
177{
178 struct moddata *md1, *md2;
179
180 SCM_DEFER_INTS;
181
182 for (md1 = registered_mods; md1; md1 = md2)
183 {
184 md2 = md1->link;
185 free (md1);
186 }
187 registered_mods = NULL;
188
189 SCM_ALLOW_INTS;
190 return SCM_UNSPECIFIED;
191}
192#undef FUNC_NAME
193
a0454d72
MV
194void
195scm_remember (SCM *ptr)
196{
197 scm_c_issue_deprecation_warning ("`scm_remember' is deprecated. "
198 "Use the `scm_remember_upto_here*' family of functions instead.");
199}
200
201SCM
202scm_protect_object (SCM obj)
203{
204 scm_c_issue_deprecation_warning ("`scm_protect_object' is deprecated. "
205 "Use `scm_gc_protect_object' instead.");
206 return scm_gc_protect_object (obj);
207}
208
209SCM
210scm_unprotect_object (SCM obj)
211{
212 scm_c_issue_deprecation_warning ("`scm_unprotect_object' is deprecated. "
213 "Use `scm_gc_unprotect_object' instead.");
214 return scm_gc_unprotect_object (obj);
215}
216
217SCM_SYMBOL (scm_sym_app, "app");
218SCM_SYMBOL (scm_sym_modules, "modules");
219static SCM module_prefix = SCM_BOOL_F;
220static SCM make_modules_in_var;
221static SCM beautify_user_module_x_var;
222static SCM try_module_autoload_var;
223
224static void
225init_module_stuff ()
226{
227#define PERM(x) scm_permanent_object(x)
228
229 if (module_prefix == SCM_BOOL_F)
230 {
231 module_prefix = PERM (scm_list_2 (scm_sym_app, scm_sym_modules));
232 make_modules_in_var = PERM (scm_c_lookup ("make-modules-in"));
233 beautify_user_module_x_var =
234 PERM (scm_c_lookup ("beautify-user-module!"));
235 try_module_autoload_var = PERM (scm_c_lookup ("try-module-autoload"));
236 }
237}
238
239SCM
240scm_the_root_module ()
241{
242 init_module_stuff ();
243 scm_c_issue_deprecation_warning ("`scm_the_root_module' is deprecated. "
244 "Use `scm_c_resolve_module (\"guile\")' "
245 "instead.");
246
247 return scm_c_resolve_module ("guile");
248}
249
250static SCM
251scm_module_full_name (SCM name)
252{
253 init_module_stuff ();
254 if (SCM_EQ_P (SCM_CAR (name), scm_sym_app))
255 return name;
256 else
257 return scm_append (scm_list_2 (module_prefix, name));
258}
259
260SCM
261scm_make_module (SCM name)
262{
263 init_module_stuff ();
264 scm_c_issue_deprecation_warning ("`scm_make_module' is deprecated. "
265 "Use `scm_c_define_module instead.");
266
267 return scm_call_2 (SCM_VARIABLE_REF (make_modules_in_var),
268 scm_the_root_module (),
269 scm_module_full_name (name));
270}
271
272SCM
273scm_ensure_user_module (SCM module)
274{
275 init_module_stuff ();
276 scm_c_issue_deprecation_warning ("`scm_ensure_user_module' is deprecated. "
277 "Use `scm_c_define_module instead.");
278
279 scm_call_1 (SCM_VARIABLE_REF (beautify_user_module_x_var), module);
280 return SCM_UNSPECIFIED;
281}
282
283SCM
284scm_load_scheme_module (SCM name)
285{
286 init_module_stuff ();
287 scm_c_issue_deprecation_warning ("`scm_load_scheme_module' is deprecated. "
288 "Use `scm_c_resolve_module instead.");
289
290 return scm_call_1 (SCM_VARIABLE_REF (try_module_autoload_var), name);
291}
292
293/* This is implemented in C solely for SCM_COERCE_OUTPORT ... */
294
295static void
296maybe_close_port (void *data, SCM port)
297{
298 SCM except = (SCM)data;
299
300 while (!SCM_NULLP (except))
301 {
302 SCM p = SCM_COERCE_OUTPORT (SCM_CAR (except));
303 if (SCM_EQ_P (p, port))
304 return;
305 except = SCM_CDR (except);
306 }
307
308 scm_close_port (port);
309}
310
311SCM_DEFINE (scm_close_all_ports_except, "close-all-ports-except", 0, 0, 1,
312 (SCM ports),
313 "[DEPRECATED] Close all open file ports used by the interpreter\n"
314 "except for those supplied as arguments. This procedure\n"
315 "was intended to be used before an exec call to close file descriptors\n"
316 "which are not needed in the new process. However it has the\n"
317 "undesirable side effect of flushing buffers, so it's deprecated.\n"
318 "Use port-for-each instead.")
319#define FUNC_NAME s_scm_close_all_ports_except
320{
321 SCM p;
322 SCM_VALIDATE_REST_ARGUMENT (ports);
323
324 for (p = ports; !SCM_NULLP (p); p = SCM_CDR (p))
325 SCM_VALIDATE_OPPORT (SCM_ARG1, SCM_COERCE_OUTPORT (SCM_CAR (p)));
326
327 scm_c_port_for_each (maybe_close_port, ports);
328
329 return SCM_UNSPECIFIED;
330}
331#undef FUNC_NAME
55d30fac 332
965445d4
MV
333SCM_DEFINE (scm_variable_set_name_hint, "variable-set-name-hint!", 2, 0, 0,
334 (SCM var, SCM hint),
335 "Do not use this function.")
336#define FUNC_NAME s_scm_variable_set_name_hint
337{
338 SCM_VALIDATE_VARIABLE (1, var);
339 SCM_VALIDATE_SYMBOL (2, hint);
340 scm_c_issue_deprecation_warning
341 ("'variable-set-name-hint!' is deprecated. Do not use it.");
342 return SCM_UNSPECIFIED;
343}
344#undef FUNC_NAME
345
346SCM_DEFINE (scm_builtin_variable, "builtin-variable", 1, 0, 0,
347 (SCM name),
348 "Do not use this function.")
349#define FUNC_NAME s_scm_builtin_variable
350{
351 SCM_VALIDATE_SYMBOL (1,name);
352 scm_c_issue_deprecation_warning ("`builtin-variable' is deprecated. "
353 "Use module system operations instead.");
354 return scm_sym2var (name, SCM_BOOL_F, SCM_BOOL_T);
355}
356#undef FUNC_NAME
357
358SCM
359scm_makstr (size_t len, int dummy)
360{
361 scm_c_issue_deprecation_warning
362 ("'scm_makstr' is deprecated. Use 'scm_allocate_string' instead.");
363 return scm_allocate_string (len);
364}
365
366SCM
367scm_makfromstr (const char *src, size_t len, int dummy SCM_UNUSED)
368{
369 scm_c_issue_deprecation_warning ("`scm_makfromstr' is deprecated. "
370 "Use `scm_mem2string' instead.");
371
372 return scm_mem2string (src, len);
373}
374
375SCM
376scm_internal_with_fluids (SCM fluids, SCM values, SCM (*cproc) (), void *cdata)
377{
378 scm_c_issue_deprecation_warning ("`scm_internal_with_fluids' is deprecated. "
379 "Use `scm_c_with_fluids' instead.");
380
381 return scm_c_with_fluids (fluids, values, cproc, cdata);
382}
383
384SCM
385scm_make_gsubr (const char *name, int req, int opt, int rst, SCM (*fcn)())
386{
387 scm_c_issue_deprecation_warning
388 ("`scm_make_gsubr' is deprecated. Use `scm_c_define_gsubr' instead.");
389
390 return scm_c_define_gsubr (name, req, opt, rst, fcn);
391}
392
393SCM
394scm_make_gsubr_with_generic (const char *name,
395 int req, int opt, int rst,
396 SCM (*fcn)(), SCM *gf)
397{
398 scm_c_issue_deprecation_warning
399 ("`scm_make_gsubr_with_generic' is deprecated. "
400 "Use `scm_c_define_gsubr_with_generic' instead.");
401
402 return scm_c_define_gsubr_with_generic (name, req, opt, rst, fcn, gf);
403}
404
405SCM
406scm_create_hook (const char *name, int n_args)
407{
408 scm_c_issue_deprecation_warning
409 ("'scm_create_hook' is deprecated. "
410 "Use 'scm_make_hook' and 'scm_c_define' instead.");
411 {
412 SCM hook = scm_make_hook (SCM_MAKINUM (n_args));
413 scm_c_define (name, hook);
414 return scm_permanent_object (hook);
415 }
416}
417
418SCM_DEFINE (scm_sloppy_memq, "sloppy-memq", 2, 0, 0,
419 (SCM x, SCM lst),
420 "This procedure behaves like @code{memq}, but does no type or error checking.\n"
421 "Its use is recommended only in writing Guile internals,\n"
422 "not for high-level Scheme programs.")
423#define FUNC_NAME s_scm_sloppy_memq
424{
425 scm_c_issue_deprecation_warning
426 ("'sloppy-memq' is deprecated. Use 'memq' instead.");
427
428 for(; SCM_CONSP (lst); lst = SCM_CDR(lst))
429 {
430 if (SCM_EQ_P (SCM_CAR (lst), x))
431 return lst;
432 }
433 return lst;
434}
435#undef FUNC_NAME
436
437
438SCM_DEFINE (scm_sloppy_memv, "sloppy-memv", 2, 0, 0,
439 (SCM x, SCM lst),
440 "This procedure behaves like @code{memv}, 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_memv
444{
445 scm_c_issue_deprecation_warning
446 ("'sloppy-memv' is deprecated. Use 'memv' instead.");
447
448 for(; SCM_CONSP (lst); lst = SCM_CDR(lst))
449 {
450 if (! SCM_FALSEP (scm_eqv_p (SCM_CAR (lst), x)))
451 return lst;
452 }
453 return lst;
454}
455#undef FUNC_NAME
456
457
458SCM_DEFINE (scm_sloppy_member, "sloppy-member", 2, 0, 0,
459 (SCM x, SCM lst),
460 "This procedure behaves like @code{member}, 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_member
464{
465 scm_c_issue_deprecation_warning
466 ("'sloppy-member' is deprecated. Use 'member' instead.");
467
468 for(; SCM_CONSP (lst); lst = SCM_CDR(lst))
469 {
470 if (! SCM_FALSEP (scm_equal_p (SCM_CAR (lst), x)))
471 return lst;
472 }
473 return lst;
474}
475#undef FUNC_NAME
476
477SCM_SYMBOL (scm_end_of_file_key, "end-of-file");
478
479SCM_DEFINE (scm_read_and_eval_x, "read-and-eval!", 0, 1, 0,
480 (SCM port),
481 "Read a form from @var{port} (standard input by default), and evaluate it\n"
482 "(memoizing it in the process) in the top-level environment. If no data\n"
483 "is left to be read from @var{port}, an @code{end-of-file} error is\n"
484 "signalled.")
485#define FUNC_NAME s_scm_read_and_eval_x
486{
487 scm_c_issue_deprecation_warning
488 ("'read-and-eval!' is deprecated. Use 'read' and 'eval' instead.");
489
490 SCM form = scm_read (port);
491 if (SCM_EOF_OBJECT_P (form))
492 scm_ithrow (scm_end_of_file_key, SCM_EOL, 1);
493 return scm_eval_x (form, scm_current_module ());
494}
495#undef FUNC_NAME
496
4abecea8
MV
497SCM
498scm_make_subr_opt (const char *name, int type, SCM (*fcn) (), int set)
499{
500 scm_c_issue_deprecation_warning
501 ("`scm_make_subr_opt' is deprecated. Use `scm_c_make_subr' or "
502 "`scm_c_define_subr' instead.");
503
504 if (set)
505 return scm_c_define_subr (name, type, fcn);
506 else
507 return scm_c_make_subr (name, type, fcn);
508}
509
510SCM
511scm_make_subr (const char *name, int type, SCM (*fcn) ())
512{
513 scm_c_issue_deprecation_warning
514 ("`scm_make_subr' is deprecated. Use `scm_c_define_subr' instead.");
515
516 return scm_c_define_subr (name, type, fcn);
517}
518
519SCM
520scm_make_subr_with_generic (const char *name, int type, SCM (*fcn) (), SCM *gf)
521{
522 scm_c_issue_deprecation_warning
523 ("`scm_make_subr_with_generic' is deprecated. Use "
524 "`scm_c_define_subr_with_generic' instead.");
525
526 return scm_c_define_subr_with_generic (name, type, fcn, gf);
527}
528
529/* Call thunk(closure) underneath a top-level error handler.
530 * If an error occurs, pass the exitval through err_filter and return it.
531 * If no error occurs, return the value of thunk.
532 */
533
534#ifdef _UNICOS
535typedef int setjmp_type;
536#else
537typedef long setjmp_type;
538#endif
539
540struct cce_handler_data {
541 SCM (*err_filter) ();
542 void *closure;
543};
544
545static SCM
546invoke_err_filter (void *d, SCM tag, SCM args)
547{
548 struct cce_handler_data *data = (struct cce_handler_data *)d;
549 return data->err_filter (SCM_BOOL_F, data->closure);
550}
551
552SCM
553scm_call_catching_errors (SCM (*thunk)(), SCM (*err_filter)(), void *closure)
554{
555 scm_c_issue_deprecation_warning
556 ("'scm_call_catching_errors' is deprecated. "
557 "Use 'scm_internal_catch' instead.");
558
559 {
560 struct cce_handler_data data;
561 data.err_filter = err_filter;
562 data.closure = closure;
563 return scm_internal_catch (SCM_BOOL_T,
564 (scm_t_catch_body)thunk, closure,
565 (scm_t_catch_handler)invoke_err_filter, &data);
566 }
567}
568
569long
570scm_make_smob_type_mfpe (char *name, size_t size,
571 SCM (*mark) (SCM),
572 size_t (*free) (SCM),
573 int (*print) (SCM, SCM, scm_print_state *),
574 SCM (*equalp) (SCM, SCM))
575{
576 scm_c_issue_deprecation_warning
577 ("'scm_make_smob_type_mfpe' is deprecated. "
578 "Use 'scm_make_smob_type' plus 'scm_set_smob_*' instead.");
579
580 {
581 long answer = scm_make_smob_type (name, size);
582 scm_set_smob_mfpe (answer, mark, free, print, equalp);
583 return answer;
584 }
585}
586
587void
588scm_set_smob_mfpe (long tc,
589 SCM (*mark) (SCM),
590 size_t (*free) (SCM),
591 int (*print) (SCM, SCM, scm_print_state *),
592 SCM (*equalp) (SCM, SCM))
593{
594 scm_c_issue_deprecation_warning
595 ("'scm_set_smob_mfpe' is deprecated. "
596 "Use 'scm_set_smob_mark' instead, for example.");
597
598 if (mark) scm_set_smob_mark (tc, mark);
599 if (free) scm_set_smob_free (tc, free);
600 if (print) scm_set_smob_print (tc, print);
601 if (equalp) scm_set_smob_equalp (tc, equalp);
602}
603
604SCM
605scm_read_0str (char *expr)
606{
607 scm_c_issue_deprecation_warning
608 ("scm_read_0str is deprecated. Use scm_c_read_string instead.");
609
610 return scm_c_read_string (expr);
611}
612
613SCM
614scm_eval_0str (const char *expr)
615{
616 scm_c_issue_deprecation_warning
617 ("scm_eval_0str is deprecated. Use scm_c_eval_string instead.");
618
619 return scm_c_eval_string (expr);
620}
621
622SCM
623scm_strprint_obj (SCM obj)
624{
625 scm_c_issue_deprecation_warning
626 ("scm_strprint_obj is deprecated. Use scm_object_to_string instead.");
627 return scm_object_to_string (obj, SCM_UNDEFINED);
628}
629
630char *
631scm_i_object_chars (SCM obj)
632{
633 scm_c_issue_deprecation_warning
634 ("SCM_CHARS is deprecated. Use SCM_STRING_CHARS or "
635 "SCM_SYMBOL_CHARS instead.");
636 if (SCM_STRINGP (obj))
637 return SCM_STRING_CHARS (obj);
638 if (SCM_SYMBOLP (obj))
639 return SCM_SYMBOL_CHARS (obj);
640 abort ();
641}
642
643long
644scm_i_object_length (SCM obj)
645{
646 scm_c_issue_deprecation_warning
647 ("SCM_LENGTH is deprecated. Use SCM_STRING_LENGTH instead, for example.");
648 if (SCM_STRINGP (obj))
649 return SCM_STRING_LENGTH (obj);
650 if (SCM_SYMBOLP (obj))
651 return SCM_SYMBOL_LENGTH (obj);
652 if (SCM_VECTORP (obj))
653 return SCM_VECTOR_LENGTH (obj);
654 abort ();
655}
656
19e2247d
MV
657void
658scm_i_init_deprecated ()
659{
660#include "libguile/deprecated.x"
661}
662
663#endif