Deprecate htons, htonl, ntohs, ntohl
[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, 2006, 2008, 2009, 2010, 2011, 2012, 2013, 2014 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 License
9 * as published by the Free Software Foundation; either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful, but
13 * 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., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 */
22
23 #ifdef HAVE_CONFIG_H
24 # include <config.h>
25 #endif
26
27 #include <math.h>
28 #include <stdio.h>
29 #include <string.h>
30
31 #include <arpa/inet.h>
32
33 #define SCM_BUILDING_DEPRECATED_CODE
34
35 #include "libguile/_scm.h"
36 #include "libguile/async.h"
37 #include "libguile/arrays.h"
38 #include "libguile/array-map.h"
39 #include "libguile/generalized-arrays.h"
40 #include "libguile/bytevectors.h"
41 #include "libguile/bitvectors.h"
42 #include "libguile/deprecated.h"
43 #include "libguile/deprecation.h"
44 #include "libguile/snarf.h"
45 #include "libguile/validate.h"
46 #include "libguile/strings.h"
47 #include "libguile/srfi-13.h"
48 #include "libguile/modules.h"
49 #include "libguile/eval.h"
50 #include "libguile/smob.h"
51 #include "libguile/procprop.h"
52 #include "libguile/vectors.h"
53 #include "libguile/hashtab.h"
54 #include "libguile/struct.h"
55 #include "libguile/variable.h"
56 #include "libguile/fluids.h"
57 #include "libguile/ports.h"
58 #include "libguile/eq.h"
59 #include "libguile/read.h"
60 #include "libguile/r6rs-ports.h"
61 #include "libguile/strports.h"
62 #include "libguile/smob.h"
63 #include "libguile/alist.h"
64 #include "libguile/keywords.h"
65 #include "libguile/socket.h"
66 #include "libguile/feature.h"
67 #include "libguile/uniform.h"
68
69
70 #if (SCM_ENABLE_DEPRECATED == 1)
71
72 /* From print.c: Internal symbol names of isyms. Deprecated in guile 1.7.0 on
73 * 2004-04-22. */
74 char *scm_isymnames[] =
75 {
76 "#@<deprecated>"
77 };
78
79
80 SCM_REGISTER_PROC(s_substring_move_left_x, "substring-move-left!", 5, 0, 0, scm_substring_move_x);
81
82 SCM_REGISTER_PROC(s_substring_move_right_x, "substring-move-right!", 5, 0, 0, scm_substring_move_x);
83
84 SCM
85 scm_wta (SCM arg, const char *pos, const char *s_subr)
86 {
87 if (!s_subr || !*s_subr)
88 s_subr = NULL;
89 if ((~0x1fL) & (long) pos)
90 {
91 /* error string supplied. */
92 scm_misc_error (s_subr, pos, scm_list_1 (arg));
93 }
94 else
95 {
96 /* numerical error code. */
97 scm_t_bits error = (scm_t_bits) pos;
98
99 switch (error)
100 {
101 case SCM_ARGn:
102 scm_wrong_type_arg (s_subr, 0, arg);
103 case SCM_ARG1:
104 scm_wrong_type_arg (s_subr, 1, arg);
105 case SCM_ARG2:
106 scm_wrong_type_arg (s_subr, 2, arg);
107 case SCM_ARG3:
108 scm_wrong_type_arg (s_subr, 3, arg);
109 case SCM_ARG4:
110 scm_wrong_type_arg (s_subr, 4, arg);
111 case SCM_ARG5:
112 scm_wrong_type_arg (s_subr, 5, arg);
113 case SCM_ARG6:
114 scm_wrong_type_arg (s_subr, 6, arg);
115 case SCM_ARG7:
116 scm_wrong_type_arg (s_subr, 7, arg);
117 case SCM_WNA:
118 scm_wrong_num_args (arg);
119 case SCM_OUTOFRANGE:
120 scm_out_of_range (s_subr, arg);
121 case SCM_NALLOC:
122 scm_memory_error (s_subr);
123 default:
124 /* this shouldn't happen. */
125 scm_misc_error (s_subr, "Unknown error", SCM_EOL);
126 }
127 }
128 return SCM_UNSPECIFIED;
129 }
130
131 /* Module registry
132 */
133
134 /* We can't use SCM objects here. One should be able to call
135 SCM_REGISTER_MODULE from a C++ constructor for a static
136 object. This happens before main and thus before libguile is
137 initialized. */
138
139 struct moddata {
140 struct moddata *link;
141 char *module_name;
142 void *init_func;
143 };
144
145 static struct moddata *registered_mods = NULL;
146
147 void
148 scm_register_module_xxx (char *module_name, void *init_func)
149 {
150 struct moddata *md;
151
152 scm_c_issue_deprecation_warning
153 ("`scm_register_module_xxx' is deprecated. Use extensions instead.");
154
155 /* XXX - should we (and can we) DEFER_INTS here? */
156
157 for (md = registered_mods; md; md = md->link)
158 if (!strcmp (md->module_name, module_name))
159 {
160 md->init_func = init_func;
161 return;
162 }
163
164 md = (struct moddata *) malloc (sizeof (struct moddata));
165 if (md == NULL)
166 {
167 fprintf (stderr,
168 "guile: can't register module (%s): not enough memory",
169 module_name);
170 return;
171 }
172
173 md->module_name = module_name;
174 md->init_func = init_func;
175 md->link = registered_mods;
176 registered_mods = md;
177 }
178
179 SCM_DEFINE (scm_registered_modules, "c-registered-modules", 0, 0, 0,
180 (),
181 "Return a list of the object code modules that have been imported into\n"
182 "the current Guile process. Each element of the list is a pair whose\n"
183 "car is the name of the module, and whose cdr is the function handle\n"
184 "for that module's initializer function. The name is the string that\n"
185 "has been passed to scm_register_module_xxx.")
186 #define FUNC_NAME s_scm_registered_modules
187 {
188 SCM res;
189 struct moddata *md;
190
191 res = SCM_EOL;
192 for (md = registered_mods; md; md = md->link)
193 res = scm_cons (scm_cons (scm_from_locale_string (md->module_name),
194 scm_from_ulong ((unsigned long) md->init_func)),
195 res);
196 return res;
197 }
198 #undef FUNC_NAME
199
200 SCM_DEFINE (scm_clear_registered_modules, "c-clear-registered-modules", 0, 0, 0,
201 (),
202 "Destroy the list of modules registered with the current Guile process.\n"
203 "The return value is unspecified. @strong{Warning:} this function does\n"
204 "not actually unlink or deallocate these modules, but only destroys the\n"
205 "records of which modules have been loaded. It should therefore be used\n"
206 "only by module bookkeeping operations.")
207 #define FUNC_NAME s_scm_clear_registered_modules
208 {
209 struct moddata *md1, *md2;
210
211 SCM_CRITICAL_SECTION_START;
212
213 for (md1 = registered_mods; md1; md1 = md2)
214 {
215 md2 = md1->link;
216 free (md1);
217 }
218 registered_mods = NULL;
219
220 SCM_CRITICAL_SECTION_END;
221 return SCM_UNSPECIFIED;
222 }
223 #undef FUNC_NAME
224
225 void
226 scm_remember (SCM *ptr)
227 {
228 scm_c_issue_deprecation_warning ("`scm_remember' is deprecated. "
229 "Use the `scm_remember_upto_here*' family of functions instead.");
230 }
231
232 SCM
233 scm_protect_object (SCM obj)
234 {
235 scm_c_issue_deprecation_warning ("`scm_protect_object' is deprecated. "
236 "Use `scm_gc_protect_object' instead.");
237 return scm_gc_protect_object (obj);
238 }
239
240 SCM
241 scm_unprotect_object (SCM obj)
242 {
243 scm_c_issue_deprecation_warning ("`scm_unprotect_object' is deprecated. "
244 "Use `scm_gc_unprotect_object' instead.");
245 return scm_gc_unprotect_object (obj);
246 }
247
248 SCM_SYMBOL (scm_sym_app, "app");
249 SCM_SYMBOL (scm_sym_modules, "modules");
250 static SCM module_prefix = SCM_BOOL_F;
251 static SCM make_modules_in_var;
252 static SCM beautify_user_module_x_var;
253 static SCM try_module_autoload_var;
254
255 static void
256 init_module_stuff ()
257 {
258 if (scm_is_false (module_prefix))
259 {
260 module_prefix = scm_list_2 (scm_sym_app, scm_sym_modules);
261 make_modules_in_var = scm_c_lookup ("make-modules-in");
262 beautify_user_module_x_var =
263 scm_c_lookup ("beautify-user-module!");
264 try_module_autoload_var = scm_c_lookup ("try-module-autoload");
265 }
266 }
267
268 static SCM
269 scm_module_full_name (SCM name)
270 {
271 init_module_stuff ();
272 if (scm_is_eq (SCM_CAR (name), scm_sym_app))
273 return name;
274 else
275 return scm_append (scm_list_2 (module_prefix, name));
276 }
277
278 SCM
279 scm_make_module (SCM name)
280 {
281 init_module_stuff ();
282 scm_c_issue_deprecation_warning ("`scm_make_module' is deprecated. "
283 "Use `scm_c_define_module instead.");
284
285 return scm_call_2 (SCM_VARIABLE_REF (make_modules_in_var),
286 scm_the_root_module (),
287 scm_module_full_name (name));
288 }
289
290 SCM
291 scm_ensure_user_module (SCM module)
292 {
293 init_module_stuff ();
294 scm_c_issue_deprecation_warning ("`scm_ensure_user_module' is deprecated. "
295 "Use `scm_c_define_module instead.");
296
297 scm_call_1 (SCM_VARIABLE_REF (beautify_user_module_x_var), module);
298 return SCM_UNSPECIFIED;
299 }
300
301 SCM
302 scm_load_scheme_module (SCM name)
303 {
304 init_module_stuff ();
305 scm_c_issue_deprecation_warning ("`scm_load_scheme_module' is deprecated. "
306 "Use `scm_c_resolve_module instead.");
307
308 return scm_call_1 (SCM_VARIABLE_REF (try_module_autoload_var), name);
309 }
310
311 /* This is implemented in C solely for SCM_COERCE_OUTPORT ... */
312
313 static void
314 maybe_close_port (void *data, SCM port)
315 {
316 SCM except_set = PTR2SCM (data);
317
318 while (!scm_is_null (except_set))
319 {
320 SCM p = SCM_COERCE_OUTPORT (SCM_CAR (except_set));
321 if (scm_is_eq (p, port))
322 return;
323 except_set = SCM_CDR (except_set);
324 }
325
326 scm_close_port (port);
327 }
328
329 SCM_DEFINE (scm_close_all_ports_except, "close-all-ports-except", 0, 0, 1,
330 (SCM ports),
331 "[DEPRECATED] Close all open file ports used by the interpreter\n"
332 "except for those supplied as arguments. This procedure\n"
333 "was intended to be used before an exec call to close file descriptors\n"
334 "which are not needed in the new process. However it has the\n"
335 "undesirable side effect of flushing buffers, so it's deprecated.\n"
336 "Use port-for-each instead.")
337 #define FUNC_NAME s_scm_close_all_ports_except
338 {
339 SCM p;
340 SCM_VALIDATE_REST_ARGUMENT (ports);
341
342 for (p = ports; !scm_is_null (p); p = SCM_CDR (p))
343 SCM_VALIDATE_OPPORT (SCM_ARG1, SCM_COERCE_OUTPORT (SCM_CAR (p)));
344
345 scm_c_port_for_each (maybe_close_port, SCM2PTR (ports));
346
347 return SCM_UNSPECIFIED;
348 }
349 #undef FUNC_NAME
350
351 SCM_DEFINE (scm_variable_set_name_hint, "variable-set-name-hint!", 2, 0, 0,
352 (SCM var, SCM hint),
353 "Do not use this function.")
354 #define FUNC_NAME s_scm_variable_set_name_hint
355 {
356 SCM_VALIDATE_VARIABLE (1, var);
357 SCM_VALIDATE_SYMBOL (2, hint);
358 scm_c_issue_deprecation_warning
359 ("'variable-set-name-hint!' is deprecated. Do not use it.");
360 return SCM_UNSPECIFIED;
361 }
362 #undef FUNC_NAME
363
364 SCM_DEFINE (scm_builtin_variable, "builtin-variable", 1, 0, 0,
365 (SCM name),
366 "Do not use this function.")
367 #define FUNC_NAME s_scm_builtin_variable
368 {
369 SCM_VALIDATE_SYMBOL (1,name);
370 scm_c_issue_deprecation_warning ("`builtin-variable' is deprecated. "
371 "Use module system operations instead.");
372 return scm_sym2var (name, SCM_BOOL_F, SCM_BOOL_T);
373 }
374 #undef FUNC_NAME
375
376 SCM
377 scm_makstr (size_t len, int dummy)
378 {
379 scm_c_issue_deprecation_warning
380 ("'scm_makstr' is deprecated. Use 'scm_c_make_string' instead.");
381 return scm_c_make_string (len, SCM_UNDEFINED);
382 }
383
384 SCM
385 scm_makfromstr (const char *src, size_t len, int dummy SCM_UNUSED)
386 {
387 scm_c_issue_deprecation_warning ("`scm_makfromstr' is deprecated. "
388 "Use `scm_from_locale_stringn' instead.");
389
390 return scm_from_locale_stringn (src, len);
391 }
392
393 SCM
394 scm_internal_with_fluids (SCM fluids, SCM values, SCM (*cproc) (), void *cdata)
395 {
396 scm_c_issue_deprecation_warning ("`scm_internal_with_fluids' is deprecated. "
397 "Use `scm_c_with_fluids' instead.");
398
399 return scm_c_with_fluids (fluids, values, cproc, cdata);
400 }
401
402 SCM
403 scm_make_gsubr (const char *name, int req, int opt, int rst, SCM (*fcn)())
404 {
405 scm_c_issue_deprecation_warning
406 ("`scm_make_gsubr' is deprecated. Use `scm_c_define_gsubr' instead.");
407
408 return scm_c_define_gsubr (name, req, opt, rst, fcn);
409 }
410
411 SCM
412 scm_make_gsubr_with_generic (const char *name,
413 int req, int opt, int rst,
414 SCM (*fcn)(), SCM *gf)
415 {
416 scm_c_issue_deprecation_warning
417 ("`scm_make_gsubr_with_generic' is deprecated. "
418 "Use `scm_c_define_gsubr_with_generic' instead.");
419
420 return scm_c_define_gsubr_with_generic (name, req, opt, rst, fcn, gf);
421 }
422
423 SCM
424 scm_create_hook (const char *name, int n_args)
425 {
426 scm_c_issue_deprecation_warning
427 ("'scm_create_hook' is deprecated. "
428 "Use 'scm_make_hook' and 'scm_c_define' instead.");
429 {
430 SCM hook = scm_make_hook (scm_from_int (n_args));
431 scm_c_define (name, hook);
432 return hook;
433 }
434 }
435
436 SCM_DEFINE (scm_sloppy_memq, "sloppy-memq", 2, 0, 0,
437 (SCM x, SCM lst),
438 "This procedure behaves like @code{memq}, but does no type or error checking.\n"
439 "Its use is recommended only in writing Guile internals,\n"
440 "not for high-level Scheme programs.")
441 #define FUNC_NAME s_scm_sloppy_memq
442 {
443 scm_c_issue_deprecation_warning
444 ("'sloppy-memq' is deprecated. Use 'memq' instead.");
445
446 for(; scm_is_pair (lst); lst = SCM_CDR(lst))
447 {
448 if (scm_is_eq (SCM_CAR (lst), x))
449 return lst;
450 }
451 return lst;
452 }
453 #undef FUNC_NAME
454
455
456 SCM_DEFINE (scm_sloppy_memv, "sloppy-memv", 2, 0, 0,
457 (SCM x, SCM lst),
458 "This procedure behaves like @code{memv}, but does no type or error checking.\n"
459 "Its use is recommended only in writing Guile internals,\n"
460 "not for high-level Scheme programs.")
461 #define FUNC_NAME s_scm_sloppy_memv
462 {
463 scm_c_issue_deprecation_warning
464 ("'sloppy-memv' is deprecated. Use 'memv' instead.");
465
466 for(; scm_is_pair (lst); lst = SCM_CDR(lst))
467 {
468 if (! scm_is_false (scm_eqv_p (SCM_CAR (lst), x)))
469 return lst;
470 }
471 return lst;
472 }
473 #undef FUNC_NAME
474
475
476 SCM_DEFINE (scm_sloppy_member, "sloppy-member", 2, 0, 0,
477 (SCM x, SCM lst),
478 "This procedure behaves like @code{member}, but does no type or error checking.\n"
479 "Its use is recommended only in writing Guile internals,\n"
480 "not for high-level Scheme programs.")
481 #define FUNC_NAME s_scm_sloppy_member
482 {
483 scm_c_issue_deprecation_warning
484 ("'sloppy-member' is deprecated. Use 'member' instead.");
485
486 for(; scm_is_pair (lst); lst = SCM_CDR(lst))
487 {
488 if (! scm_is_false (scm_equal_p (SCM_CAR (lst), x)))
489 return lst;
490 }
491 return lst;
492 }
493 #undef FUNC_NAME
494
495 SCM_SYMBOL (scm_end_of_file_key, "end-of-file");
496
497 SCM_DEFINE (scm_read_and_eval_x, "read-and-eval!", 0, 1, 0,
498 (SCM port),
499 "Read a form from @var{port} (standard input by default), and evaluate it\n"
500 "(memoizing it in the process) in the top-level environment. If no data\n"
501 "is left to be read from @var{port}, an @code{end-of-file} error is\n"
502 "signalled.")
503 #define FUNC_NAME s_scm_read_and_eval_x
504 {
505 SCM form;
506
507 scm_c_issue_deprecation_warning
508 ("'read-and-eval!' is deprecated. Use 'read' and 'eval' instead.");
509
510 form = scm_read (port);
511 if (SCM_EOF_OBJECT_P (form))
512 scm_ithrow (scm_end_of_file_key, SCM_EOL, 1);
513 return scm_eval_x (form, scm_current_module ());
514 }
515 #undef FUNC_NAME
516
517 /* Call thunk(closure) underneath a top-level error handler.
518 * If an error occurs, pass the exitval through err_filter and return it.
519 * If no error occurs, return the value of thunk.
520 */
521
522 #ifdef _UNICOS
523 typedef int setjmp_type;
524 #else
525 typedef long setjmp_type;
526 #endif
527
528 struct cce_handler_data {
529 SCM (*err_filter) ();
530 void *closure;
531 };
532
533 static SCM
534 invoke_err_filter (void *d, SCM tag, SCM args)
535 {
536 struct cce_handler_data *data = (struct cce_handler_data *)d;
537 return data->err_filter (SCM_BOOL_F, data->closure);
538 }
539
540 SCM
541 scm_call_catching_errors (SCM (*thunk)(), SCM (*err_filter)(), void *closure)
542 {
543 scm_c_issue_deprecation_warning
544 ("'scm_call_catching_errors' is deprecated. "
545 "Use 'scm_internal_catch' instead.");
546
547 {
548 struct cce_handler_data data;
549 data.err_filter = err_filter;
550 data.closure = closure;
551 return scm_internal_catch (SCM_BOOL_T,
552 (scm_t_catch_body)thunk, closure,
553 (scm_t_catch_handler)invoke_err_filter, &data);
554 }
555 }
556
557 long
558 scm_make_smob_type_mfpe (char *name, size_t size,
559 SCM (*mark) (SCM),
560 size_t (*free) (SCM),
561 int (*print) (SCM, SCM, scm_print_state *),
562 SCM (*equalp) (SCM, SCM))
563 {
564 scm_c_issue_deprecation_warning
565 ("'scm_make_smob_type_mfpe' is deprecated. "
566 "Use 'scm_make_smob_type' plus 'scm_set_smob_*' instead.");
567
568 {
569 long answer = scm_make_smob_type (name, size);
570 scm_set_smob_mfpe (answer, mark, free, print, equalp);
571 return answer;
572 }
573 }
574
575 void
576 scm_set_smob_mfpe (long tc,
577 SCM (*mark) (SCM),
578 size_t (*free) (SCM),
579 int (*print) (SCM, SCM, scm_print_state *),
580 SCM (*equalp) (SCM, SCM))
581 {
582 scm_c_issue_deprecation_warning
583 ("'scm_set_smob_mfpe' is deprecated. "
584 "Use 'scm_set_smob_mark' instead, for example.");
585
586 if (mark) scm_set_smob_mark (tc, mark);
587 if (free) scm_set_smob_free (tc, free);
588 if (print) scm_set_smob_print (tc, print);
589 if (equalp) scm_set_smob_equalp (tc, equalp);
590 }
591
592 size_t
593 scm_smob_free (SCM obj)
594 {
595 long n = SCM_SMOBNUM (obj);
596
597 scm_c_issue_deprecation_warning
598 ("`scm_smob_free' is deprecated. "
599 "It is no longer needed.");
600
601 if (scm_smobs[n].size > 0)
602 scm_gc_free ((void *) SCM_SMOB_DATA_1 (obj),
603 scm_smobs[n].size, SCM_SMOBNAME (n));
604 return 0;
605 }
606
607 SCM
608 scm_read_0str (char *expr)
609 {
610 scm_c_issue_deprecation_warning
611 ("scm_read_0str is deprecated. Use scm_c_read_string instead.");
612
613 return scm_c_read_string (expr);
614 }
615
616 SCM
617 scm_eval_0str (const char *expr)
618 {
619 scm_c_issue_deprecation_warning
620 ("scm_eval_0str is deprecated. Use scm_c_eval_string instead.");
621
622 return scm_c_eval_string (expr);
623 }
624
625 SCM
626 scm_strprint_obj (SCM obj)
627 {
628 scm_c_issue_deprecation_warning
629 ("scm_strprint_obj is deprecated. Use scm_object_to_string instead.");
630 return scm_object_to_string (obj, SCM_UNDEFINED);
631 }
632
633 char *
634 scm_i_object_chars (SCM obj)
635 {
636 scm_c_issue_deprecation_warning
637 ("SCM_CHARS is deprecated. See the manual for alternatives.");
638 if (SCM_STRINGP (obj))
639 return SCM_STRING_CHARS (obj);
640 if (SCM_SYMBOLP (obj))
641 return SCM_SYMBOL_CHARS (obj);
642 abort ();
643 }
644
645 long
646 scm_i_object_length (SCM obj)
647 {
648 scm_c_issue_deprecation_warning
649 ("SCM_LENGTH is deprecated. "
650 "Use scm_c_string_length instead, for example, or see the manual.");
651 if (SCM_STRINGP (obj))
652 return SCM_STRING_LENGTH (obj);
653 if (SCM_SYMBOLP (obj))
654 return SCM_SYMBOL_LENGTH (obj);
655 if (SCM_VECTORP (obj))
656 return SCM_VECTOR_LENGTH (obj);
657 abort ();
658 }
659
660 SCM
661 scm_sym2ovcell_soft (SCM sym, SCM obarray)
662 {
663 SCM lsym, z;
664 size_t hash = scm_i_symbol_hash (sym) % SCM_VECTOR_LENGTH (obarray);
665
666 scm_c_issue_deprecation_warning ("`scm_sym2ovcell_soft' is deprecated. "
667 "Use hashtables instead.");
668
669 SCM_CRITICAL_SECTION_START;
670 for (lsym = SCM_VECTOR_REF (obarray, hash);
671 SCM_NIMP (lsym);
672 lsym = SCM_CDR (lsym))
673 {
674 z = SCM_CAR (lsym);
675 if (scm_is_eq (SCM_CAR (z), sym))
676 {
677 SCM_CRITICAL_SECTION_END;
678 return z;
679 }
680 }
681 SCM_CRITICAL_SECTION_END;
682 return SCM_BOOL_F;
683 }
684
685
686 SCM
687 scm_sym2ovcell (SCM sym, SCM obarray)
688 #define FUNC_NAME "scm_sym2ovcell"
689 {
690 SCM answer;
691
692 scm_c_issue_deprecation_warning ("`scm_sym2ovcell' is deprecated. "
693 "Use hashtables instead.");
694
695 answer = scm_sym2ovcell_soft (sym, obarray);
696 if (scm_is_true (answer))
697 return answer;
698 SCM_MISC_ERROR ("uninterned symbol: ~S", scm_list_1 (sym));
699 return SCM_UNSPECIFIED; /* not reached */
700 }
701 #undef FUNC_NAME
702
703
704 /* Intern a symbol whose name is the LEN characters at NAME in OBARRAY.
705
706 OBARRAY should be a vector of lists, indexed by the name's hash
707 value, modulo OBARRAY's length. Each list has the form
708 ((SYMBOL . VALUE) ...), where SYMBOL is a symbol, and VALUE is the
709 value associated with that symbol (in the current module? in the
710 system module?)
711
712 To "intern" a symbol means: if OBARRAY already contains a symbol by
713 that name, return its (SYMBOL . VALUE) pair; otherwise, create a
714 new symbol, add the pair (SYMBOL . SCM_UNDEFINED) to the
715 appropriate list of the OBARRAY, and return the pair.
716
717 If softness is non-zero, don't create a symbol if it isn't already
718 in OBARRAY; instead, just return #f.
719
720 If OBARRAY is SCM_BOOL_F, create a symbol listed in no obarray and
721 return (SYMBOL . SCM_UNDEFINED). */
722
723
724 static SCM
725 intern_obarray_soft (SCM symbol, SCM obarray, unsigned int softness)
726 {
727 size_t raw_hash = scm_i_symbol_hash (symbol);
728 size_t hash;
729 SCM lsym;
730
731 if (scm_is_false (obarray))
732 {
733 if (softness)
734 return SCM_BOOL_F;
735 else
736 return scm_cons (symbol, SCM_UNDEFINED);
737 }
738
739 hash = raw_hash % SCM_VECTOR_LENGTH (obarray);
740
741 for (lsym = SCM_VECTOR_REF(obarray, hash);
742 SCM_NIMP (lsym); lsym = SCM_CDR (lsym))
743 {
744 SCM a = SCM_CAR (lsym);
745 SCM z = SCM_CAR (a);
746 if (scm_is_eq (z, symbol))
747 return a;
748 }
749
750 if (softness)
751 {
752 return SCM_BOOL_F;
753 }
754 else
755 {
756 SCM cell = scm_cons (symbol, SCM_UNDEFINED);
757 SCM slot = SCM_VECTOR_REF (obarray, hash);
758
759 SCM_VECTOR_SET (obarray, hash, scm_cons (cell, slot));
760
761 return cell;
762 }
763 }
764
765
766 SCM
767 scm_intern_obarray_soft (const char *name, size_t len, SCM obarray,
768 unsigned int softness)
769 {
770 SCM symbol = scm_from_locale_symboln (name, len);
771
772 scm_c_issue_deprecation_warning ("`scm_intern_obarray_soft' is deprecated. "
773 "Use hashtables instead.");
774
775 return intern_obarray_soft (symbol, obarray, softness);
776 }
777
778 SCM
779 scm_intern_obarray (const char *name,size_t len,SCM obarray)
780 {
781 scm_c_issue_deprecation_warning ("`scm_intern_obarray' is deprecated. "
782 "Use hashtables instead.");
783
784 return scm_intern_obarray_soft (name, len, obarray, 0);
785 }
786
787 /* Lookup the value of the symbol named by the nul-terminated string
788 NAME in the current module. */
789 SCM
790 scm_symbol_value0 (const char *name)
791 {
792 scm_c_issue_deprecation_warning ("`scm_symbol_value0' is deprecated. "
793 "Use `scm_lookup' instead.");
794
795 return scm_variable_ref (scm_c_lookup (name));
796 }
797
798 SCM_DEFINE (scm_string_to_obarray_symbol, "string->obarray-symbol", 2, 1, 0,
799 (SCM o, SCM s, SCM softp),
800 "Intern a new symbol in @var{obarray}, a symbol table, with name\n"
801 "@var{string}.\n\n"
802 "If @var{obarray} is @code{#f}, use the default system symbol table. If\n"
803 "@var{obarray} is @code{#t}, the symbol should not be interned in any\n"
804 "symbol table; merely return the pair (@var{symbol}\n"
805 ". @var{#<undefined>}).\n\n"
806 "The @var{soft?} argument determines whether new symbol table entries\n"
807 "should be created when the specified symbol is not already present in\n"
808 "@var{obarray}. If @var{soft?} is specified and is a true value, then\n"
809 "new entries should not be added for symbols not already present in the\n"
810 "table; instead, simply return @code{#f}.")
811 #define FUNC_NAME s_scm_string_to_obarray_symbol
812 {
813 SCM vcell;
814 SCM answer;
815 int softness;
816
817 SCM_VALIDATE_STRING (2, s);
818 SCM_ASSERT (scm_is_bool (o) || SCM_VECTORP (o), o, SCM_ARG1, FUNC_NAME);
819
820 scm_c_issue_deprecation_warning ("`string->obarray-symbol' is deprecated. "
821 "Use hashtables instead.");
822
823 softness = (!SCM_UNBNDP (softp) && scm_is_true(softp));
824 /* iron out some screwy calling conventions */
825 if (scm_is_false (o))
826 {
827 /* nothing interesting to do here. */
828 return scm_string_to_symbol (s);
829 }
830 else if (scm_is_eq (o, SCM_BOOL_T))
831 o = SCM_BOOL_F;
832
833 vcell = intern_obarray_soft (scm_string_to_symbol (s), o, softness);
834 if (scm_is_false (vcell))
835 return vcell;
836 answer = SCM_CAR (vcell);
837 return answer;
838 }
839 #undef FUNC_NAME
840
841 SCM_DEFINE (scm_intern_symbol, "intern-symbol", 2, 0, 0,
842 (SCM o, SCM s),
843 "Add a new symbol to @var{obarray} with name @var{string}, bound to an\n"
844 "unspecified initial value. The symbol table is not modified if a symbol\n"
845 "with this name is already present.")
846 #define FUNC_NAME s_scm_intern_symbol
847 {
848 size_t hval;
849 SCM_VALIDATE_SYMBOL (2,s);
850 if (scm_is_false (o))
851 return SCM_UNSPECIFIED;
852
853 scm_c_issue_deprecation_warning ("`intern-symbol' is deprecated. "
854 "Use hashtables instead.");
855
856 SCM_VALIDATE_VECTOR (1,o);
857 hval = scm_i_symbol_hash (s) % SCM_VECTOR_LENGTH (o);
858 /* If the symbol is already interned, simply return. */
859 SCM_CRITICAL_SECTION_START;
860 {
861 SCM lsym;
862 SCM sym;
863 for (lsym = SCM_VECTOR_REF (o, hval);
864 SCM_NIMP (lsym);
865 lsym = SCM_CDR (lsym))
866 {
867 sym = SCM_CAR (lsym);
868 if (scm_is_eq (SCM_CAR (sym), s))
869 {
870 SCM_CRITICAL_SECTION_END;
871 return SCM_UNSPECIFIED;
872 }
873 }
874 SCM_VECTOR_SET (o, hval,
875 scm_acons (s, SCM_UNDEFINED,
876 SCM_VECTOR_REF (o, hval)));
877 }
878 SCM_CRITICAL_SECTION_END;
879 return SCM_UNSPECIFIED;
880 }
881 #undef FUNC_NAME
882
883 SCM_DEFINE (scm_unintern_symbol, "unintern-symbol", 2, 0, 0,
884 (SCM o, SCM s),
885 "Remove the symbol with name @var{string} from @var{obarray}. This\n"
886 "function returns @code{#t} if the symbol was present and @code{#f}\n"
887 "otherwise.")
888 #define FUNC_NAME s_scm_unintern_symbol
889 {
890 size_t hval;
891
892 scm_c_issue_deprecation_warning ("`unintern-symbol' is deprecated. "
893 "Use hashtables instead.");
894
895 SCM_VALIDATE_SYMBOL (2,s);
896 if (scm_is_false (o))
897 return SCM_BOOL_F;
898 SCM_VALIDATE_VECTOR (1,o);
899 hval = scm_i_symbol_hash (s) % SCM_VECTOR_LENGTH (o);
900 SCM_CRITICAL_SECTION_START;
901 {
902 SCM lsym_follow;
903 SCM lsym;
904 SCM sym;
905 for (lsym = SCM_VECTOR_REF (o, hval), lsym_follow = SCM_BOOL_F;
906 SCM_NIMP (lsym);
907 lsym_follow = lsym, lsym = SCM_CDR (lsym))
908 {
909 sym = SCM_CAR (lsym);
910 if (scm_is_eq (SCM_CAR (sym), s))
911 {
912 /* Found the symbol to unintern. */
913 if (scm_is_false (lsym_follow))
914 SCM_VECTOR_SET (o, hval, lsym);
915 else
916 SCM_SETCDR (lsym_follow, SCM_CDR(lsym));
917 SCM_CRITICAL_SECTION_END;
918 return SCM_BOOL_T;
919 }
920 }
921 }
922 SCM_CRITICAL_SECTION_END;
923 return SCM_BOOL_F;
924 }
925 #undef FUNC_NAME
926
927 SCM_DEFINE (scm_symbol_binding, "symbol-binding", 2, 0, 0,
928 (SCM o, SCM s),
929 "Look up in @var{obarray} the symbol whose name is @var{string}, and\n"
930 "return the value to which it is bound. If @var{obarray} is @code{#f},\n"
931 "use the global symbol table. If @var{string} is not interned in\n"
932 "@var{obarray}, an error is signalled.")
933 #define FUNC_NAME s_scm_symbol_binding
934 {
935 SCM vcell;
936
937 scm_c_issue_deprecation_warning ("`symbol-binding' is deprecated. "
938 "Use hashtables instead.");
939
940 SCM_VALIDATE_SYMBOL (2,s);
941 if (scm_is_false (o))
942 return scm_variable_ref (scm_lookup (s));
943 SCM_VALIDATE_VECTOR (1,o);
944 vcell = scm_sym2ovcell (s, o);
945 return SCM_CDR(vcell);
946 }
947 #undef FUNC_NAME
948
949 #if 0
950 SCM_DEFINE (scm_symbol_interned_p, "symbol-interned?", 2, 0, 0,
951 (SCM o, SCM s),
952 "Return @code{#t} if @var{obarray} contains a symbol with name\n"
953 "@var{string}, and @code{#f} otherwise.")
954 #define FUNC_NAME s_scm_symbol_interned_p
955 {
956 SCM vcell;
957
958 scm_c_issue_deprecation_warning ("`symbol-interned?' is deprecated. "
959 "Use hashtables instead.");
960
961 SCM_VALIDATE_SYMBOL (2,s);
962 if (scm_is_false (o))
963 {
964 SCM var = scm_sym2var (s, SCM_BOOL_F, SCM_BOOL_F);
965 if (var != SCM_BOOL_F)
966 return SCM_BOOL_T;
967 return SCM_BOOL_F;
968 }
969 SCM_VALIDATE_VECTOR (1,o);
970 vcell = scm_sym2ovcell_soft (s, o);
971 return (SCM_NIMP(vcell)
972 ? SCM_BOOL_T
973 : SCM_BOOL_F);
974 }
975 #undef FUNC_NAME
976 #endif
977
978 SCM_DEFINE (scm_symbol_bound_p, "symbol-bound?", 2, 0, 0,
979 (SCM o, SCM s),
980 "Return @code{#t} if @var{obarray} contains a symbol with name\n"
981 "@var{string} bound to a defined value. This differs from\n"
982 "@var{symbol-interned?} in that the mere mention of a symbol\n"
983 "usually causes it to be interned; @code{symbol-bound?}\n"
984 "determines whether a symbol has been given any meaningful\n"
985 "value.")
986 #define FUNC_NAME s_scm_symbol_bound_p
987 {
988 SCM vcell;
989
990 scm_c_issue_deprecation_warning ("`symbol-bound?' is deprecated. "
991 "Use hashtables instead.");
992
993 SCM_VALIDATE_SYMBOL (2,s);
994 if (scm_is_false (o))
995 {
996 SCM var = scm_sym2var (s, SCM_BOOL_F, SCM_BOOL_F);
997 if (SCM_VARIABLEP(var) && !SCM_UNBNDP(SCM_VARIABLE_REF(var)))
998 return SCM_BOOL_T;
999 return SCM_BOOL_F;
1000 }
1001 SCM_VALIDATE_VECTOR (1,o);
1002 vcell = scm_sym2ovcell_soft (s, o);
1003 return scm_from_bool (SCM_NIMP (vcell) && !SCM_UNBNDP (SCM_CDR (vcell)));
1004 }
1005 #undef FUNC_NAME
1006
1007
1008 SCM_DEFINE (scm_symbol_set_x, "symbol-set!", 3, 0, 0,
1009 (SCM o, SCM s, SCM v),
1010 "Find the symbol in @var{obarray} whose name is @var{string}, and rebind\n"
1011 "it to @var{value}. An error is signalled if @var{string} is not present\n"
1012 "in @var{obarray}.")
1013 #define FUNC_NAME s_scm_symbol_set_x
1014 {
1015 SCM vcell;
1016
1017 scm_c_issue_deprecation_warning ("`symbol-set!' is deprecated. "
1018 "Use the module system instead.");
1019
1020 SCM_VALIDATE_SYMBOL (2,s);
1021 if (scm_is_false (o))
1022 {
1023 scm_define (s, v);
1024 return SCM_UNSPECIFIED;
1025 }
1026 SCM_VALIDATE_VECTOR (1,o);
1027 vcell = scm_sym2ovcell (s, o);
1028 SCM_SETCDR (vcell, v);
1029 return SCM_UNSPECIFIED;
1030 }
1031 #undef FUNC_NAME
1032
1033 #define MAX_PREFIX_LENGTH 30
1034
1035 static int gentemp_counter;
1036
1037 SCM_DEFINE (scm_gentemp, "gentemp", 0, 2, 0,
1038 (SCM prefix, SCM obarray),
1039 "Create a new symbol with a name unique in an obarray.\n"
1040 "The name is constructed from an optional string @var{prefix}\n"
1041 "and a counter value. The default prefix is @code{t}. The\n"
1042 "@var{obarray} is specified as a second optional argument.\n"
1043 "Default is the system obarray where all normal symbols are\n"
1044 "interned. The counter is increased by 1 at each\n"
1045 "call. There is no provision for resetting the counter.")
1046 #define FUNC_NAME s_scm_gentemp
1047 {
1048 char buf[MAX_PREFIX_LENGTH + SCM_INTBUFLEN];
1049 char *name = buf;
1050 int n_digits;
1051 size_t len;
1052
1053 scm_c_issue_deprecation_warning ("`gentemp' is deprecated. "
1054 "Use `gensym' instead.");
1055
1056 if (SCM_UNBNDP (prefix))
1057 {
1058 name[0] = 't';
1059 len = 1;
1060 }
1061 else
1062 {
1063 SCM_VALIDATE_STRING (1, prefix);
1064 len = scm_i_string_length (prefix);
1065 name = scm_to_locale_stringn (prefix, &len);
1066 name = scm_realloc (name, len + SCM_INTBUFLEN);
1067 }
1068
1069 if (SCM_UNBNDP (obarray))
1070 return scm_gensym (prefix);
1071 else
1072 SCM_ASSERT ((scm_is_vector (obarray) || SCM_I_WVECTP (obarray)),
1073 obarray,
1074 SCM_ARG2,
1075 FUNC_NAME);
1076 do
1077 n_digits = scm_iint2str (gentemp_counter++, 10, &name[len]);
1078 while (scm_is_true (scm_intern_obarray_soft (name,
1079 len + n_digits,
1080 obarray,
1081 1)));
1082 {
1083 SCM vcell = scm_intern_obarray_soft (name,
1084 len + n_digits,
1085 obarray,
1086 0);
1087 if (name != buf)
1088 free (name);
1089 return SCM_CAR (vcell);
1090 }
1091 }
1092 #undef FUNC_NAME
1093
1094 SCM
1095 scm_i_makinum (scm_t_signed_bits val)
1096 {
1097 scm_c_issue_deprecation_warning
1098 ("SCM_MAKINUM is deprecated. Use scm_from_int or similar instead.");
1099 return SCM_I_MAKINUM (val);
1100 }
1101
1102 int
1103 scm_i_inump (SCM obj)
1104 {
1105 scm_c_issue_deprecation_warning
1106 ("SCM_INUMP is deprecated. Use scm_is_integer or similar instead.");
1107 return SCM_I_INUMP (obj);
1108 }
1109
1110 scm_t_signed_bits
1111 scm_i_inum (SCM obj)
1112 {
1113 scm_c_issue_deprecation_warning
1114 ("SCM_INUM is deprecated. Use scm_to_int or similar instead.");
1115 return scm_to_intmax (obj);
1116 }
1117
1118 char *
1119 scm_c_string2str (SCM obj, char *str, size_t *lenp)
1120 {
1121 scm_c_issue_deprecation_warning
1122 ("scm_c_string2str is deprecated. Use scm_to_locale_stringbuf or similar instead.");
1123
1124 if (str == NULL)
1125 {
1126 char *result = scm_to_locale_string (obj);
1127 if (lenp)
1128 *lenp = scm_i_string_length (obj);
1129 return result;
1130 }
1131 else
1132 {
1133 /* Pray that STR is large enough.
1134 */
1135 size_t len = scm_to_locale_stringbuf (obj, str, SCM_I_SIZE_MAX);
1136 str[len] = '\0';
1137 if (lenp)
1138 *lenp = len;
1139 return str;
1140 }
1141 }
1142
1143 char *
1144 scm_c_substring2str (SCM obj, char *str, size_t start, size_t len)
1145 {
1146 scm_c_issue_deprecation_warning
1147 ("scm_c_substring2str is deprecated. Use scm_substring plus scm_to_locale_stringbuf instead.");
1148
1149 if (start)
1150 obj = scm_substring (obj, scm_from_size_t (start), SCM_UNDEFINED);
1151
1152 scm_to_locale_stringbuf (obj, str, len);
1153 return str;
1154 }
1155
1156 /* Converts the given Scheme symbol OBJ into a C string, containing a copy
1157 of OBJ's content with a trailing null byte. If LENP is non-NULL, set
1158 *LENP to the string's length.
1159
1160 When STR is non-NULL it receives the copy and is returned by the function,
1161 otherwise new memory is allocated and the caller is responsible for
1162 freeing it via free(). If out of memory, NULL is returned.
1163
1164 Note that Scheme symbols may contain arbitrary data, including null
1165 characters. This means that null termination is not a reliable way to
1166 determine the length of the returned value. However, the function always
1167 copies the complete contents of OBJ, and sets *LENP to the length of the
1168 scheme symbol (if LENP is non-null). */
1169 char *
1170 scm_c_symbol2str (SCM obj, char *str, size_t *lenp)
1171 {
1172 return scm_c_string2str (scm_symbol_to_string (obj), str, lenp);
1173 }
1174
1175 double
1176 scm_truncate (double x)
1177 {
1178 scm_c_issue_deprecation_warning
1179 ("scm_truncate is deprecated. Use scm_c_truncate instead.");
1180 return scm_c_truncate (x);
1181 }
1182
1183 double
1184 scm_round (double x)
1185 {
1186 scm_c_issue_deprecation_warning
1187 ("scm_round is deprecated. Use scm_c_round instead.");
1188 return scm_c_round (x);
1189 }
1190
1191 SCM
1192 scm_sys_expt (SCM x, SCM y)
1193 {
1194 scm_c_issue_deprecation_warning
1195 ("scm_sys_expt is deprecated. Use scm_expt instead.");
1196 return scm_expt (x, y);
1197 }
1198
1199 double
1200 scm_asinh (double x)
1201 {
1202 scm_c_issue_deprecation_warning
1203 ("scm_asinh is deprecated. Use asinh instead.");
1204 #if HAVE_ASINH
1205 return asinh (x);
1206 #else
1207 return log (x + sqrt (x * x + 1));
1208 #endif
1209 }
1210
1211 double
1212 scm_acosh (double x)
1213 {
1214 scm_c_issue_deprecation_warning
1215 ("scm_acosh is deprecated. Use acosh instead.");
1216 #if HAVE_ACOSH
1217 return acosh (x);
1218 #else
1219 return log (x + sqrt (x * x - 1));
1220 #endif
1221 }
1222
1223 double
1224 scm_atanh (double x)
1225 {
1226 scm_c_issue_deprecation_warning
1227 ("scm_atanh is deprecated. Use atanh instead.");
1228 #if HAVE_ATANH
1229 return atanh (x);
1230 #else
1231 return 0.5 * log ((1 + x) / (1 - x));
1232 #endif
1233 }
1234
1235 SCM
1236 scm_sys_atan2 (SCM z1, SCM z2)
1237 {
1238 scm_c_issue_deprecation_warning
1239 ("scm_sys_atan2 is deprecated. Use scm_atan instead.");
1240 return scm_atan (z1, z2);
1241 }
1242
1243 char *
1244 scm_i_deprecated_symbol_chars (SCM sym)
1245 {
1246 scm_c_issue_deprecation_warning
1247 ("SCM_SYMBOL_CHARS is deprecated. Use scm_symbol_to_string.");
1248
1249 return (char *)scm_i_symbol_chars (sym);
1250 }
1251
1252 size_t
1253 scm_i_deprecated_symbol_length (SCM sym)
1254 {
1255 scm_c_issue_deprecation_warning
1256 ("SCM_SYMBOL_LENGTH is deprecated. Use scm_symbol_to_string.");
1257 return scm_i_symbol_length (sym);
1258 }
1259
1260 int
1261 scm_i_keywordp (SCM obj)
1262 {
1263 scm_c_issue_deprecation_warning
1264 ("SCM_KEYWORDP is deprecated. Use scm_is_keyword instead.");
1265 return scm_is_keyword (obj);
1266 }
1267
1268 SCM
1269 scm_i_keywordsym (SCM keyword)
1270 {
1271 scm_c_issue_deprecation_warning
1272 ("SCM_KEYWORDSYM is deprecated. See scm_keyword_to_symbol instead.");
1273 return scm_keyword_dash_symbol (keyword);
1274 }
1275
1276 int
1277 scm_i_vectorp (SCM x)
1278 {
1279 scm_c_issue_deprecation_warning
1280 ("SCM_VECTORP is deprecated. Use scm_is_vector instead.");
1281 return SCM_I_IS_VECTOR (x);
1282 }
1283
1284 unsigned long
1285 scm_i_vector_length (SCM x)
1286 {
1287 scm_c_issue_deprecation_warning
1288 ("SCM_VECTOR_LENGTH is deprecated. Use scm_c_vector_length instead.");
1289 return SCM_I_VECTOR_LENGTH (x);
1290 }
1291
1292 const SCM *
1293 scm_i_velts (SCM x)
1294 {
1295 scm_c_issue_deprecation_warning
1296 ("SCM_VELTS is deprecated. Use scm_vector_elements instead.");
1297 return SCM_I_VECTOR_ELTS (x);
1298 }
1299
1300 SCM *
1301 scm_i_writable_velts (SCM x)
1302 {
1303 scm_c_issue_deprecation_warning
1304 ("SCM_WRITABLE_VELTS is deprecated. "
1305 "Use scm_vector_writable_elements instead.");
1306 return SCM_I_VECTOR_WELTS (x);
1307 }
1308
1309 SCM
1310 scm_i_vector_ref (SCM x, size_t idx)
1311 {
1312 scm_c_issue_deprecation_warning
1313 ("SCM_VECTOR_REF is deprecated. "
1314 "Use scm_c_vector_ref or scm_vector_elements instead.");
1315 return scm_c_vector_ref (x, idx);
1316 }
1317
1318 void
1319 scm_i_vector_set (SCM x, size_t idx, SCM val)
1320 {
1321 scm_c_issue_deprecation_warning
1322 ("SCM_VECTOR_SET is deprecated. "
1323 "Use scm_c_vector_set_x or scm_vector_writable_elements instead.");
1324 scm_c_vector_set_x (x, idx, val);
1325 }
1326
1327 SCM
1328 scm_vector_equal_p (SCM x, SCM y)
1329 {
1330 scm_c_issue_deprecation_warning
1331 ("scm_vector_euqal_p is deprecated. "
1332 "Use scm_equal_p instead.");
1333 return scm_equal_p (x, y);
1334 }
1335
1336 SCM_DEFINE (scm_uniform_vector_read_x, "uniform-vector-read!", 1, 3, 0,
1337 (SCM uvec, SCM port_or_fd, SCM start, SCM end),
1338 "Fill the elements of @var{uvec} by reading\n"
1339 "raw bytes from @var{port-or-fdes}, using host byte order.\n\n"
1340 "The optional arguments @var{start} (inclusive) and @var{end}\n"
1341 "(exclusive) allow a specified region to be read,\n"
1342 "leaving the remainder of the vector unchanged.\n\n"
1343 "When @var{port-or-fdes} is a port, all specified elements\n"
1344 "of @var{uvec} are attempted to be read, potentially blocking\n"
1345 "while waiting for more input or end-of-file.\n"
1346 "When @var{port-or-fd} is an integer, a single call to\n"
1347 "read(2) is made.\n\n"
1348 "An error is signalled when the last element has only\n"
1349 "been partially filled before reaching end-of-file or in\n"
1350 "the single call to read(2).\n\n"
1351 "@code{uniform-vector-read!} returns the number of elements\n"
1352 "read.\n\n"
1353 "@var{port-or-fdes} may be omitted, in which case it defaults\n"
1354 "to the value returned by @code{(current-input-port)}.")
1355 #define FUNC_NAME s_scm_uniform_vector_read_x
1356 {
1357 SCM result;
1358 size_t c_width, c_start, c_end;
1359
1360 SCM_VALIDATE_BYTEVECTOR (SCM_ARG1, uvec);
1361
1362 scm_c_issue_deprecation_warning
1363 ("`uniform-vector-read!' is deprecated. Use `get-bytevector-n!' from\n"
1364 "`(rnrs io ports)' instead.");
1365
1366 if (SCM_UNBNDP (port_or_fd))
1367 port_or_fd = scm_current_input_port ();
1368
1369 c_width = scm_to_size_t (scm_uniform_vector_element_size (uvec));
1370
1371 c_start = SCM_UNBNDP (start) ? 0 : scm_to_size_t (start);
1372 c_start *= c_width;
1373
1374 c_end = SCM_UNBNDP (end) ? SCM_BYTEVECTOR_LENGTH (uvec)
1375 : scm_to_size_t (end) * c_width;
1376
1377 result = scm_get_bytevector_n_x (port_or_fd, uvec,
1378 scm_from_size_t (c_start),
1379 scm_from_size_t (c_end - c_start));
1380
1381 if (SCM_EOF_OBJECT_P (result))
1382 result = SCM_INUM0;
1383
1384 return result;
1385 }
1386 #undef FUNC_NAME
1387
1388 SCM_DEFINE (scm_uniform_vector_write, "uniform-vector-write", 1, 3, 0,
1389 (SCM uvec, SCM port_or_fd, SCM start, SCM end),
1390 "Write the elements of @var{uvec} as raw bytes to\n"
1391 "@var{port-or-fdes}, in the host byte order.\n\n"
1392 "The optional arguments @var{start} (inclusive)\n"
1393 "and @var{end} (exclusive) allow\n"
1394 "a specified region to be written.\n\n"
1395 "When @var{port-or-fdes} is a port, all specified elements\n"
1396 "of @var{uvec} are attempted to be written, potentially blocking\n"
1397 "while waiting for more room.\n"
1398 "When @var{port-or-fd} is an integer, a single call to\n"
1399 "write(2) is made.\n\n"
1400 "An error is signalled when the last element has only\n"
1401 "been partially written in the single call to write(2).\n\n"
1402 "The number of objects actually written is returned.\n"
1403 "@var{port-or-fdes} may be\n"
1404 "omitted, in which case it defaults to the value returned by\n"
1405 "@code{(current-output-port)}.")
1406 #define FUNC_NAME s_scm_uniform_vector_write
1407 {
1408 size_t c_width, c_start, c_end;
1409
1410 SCM_VALIDATE_BYTEVECTOR (SCM_ARG1, uvec);
1411
1412 scm_c_issue_deprecation_warning
1413 ("`uniform-vector-write' is deprecated. Use `put-bytevector' from\n"
1414 "`(rnrs io ports)' instead.");
1415
1416 if (SCM_UNBNDP (port_or_fd))
1417 port_or_fd = scm_current_output_port ();
1418
1419 port_or_fd = SCM_COERCE_OUTPORT (port_or_fd);
1420
1421 c_width = scm_to_size_t (scm_uniform_vector_element_size (uvec));
1422
1423 c_start = SCM_UNBNDP (start) ? 0 : scm_to_size_t (start);
1424 c_start *= c_width;
1425
1426 c_end = SCM_UNBNDP (end) ? SCM_BYTEVECTOR_LENGTH (uvec) : scm_to_size_t (end);
1427 c_end *= c_width;
1428
1429 return scm_put_bytevector (port_or_fd, uvec,
1430 scm_from_size_t (c_start),
1431 scm_from_size_t (c_end - c_start));
1432 }
1433 #undef FUNC_NAME
1434
1435 static SCM
1436 scm_ra2contig (SCM ra, int copy)
1437 {
1438 SCM ret;
1439 long inc = 1;
1440 size_t k, len = 1;
1441 for (k = SCM_I_ARRAY_NDIM (ra); k--;)
1442 len *= SCM_I_ARRAY_DIMS (ra)[k].ubnd - SCM_I_ARRAY_DIMS (ra)[k].lbnd + 1;
1443 k = SCM_I_ARRAY_NDIM (ra);
1444 if (SCM_I_ARRAY_CONTP (ra) && ((0 == k) || (1 == SCM_I_ARRAY_DIMS (ra)[k - 1].inc)))
1445 {
1446 if (!scm_is_bitvector (SCM_I_ARRAY_V (ra)))
1447 return ra;
1448 if ((len == scm_c_bitvector_length (SCM_I_ARRAY_V (ra)) &&
1449 0 == SCM_I_ARRAY_BASE (ra) % SCM_LONG_BIT &&
1450 0 == len % SCM_LONG_BIT))
1451 return ra;
1452 }
1453 ret = scm_i_make_array (k);
1454 SCM_I_ARRAY_BASE (ret) = 0;
1455 while (k--)
1456 {
1457 SCM_I_ARRAY_DIMS (ret)[k].lbnd = SCM_I_ARRAY_DIMS (ra)[k].lbnd;
1458 SCM_I_ARRAY_DIMS (ret)[k].ubnd = SCM_I_ARRAY_DIMS (ra)[k].ubnd;
1459 SCM_I_ARRAY_DIMS (ret)[k].inc = inc;
1460 inc *= SCM_I_ARRAY_DIMS (ra)[k].ubnd - SCM_I_ARRAY_DIMS (ra)[k].lbnd + 1;
1461 }
1462 SCM_I_ARRAY_V (ret) =
1463 scm_make_generalized_vector (scm_array_type (ra), scm_from_size_t (inc),
1464 SCM_UNDEFINED);
1465 if (copy)
1466 scm_array_copy_x (ra, ret);
1467 return ret;
1468 }
1469
1470 SCM_DEFINE (scm_uniform_array_read_x, "uniform-array-read!", 1, 3, 0,
1471 (SCM ura, SCM port_or_fd, SCM start, SCM end),
1472 "@deffnx {Scheme Procedure} uniform-vector-read! uve [port-or-fdes] [start] [end]\n"
1473 "Attempt to read all elements of @var{ura}, in lexicographic order, as\n"
1474 "binary objects from @var{port-or-fdes}.\n"
1475 "If an end of file is encountered,\n"
1476 "the objects up to that point are put into @var{ura}\n"
1477 "(starting at the beginning) and the remainder of the array is\n"
1478 "unchanged.\n\n"
1479 "The optional arguments @var{start} and @var{end} allow\n"
1480 "a specified region of a vector (or linearized array) to be read,\n"
1481 "leaving the remainder of the vector unchanged.\n\n"
1482 "@code{uniform-array-read!} returns the number of objects read.\n"
1483 "@var{port-or-fdes} may be omitted, in which case it defaults to the value\n"
1484 "returned by @code{(current-input-port)}.")
1485 #define FUNC_NAME s_scm_uniform_array_read_x
1486 {
1487 if (SCM_UNBNDP (port_or_fd))
1488 port_or_fd = scm_current_input_port ();
1489
1490 if (scm_is_uniform_vector (ura))
1491 {
1492 return scm_uniform_vector_read_x (ura, port_or_fd, start, end);
1493 }
1494 else if (SCM_I_ARRAYP (ura))
1495 {
1496 size_t base, vlen, cstart, cend;
1497 SCM cra, ans;
1498
1499 cra = scm_ra2contig (ura, 0);
1500 base = SCM_I_ARRAY_BASE (cra);
1501 vlen = SCM_I_ARRAY_DIMS (cra)->inc *
1502 (SCM_I_ARRAY_DIMS (cra)->ubnd - SCM_I_ARRAY_DIMS (cra)->lbnd + 1);
1503
1504 cstart = 0;
1505 cend = vlen;
1506 if (!SCM_UNBNDP (start))
1507 {
1508 cstart = scm_to_unsigned_integer (start, 0, vlen);
1509 if (!SCM_UNBNDP (end))
1510 cend = scm_to_unsigned_integer (end, cstart, vlen);
1511 }
1512
1513 ans = scm_uniform_vector_read_x (SCM_I_ARRAY_V (cra), port_or_fd,
1514 scm_from_size_t (base + cstart),
1515 scm_from_size_t (base + cend));
1516
1517 if (!scm_is_eq (cra, ura))
1518 scm_array_copy_x (cra, ura);
1519 return ans;
1520 }
1521 else
1522 scm_wrong_type_arg_msg (NULL, 0, ura, "array");
1523 }
1524 #undef FUNC_NAME
1525
1526 SCM_DEFINE (scm_uniform_array_write, "uniform-array-write", 1, 3, 0,
1527 (SCM ura, SCM port_or_fd, SCM start, SCM end),
1528 "Writes all elements of @var{ura} as binary objects to\n"
1529 "@var{port-or-fdes}.\n\n"
1530 "The optional arguments @var{start}\n"
1531 "and @var{end} allow\n"
1532 "a specified region of a vector (or linearized array) to be written.\n\n"
1533 "The number of objects actually written is returned.\n"
1534 "@var{port-or-fdes} may be\n"
1535 "omitted, in which case it defaults to the value returned by\n"
1536 "@code{(current-output-port)}.")
1537 #define FUNC_NAME s_scm_uniform_array_write
1538 {
1539 if (SCM_UNBNDP (port_or_fd))
1540 port_or_fd = scm_current_output_port ();
1541
1542 if (scm_is_uniform_vector (ura))
1543 {
1544 return scm_uniform_vector_write (ura, port_or_fd, start, end);
1545 }
1546 else if (SCM_I_ARRAYP (ura))
1547 {
1548 size_t base, vlen, cstart, cend;
1549 SCM cra, ans;
1550
1551 cra = scm_ra2contig (ura, 1);
1552 base = SCM_I_ARRAY_BASE (cra);
1553 vlen = SCM_I_ARRAY_DIMS (cra)->inc *
1554 (SCM_I_ARRAY_DIMS (cra)->ubnd - SCM_I_ARRAY_DIMS (cra)->lbnd + 1);
1555
1556 cstart = 0;
1557 cend = vlen;
1558 if (!SCM_UNBNDP (start))
1559 {
1560 cstart = scm_to_unsigned_integer (start, 0, vlen);
1561 if (!SCM_UNBNDP (end))
1562 cend = scm_to_unsigned_integer (end, cstart, vlen);
1563 }
1564
1565 ans = scm_uniform_vector_write (SCM_I_ARRAY_V (cra), port_or_fd,
1566 scm_from_size_t (base + cstart),
1567 scm_from_size_t (base + cend));
1568
1569 return ans;
1570 }
1571 else
1572 scm_wrong_type_arg_msg (NULL, 0, ura, "array");
1573 }
1574 #undef FUNC_NAME
1575
1576 SCM
1577 scm_i_cur_inp (void)
1578 {
1579 scm_c_issue_deprecation_warning
1580 ("scm_cur_inp is deprecated. Use scm_current_input_port instead.");
1581 return scm_current_input_port ();
1582 }
1583
1584 SCM
1585 scm_i_cur_outp (void)
1586 {
1587 scm_c_issue_deprecation_warning
1588 ("scm_cur_outp is deprecated. Use scm_current_output_port instead.");
1589 return scm_current_output_port ();
1590 }
1591
1592 SCM
1593 scm_i_cur_errp (void)
1594 {
1595 scm_c_issue_deprecation_warning
1596 ("scm_cur_errp is deprecated. Use scm_current_error_port instead.");
1597 return scm_current_error_port ();
1598 }
1599
1600 SCM
1601 scm_i_cur_loadp (void)
1602 {
1603 scm_c_issue_deprecation_warning
1604 ("scm_cur_loadp is deprecated. Use scm_current_load_port instead.");
1605 return scm_current_load_port ();
1606 }
1607
1608 SCM
1609 scm_i_progargs (void)
1610 {
1611 scm_c_issue_deprecation_warning
1612 ("scm_progargs is deprecated. Use scm_program_arguments instead.");
1613 return scm_program_arguments ();
1614 }
1615
1616 SCM
1617 scm_i_deprecated_dynwinds (void)
1618 {
1619 scm_c_issue_deprecation_warning
1620 ("scm_dynwinds is deprecated. Do not use it.");
1621 return scm_i_dynwinds ();
1622 }
1623
1624 SCM_STACKITEM *
1625 scm_i_stack_base (void)
1626 {
1627 scm_c_issue_deprecation_warning
1628 ("scm_stack_base is deprecated. Do not use it.");
1629 return SCM_I_CURRENT_THREAD->base;
1630 }
1631
1632 int
1633 scm_i_fluidp (SCM x)
1634 {
1635 scm_c_issue_deprecation_warning
1636 ("SCM_FLUIDP is deprecated. Use scm_is_fluid instead.");
1637 return scm_is_fluid (x);
1638 }
1639
1640 \f
1641 /* Networking. */
1642
1643 #ifdef HAVE_NETWORKING
1644
1645 SCM_DEFINE (scm_inet_aton, "inet-aton", 1, 0, 0,
1646 (SCM address),
1647 "Convert an IPv4 Internet address from printable string\n"
1648 "(dotted decimal notation) to an integer. E.g.,\n\n"
1649 "@lisp\n"
1650 "(inet-aton \"127.0.0.1\") @result{} 2130706433\n"
1651 "@end lisp")
1652 #define FUNC_NAME s_scm_inet_aton
1653 {
1654 scm_c_issue_deprecation_warning
1655 ("`inet-aton' is deprecated. Use `inet-pton' instead.");
1656
1657 return scm_inet_pton (scm_from_int (AF_INET), address);
1658 }
1659 #undef FUNC_NAME
1660
1661
1662 SCM_DEFINE (scm_inet_ntoa, "inet-ntoa", 1, 0, 0,
1663 (SCM inetid),
1664 "Convert an IPv4 Internet address to a printable\n"
1665 "(dotted decimal notation) string. E.g.,\n\n"
1666 "@lisp\n"
1667 "(inet-ntoa 2130706433) @result{} \"127.0.0.1\"\n"
1668 "@end lisp")
1669 #define FUNC_NAME s_scm_inet_ntoa
1670 {
1671 scm_c_issue_deprecation_warning
1672 ("`inet-ntoa' is deprecated. Use `inet-ntop' instead.");
1673
1674 return scm_inet_ntop (scm_from_int (AF_INET), inetid);
1675 }
1676 #undef FUNC_NAME
1677
1678 #endif /* HAVE_NETWORKING */
1679
1680 \f
1681 void
1682 scm_i_defer_ints_etc ()
1683 {
1684 scm_c_issue_deprecation_warning
1685 ("SCM_DEFER_INTS etc are deprecated. "
1686 "Use a mutex instead if appropriate.");
1687 }
1688
1689 int
1690 scm_i_mask_ints (void)
1691 {
1692 scm_c_issue_deprecation_warning ("`scm_mask_ints' is deprecated.");
1693 return (SCM_I_CURRENT_THREAD->block_asyncs != 0);
1694 }
1695
1696 \f
1697 SCM
1698 scm_guard (SCM guardian, SCM obj, int throw_p)
1699 {
1700 scm_c_issue_deprecation_warning
1701 ("scm_guard is deprecated. Use scm_call_1 instead.");
1702
1703 return scm_call_1 (guardian, obj);
1704 }
1705
1706 SCM
1707 scm_get_one_zombie (SCM guardian)
1708 {
1709 scm_c_issue_deprecation_warning
1710 ("scm_guard is deprecated. Use scm_call_0 instead.");
1711
1712 return scm_call_0 (guardian);
1713 }
1714
1715 SCM_DEFINE (scm_guardian_destroyed_p, "guardian-destroyed?", 1, 0, 0,
1716 (SCM guardian),
1717 "Return @code{#t} if @var{guardian} has been destroyed, otherwise @code{#f}.")
1718 #define FUNC_NAME s_scm_guardian_destroyed_p
1719 {
1720 scm_c_issue_deprecation_warning
1721 ("'guardian-destroyed?' is deprecated.");
1722 return SCM_BOOL_F;
1723 }
1724 #undef FUNC_NAME
1725
1726 SCM_DEFINE (scm_guardian_greedy_p, "guardian-greedy?", 1, 0, 0,
1727 (SCM guardian),
1728 "Return @code{#t} if @var{guardian} is a greedy guardian, otherwise @code{#f}.")
1729 #define FUNC_NAME s_scm_guardian_greedy_p
1730 {
1731 scm_c_issue_deprecation_warning
1732 ("'guardian-greedy?' is deprecated.");
1733 return SCM_BOOL_F;
1734 }
1735 #undef FUNC_NAME
1736
1737 SCM_DEFINE (scm_destroy_guardian_x, "destroy-guardian!", 1, 0, 0,
1738 (SCM guardian),
1739 "Destroys @var{guardian}, by making it impossible to put any more\n"
1740 "objects in it or get any objects from it. It also unguards any\n"
1741 "objects guarded by @var{guardian}.")
1742 #define FUNC_NAME s_scm_destroy_guardian_x
1743 {
1744 scm_c_issue_deprecation_warning
1745 ("'destroy-guardian!' is deprecated and ineffective.");
1746 return SCM_UNSPECIFIED;
1747 }
1748 #undef FUNC_NAME
1749
1750 \f
1751 /* GC-related things. */
1752
1753 unsigned long scm_mallocated, scm_mtrigger;
1754 size_t scm_max_segment_size;
1755
1756 #if defined (GUILE_DEBUG) || defined (GUILE_DEBUG_FREELIST)
1757 SCM
1758 scm_map_free_list (void)
1759 {
1760 return SCM_EOL;
1761 }
1762 #endif
1763
1764 #if defined (GUILE_DEBUG_FREELIST)
1765 SCM
1766 scm_gc_set_debug_check_freelist_x (SCM flag)
1767 {
1768 return SCM_UNSPECIFIED;
1769 }
1770 #endif
1771
1772 \f
1773 /* Trampolines
1774 *
1775 * Trampolines were an intent to speed up calling the same Scheme procedure many
1776 * times from C.
1777 *
1778 * However, this was the wrong thing to optimize; if you really know what you're
1779 * calling, call its function directly, otherwise you're in Scheme-land, and we
1780 * have many better tricks there (inlining, for example, which can remove the
1781 * need for closures and free variables).
1782 *
1783 * Also, in the normal debugging case, trampolines were being computed but not
1784 * used. Silliness.
1785 */
1786
1787 scm_t_trampoline_0
1788 scm_trampoline_0 (SCM proc)
1789 {
1790 scm_c_issue_deprecation_warning
1791 ("`scm_trampoline_0' is deprecated. Just use `scm_call_0' instead.");
1792 return scm_call_0;
1793 }
1794
1795 scm_t_trampoline_1
1796 scm_trampoline_1 (SCM proc)
1797 {
1798 scm_c_issue_deprecation_warning
1799 ("`scm_trampoline_1' is deprecated. Just use `scm_call_1' instead.");
1800 return scm_call_1;
1801 }
1802
1803 scm_t_trampoline_2
1804 scm_trampoline_2 (SCM proc)
1805 {
1806 scm_c_issue_deprecation_warning
1807 ("`scm_trampoline_2' is deprecated. Just use `scm_call_2' instead.");
1808 return scm_call_2;
1809 }
1810
1811 int
1812 scm_i_subr_p (SCM x)
1813 {
1814 scm_c_issue_deprecation_warning ("`scm_subr_p' is deprecated. Use SCM_PRIMITIVE_P instead.");
1815 return SCM_PRIMITIVE_P (x);
1816 }
1817
1818 \f
1819
1820 SCM
1821 scm_internal_lazy_catch (SCM tag, scm_t_catch_body body, void *body_data, scm_t_catch_handler handler, void *handler_data)
1822 {
1823 scm_c_issue_deprecation_warning
1824 ("`scm_internal_lazy_catch' is no longer supported. Instead this call will\n"
1825 "dispatch to `scm_c_with_throw_handler'. Your handler will be invoked from\n"
1826 "within the dynamic context of the corresponding `throw'.\n"
1827 "\nTHIS COULD CHANGE YOUR PROGRAM'S BEHAVIOR.\n\n"
1828 "Please modify your program to use `scm_c_with_throw_handler' directly,\n"
1829 "and adapt it (if necessary) to expect to be within the dynamic context\n"
1830 "of the throw.");
1831 return scm_c_with_throw_handler (tag, body, body_data, handler, handler_data, 0);
1832 }
1833
1834 SCM_DEFINE (scm_lazy_catch, "lazy-catch", 3, 0, 0,
1835 (SCM key, SCM thunk, SCM handler),
1836 "This behaves exactly like @code{catch}, except that it does\n"
1837 "not unwind the stack before invoking @var{handler}.\n"
1838 "If the @var{handler} procedure returns normally, Guile\n"
1839 "rethrows the same exception again to the next innermost catch,\n"
1840 "lazy-catch or throw handler. If the @var{handler} exits\n"
1841 "non-locally, that exit determines the continuation.")
1842 #define FUNC_NAME s_scm_lazy_catch
1843 {
1844 struct scm_body_thunk_data c;
1845
1846 SCM_ASSERT (scm_is_symbol (key) || scm_is_eq (key, SCM_BOOL_T),
1847 key, SCM_ARG1, FUNC_NAME);
1848
1849 c.tag = key;
1850 c.body_proc = thunk;
1851
1852 scm_c_issue_deprecation_warning
1853 ("`lazy-catch' is no longer supported. Instead this call will dispatch\n"
1854 "to `with-throw-handler'. Your handler will be invoked from within the\n"
1855 "dynamic context of the corresponding `throw'.\n"
1856 "\nTHIS COULD CHANGE YOUR PROGRAM'S BEHAVIOR.\n\n"
1857 "Please modify your program to use `with-throw-handler' directly, and\n"
1858 "adapt it (if necessary) to expect to be within the dynamic context of\n"
1859 "the throw.");
1860
1861 return scm_c_with_throw_handler (key,
1862 scm_body_thunk, &c,
1863 scm_handle_by_proc, &handler, 0);
1864 }
1865 #undef FUNC_NAME
1866
1867
1868 \f
1869
1870
1871 SCM
1872 scm_raequal (SCM ra0, SCM ra1)
1873 {
1874 return scm_array_equal_p (ra0, ra1);
1875 }
1876
1877
1878 \f
1879
1880
1881 SCM_DEFINE (scm_dynamic_args_call, "dynamic-args-call", 3, 0, 0,
1882 (SCM func, SCM dobj, SCM args),
1883 "Call the C function indicated by @var{func} and @var{dobj},\n"
1884 "just like @code{dynamic-call}, but pass it some arguments and\n"
1885 "return its return value. The C function is expected to take\n"
1886 "two arguments and return an @code{int}, just like @code{main}:\n"
1887 "@smallexample\n"
1888 "int c_func (int argc, char **argv);\n"
1889 "@end smallexample\n\n"
1890 "The parameter @var{args} must be a list of strings and is\n"
1891 "converted into an array of @code{char *}. The array is passed\n"
1892 "in @var{argv} and its size in @var{argc}. The return value is\n"
1893 "converted to a Scheme number and returned from the call to\n"
1894 "@code{dynamic-args-call}.")
1895 #define FUNC_NAME s_scm_dynamic_args_call
1896 {
1897 int (*fptr) (int argc, char **argv);
1898 int result, argc;
1899 char **argv;
1900
1901 if (scm_is_string (func))
1902 {
1903 #if HAVE_MODULES
1904 func = scm_dynamic_func (func, dobj);
1905 #else
1906 scm_misc_error ("dynamic-args-call",
1907 "dynamic-func not available to resolve ~S",
1908 scm_list_1 (func));
1909 #endif
1910 }
1911 SCM_VALIDATE_POINTER (SCM_ARG1, func);
1912
1913 fptr = SCM_POINTER_VALUE (func);
1914
1915 argv = scm_i_allocate_string_pointers (args);
1916 for (argc = 0; argv[argc]; argc++)
1917 ;
1918 result = (*fptr) (argc, argv);
1919
1920 return scm_from_int (result);
1921 }
1922 #undef FUNC_NAME
1923
1924
1925 \f
1926
1927
1928 int
1929 scm_badargsp (SCM formals, SCM args)
1930 {
1931 scm_c_issue_deprecation_warning
1932 ("`scm_badargsp' is deprecated. Copy it into your project if you need it.");
1933
1934 while (!scm_is_null (formals))
1935 {
1936 if (!scm_is_pair (formals))
1937 return 0;
1938 if (scm_is_null (args))
1939 return 1;
1940 formals = scm_cdr (formals);
1941 args = scm_cdr (args);
1942 }
1943 return !scm_is_null (args) ? 1 : 0;
1944 }
1945
1946 \f
1947
1948 /* scm_internal_stack_catch
1949 Use this one if you want debugging information to be stored in
1950 the-last-stack on error. */
1951
1952 static SCM
1953 ss_handler (void *data SCM_UNUSED, SCM tag, SCM throw_args)
1954 {
1955 /* In the stack */
1956 scm_fluid_set_x (scm_variable_ref
1957 (scm_c_module_lookup
1958 (scm_c_resolve_module ("ice-9 save-stack"),
1959 "the-last-stack")),
1960 scm_make_stack (SCM_BOOL_T, SCM_EOL));
1961 /* Throw the error */
1962 return scm_throw (tag, throw_args);
1963 }
1964
1965 struct cwss_data
1966 {
1967 SCM tag;
1968 scm_t_catch_body body;
1969 void *data;
1970 };
1971
1972 static SCM
1973 cwss_body (void *data)
1974 {
1975 struct cwss_data *d = data;
1976 return scm_c_with_throw_handler (d->tag, d->body, d->data, ss_handler, NULL, 0);
1977 }
1978
1979 SCM
1980 scm_internal_stack_catch (SCM tag,
1981 scm_t_catch_body body,
1982 void *body_data,
1983 scm_t_catch_handler handler,
1984 void *handler_data)
1985 {
1986 struct cwss_data d;
1987 d.tag = tag;
1988 d.body = body;
1989 d.data = body_data;
1990 scm_c_issue_deprecation_warning
1991 ("`scm_internal_stack_catch' is deprecated. Talk to guile-devel if you see this message.");
1992 return scm_internal_catch (tag, cwss_body, &d, handler, handler_data);
1993 }
1994
1995 \f
1996
1997 SCM
1998 scm_short2num (short x)
1999 {
2000 scm_c_issue_deprecation_warning
2001 ("`scm_short2num' is deprecated. Use scm_from_short instead.");
2002 return scm_from_short (x);
2003 }
2004
2005 SCM
2006 scm_ushort2num (unsigned short x)
2007 {
2008 scm_c_issue_deprecation_warning
2009 ("`scm_ushort2num' is deprecated. Use scm_from_ushort instead.");
2010 return scm_from_ushort (x);
2011 }
2012
2013 SCM
2014 scm_int2num (int x)
2015 {
2016 scm_c_issue_deprecation_warning
2017 ("`scm_int2num' is deprecated. Use scm_from_int instead.");
2018 return scm_from_int (x);
2019 }
2020
2021 SCM
2022 scm_uint2num (unsigned int x)
2023 {
2024 scm_c_issue_deprecation_warning
2025 ("`scm_uint2num' is deprecated. Use scm_from_uint instead.");
2026 return scm_from_uint (x);
2027 }
2028
2029 SCM
2030 scm_long2num (long x)
2031 {
2032 scm_c_issue_deprecation_warning
2033 ("`scm_long2num' is deprecated. Use scm_from_long instead.");
2034 return scm_from_long (x);
2035 }
2036
2037 SCM
2038 scm_ulong2num (unsigned long x)
2039 {
2040 scm_c_issue_deprecation_warning
2041 ("`scm_ulong2num' is deprecated. Use scm_from_ulong instead.");
2042 return scm_from_ulong (x);
2043 }
2044
2045 SCM
2046 scm_size2num (size_t x)
2047 {
2048 scm_c_issue_deprecation_warning
2049 ("`scm_size2num' is deprecated. Use scm_from_size_t instead.");
2050 return scm_from_size_t (x);
2051 }
2052
2053 SCM
2054 scm_ptrdiff2num (ptrdiff_t x)
2055 {
2056 scm_c_issue_deprecation_warning
2057 ("`scm_ptrdiff2num' is deprecated. Use scm_from_ssize_t instead.");
2058 return scm_from_ssize_t (x);
2059 }
2060
2061 short
2062 scm_num2short (SCM x, unsigned long pos, const char *s_caller)
2063 {
2064 scm_c_issue_deprecation_warning
2065 ("`scm_num2short' is deprecated. Use scm_to_short instead.");
2066 return scm_to_short (x);
2067 }
2068
2069 unsigned short
2070 scm_num2ushort (SCM x, unsigned long pos, const char *s_caller)
2071 {
2072 scm_c_issue_deprecation_warning
2073 ("`scm_num2ushort' is deprecated. Use scm_to_ushort instead.");
2074 return scm_to_ushort (x);
2075 }
2076
2077 int
2078 scm_num2int (SCM x, unsigned long pos, const char *s_caller)
2079 {
2080 scm_c_issue_deprecation_warning
2081 ("`scm_num2int' is deprecated. Use scm_to_int instead.");
2082 return scm_to_int (x);
2083 }
2084
2085 unsigned int
2086 scm_num2uint (SCM x, unsigned long pos, const char *s_caller)
2087 {
2088 scm_c_issue_deprecation_warning
2089 ("`scm_num2uint' is deprecated. Use scm_to_uint instead.");
2090 return scm_to_uint (x);
2091 }
2092
2093 long
2094 scm_num2long (SCM x, unsigned long pos, const char *s_caller)
2095 {
2096 scm_c_issue_deprecation_warning
2097 ("`scm_num2long' is deprecated. Use scm_to_long instead.");
2098 return scm_to_long (x);
2099 }
2100
2101 unsigned long
2102 scm_num2ulong (SCM x, unsigned long pos, const char *s_caller)
2103 {
2104 scm_c_issue_deprecation_warning
2105 ("`scm_num2ulong' is deprecated. Use scm_to_ulong instead.");
2106 return scm_to_ulong (x);
2107 }
2108
2109 size_t
2110 scm_num2size (SCM x, unsigned long pos, const char *s_caller)
2111 {
2112 scm_c_issue_deprecation_warning
2113 ("`scm_num2size' is deprecated. Use scm_to_size_t instead.");
2114 return scm_to_size_t (x);
2115 }
2116
2117 ptrdiff_t
2118 scm_num2ptrdiff (SCM x, unsigned long pos, const char *s_caller)
2119 {
2120 scm_c_issue_deprecation_warning
2121 ("`scm_num2ptrdiff' is deprecated. Use scm_to_ssize_t instead.");
2122 return scm_to_ssize_t (x);
2123 }
2124
2125 #if SCM_SIZEOF_LONG_LONG != 0
2126
2127 SCM
2128 scm_long_long2num (long long x)
2129 {
2130 scm_c_issue_deprecation_warning
2131 ("`scm_long_long2num' is deprecated. Use scm_from_long_long instead.");
2132 return scm_from_long_long (x);
2133 }
2134
2135 SCM
2136 scm_ulong_long2num (unsigned long long x)
2137 {
2138 scm_c_issue_deprecation_warning
2139 ("`scm_ulong_long2num' is deprecated. Use scm_from_ulong_long instead.");
2140 return scm_from_ulong_long (x);
2141 }
2142
2143 long long
2144 scm_num2long_long (SCM x, unsigned long pos, const char *s_caller)
2145 {
2146 scm_c_issue_deprecation_warning
2147 ("`scm_num2long_long' is deprecated. Use scm_to_long_long instead.");
2148 return scm_to_long_long (x);
2149 }
2150
2151 unsigned long long
2152 scm_num2ulong_long (SCM x, unsigned long pos, const char *s_caller)
2153 {
2154 scm_c_issue_deprecation_warning
2155 ("`scm_num2ulong_long' is deprecated. Use scm_from_ulong_long instead.");
2156 return scm_to_ulong_long (x);
2157 }
2158
2159 #endif
2160
2161 SCM
2162 scm_make_real (double x)
2163 {
2164 scm_c_issue_deprecation_warning
2165 ("`scm_make_real' is deprecated. Use scm_from_double instead.");
2166 return scm_from_double (x);
2167 }
2168
2169 double
2170 scm_num2dbl (SCM a, const char *why)
2171 {
2172 scm_c_issue_deprecation_warning
2173 ("`scm_num2dbl' is deprecated. Use scm_to_double instead.");
2174 return scm_to_double (a);
2175 }
2176
2177 SCM
2178 scm_float2num (float n)
2179 {
2180 scm_c_issue_deprecation_warning
2181 ("`scm_float2num' is deprecated. Use scm_from_double instead.");
2182 return scm_from_double ((double) n);
2183 }
2184
2185 SCM
2186 scm_double2num (double n)
2187 {
2188 scm_c_issue_deprecation_warning
2189 ("`scm_double2num' is deprecated. Use scm_from_double instead.");
2190 return scm_from_double (n);
2191 }
2192
2193 SCM
2194 scm_make_complex (double x, double y)
2195 {
2196 scm_c_issue_deprecation_warning
2197 ("`scm_make_complex' is deprecated. Use scm_c_make_rectangular instead.");
2198 return scm_c_make_rectangular (x, y);
2199 }
2200
2201 SCM
2202 scm_mem2symbol (const char *mem, size_t len)
2203 {
2204 scm_c_issue_deprecation_warning
2205 ("`scm_mem2symbol' is deprecated. Use scm_from_locale_symboln instead.");
2206 return scm_from_locale_symboln (mem, len);
2207 }
2208
2209 SCM
2210 scm_mem2uninterned_symbol (const char *mem, size_t len)
2211 {
2212 scm_c_issue_deprecation_warning
2213 ("`scm_mem2uninterned_symbol' is deprecated. "
2214 "Use scm_make_symbol and scm_from_locale_symboln instead.");
2215 return scm_make_symbol (scm_from_locale_stringn (mem, len));
2216 }
2217
2218 SCM
2219 scm_str2symbol (const char *str)
2220 {
2221 scm_c_issue_deprecation_warning
2222 ("`scm_str2symbol' is deprecated. Use scm_from_locale_symbol instead.");
2223 return scm_from_locale_symbol (str);
2224 }
2225
2226
2227 /* This function must only be applied to memory obtained via malloc,
2228 since the GC is going to apply `free' to it when the string is
2229 dropped.
2230
2231 Also, s[len] must be `\0', since we promise that strings are
2232 null-terminated. Perhaps we could handle non-null-terminated
2233 strings by claiming they're shared substrings of a string we just
2234 made up. */
2235 SCM
2236 scm_take_str (char *s, size_t len)
2237 {
2238 scm_c_issue_deprecation_warning
2239 ("`scm_take_str' is deprecated. Use scm_take_locale_stringn instead.");
2240 return scm_take_locale_stringn (s, len);
2241 }
2242
2243 /* `s' must be a malloc'd string. See scm_take_str. */
2244 SCM
2245 scm_take0str (char *s)
2246 {
2247 scm_c_issue_deprecation_warning
2248 ("`scm_take0str' is deprecated. Use scm_take_locale_string instead.");
2249 return scm_take_locale_string (s);
2250 }
2251
2252 SCM
2253 scm_mem2string (const char *src, size_t len)
2254 {
2255 scm_c_issue_deprecation_warning
2256 ("`scm_mem2string' is deprecated. Use scm_from_locale_stringn instead.");
2257 return scm_from_locale_stringn (src, len);
2258 }
2259
2260 SCM
2261 scm_str2string (const char *src)
2262 {
2263 scm_c_issue_deprecation_warning
2264 ("`scm_str2string' is deprecated. Use scm_from_locale_string instead.");
2265 return scm_from_locale_string (src);
2266 }
2267
2268 SCM
2269 scm_makfrom0str (const char *src)
2270 {
2271 scm_c_issue_deprecation_warning
2272 ("`scm_makfrom0str' is deprecated."
2273 "Use scm_from_locale_string instead, but check for NULL first.");
2274 if (!src) return SCM_BOOL_F;
2275 return scm_from_locale_string (src);
2276 }
2277
2278 SCM
2279 scm_makfrom0str_opt (const char *src)
2280 {
2281 scm_c_issue_deprecation_warning
2282 ("`scm_makfrom0str_opt' is deprecated."
2283 "Use scm_from_locale_string instead, but check for NULL first.");
2284 return scm_makfrom0str (src);
2285 }
2286
2287
2288 SCM
2289 scm_allocate_string (size_t len)
2290 {
2291 scm_c_issue_deprecation_warning
2292 ("`scm_allocate_string' is deprecated. Use scm_c_make_string instead.");
2293 return scm_i_make_string (len, NULL, 0);
2294 }
2295
2296 SCM_DEFINE (scm_make_keyword_from_dash_symbol, "make-keyword-from-dash-symbol", 1, 0, 0,
2297 (SCM symbol),
2298 "Make a keyword object from a @var{symbol} that starts with a dash.")
2299 #define FUNC_NAME s_scm_make_keyword_from_dash_symbol
2300 {
2301 SCM dash_string, non_dash_symbol;
2302
2303 scm_c_issue_deprecation_warning
2304 ("`scm_make_keyword_from_dash_symbol' is deprecated. Don't use dash symbols.");
2305
2306 SCM_ASSERT (scm_is_symbol (symbol)
2307 && (scm_i_symbol_ref (symbol, 0) == '-'),
2308 symbol, SCM_ARG1, FUNC_NAME);
2309
2310 dash_string = scm_symbol_to_string (symbol);
2311 non_dash_symbol =
2312 scm_string_to_symbol (scm_c_substring (dash_string,
2313 1,
2314 scm_c_string_length (dash_string)));
2315
2316 return scm_symbol_to_keyword (non_dash_symbol);
2317 }
2318 #undef FUNC_NAME
2319
2320 SCM_DEFINE (scm_keyword_dash_symbol, "keyword-dash-symbol", 1, 0, 0,
2321 (SCM keyword),
2322 "Return the dash symbol for @var{keyword}.\n"
2323 "This is the inverse of @code{make-keyword-from-dash-symbol}.")
2324 #define FUNC_NAME s_scm_keyword_dash_symbol
2325 {
2326 SCM symbol = scm_keyword_to_symbol (keyword);
2327 SCM parts = scm_list_2 (scm_from_locale_string ("-"),
2328 scm_symbol_to_string (symbol));
2329 scm_c_issue_deprecation_warning
2330 ("`scm_keyword_dash_symbol' is deprecated. Don't use dash symbols.");
2331
2332 return scm_string_to_symbol (scm_string_append (parts));
2333 }
2334 #undef FUNC_NAME
2335
2336 SCM
2337 scm_c_make_keyword (const char *s)
2338 {
2339 scm_c_issue_deprecation_warning
2340 ("`scm_c_make_keyword' is deprecated. Use scm_from_locale_keyword instead.");
2341 return scm_from_locale_keyword (s);
2342 }
2343
2344 unsigned int
2345 scm_thread_sleep (unsigned int t)
2346 {
2347 scm_c_issue_deprecation_warning
2348 ("`scm_thread_sleep' is deprecated. Use scm_std_sleep instead.");
2349 return scm_std_sleep (t);
2350 }
2351
2352 unsigned long
2353 scm_thread_usleep (unsigned long t)
2354 {
2355 scm_c_issue_deprecation_warning
2356 ("`scm_thread_usleep' is deprecated. Use scm_std_usleep instead.");
2357 return scm_std_usleep (t);
2358 }
2359
2360 #ifdef HAVE_SYS_SELECT_H
2361 int scm_internal_select (int fds,
2362 fd_set *rfds,
2363 fd_set *wfds,
2364 fd_set *efds,
2365 struct timeval *timeout)
2366 {
2367 scm_c_issue_deprecation_warning
2368 ("`scm_internal_select' is deprecated. Use scm_std_select instead.");
2369 return scm_std_select (fds, rfds, wfds, efds, timeout);
2370 }
2371 #endif /* HAVE_SYS_SELECT_H */
2372
2373 \f
2374
2375 #ifdef HAVE_CUSERID
2376
2377 # if !HAVE_DECL_CUSERID
2378 extern char *cuserid (char *);
2379 # endif
2380
2381 SCM_DEFINE (scm_cuserid, "cuserid", 0, 0, 0,
2382 (void),
2383 "Return a string containing a user name associated with the\n"
2384 "effective user id of the process. Return @code{#f} if this\n"
2385 "information cannot be obtained.")
2386 #define FUNC_NAME s_scm_cuserid
2387 {
2388 char buf[L_cuserid];
2389 char * p;
2390
2391 scm_c_issue_deprecation_warning
2392 ("`cuserid' is deprecated. Use `(passwd:name (getpwuid (geteuid)))' instead.");
2393
2394 p = cuserid (buf);
2395 if (!p || !*p)
2396 return SCM_BOOL_F;
2397 return scm_from_locale_string (p);
2398 }
2399 #undef FUNC_NAME
2400 #endif /* HAVE_CUSERID */
2401
2402 \f
2403
2404 /* {Properties}
2405 */
2406
2407 static SCM properties_whash;
2408
2409 SCM_DEFINE (scm_primitive_make_property, "primitive-make-property", 1, 0, 0,
2410 (SCM not_found_proc),
2411 "Create a @dfn{property token} that can be used with\n"
2412 "@code{primitive-property-ref} and @code{primitive-property-set!}.\n"
2413 "See @code{primitive-property-ref} for the significance of\n"
2414 "@var{not_found_proc}.")
2415 #define FUNC_NAME s_scm_primitive_make_property
2416 {
2417 scm_c_issue_deprecation_warning
2418 ("`primitive-make-property' is deprecated. Use object properties.");
2419
2420 if (!scm_is_false (not_found_proc))
2421 SCM_VALIDATE_PROC (SCM_ARG1, not_found_proc);
2422 return scm_cons (not_found_proc, SCM_EOL);
2423 }
2424 #undef FUNC_NAME
2425
2426
2427 SCM_DEFINE (scm_primitive_property_ref, "primitive-property-ref", 2, 0, 0,
2428 (SCM prop, SCM obj),
2429 "Return the property @var{prop} of @var{obj}.\n"
2430 "\n"
2431 "When no value has yet been associated with @var{prop} and\n"
2432 "@var{obj}, the @var{not-found-proc} from @var{prop} is used. A\n"
2433 "call @code{(@var{not-found-proc} @var{prop} @var{obj})} is made\n"
2434 "and the result set as the property value. If\n"
2435 "@var{not-found-proc} is @code{#f} then @code{#f} is the\n"
2436 "property value.")
2437 #define FUNC_NAME s_scm_primitive_property_ref
2438 {
2439 SCM alist;
2440
2441 scm_c_issue_deprecation_warning
2442 ("`primitive-property-ref' is deprecated. Use object properties.");
2443
2444 SCM_VALIDATE_CONS (SCM_ARG1, prop);
2445
2446 alist = scm_hashq_ref (properties_whash, obj, SCM_EOL);
2447 if (scm_is_pair (alist))
2448 {
2449 SCM assoc = scm_assq (prop, alist);
2450 if (scm_is_true (assoc))
2451 return SCM_CDR (assoc);
2452 }
2453
2454 if (scm_is_false (SCM_CAR (prop)))
2455 return SCM_BOOL_F;
2456 else
2457 {
2458 SCM val = scm_call_2 (SCM_CAR (prop), prop, obj);
2459 scm_hashq_set_x (properties_whash, obj,
2460 scm_acons (prop, val, alist));
2461 return val;
2462 }
2463 }
2464 #undef FUNC_NAME
2465
2466
2467 SCM_DEFINE (scm_primitive_property_set_x, "primitive-property-set!", 3, 0, 0,
2468 (SCM prop, SCM obj, SCM val),
2469 "Set the property @var{prop} of @var{obj} to @var{val}.")
2470 #define FUNC_NAME s_scm_primitive_property_set_x
2471 {
2472 SCM alist, assoc;
2473
2474 scm_c_issue_deprecation_warning
2475 ("`primitive-property-set!' is deprecated. Use object properties.");
2476
2477 SCM_VALIDATE_CONS (SCM_ARG1, prop);
2478 alist = scm_hashq_ref (properties_whash, obj, SCM_EOL);
2479 assoc = scm_assq (prop, alist);
2480 if (scm_is_pair (assoc))
2481 SCM_SETCDR (assoc, val);
2482 else
2483 scm_hashq_set_x (properties_whash, obj,
2484 scm_acons (prop, val, alist));
2485 return SCM_UNSPECIFIED;
2486 }
2487 #undef FUNC_NAME
2488
2489
2490 SCM_DEFINE (scm_primitive_property_del_x, "primitive-property-del!", 2, 0, 0,
2491 (SCM prop, SCM obj),
2492 "Remove any value associated with @var{prop} and @var{obj}.")
2493 #define FUNC_NAME s_scm_primitive_property_del_x
2494 {
2495 SCM alist;
2496
2497 scm_c_issue_deprecation_warning
2498 ("`primitive-property-del!' is deprecated. Use object properties.");
2499
2500 SCM_VALIDATE_CONS (SCM_ARG1, prop);
2501 alist = scm_hashq_ref (properties_whash, obj, SCM_EOL);
2502 if (scm_is_pair (alist))
2503 scm_hashq_set_x (properties_whash, obj, scm_assq_remove_x (alist, prop));
2504 return SCM_UNSPECIFIED;
2505 }
2506 #undef FUNC_NAME
2507
2508 \f
2509
2510 SCM
2511 scm_whash_get_handle (SCM whash, SCM key)
2512 {
2513 scm_c_issue_deprecation_warning
2514 ("The `scm_whash' API is deprecated. Use the `scm_hashq' API instead.");
2515
2516 return scm_hashq_get_handle (whash, key);
2517 }
2518
2519 int
2520 SCM_WHASHFOUNDP (SCM h)
2521 {
2522 scm_c_issue_deprecation_warning
2523 ("The `scm_whash' API is deprecated. Use the `scm_hashq' API instead.");
2524
2525 return scm_is_true (h);
2526 }
2527
2528 SCM
2529 SCM_WHASHREF (SCM whash, SCM handle)
2530 {
2531 scm_c_issue_deprecation_warning
2532 ("The `scm_whash' API is deprecated. Use the `scm_hashq' API instead.");
2533
2534 return SCM_CDR (handle);
2535 }
2536
2537 void
2538 SCM_WHASHSET (SCM whash, SCM handle, SCM obj)
2539 {
2540 scm_c_issue_deprecation_warning
2541 ("The `scm_whash' API is deprecated. Use the `scm_hashq' API instead.");
2542
2543 SCM_SETCDR (handle, obj);
2544 }
2545
2546 SCM
2547 scm_whash_create_handle (SCM whash, SCM key)
2548 {
2549 scm_c_issue_deprecation_warning
2550 ("The `scm_whash' API is deprecated. Use the `scm_hashq' API instead.");
2551
2552 return scm_hashq_create_handle_x (whash, key, SCM_UNSPECIFIED);
2553 }
2554
2555 SCM
2556 scm_whash_lookup (SCM whash, SCM obj)
2557 {
2558 scm_c_issue_deprecation_warning
2559 ("The `scm_whash' API is deprecated. Use the `scm_hashq' API instead.");
2560
2561 return scm_hashq_ref (whash, obj, SCM_BOOL_F);
2562 }
2563
2564 void
2565 scm_whash_insert (SCM whash, SCM key, SCM obj)
2566 {
2567 scm_c_issue_deprecation_warning
2568 ("The `scm_whash' API is deprecated. Use the `scm_hashq' API instead.");
2569
2570 scm_hashq_set_x (whash, key, obj);
2571 }
2572
2573 \f
2574
2575 SCM scm_struct_table = SCM_BOOL_F;
2576
2577 SCM
2578 scm_struct_create_handle (SCM obj)
2579 {
2580 scm_c_issue_deprecation_warning
2581 ("`scm_struct_create_handle' is deprecated, and has no effect.");
2582
2583 return scm_cons (obj, scm_cons (SCM_BOOL_F, SCM_BOOL_F));
2584 }
2585
2586 \f
2587
2588 SCM
2589 scm_internal_dynamic_wind (scm_t_guard before,
2590 scm_t_inner inner,
2591 scm_t_guard after,
2592 void *inner_data,
2593 void *guard_data)
2594 {
2595 SCM ans;
2596
2597 scm_c_issue_deprecation_warning
2598 ("`scm_internal_dynamic_wind' is deprecated. "
2599 "Use the `scm_dynwind_begin' / `scm_dynwind_end' API instead.");
2600
2601 scm_dynwind_begin (SCM_F_DYNWIND_REWINDABLE);
2602 scm_dynwind_rewind_handler (before, guard_data, SCM_F_WIND_EXPLICITLY);
2603 scm_dynwind_unwind_handler (after, guard_data, SCM_F_WIND_EXPLICITLY);
2604 ans = inner (inner_data);
2605 scm_dynwind_end ();
2606 return ans;
2607 }
2608
2609 \f
2610
2611 SCM
2612 scm_immutable_cell (scm_t_bits car, scm_t_bits cdr)
2613 {
2614 scm_c_issue_deprecation_warning
2615 ("scm_immutable_cell is deprecated. Use scm_cell instead.");
2616
2617 return scm_cell (car, cdr);
2618 }
2619
2620 SCM
2621 scm_immutable_double_cell (scm_t_bits car, scm_t_bits cbr,
2622 scm_t_bits ccr, scm_t_bits cdr)
2623 {
2624 scm_c_issue_deprecation_warning
2625 ("scm_immutable_double_cell is deprecated. Use scm_double_cell instead.");
2626
2627 return scm_double_cell (car, cbr, ccr, cdr);
2628 }
2629
2630 \f
2631
2632
2633 scm_t_bits
2634 scm_i_deprecated_asrtgo (scm_t_bits condition)
2635 {
2636 scm_c_issue_deprecation_warning
2637 ("SCM_ASRTGO is deprecated. Use `if (!condition) goto label;' directly.");
2638
2639 return condition;
2640 }
2641
2642
2643 \f
2644
2645
2646 /* scm_sym2var
2647 *
2648 * looks up the variable bound to SYM according to PROC. PROC should be
2649 * a `eval closure' of some module.
2650 *
2651 * When no binding exists, and DEFINEP is true, create a new binding
2652 * with a initial value of SCM_UNDEFINED. Return `#f' when DEFINEP as
2653 * false and no binding exists.
2654 *
2655 * When PROC is `#f', it is ignored and the binding is searched for in
2656 * the scm_pre_modules_obarray (a `eq' hash table).
2657 */
2658
2659 SCM
2660 scm_sym2var (SCM sym, SCM proc, SCM definep)
2661 #define FUNC_NAME "scm_sym2var"
2662 {
2663 SCM var;
2664
2665 if (scm_is_true (definep))
2666 scm_c_issue_deprecation_warning
2667 ("scm_sym2var is deprecated. Use scm_define or scm_module_define\n"
2668 "to define variables. In some rare cases you may need\n"
2669 "scm_module_ensure_local_variable.");
2670 else
2671 scm_c_issue_deprecation_warning
2672 ("scm_sym2var is deprecated. Use scm_module_variable to look up\n"
2673 "variables.");
2674
2675 if (SCM_NIMP (proc))
2676 {
2677 if (SCM_EVAL_CLOSURE_P (proc))
2678 {
2679 /* Bypass evaluator in the standard case. */
2680 var = scm_eval_closure_lookup (proc, sym, definep);
2681 }
2682 else
2683 var = scm_call_2 (proc, sym, definep);
2684 }
2685 else
2686 {
2687 if (scm_is_false (definep))
2688 var = scm_module_variable (scm_the_root_module (), sym);
2689 else
2690 var = scm_module_ensure_local_variable (scm_the_root_module (), sym);
2691 }
2692
2693 if (scm_is_true (var) && !SCM_VARIABLEP (var))
2694 SCM_MISC_ERROR ("~S is not bound to a variable", scm_list_1 (sym));
2695
2696 return var;
2697 }
2698 #undef FUNC_NAME
2699
2700 SCM
2701 scm_lookup_closure_module (SCM proc)
2702 {
2703 scm_c_issue_deprecation_warning
2704 ("Eval closures are deprecated. See \"Accessing Modules From C\" in\n"
2705 "the manual, for replacements.");
2706
2707 if (scm_is_false (proc))
2708 return scm_the_root_module ();
2709 else if (SCM_EVAL_CLOSURE_P (proc))
2710 return SCM_PACK (SCM_SMOB_DATA (proc));
2711 else
2712 /* FIXME: The `module' property is no longer set on eval closures, as it
2713 introduced a circular reference that precludes garbage collection of
2714 modules with the current weak hash table semantics (see
2715 http://lists.gnu.org/archive/html/guile-devel/2009-01/msg00102.html and
2716 http://thread.gmane.org/gmane.comp.programming.garbage-collection.boehmgc/2465
2717 for details). Since it doesn't appear to be used (only in this
2718 function, which has 1 caller), we no longer extend
2719 `set-module-eval-closure!' to set the `module' property. */
2720 abort ();
2721 }
2722
2723 SCM
2724 scm_module_lookup_closure (SCM module)
2725 {
2726 scm_c_issue_deprecation_warning
2727 ("Eval closures are deprecated. See \"Accessing Modules From C\" in\n"
2728 "the manual, for replacements.");
2729
2730 if (scm_is_false (module))
2731 return SCM_BOOL_F;
2732 else
2733 return SCM_MODULE_EVAL_CLOSURE (module);
2734 }
2735
2736 SCM
2737 scm_current_module_lookup_closure ()
2738 {
2739 scm_c_issue_deprecation_warning
2740 ("Eval closures are deprecated. See \"Accessing Modules From C\" in\n"
2741 "the manual, for replacements.");
2742
2743 if (scm_module_system_booted_p)
2744 return scm_module_lookup_closure (scm_current_module ());
2745 else
2746 return SCM_BOOL_F;
2747 }
2748
2749 scm_t_bits scm_tc16_eval_closure;
2750
2751 #define SCM_F_EVAL_CLOSURE_INTERFACE (1<<0)
2752 #define SCM_EVAL_CLOSURE_INTERFACE_P(e) \
2753 (SCM_SMOB_FLAGS (e) & SCM_F_EVAL_CLOSURE_INTERFACE)
2754
2755 /* NOTE: This function may be called by a smob application
2756 or from another C function directly. */
2757 SCM
2758 scm_eval_closure_lookup (SCM eclo, SCM sym, SCM definep)
2759 {
2760 SCM module = SCM_PACK (SCM_SMOB_DATA (eclo));
2761
2762 scm_c_issue_deprecation_warning
2763 ("Eval closures are deprecated. See \"Accessing Modules From C\" in\n"
2764 "the manual, for replacements.");
2765
2766 if (scm_is_true (definep))
2767 {
2768 if (SCM_EVAL_CLOSURE_INTERFACE_P (eclo))
2769 return SCM_BOOL_F;
2770 return scm_module_ensure_local_variable (module, sym);
2771 }
2772 else
2773 return scm_module_variable (module, sym);
2774 }
2775
2776 SCM_DEFINE (scm_standard_eval_closure, "standard-eval-closure", 1, 0, 0,
2777 (SCM module),
2778 "Return an eval closure for the module @var{module}.")
2779 #define FUNC_NAME s_scm_standard_eval_closure
2780 {
2781 scm_c_issue_deprecation_warning
2782 ("Eval closures are deprecated. See \"Accessing Modules From C\" in\n"
2783 "the manual, for replacements.");
2784
2785 SCM_RETURN_NEWSMOB (scm_tc16_eval_closure, SCM_UNPACK (module));
2786 }
2787 #undef FUNC_NAME
2788
2789
2790 SCM_DEFINE (scm_standard_interface_eval_closure,
2791 "standard-interface-eval-closure", 1, 0, 0,
2792 (SCM module),
2793 "Return a interface eval closure for the module @var{module}. "
2794 "Such a closure does not allow new bindings to be added.")
2795 #define FUNC_NAME s_scm_standard_interface_eval_closure
2796 {
2797 scm_c_issue_deprecation_warning
2798 ("Eval closures are deprecated. See \"Accessing Modules From C\" in\n"
2799 "the manual, for replacements.");
2800
2801 SCM_RETURN_NEWSMOB (scm_tc16_eval_closure | (SCM_F_EVAL_CLOSURE_INTERFACE<<16),
2802 SCM_UNPACK (module));
2803 }
2804 #undef FUNC_NAME
2805
2806 SCM_DEFINE (scm_eval_closure_module,
2807 "eval-closure-module", 1, 0, 0,
2808 (SCM eval_closure),
2809 "Return the module associated with this eval closure.")
2810 /* the idea is that eval closures are really not the way to do things, they're
2811 superfluous given our module system. this function lets mmacros migrate away
2812 from eval closures. */
2813 #define FUNC_NAME s_scm_eval_closure_module
2814 {
2815 scm_c_issue_deprecation_warning
2816 ("Eval closures are deprecated. See \"Accessing Modules From C\" in\n"
2817 "the manual, for replacements.");
2818
2819 SCM_MAKE_VALIDATE_MSG (SCM_ARG1, eval_closure, EVAL_CLOSURE_P,
2820 "eval-closure");
2821 return SCM_SMOB_OBJECT (eval_closure);
2822 }
2823 #undef FUNC_NAME
2824
2825
2826 \f
2827
2828 SCM_DEFINE (scm_struct_vtable_tag, "struct-vtable-tag", 1, 0, 0,
2829 (SCM handle),
2830 "Return the vtable tag of the structure @var{handle}.")
2831 #define FUNC_NAME s_scm_struct_vtable_tag
2832 {
2833 SCM_VALIDATE_VTABLE (1, handle);
2834 scm_c_issue_deprecation_warning
2835 ("struct-vtable-tag is deprecated. What were you doing with it anyway?");
2836
2837 return scm_from_unsigned_integer
2838 (((scm_t_bits)SCM_STRUCT_DATA (handle)) >> 3);
2839 }
2840 #undef FUNC_NAME
2841
2842
2843 \f
2844
2845 SCM_DEFINE (scm_generalized_vector_p, "generalized-vector?", 1, 0, 0,
2846 (SCM obj),
2847 "Return @code{#t} if @var{obj} is a vector, string,\n"
2848 "bitvector, or uniform numeric vector.")
2849 #define FUNC_NAME s_scm_generalized_vector_p
2850 {
2851 scm_c_issue_deprecation_warning
2852 ("generalized-vector? is deprecated. Use array? and check the "
2853 "array-rank instead.");
2854 return scm_from_bool (scm_is_generalized_vector (obj));
2855 }
2856 #undef FUNC_NAME
2857
2858 SCM_DEFINE (scm_generalized_vector_length, "generalized-vector-length", 1, 0, 0,
2859 (SCM v),
2860 "Return the length of the generalized vector @var{v}.")
2861 #define FUNC_NAME s_scm_generalized_vector_length
2862 {
2863 scm_c_issue_deprecation_warning
2864 ("generalized-vector-length is deprecated. Use array-length instead.");
2865 return scm_from_size_t (scm_c_generalized_vector_length (v));
2866 }
2867 #undef FUNC_NAME
2868
2869 SCM_DEFINE (scm_generalized_vector_ref, "generalized-vector-ref", 2, 0, 0,
2870 (SCM v, SCM idx),
2871 "Return the element at index @var{idx} of the\n"
2872 "generalized vector @var{v}.")
2873 #define FUNC_NAME s_scm_generalized_vector_ref
2874 {
2875 scm_c_issue_deprecation_warning
2876 ("generalized-vector-ref is deprecated. Use array-ref instead.");
2877 return scm_c_generalized_vector_ref (v, scm_to_size_t (idx));
2878 }
2879 #undef FUNC_NAME
2880
2881 SCM_DEFINE (scm_generalized_vector_set_x, "generalized-vector-set!", 3, 0, 0,
2882 (SCM v, SCM idx, SCM val),
2883 "Set the element at index @var{idx} of the\n"
2884 "generalized vector @var{v} to @var{val}.")
2885 #define FUNC_NAME s_scm_generalized_vector_set_x
2886 {
2887 scm_c_issue_deprecation_warning
2888 ("generalized-vector-set! is deprecated. Use array-set! instead. "
2889 "Note the change in argument order!");
2890 scm_c_generalized_vector_set_x (v, scm_to_size_t (idx), val);
2891 return SCM_UNSPECIFIED;
2892 }
2893 #undef FUNC_NAME
2894
2895 SCM_DEFINE (scm_generalized_vector_to_list, "generalized-vector->list", 1, 0, 0,
2896 (SCM v),
2897 "Return a new list whose elements are the elements of the\n"
2898 "generalized vector @var{v}.")
2899 #define FUNC_NAME s_scm_generalized_vector_to_list
2900 {
2901 /* FIXME: This duplicates `array_to_list'. */
2902 SCM ret = SCM_EOL;
2903 long inc;
2904 ssize_t pos, i;
2905 scm_t_array_handle h;
2906
2907 scm_c_issue_deprecation_warning
2908 ("generalized-vector->list is deprecated. Use array->list instead.");
2909
2910 scm_generalized_vector_get_handle (v, &h);
2911
2912 i = h.dims[0].ubnd - h.dims[0].lbnd + 1;
2913 inc = h.dims[0].inc;
2914 pos = (i - 1) * inc;
2915
2916 for (; i > 0; i--, pos -= inc)
2917 ret = scm_cons (h.impl->vref (&h, h.base + pos), ret);
2918
2919 scm_array_handle_release (&h);
2920 return ret;
2921 }
2922 #undef FUNC_NAME
2923
2924
2925 \f
2926
2927 extern SCM
2928 scm_c_program_source (SCM program, size_t ip)
2929 {
2930 scm_c_issue_deprecation_warning
2931 ("scm_c_program_source is deprecated. Use scm_program_source instead.");
2932
2933 return scm_program_source (program, scm_from_size_t (ip), SCM_UNBOUND);
2934 }
2935
2936
2937 \f
2938
2939 SCM_DEFINE (scm_gc_live_object_stats, "gc-live-object-stats", 0, 0, 0,
2940 (),
2941 "Return an alist of statistics of the current live objects. ")
2942 #define FUNC_NAME s_scm_gc_live_object_stats
2943 {
2944 scm_c_issue_deprecation_warning
2945 ("gc-live-object-stats is deprecated. There is no replacement,\n"
2946 "unfortunately.");
2947
2948 return SCM_EOL;
2949 }
2950 #undef FUNC_NAME
2951
2952
2953 \f
2954
2955 SCM_DEFINE (scm_htons, "htons", 1, 0, 0,
2956 (SCM value),
2957 "Convert a 16 bit quantity from host to network byte ordering.\n"
2958 "@var{value} is packed into 2 bytes, which are then converted\n"
2959 "and returned as a new integer.")
2960 #define FUNC_NAME s_scm_htons
2961 {
2962 scm_c_issue_deprecation_warning
2963 ("htons is deprecated. Use bytevector-u16-set! and bytevector-u16-ref "
2964 "with big endianness.");
2965
2966 return scm_from_ushort (htons (scm_to_ushort (value)));
2967 }
2968 #undef FUNC_NAME
2969
2970 SCM_DEFINE (scm_ntohs, "ntohs", 1, 0, 0,
2971 (SCM value),
2972 "Convert a 16 bit quantity from network to host byte ordering.\n"
2973 "@var{value} is packed into 2 bytes, which are then converted\n"
2974 "and returned as a new integer.")
2975 #define FUNC_NAME s_scm_ntohs
2976 {
2977 scm_c_issue_deprecation_warning
2978 ("ntohs is deprecated. Use bytevector-u16-set! and bytevector-u16-ref "
2979 "with big endianness.");
2980
2981 return scm_from_ushort (ntohs (scm_to_ushort (value)));
2982 }
2983 #undef FUNC_NAME
2984
2985 SCM_DEFINE (scm_htonl, "htonl", 1, 0, 0,
2986 (SCM value),
2987 "Convert a 32 bit quantity from host to network byte ordering.\n"
2988 "@var{value} is packed into 4 bytes, which are then converted\n"
2989 "and returned as a new integer.")
2990 #define FUNC_NAME s_scm_htonl
2991 {
2992 scm_c_issue_deprecation_warning
2993 ("htonl is deprecated. Use bytevector-u32-set! and bytevector-u32-ref "
2994 "with big endianness.");
2995
2996 return scm_from_ulong (htonl (scm_to_uint32 (value)));
2997 }
2998 #undef FUNC_NAME
2999
3000 SCM_DEFINE (scm_ntohl, "ntohl", 1, 0, 0,
3001 (SCM value),
3002 "Convert a 32 bit quantity from network to host byte ordering.\n"
3003 "@var{value} is packed into 4 bytes, which are then converted\n"
3004 "and returned as a new integer.")
3005 #define FUNC_NAME s_scm_ntohl
3006 {
3007 scm_c_issue_deprecation_warning
3008 ("ntohl is deprecated. Use bytevector-u32-set! and bytevector-u32-ref "
3009 "with big endianness.");
3010
3011 return scm_from_ulong (ntohl (scm_to_uint32 (value)));
3012 }
3013 #undef FUNC_NAME
3014
3015
3016 \f
3017
3018 void
3019 scm_i_init_deprecated ()
3020 {
3021 properties_whash = scm_make_weak_key_hash_table (SCM_UNDEFINED);
3022 scm_struct_table = scm_make_hash_table (SCM_UNDEFINED);
3023 scm_tc16_eval_closure = scm_make_smob_type ("eval-closure", 0);
3024 scm_set_smob_apply (scm_tc16_eval_closure, scm_eval_closure_lookup, 2, 0, 0);
3025
3026 #include "libguile/deprecated.x"
3027 }
3028
3029 #endif