code:
/* This file contains definitions for deprecated features.  When you
   deprecate something, move it here when that is feasible.
*/

/* Copyright (C) 2003, 2004, 2006, 2008 Free Software Foundation, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include "libguile/_scm.h"
#include "libguile/async.h"
#include "libguile/deprecated.h"
#include "libguile/discouraged.h"
#include "libguile/deprecation.h"
#include "libguile/snarf.h"
#include "libguile/validate.h"
#include "libguile/strings.h"
#include "libguile/srfi-13.h"
#include "libguile/modules.h"
#include "libguile/eval.h"
#include "libguile/smob.h"
#include "libguile/procprop.h"
#include "libguile/vectors.h"
#include "libguile/hashtab.h"
#include "libguile/struct.h"
#include "libguile/variable.h"
#include "libguile/fluids.h"
#include "libguile/ports.h"
#include "libguile/eq.h"
#include "libguile/read.h"
#include "libguile/strports.h"
#include "libguile/smob.h"
#include "libguile/alist.h"
#include "libguile/keywords.h"
#include "libguile/feature.h"

#include <stdio.h>
#include <string.h>

#if (SCM_ENABLE_DEPRECATED == 1)

/* From print.c: Internal symbol names of isyms.  Deprecated in guile 1.7.0 on
 * 2004-04-22.  */
char *scm_isymnames[] =
{
  "#@<deprecated>"
};

/* From eval.c: Error messages of the evaluator.  These were deprecated in
 * guile 1.7.0 on 2003-06-02.  */
const char scm_s_expression[] = "missing or extra expression";
const char scm_s_test[] = "bad test";
const char scm_s_body[] = "bad body";
const char scm_s_bindings[] = "bad bindings";
const char scm_s_variable[] = "bad variable";
const char scm_s_clauses[] = "bad or missing clauses";
const char scm_s_formals[] = "bad formals";

SCM_REGISTER_PROC(s_substring_move_left_x, "substring-move-left!", 5, 0, 0, scm_substring_move_x);

SCM_REGISTER_PROC(s_substring_move_right_x, "substring-move-right!", 5, 0, 0, scm_substring_move_x);

SCM
scm_wta (SCM arg, const char *pos, const char *s_subr)
{
  if (!s_subr || !*s_subr)
    s_subr = NULL;
  if ((~0x1fL) & (long) pos)
    {
      /* error string supplied.  */
      scm_misc_error (s_subr, pos, scm_list_1 (arg));
    }
  else
    {
      /* numerical error code.  */
      scm_t_bits error = (scm_t_bits) pos;

      switch (error)
	{
	case SCM_ARGn:
	  scm_wrong_type_arg (s_subr, 0, arg);
	case SCM_ARG1:
	  scm_wrong_type_arg (s_subr, 1, arg);
	case SCM_ARG2:
	  scm_wrong_type_arg (s_subr, 2, arg);
	case SCM_ARG3:
	  scm_wrong_type_arg (s_subr, 3, arg);
	case SCM_ARG4:
	  scm_wrong_type_arg (s_subr, 4, arg);
	case SCM_ARG5:
	  scm_wrong_type_arg (s_subr, 5, arg);
	case SCM_ARG6:
	  scm_wrong_type_arg (s_subr, 6, arg);
	case SCM_ARG7:
	  scm_wrong_type_arg (s_subr, 7, arg);
	case SCM_WNA:
	  scm_wrong_num_args (arg);
	case SCM_OUTOFRANGE:
	  scm_out_of_range (s_subr, arg);
	case SCM_NALLOC:
	  scm_memory_error (s_subr);
	default:
	  /* this shouldn't happen.  */
	  scm_misc_error (s_subr, "Unknown error", SCM_EOL);
	}
    }
  return SCM_UNSPECIFIED;
}

/* Module registry
 */

/* We can't use SCM objects here. One should be able to call
   SCM_REGISTER_MODULE from a C++ constructor for a static
   object. This happens before main and thus before libguile is
   initialized. */

struct moddata {
  struct moddata *link;
  char *module_name;
  void *init_func;
};

static struct moddata *registered_mods = NULL;

void
scm_register_module_xxx (char *module_name, void *init_func)
{
  struct moddata *md;

  scm_c_issue_deprecation_warning
    ("`scm_register_module_xxx' is deprecated.  Use extensions instead.");

  /* XXX - should we (and can we) DEFER_INTS here? */

  for (md = registered_mods; md; md = md->link)
    if (!strcmp (md->module_name, module_name))
      {
	md->init_func = init_func;
	return;
      }

  md = (struct moddata *) malloc (sizeof (struct moddata));
  if (md == NULL)
    {
      fprintf (stderr,
	       "guile: can't register module (%s): not enough memory",
	       module_name);
      return;
    }

  md->module_name = module_name;
  md->init_func = init_func;
  md->link = registered_mods;
  registered_mods = md;
}

SCM_DEFINE (scm_registered_modules, "c-registered-modules", 0, 0, 0,
            (),
	    "Return a list of the object code modules that have been imported into\n"
	    "the current Guile process.  Each element of the list is a pair whose\n"
	    "car is the name of the module, and whose cdr is the function handle\n"
	    "for that module's initializer function.  The name is the string that\n"
	    "has been passed to scm_register_module_xxx.")
#define FUNC_NAME s_scm_registered_modules
{
  SCM res;
  struct moddata *md;

  res = SCM_EOL;
  for (md = registered_mods; md; md = md->link)
    res = scm_cons (scm_cons (scm_from_locale_string (md->module_name),
			      scm_from_ulong ((unsigned long) md->init_func)),
		    res);
  return res;
}
#undef FUNC_NAME

SCM_DEFINE (scm_clear_registered_modules, "c-clear-registered-modules", 0, 0, 0,
            (),
	    "Destroy the list of modules registered with the current Guile process.\n"
	    "The return value is unspecified.  @strong{Warning:} this function does\n"
	    "not actually unlink or deallocate these modules, but only destroys the\n"
	    "records of which modules have been loaded.  It should therefore be used\n"
	    "only by module bookkeeping operations.")
#define FUNC_NAME s_scm_clear_registered_modules
{
  struct moddata *md1, *md2;

  SCM_CRITICAL_SECTION_START;

  for (md1 = registered_mods; md1; md1 = md2)
    {
      md2 = md1->link;
      free (md1);
    }
  registered_mods = NULL;

  SCM_CRITICAL_SECTION_END;
  return SCM_UNSPECIFIED;
}
#undef FUNC_NAME

void
scm_remember (SCM *ptr)
{
  scm_c_issue_deprecation_warning ("`scm_remember' is deprecated. "
                                   "Use the `scm_remember_upto_here*' family of functions instead.");
}

SCM
scm_protect_object (SCM obj)
{
  scm_c_issue_deprecation_warning ("`scm_protect_object' is deprecated. "
                                   "Use `scm_gc_protect_object' instead.");
  return scm_gc_protect_object (obj);
}

SCM
scm_unprotect_object (SCM obj)
{
  scm_c_issue_deprecation_warning ("`scm_unprotect_object' is deprecated. "
                                   "Use `scm_gc_unprotect_object' instead.");
  return scm_gc_unprotect_object (obj);
}

SCM_SYMBOL (scm_sym_app, "app");
SCM_SYMBOL (scm_sym_modules, "modules");
static SCM module_prefix = SCM_BOOL_F;
static SCM make_modules_in_var;
static SCM beautify_user_module_x_var;
static SCM try_module_autoload_var;

static void
init_module_stuff ()
{
#define PERM(x) scm_permanent_object(x)

  if (module_prefix == SCM_BOOL_F)
    {
      module_prefix = PERM (scm_list_2 (scm_sym_app, scm_sym_modules));
      make_modules_in_var = PERM (scm_c_lookup ("make-modules-in"));
      beautify_user_module_x_var =
	PERM (scm_c_lookup ("beautify-user-module!"));
      try_module_autoload_var = PERM (scm_c_lookup ("try-module-autoload"));
    }
}

SCM
scm_the_root_module ()
{
  init_module_stuff ();
  scm_c_issue_deprecation_warning ("`scm_the_root_module' is deprecated. "
				   "Use `scm_c_resolve_module (\"guile\")' "
				   "instead.");

  return scm_c_resolve_module ("guile");
}

static SCM
scm_module_full_name (SCM name)
{
  init_module_stuff ();
  if (scm_is_eq (SCM_CAR (name), scm_sym_app))
    return name;
  else
    return scm_append (scm_list_2 (module_prefix, name));
}

SCM
scm_make_module (SCM name)
{
  init_module_stuff ();
  scm_c_issue_deprecation_warning ("`scm_make_module' is deprecated. "
				   "Use `scm_c_define_module instead.");

  return scm_call_2 (SCM_VARIABLE_REF (make_modules_in_var),
		     scm_the_root_module (),
		     scm_module_full_name (name));
}

SCM
scm_ensure_user_module (SCM module)
{
  init_module_stuff ();
  scm_c_issue_deprecation_warning ("`scm_ensure_user_module' is deprecated. "
				   "Use `scm_c_define_module instead.");

  scm_call_1 (SCM_VARIABLE_REF (beautify_user_module_x_var), module);
  return SCM_UNSPECIFIED;
}

SCM
scm_load_scheme_module (SCM name)
{
  init_module_stuff ();
  scm_c_issue_deprecation_warning ("`scm_load_scheme_module' is deprecated. "
				   "Use `scm_c_resolve_module instead.");

  return scm_call_1 (SCM_VARIABLE_REF (try_module_autoload_var), name);
}

/* This is implemented in C solely for SCM_COERCE_OUTPORT ... */

static void
maybe_close_port (void *data, SCM port)
{
  SCM except_set = (SCM) data;

  while (!scm_is_null (except_set))
    {
      SCM p = SCM_COERCE_OUTPORT (SCM_CAR (except_set));
      if (scm_is_eq (p, port))
	return;
      except_set = SCM_CDR (except_set);
    }

  scm_close_port (port);
}

SCM_DEFINE (scm_close_all_ports_except, "close-all-ports-except", 0, 0, 1,
           (SCM ports),
	    "[DEPRECATED] Close all open file ports used by the interpreter\n"
	    "except for those supplied as arguments.  This procedure\n"
	    "was intended to be used before an exec call to close file descriptors\n"
	    "which are not needed in the new process.  However it has the\n"
	    "undesirable side effect of flushing buffers, so it's deprecated.\n"
	    "Use port-for-each instead.")
#define FUNC_NAME s_scm_close_all_ports_except
{
  SCM p;
  SCM_VALIDATE_REST_ARGUMENT (ports);

  for (p = ports; !scm_is_null (p); p = SCM_CDR (p))
    SCM_VALIDATE_OPPORT (SCM_ARG1, SCM_COERCE_OUTPORT (SCM_CAR (p)));

  scm_c_port_for_each (maybe_close_port, ports);

  return SCM_UNSPECIFIED;
}
#undef FUNC_NAME

SCM_DEFINE (scm_variable_set_name_hint, "variable-set-name-hint!", 2, 0, 0,
	    (SCM var, SCM hint),
	    "Do not use this function.")
#define FUNC_NAME s_scm_variable_set_name_hint
{
  SCM_VALIDATE_VARIABLE (1, var);
  SCM_VALIDATE_SYMBOL (2, hint);
  scm_c_issue_deprecation_warning
    ("'variable-set-name-hint!' is deprecated.  Do not use it.");
  return SCM_UNSPECIFIED;
}
#undef FUNC_NAME

SCM_DEFINE (scm_builtin_variable, "builtin-variable", 1, 0, 0,
            (SCM name),
	    "Do not use this function.")
#define FUNC_NAME s_scm_builtin_variable
{
  SCM_VALIDATE_SYMBOL (1,name);
  scm_c_issue_deprecation_warning ("`builtin-variable' is deprecated. "
				   "Use module system operations instead.");
  return scm_sym2var (name, SCM_BOOL_F, SCM_BOOL_T);
}
#undef FUNC_NAME

SCM
scm_makstr (size_t len, int dummy)
{
  scm_c_issue_deprecation_warning
    ("'scm_makstr' is deprecated.  Use 'scm_c_make_string' instead.");
  return scm_c_make_string (len, SCM_UNDEFINED);
}

SCM
scm_makfromstr (const char *src, size_t len, int dummy SCM_UNUSED)
{
  scm_c_issue_deprecation_warning ("`scm_makfromstr' is deprecated. "
				   "Use `scm_from_locale_stringn' instead.");

  return scm_from_locale_stringn (src, len);
}

SCM
scm_internal_with_fluids (SCM fluids, SCM values, SCM (*cproc) (), void *cdata)
{
  scm_c_issue_deprecation_warning ("`scm_internal_with_fluids' is deprecated. "
				   "Use `scm_c_with_fluids' instead.");

  return scm_c_with_fluids (fluids, values, cproc, cdata);
}

SCM
scm_make_gsubr (const char *name, int req, int opt, int rst, SCM (*fcn)())
{
  scm_c_issue_deprecation_warning
    ("`scm_make_gsubr' is deprecated.  Use `scm_c_define_gsubr' instead.");

  return scm_c_define_gsubr (name, req, opt, rst, fcn);
}

SCM
scm_make_gsubr_with_generic (const char *name,
			     int req, int opt, int rst,
			     SCM (*fcn)(), SCM *gf)
{
  scm_c_issue_deprecation_warning
    ("`scm_make_gsubr_with_generic' is deprecated.  "
     "Use `scm_c_define_gsubr_with_generic' instead.");

  return scm_c_define_gsubr_with_generic (name, req, opt, rst, fcn, gf);
}

SCM
scm_create_hook (const char *name, int n_args)
{
  scm_c_issue_deprecation_warning
    ("'scm_create_hook' is deprecated.  "
     "Use 'scm_make_hook' and 'scm_c_define' instead.");
  {
    SCM hook = scm_make_hook (scm_from_int (n_args));
    scm_c_define (name, hook);
    return scm_permanent_object (hook);
  }
}

SCM_DEFINE (scm_sloppy_memq, "sloppy-memq", 2, 0, 0,
            (SCM x, SCM lst),
	    "This procedure behaves like @code{memq}, but does no type or error checking.\n"
	    "Its use is recommended only in writing Guile internals,\n"
            "not for high-level Scheme programs.")
#define FUNC_NAME s_scm_sloppy_memq
{
  scm_c_issue_deprecation_warning
    ("'sloppy-memq' is deprecated.  Use 'memq' instead.");

  for(;  scm_is_pair (lst);  lst = SCM_CDR(lst))
    {
      if (scm_is_eq (SCM_CAR (lst), x))
	return lst;
    }
  return lst;
}
#undef FUNC_NAME

SCM_DEFINE (scm_sloppy_memv, "sloppy-memv", 2, 0, 0,
            (SCM x, SCM lst),
 	    "This procedure behaves like @code{memv}, but does no type or error checking.\n"
	    "Its use is recommended only in writing Guile internals,\n"
            "not for high-level Scheme programs.")
#define FUNC_NAME s_scm_sloppy_memv
{
  scm_c_issue_deprecation_warning
    ("'sloppy-memv' is deprecated.  Use 'memv' instead.");

  for(;  scm_is_pair (lst);  lst = SCM_CDR(lst))
    {
      if (! scm_is_false (scm_eqv_p (SCM_CAR (lst), x)))
	return lst;
    }
  return lst;
}
#undef FUNC_NAME

SCM_DEFINE (scm_sloppy_member, "sloppy-member", 2, 0, 0,
            (SCM x, SCM lst),
 	    "This procedure behaves like @code{member}, but does no type or error checking.\n"
	    "Its use is recommended only in writing Guile internals,\n"
            "not for high-level Scheme programs.")
#define FUNC_NAME s_scm_sloppy_member
{
  scm_c_issue_deprecation_warning
    ("'sloppy-member' is deprecated.  Use 'member' instead.");

  for(;  scm_is_pair (lst);  lst = SCM_CDR(lst))
    {
      if (! scm_is_false (scm_equal_p (SCM_CAR (lst), x)))
	return lst;
    }
  return lst;
}
#undef FUNC_NAME

SCM_SYMBOL (scm_end_of_file_key, "end-of-file");

SCM_DEFINE (scm_read_and_eval_x, "read-and-eval!", 0, 1, 0,
            (SCM port),
	    "Read a form from @var{port} (standard input by default), and evaluate it\n"
	    "(memoizing it in the process) in the top-level environment.  If no data\n"
	    "is left to be read from @var{port}, an @code{end-of-file} error is\n"
	    "signalled.")
#define FUNC_NAME s_scm_read_and_eval_x
{
  SCM form;

  scm_c_issue_deprecation_warning
    ("'read-and-eval!' is deprecated.  Use 'read' and 'eval' instead.");

  form = scm_read (port);
  if (SCM_EOF_OBJECT_P (form))
    scm_ithrow (scm_end_of_file_key, SCM_EOL, 1);
  return scm_eval_x (form, scm_current_module ());
}
#undef FUNC_NAME

SCM
scm_make_subr_opt (const char *name, int type, SCM (*fcn) (), int set)
{
  scm_c_issue_deprecation_warning
    ("`scm_make_subr_opt' is deprecated.  Use `scm_c_make_subr' or "
     "`scm_c_define_subr' instead.");

  if (set)
    return scm_c_define_subr (name, type, fcn);
  else
    return scm_c_make_subr (name, type, fcn);
}

SCM
scm_make_subr (const char *name, int type, SCM (*fcn) ())
{
  scm_c_issue_deprecation_warning
    ("`scm_make_subr' is deprecated.  Use `scm_c_define_subr' instead.");

  return scm_c_define_subr (name, type, fcn);
}

SCM
scm_make_subr_with_generic (const char *name, int type, SCM (*fcn) (), SCM *gf)
{
  scm_c_issue_deprecation_warning
    ("`scm_make_subr_with_generic' is deprecated.  Use "
     "`scm_c_define_subr_with_generic' instead.");

  return scm_c_define_subr_with_generic (name, type, fcn, gf);
}

/* Call thunk(closure) underneath a top-level error handler.
 * If an error occurs, pass the exitval through err_filter and return it.
 * If no error occurs, return the value of thunk.
 */

#ifdef _UNICOS
typedef int setjmp_type;
#else
typedef long setjmp_type;
#endif

struct cce_handler_data {
  SCM (*err_filter) ();
  void *closure;
};

static SCM
invoke_err_filter (void *d, SCM tag, SCM args)
{
  struct cce_handler_data *data = (struct cce_handler_data *)d;
  return data->err_filter (SCM_BOOL_F, data->closure);
}

SCM
scm_call_catching_errors (SCM (*thunk)(), SCM (*err_filter)(), void *closure)
{
  scm_c_issue_deprecation_warning
    ("'scm_call_catching_errors' is deprecated.  "
     "Use 'scm_internal_catch' instead.");

  {
    struct cce_handler_data data;
    data.err_filter = err_filter;
    data.closure = closure;
    return scm_internal_catch (SCM_BOOL_T,
			       (scm_t_catch_body)thunk, closure,
			       (scm_t_catch_handler)invoke_err_filter, &data);
  }
}

long
scm_make_smob_type_mfpe (char *name, size_t size,
                        SCM (*mark) (SCM),
                        size_t (*free) (SCM),
                        int (*print) (SCM, SCM, scm_print_state *),
                        SCM (*equalp) (SCM, SCM))
{
  scm_c_issue_deprecation_warning
    ("'scm_make_smob_type_mfpe' is deprecated.  "
     "Use 'scm_make_smob_type' plus 'scm_set_smob_*' instead.");

  {
    long answer = scm_make_smob_type (name, size);
    scm_set_smob_mfpe (answer, mark, free, print, equalp);
    return answer;
  }
}

void
scm_set_smob_mfpe (long tc,
		   SCM (*mark) (SCM),
		   size_t (*free) (SCM),
		   int (*print) (SCM, SCM, scm_print_state *),
		   SCM (*equalp) (SCM, SCM))
{
  scm_c_issue_deprecation_warning
    ("'scm_set_smob_mfpe' is deprecated.  "
     "Use 'scm_set_smob_mark' instead, for example.");

  if (mark) scm_set_smob_mark (tc, mark);
  if (free) scm_set_smob_free (tc, free);
  if (print) scm_set_smob_print (tc, print);
  if (equalp) scm_set_smob_equalp (tc, equalp);
}

SCM
scm_read_0str (char *expr)
{
  scm_c_issue_deprecation_warning
    ("scm_read_0str is deprecated.  Use scm_c_read_string instead.");

  return scm_c_read_string (expr);
}

SCM
scm_eval_0str (const char *expr)
{
  scm_c_issue_deprecation_warning
    ("scm_eval_0str is deprecated.  Use scm_c_eval_string instead.");

  return scm_c_eval_string (expr);
}

SCM
scm_strprint_obj (SCM obj)
{
  scm_c_issue_deprecation_warning
    ("scm_strprint_obj is deprecated.  Use scm_object_to_string instead.");
  return scm_object_to_string (obj, SCM_UNDEFINED);
}

char *
scm_i_object_chars (SCM obj)
{
  scm_c_issue_deprecation_warning
    ("SCM_CHARS is deprecated.  See the manual for alternatives.");
  if (SCM_STRINGP (obj))
    return SCM_STRING_CHARS (obj);
  if (SCM_SYMBOLP (obj))
    return SCM_SYMBOL_CHARS (obj);
  abort ();
}

long
scm_i_object_length (SCM obj)
{
  scm_c_issue_deprecation_warning
    ("SCM_LENGTH is deprecated.  "
     "Use scm_c_string_length instead, for example, or see the manual.");
  if (SCM_STRINGP (obj))
    return SCM_STRING_LENGTH (obj);
  if (SCM_SYMBOLP (obj))
    return SCM_SYMBOL_LENGTH (obj);
  if (SCM_VECTORP (obj))
    return SCM_VECTOR_LENGTH (obj);
  abort ();
}

SCM
scm_sym2ovcell_soft (SCM sym, SCM obarray)
{
  SCM lsym, z;
  size_t hash = scm_i_symbol_hash (sym) % SCM_VECTOR_LENGTH (obarray);

  scm_c_issue_deprecation_warning ("`scm_sym2ovcell_soft' is deprecated. "
				   "Use hashtables instead.");

  SCM_CRITICAL_SECTION_START;
  for (lsym = SCM_VECTOR_REF (obarray, hash);
       SCM_NIMP (lsym);
       lsym = SCM_CDR (lsym))
    {
      z = SCM_CAR (lsym);
      if (scm_is_eq (SCM_CAR (z), sym))
	{
	  SCM_CRITICAL_SECTION_END;
	  return z;
	}
    }
  SCM_CRITICAL_SECTION_END;
  return SCM_BOOL_F;
}

SCM
scm_sym2ovcell (SCM sym, SCM obarray)
#define FUNC_NAME "scm_sym2ovcell"
{
  SCM answer;

  scm_c_issue_deprecation_warning ("`scm_sym2ovcell' is deprecated. "
				   "Use hashtables instead.");

  answer = scm_sym2ovcell_soft (sym, obarray);
  if (scm_is_true (answer))
    return answer;
  SCM_MISC_ERROR ("uninterned symbol: ~S", scm_list_1 (sym));
  return SCM_UNSPECIFIED;		/* not reached */
}
#undef FUNC_NAME

/* Intern a symbol whose name is the LEN characters at NAME in OBARRAY.

   OBARRAY should be a vector of lists, indexed by the name's hash
   value, modulo OBARRAY's length.  Each list has the form
   ((SYMBOL . VALUE) ...), where SYMBOL is a symbol, and VALUE is the
   value associated with that symbol (in the current module?  in the
   system module?)

   To "intern" a symbol means: if OBARRAY already contains a symbol by
   that name, return its (SYMBOL . VALUE) pair; otherwise, create a
   new symbol, add the pair (SYMBOL . SCM_UNDEFINED) to the
   appropriate list of the OBARRAY, and return the pair.

   If softness is non-zero, don't create a symbol if it isn't already
   in OBARRAY; instead, just return #f.

   If OBARRAY is SCM_BOOL_F, create a symbol listed in no obarray and
   return (SYMBOL . SCM_UNDEFINED).  */

SCM
scm_intern_obarray_soft (const char *name,size_t len,SCM obarray,unsigned int softness)
{
  SCM symbol = scm_from_locale_symboln (name, len);
  size_t raw_hash = scm_i_symbol_hash (symbol);
  size_t hash;
  SCM lsym;

  scm_c_issue_deprecation_warning ("`scm_intern_obarray_soft' is deprecated. "
				   "Use hashtables instead.");

  if (scm_is_false (obarray))
    {
      if (softness)
	return SCM_BOOL_F;
      else
	return scm_cons (symbol, SCM_UNDEFINED);
    }

  hash = raw_hash % SCM_VECTOR_LENGTH (obarray);

  for (lsym = SCM_VECTOR_REF(obarray, hash);
       SCM_NIMP (lsym); lsym = SCM_CDR (lsym))
    {
      SCM a = SCM_CAR (lsym);
      SCM z = SCM_CAR (a);
      if (scm_is_eq (z, symbol))
	return a;
    }

  if (softness)
    {
      return SCM_BOOL_F;
    }
  else
    {
      SCM cell = scm_cons (symbol, SCM_UNDEFINED);
      SCM slot = SCM_VECTOR_REF (obarray, hash);

      SCM_VECTOR_SET (obarray, hash, scm_cons (cell, slot));

      return cell;
    }
}

SCM
scm_intern_obarray (const char *name,size_t len,SCM obarray)
{
  scm_c_issue_deprecation_warning ("`scm_intern_obarray' is deprecated. "
				   "Use hashtables instead.");

  return scm_intern_obarray_soft (name, len, obarray, 0);
}

/* Lookup the value of the symbol named by the nul-terminated string
   NAME in the current module.  */
SCM
scm_symbol_value0 (const char *name)
{
  scm_c_issue_deprecation_warning ("`scm_symbol_value0' is deprecated. "
				   "Use `scm_lookup' instead.");

  return scm_variable_ref (scm_c_lookup (name));
}

SCM_DEFINE (scm_string_to_obarray_symbol, "string->obarray-symbol", 2, 1, 0,
           (SCM o, SCM s, SCM softp),
	    "Intern a new symbol in @var{obarray}, a symbol table, with name\n"
	    "@var{string}.\n\n"
	    "If @var{obarray} is @code{#f}, use the default system symbol table.  If\n"
	    "@var{obarray} is @code{#t}, the symbol should not be interned in any\n"
	    "symbol table; merely return the pair (@var{symbol}\n"
	    ". @var{#<undefined>}).\n\n"
	    "The @var{soft?} argument determines whether new symbol table entries\n"
	    "should be created when the specified symbol is not already present in\n"
	    "@var{obarray}.  If @var{soft?} is specified and is a true value, then\n"
	    "new entries should not be added for symbols not already present in the\n"
	    "table; instead, simply return @code{#f}.")
#define FUNC_NAME s_scm_string_to_obarray_symbol
{
  SCM vcell;
  SCM answer;
  int softness;

  SCM_VALIDATE_STRING (2, s);
  SCM_ASSERT (scm_is_bool (o) || SCM_VECTORP (o), o, SCM_ARG1, FUNC_NAME);

  scm_c_issue_deprecation_warning ("`string->obarray-symbol' is deprecated. "
				   "Use hashtables instead.");

  softness = (!SCM_UNBNDP (softp) && scm_is_true(softp));
  /* iron out some screwy calling conventions */
  if (scm_is_false (o))
    {
      /* nothing interesting to do here. */
      return scm_string_to_symbol (s);
    }
  else if (scm_is_eq (o, SCM_BOOL_T))
    o = SCM_BOOL_F;

  vcell = scm_intern_obarray_soft (scm_i_string_chars (s),
				   scm_i_string_length (s),
				   o,
				   softness);
  if (scm_is_false (vcell))
    return vcell;
  answer = SCM_CAR (vcell);
  return answer;
}
#undef FUNC_NAME

SCM_DEFINE (scm_intern_symbol, "intern-symbol", 2, 0, 0,
           (SCM o, SCM s),
	    "Add a new symbol to @var{obarray} with name @var{string}, bound to an\n"
	    "unspecified initial value.  The symbol table is not modified if a symbol\n"
	    "with this name is already present.")
#define FUNC_NAME s_scm_intern_symbol
{
  size_t hval;
  SCM_VALIDATE_SYMBOL (2,s);
  if (scm_is_false (o))
    return SCM_UNSPECIFIED;

  scm_c_issue_deprecation_warning ("`intern-symbol' is deprecated. "
				   "Use hashtables instead.");

  SCM_VALIDATE_VECTOR (1,o);
  hval = scm_i_symbol_hash (s) % SCM_VECTOR_LENGTH (o);
  /* If the symbol is already interned, simply return. */
  SCM_CRITICAL_SECTION_START;
  {
    SCM lsym;
    SCM sym;
    for (lsym = SCM_VECTOR_REF (o, hval);
	 SCM_NIMP (lsym);
	 lsym = SCM_CDR (lsym))
      {
	sym = SCM_CAR (lsym);
	if (scm_is_eq (SCM_CAR (sym), s))
	  {
	    SCM_CRITICAL_SECTION_END;
	    return SCM_UNSPECIFIED;
	  }
      }
    SCM_VECTOR_SET (o, hval,
		    scm_acons (s, SCM_UNDEFINED,
			       SCM_VECTOR_REF (o, hval)));
  }
  SCM_CRITICAL_SECTION_END;
  return SCM_UNSPECIFIED;
}
#undef FUNC_NAME

SCM_DEFINE (scm_unintern_symbol, "unintern-symbol", 2, 0, 0,
           (SCM o, SCM s),
	    "Remove the symbol with name @var{string} from @var{obarray}.  This\n"
	    "function returns @code{#t} if the symbol was present and @code{#f}\n"
	    "otherwise.")
#define FUNC_NAME s_scm_unintern_symbol
{
  size_t hval;

  scm_c_issue_deprecation_warning ("`unintern-symbol' is deprecated. "
				   "Use hashtables instead.");

  SCM_VALIDATE_SYMBOL (2,s);
  if (scm_is_false (o))
    return SCM_BOOL_F;
  SCM_VALIDATE_VECTOR (1,o);
  hval = scm_i_symbol_hash (s) % SCM_VECTOR_LENGTH (o);
  SCM_CRITICAL_SECTION_START;
  {
    SCM lsym_follow;
    SCM lsym;
    SCM sym;
    for (lsym = SCM_VECTOR_REF (o, hval), lsym_follow = SCM_BOOL_F;
	 SCM_NIMP (lsym);
	 lsym_follow = lsym, lsym = SCM_CDR (lsym))
      {
	sym = SCM_CAR (lsym);
	if (scm_is_eq (SCM_CAR (sym), s))
	  {
	    /* Found the symbol to unintern. */
	    if (scm_is_false (lsym_follow))
	      SCM_VECTOR_SET (o, hval, lsym);
	    else
	      SCM_SETCDR (lsym_follow, SCM_CDR(lsym));
	    SCM_CRITICAL_SECTION_END;
	    return SCM_BOOL_T;
	  }
      }
  }
  SCM_CRITICAL_SECTION_END;
  return SCM_BOOL_F;
}
#undef FUNC_NAME

SCM_DEFINE (scm_symbol_binding, "symbol-binding", 2, 0, 0,
           (SCM o, SCM s),
	    "Look up in @var{obarray} the symbol whose name is @var{string}, and\n"
	    "return the value to which it is bound.  If @var{obarray} is @code{#f},\n"
	    "use the global symbol table.  If @var{string} is not interned in\n"
	    "@var{obarray}, an error is signalled.")
#define FUNC_NAME s_scm_symbol_binding
{
  SCM vcell;

  scm_c_issue_deprecation_warning ("`symbol-binding' is deprecated. "
				   "Use hashtables instead.");

  SCM_VALIDATE_SYMBOL (2,s);
  if (scm_is_false (o))
    return scm_variable_ref (scm_lookup (s));
  SCM_VALIDATE_VECTOR (1,o);
  vcell = scm_sym2ovcell (s, o);
  return SCM_CDR(vcell);
}
#undef FUNC_NAME

#if 0
SCM_DEFINE (scm_symbol_interned_p, "symbol-interned?", 2, 0, 0,
	    (SCM o, SCM s),
	    "Return @code{#t} if @var{obarray} contains a symbol with name\n"
	    "@var{string}, and @code{#f} otherwise.")
#define FUNC_NAME s_scm_symbol_interned_p
{
  SCM vcell;

  scm_c_issue_deprecation_warning ("`symbol-interned?' is deprecated. "
				   "Use hashtables instead.");

  SCM_VALIDATE_SYMBOL (2,s);
  if (scm_is_false (o))
    {
      SCM var = scm_sym2var (s, SCM_BOOL_F, SCM_BOOL_F);
      if (var != SCM_BOOL_F)
	return SCM_BOOL_T;
      return SCM_BOOL_F;
    }
  SCM_VALIDATE_VECTOR (1,o);
  vcell = scm_sym2ovcell_soft (s, o);
  return (SCM_NIMP(vcell)
	  ? SCM_BOOL_T
	  : SCM_BOOL_F);
}
#undef FUNC_NAME
#endif

SCM_DEFINE (scm_symbol_bound_p, "symbol-bound?", 2, 0, 0,
	    (SCM o, SCM s),
	    "Return @code{#t} if @var{obarray} contains a symbol with name\n"
	    "@var{string} bound to a defined value.  This differs from\n"
	    "@var{symbol-interned?} in that the mere mention of a symbol\n"
	    "usually causes it to be interned; @code{symbol-bound?}\n"
	    "determines whether a symbol has been given any meaningful\n"
	    "value.")
#define FUNC_NAME s_scm_symbol_bound_p
{
  SCM vcell;

  scm_c_issue_deprecation_warning ("`symbol-bound?' is deprecated. "
				   "Use hashtables instead.");

  SCM_VALIDATE_SYMBOL (2,s);
  if (scm_is_false (o))
    {
      SCM var = scm_sym2var (s, SCM_BOOL_F, SCM_BOOL_F);
      if (SCM_VARIABLEP(var) && !SCM_UNBNDP(SCM_VARIABLE_REF(var)))
	return SCM_BOOL_T;
      return SCM_BOOL_F;
    }
  SCM_VALIDATE_VECTOR (1,o);
  vcell = scm_sym2ovcell_soft (s, o);
  return scm_from_bool (SCM_NIMP (vcell) && !SCM_UNBNDP (SCM_CDR (vcell)));
}
#undef FUNC_NAME

SCM_DEFINE (scm_symbol_set_x, "symbol-set!", 3, 0, 0,
           (SCM o, SCM s, SCM v),
	    "Find the symbol in @var{obarray} whose name is @var{string}, and rebind\n"
	    "it to @var{value}.  An error is signalled if @var{string} is not present\n"
	    "in @var{obarray}.")
#define FUNC_NAME s_scm_symbol_set_x
{
  SCM vcell;

  scm_c_issue_deprecation_warning ("`symbol-set!' is deprecated. "
				   "Use the module system instead.");

  SCM_VALIDATE_SYMBOL (2,s);
  if (scm_is_false (o))
    {
      scm_define (s, v);
      return SCM_UNSPECIFIED;
    }
  SCM_VALIDATE_VECTOR (1,o);
  vcell = scm_sym2ovcell (s, o);
  SCM_SETCDR (vcell, v);
  return SCM_UNSPECIFIED;
}
#undef FUNC_NAME

#define MAX_PREFIX_LENGTH 30

static int gentemp_counter;

SCM_DEFINE (scm_gentemp, "gentemp", 0, 2, 0,
            (SCM prefix, SCM obarray),
	    "Create a new symbol with a name unique in an obarray.\n"
	    "The name is constructed from an optional string @var{prefix}\n"
	    "and a counter value.  The default prefix is @code{t}.  The\n"
	    "@var{obarray} is specified as a second optional argument.\n"
	    "Default is the system obarray where all normal symbols are\n"
	    "interned.  The counter is increased by 1 at each\n"
	    "call.  There is no provision for resetting the counter.")
#define FUNC_NAME s_scm_gentemp
{
  char buf[MAX_PREFIX_LENGTH + SCM_INTBUFLEN];
  char *name = buf;
  int len, n_digits;

  scm_c_issue_deprecation_warning ("`gentemp' is deprecated. "
				   "Use `gensym' instead.");

  if (SCM_UNBNDP (prefix))
    {
      name[0] = 't';
      len = 1;
    }
  else
    {
      SCM_VALIDATE_STRING (1, prefix);
      len = scm_i_string_length (prefix);
      if (len > MAX_PREFIX_LENGTH)
	name = SCM_MUST_MALLOC (MAX_PREFIX_LENGTH + SCM_INTBUFLEN);
      strncpy (name, scm_i_string_chars (prefix), len);
    }

  if (SCM_UNBNDP (obarray))
    return scm_gensym (prefix);
  else
    SCM_ASSERT ((scm_is_vector (obarray) || SCM_I_WVECTP (obarray)),
		obarray,
		SCM_ARG2,
		FUNC_NAME);
  do
    n_digits = scm_iint2str (gentemp_counter++, 10, &name[len]);
  while (scm_is_true (scm_intern_obarray_soft (name,
					       len + n_digits,
					       obarray,
					       1)));
  {
    SCM vcell = scm_intern_obarray_soft (name,
					 len + n_digits,
					 obarray,
					 0);
    if (name != buf)
      scm_must_free (name);
    return SCM_CAR (vcell);
  }
}
#undef FUNC_NAME

SCM
scm_i_makinum (scm_t_signed_bits val)
{
  scm_c_issue_deprecation_warning
    ("SCM_MAKINUM is deprecated.  Use scm_from_int or similar instead.");
  return SCM_I_MAKINUM (val);
}

int
scm_i_inump (SCM obj)
{
  scm_c_issue_deprecation_warning
    ("SCM_INUMP is deprecated.  Use scm_is_integer or similar instead.");
  return SCM_I_INUMP (obj);
}

scm_t_signed_bits
scm_i_inum (SCM obj)
{
  scm_c_issue_deprecation_warning
    ("SCM_INUM is deprecated.  Use scm_to_int or similar instead.");
  return scm_to_intmax (obj);
}

char *
scm_c_string2str (SCM obj, char *str, size_t *lenp)
{
  scm_c_issue_deprecation_warning
    ("scm_c_string2str is deprecated.  Use scm_to_locale_stringbuf or similar instead.");

  if (str == NULL)
    {
      char *result = scm_to_locale_string (obj);
      if (lenp)
	*lenp = scm_i_string_length (obj);
      return result;
    }
  else
    {
      /* Pray that STR is large enough.
       */
      size_t len = scm_to_locale_stringbuf (obj, str, SCM_I_SIZE_MAX);
      str[len] = '\0';
      if (lenp)
	*lenp = len;
      return str;
    }
}

char *
scm_c_substring2str (SCM obj, char *str, size_t start, size_t len)
{
  scm_c_issue_deprecation_warning
    ("scm_c_substring2str is deprecated.  Use scm_substring plus scm_to_locale_stringbuf instead.");

  if (start)
    obj = scm_substring (obj, scm_from_size_t (start), SCM_UNDEFINED);

  scm_to_locale_stringbuf (obj, str, len);
  return str;
}

/* Converts the given Scheme symbol OBJ into a C string, containing a copy
   of OBJ's content with a trailing null byte.  If LENP is non-NULL, set
   *LENP to the string's length.

   When STR is non-NULL it receives the copy and is returned by the function,
   otherwise new memory is allocated and the caller is responsible for
   freeing it via free().  If out of memory, NULL is returned.

   Note that Scheme symbols may contain arbitrary data, including null
   characters.  This means that null termination is not a reliable way to
   determine the length of the returned value.  However, the function always
   copies the complete contents of OBJ, and sets *LENP to the length of the
   scheme symbol (if LENP is non-null).  */
char *
scm_c_symbol2str (SCM obj, char *str, size_t *lenp)
{
  return scm_c_string2str (scm_symbol_to_string (obj), str, lenp);
}

double
scm_truncate (double x)
{
  scm_c_issue_deprecation_warning
    ("scm_truncate is deprecated.  Use scm_c_truncate instead.");
  return scm_c_truncate (x);
}

double
scm_round (double x)
{
  scm_c_issue_deprecation_warning
    ("scm_round is deprecated.  Use scm_c_round instead.");
  return scm_c_round (x);
}

char *
scm_i_deprecated_symbol_chars (SCM sym)
{
  scm_c_issue_deprecation_warning
    ("SCM_SYMBOL_CHARS is deprecated.  Use scm_symbol_to_string.");

  return (char *)scm_i_symbol_chars (sym);
}

size_t
scm_i_deprecated_symbol_length (SCM sym)
{
  scm_c_issue_deprecation_warning
    ("SCM_SYMBOL_LENGTH is deprecated.  Use scm_symbol_to_string.");
  return scm_i_symbol_length (sym);
}

int
scm_i_keywordp (SCM obj)
{
  scm_c_issue_deprecation_warning
    ("SCM_KEYWORDP is deprecated.  Use scm_is_keyword instead.");
  return scm_is_keyword (obj);
}

SCM
scm_i_keywordsym (SCM keyword)
{
  scm_c_issue_deprecation_warning
    ("SCM_KEYWORDSYM is deprecated.  See scm_keyword_to_symbol instead.");
  return scm_keyword_dash_symbol (keyword);
}

int
scm_i_vectorp (SCM x)
{
  scm_c_issue_deprecation_warning
    ("SCM_VECTORP is deprecated.  Use scm_is_vector instead.");
  return SCM_I_IS_VECTOR (x);
}

unsigned long
scm_i_vector_length (SCM x)
{
  scm_c_issue_deprecation_warning
    ("SCM_VECTOR_LENGTH is deprecated.  Use scm_c_vector_length instead.");
  return SCM_I_VECTOR_LENGTH (x);
}

const SCM *
scm_i_velts (SCM x)
{
  scm_c_issue_deprecation_warning
    ("SCM_VELTS is deprecated.  Use scm_vector_elements instead.");
  return SCM_I_VECTOR_ELTS (x);
}

SCM *
scm_i_writable_velts (SCM x)
{
  scm_c_issue_deprecation_warning
    ("SCM_WRITABLE_VELTS is deprecated.  "
     "Use scm_vector_writable_elements instead.");
  return SCM_I_VECTOR_WELTS (x);
}

SCM
scm_i_vector_ref (SCM x, size_t idx)
{
  scm_c_issue_deprecation_warning
    ("SCM_VECTOR_REF is deprecated.  "
     "Use scm_c_vector_ref or scm_vector_elements instead.");
  return scm_c_vector_ref (x, idx);
}

void
scm_i_vector_set (SCM x, size_t idx, SCM val)
{
  scm_c_issue_deprecation_warning
    ("SCM_VECTOR_SET is deprecated.  "
     "Use scm_c_vector_set_x or scm_vector_writable_elements instead.");
  scm_c_vector_set_x (x, idx, val);
}

SCM
scm_vector_equal_p (SCM x, SCM y)
{
  scm_c_issue_deprecation_warning
    ("scm_vector_euqal_p is deprecated.  "
     "Use scm_equal_p instead.");
  return scm_equal_p (x, y);
}

int
scm_i_arrayp (SCM a)
{
  scm_c_issue_deprecation_warning
    ("SCM_ARRAYP is deprecated.  Use scm_is_array instead.");
  return SCM_I_ARRAYP(a) || SCM_I_ENCLOSED_ARRAYP(a);
}

size_t
scm_i_array_ndim (SCM a)
{
  scm_c_issue_deprecation_warning
    ("SCM_ARRAY_NDIM is deprecated.  "
     "Use scm_c_array_rank or scm_array_handle_rank instead.");
  return scm_c_array_rank (a);
}

int
scm_i_array_contp (SCM a)
{
  scm_c_issue_deprecation_warning
    ("SCM_ARRAY_CONTP is deprecated.  Do not use it.");
  return SCM_I_ARRAY_CONTP (a);
}

scm_t_array *
scm_i_array_mem (SCM a)
{
  scm_c_issue_deprecation_warning
    ("SCM_ARRAY_MEM is deprecated.  Do not use it.");
  return (scm_t_array *)SCM_I_ARRAY_MEM (a);
}

SCM
scm_i_array_v (SCM a)
{
  /* We could use scm_shared_array_root here, but it is better to move
     them away from expecting vectors as the basic storage for arrays.
  */
  scm_c_issue_deprecation_warning
    ("SCM_ARRAY_V is deprecated.  Do not use it.");
  return SCM_I_ARRAY_V (a);
}

size_t
scm_i_array_base (SCM a)
{
  scm_c_issue_deprecation_warning
    ("SCM_ARRAY_BASE is deprecated.  Do not use it.");
  return SCM_I_ARRAY_BASE (a);
}

scm_t_array_dim *
scm_i_array_dims (SCM a)
{
  scm_c_issue_deprecation_warning
    ("SCM_ARRAY_DIMS is deprecated.  Use scm_array_handle_dims instead.");
  return SCM_I_ARRAY_DIMS (a);
}

SCM
scm_i_cur_inp (void)
{
  scm_c_issue_deprecation_warning
    ("scm_cur_inp is deprecated.  Use scm_current_input_port instead.");
  return scm_current_input_port ();
}

SCM
scm_i_cur_outp (void)
{
  scm_c_issue_deprecation_warning
    ("scm_cur_outp is deprecated.  Use scm_current_output_port instead.");
  return scm_current_output_port ();
}

SCM
scm_i_cur_errp (void)
{
  scm_c_issue_deprecation_warning
    ("scm_cur_errp is deprecated.  Use scm_current_error_port instead.");
  return scm_current_error_port ();
}

SCM
scm_i_cur_loadp (void)
{
  scm_c_issue_deprecation_warning
    ("scm_cur_loadp is deprecated.  Use scm_current_load_port instead.");
  return scm_current_load_port ();
}

SCM
scm_i_progargs (void)
{
  scm_c_issue_deprecation_warning
    ("scm_progargs is deprecated.  Use scm_program_arguments instead.");
  return scm_program_arguments ();
}

SCM
scm_i_deprecated_dynwinds (void)
{
  scm_c_issue_deprecation_warning
    ("scm_dynwinds is deprecated.  Do not use it.");
  return scm_i_dynwinds ();
}

scm_t_debug_frame *
scm_i_deprecated_last_debug_frame (void)
{
  scm_c_issue_deprecation_warning
    ("scm_last_debug_frame is deprecated.  Do not use it.");
  return scm_i_last_debug_frame ();
}

SCM_STACKITEM *
scm_i_stack_base (void)
{
  scm_c_issue_deprecation_warning
    ("scm_stack_base is deprecated.  Do not use it.");
  return SCM_I_CURRENT_THREAD->base;
}

int
scm_i_fluidp (SCM x)
{
  scm_c_issue_deprecation_warning
    ("SCM_FLUIDP is deprecated.  Use scm_is_fluid instead.");
  return scm_is_fluid (x);
}

void
scm_i_defer_ints_etc ()
{
  scm_c_issue_deprecation_warning
    ("SCM_DEFER_INTS etc are deprecated.  "
     "Use a mutex instead if appropriate.");
}

SCM
scm_guard (SCM guardian, SCM obj, int throw_p)
{
  scm_c_issue_deprecation_warning
    ("scm_guard is deprecated.  Use scm_call_1 instead.");

  return scm_call_1 (guardian, obj);
}

SCM
scm_get_one_zombie (SCM guardian)
{
  scm_c_issue_deprecation_warning
    ("scm_guard is deprecated.  Use scm_call_0 instead.");

  return scm_call_0 (guardian);
}

SCM_DEFINE (scm_guardian_destroyed_p, "guardian-destroyed?", 1, 0, 0,
            (SCM guardian),
            "Return @code{#t} if @var{guardian} has been destroyed, otherwise @code{#f}.")
#define FUNC_NAME s_scm_guardian_destroyed_p
{
  scm_c_issue_deprecation_warning
    ("'guardian-destroyed?' is deprecated.");
  return SCM_BOOL_F;
}
#undef FUNC_NAME

SCM_DEFINE (scm_guardian_greedy_p, "guardian-greedy?", 1, 0, 0,
            (SCM guardian),
            "Return @code{#t} if @var{guardian} is a greedy guardian, otherwise @code{#f}.")
#define FUNC_NAME s_scm_guardian_greedy_p
{
  scm_c_issue_deprecation_warning
    ("'guardian-greedy?' is deprecated.");
  return SCM_BOOL_F;
}
#undef FUNC_NAME

SCM_DEFINE (scm_destroy_guardian_x, "destroy-guardian!", 1, 0, 0,
            (SCM guardian),
            "Destroys @var{guardian}, by making it impossible to put any more\n"
            "objects in it or get any objects from it.  It also unguards any\n"
            "objects guarded by @var{guardian}.")
#define FUNC_NAME s_scm_destroy_guardian_x
{
  scm_c_issue_deprecation_warning
    ("'destroy-guardian!' is deprecated and ineffective.");
  return SCM_UNSPECIFIED;
}
#undef FUNC_NAME

void
scm_i_init_deprecated ()
{
#include "libguile/deprecated.x"
}

#endif


code:
/* This file contains definitions for deprecated features.  When you
   deprecate something, move it here when that is feasible.
*/

#ifndef SCM_DEPRECATED_H
#define SCM_DEPRECATED_H

/* Copyright (C) 2003,2004, 2005, 2006, 2007 Free Software Foundation, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include "libguile/__scm.h"
#include "libguile/strings.h"

#if (SCM_ENABLE_DEPRECATED == 1)

/* From eval.h: Macros for handling ilocs.  These were deprecated in guile
 * 1.7.0 on 2004-04-22.  */
#define SCM_IFRINC             (0x00000100L)
#define SCM_ICDR               (0x00080000L)
#define SCM_IFRAME(n)          ((long)((SCM_ICDR-SCM_IFRINC)>>8) \
                                & (SCM_UNPACK (n) >> 8))
#define SCM_IDIST(n)           (SCM_UNPACK (n) >> 20)
#define SCM_ICDRP(n)           (SCM_ICDR & SCM_UNPACK (n))

/* From tags.h: Macros to access internal symbol names of isyms.  Deprecated
 * in guile 1.7.0 on 2004-04-22.  */
SCM_API char *scm_isymnames[];
#define SCM_ISYMNUM(n) 	       0
#define SCM_ISYMCHARS(n)       "#@<deprecated>"

/* From tags.h: Macro checking for two tc16 types that are allocated to differ
 * only in the 's'-bit.  Deprecated in guile 1.7.0 on 2003-09-21.  */
#define SCM_TYP16S(x) 		(0xfeff & SCM_CELL_TYPE (x))

/* From numbers.h: Macros checking for types, but avoiding a redundant check
 * for !SCM_IMP.  These were deprecated in guile 1.7.0 on 2003-09-06.  */
#define SCM_SLOPPY_INEXACTP(x) (SCM_TYP16S (x) == scm_tc16_real)
#define SCM_SLOPPY_REALP(x) (SCM_TYP16 (x) == scm_tc16_real)
#define SCM_SLOPPY_COMPLEXP(x) (SCM_TYP16 (x) == scm_tc16_complex)

/* From eval.h: Macros for handling ilocs.  These were deprecated in guile
 * 1.7.0 on 2003-06-04.  */
#define SCM_ILOC00		SCM_MAKE_ITAG8(0L, scm_tc8_iloc)
#define SCM_IDINC		(0x00100000L)
#define SCM_IDSTMSK		(-SCM_IDINC)

/* From eval.h: Error messages of the evaluator.  These were deprecated in
 * guile 1.7.0 on 2003-06-02.  */
SCM_API const char scm_s_expression[];
SCM_API const char scm_s_test[];
SCM_API const char scm_s_body[];
SCM_API const char scm_s_bindings[];
SCM_API const char scm_s_variable[];
SCM_API const char scm_s_clauses[];
SCM_API const char scm_s_formals[];

/* From eval.h: Helper macros for evaluation and application.  These were
 * deprecated in guile 1.7.0 on 2003-06-02.  */
#define SCM_EVALIM2(x) \
  ((scm_is_eq ((x), SCM_EOL) \
    ? scm_misc_error (NULL, scm_s_expression, SCM_EOL), 0 \
    : 0), \
   (x))
#define SCM_EVALIM(x, env) (SCM_ILOCP (x) \
                            ? *scm_ilookup ((x), env) \
			    : SCM_EVALIM2(x))
#define SCM_XEVAL(x, env) (scm_i_eval_x ((x), (env)))
#define SCM_XEVALCAR(x, env) (SCM_SYMBOLP (SCM_CAR (x)) \
			      ? *scm_lookupcar (x, env, 1) \
			      : scm_i_eval_x (SCM_CAR (x), (env)))

#define scm_substring_move_left_x scm_substring_move_x
#define scm_substring_move_right_x scm_substring_move_x

#define scm_sizet size_t

SCM_API SCM scm_wta (SCM arg, const char *pos, const char *s_subr);

#define SCM_WNA 		8
#define SCM_OUTOFRANGE         10
#define SCM_NALLOC             11

SCM_API void scm_register_module_xxx (char *module_name, void *init_func);
SCM_API SCM scm_registered_modules (void);
SCM_API SCM scm_clear_registered_modules (void);

SCM_API SCM scm_protect_object (SCM obj);
SCM_API SCM scm_unprotect_object (SCM obj);

#define SCM_SETAND_CAR(x, y) \
  (SCM_SETCAR ((x), SCM_PACK (SCM_UNPACK (SCM_CAR (x)) & (y))))
#define SCM_SETOR_CAR(x, y)\
  (SCM_SETCAR ((x), SCM_PACK (SCM_UNPACK (SCM_CAR (x)) | (y))))
#define SCM_SETAND_CDR(x, y)\
  (SCM_SETCDR ((x), SCM_PACK (SCM_UNPACK (SCM_CDR (x)) & (y))))
#define SCM_SETOR_CDR(x, y)\
  (SCM_SETCDR ((x), SCM_PACK (SCM_UNPACK (SCM_CDR (x)) | (y))))
#define SCM_FREEP(x) (SCM_FREE_CELL_P (x))
#define SCM_NFREEP(x) (!SCM_FREE_CELL_P (x))
#define SCM_GC8MARKP(x) SCM_GC_MARK_P (x)
#define SCM_SETGC8MARK(x) SCM_SET_GC_MARK (x)
#define SCM_CLRGC8MARK(x) SCM_CLEAR_GC_MARK (x)
#define SCM_GCTYP16(x) SCM_TYP16 (x)
#define SCM_GCCDR(x) SCM_CDR (x)
SCM_API void scm_remember (SCM * ptr);

SCM_API SCM scm_the_root_module (void);
SCM_API SCM scm_make_module (SCM name);
SCM_API SCM scm_ensure_user_module (SCM name);
SCM_API SCM scm_load_scheme_module (SCM name);

#define scm_port scm_t_port
#define scm_ptob_descriptor scm_t_ptob_descriptor
#define scm_port_rw_active scm_t_port_rw_active

SCM_API SCM scm_close_all_ports_except (SCM ports);

#define scm_rstate scm_t_rstate
#define scm_rng scm_t_rng

#define SCM_SLOPPY_CONSP(x)  ((1 & SCM_CELL_TYPE (x)) == 0)
#define SCM_SLOPPY_NCONSP(x) (!SCM_SLOPPY_CONSP(x))

#define scm_tc7_ssymbol		scm_tc7_symbol
#define scm_tc7_msymbol		scm_tc7_symbol
#define scm_tcs_symbols         scm_tc7_symbol

SCM_API SCM scm_makstr (size_t len, int);
SCM_API SCM scm_makfromstr (const char *src, size_t len, int);

SCM_API SCM scm_variable_set_name_hint (SCM var, SCM hint);
SCM_API SCM scm_builtin_variable (SCM name);

SCM_API SCM scm_internal_with_fluids (SCM fluids, SCM vals,
				      SCM (*cproc)(void *), void *cdata);

SCM_API SCM scm_make_gsubr (const char *name, int req, int opt, int rst,
			    SCM (*fcn)());
SCM_API SCM scm_make_gsubr_with_generic (const char *name,
					 int req,
					 int opt,
					 int rst,
					 SCM (*fcn)(),
					 SCM *gf);

SCM_API SCM scm_create_hook (const char* name, int n_args);

#define SCM_LIST0 SCM_EOL
#define SCM_LIST1(e0) scm_cons ((e0), SCM_EOL)
#define SCM_LIST2(e0, e1) scm_cons2 ((e0), (e1), SCM_EOL)
#define SCM_LIST3(e0, e1, e2) scm_cons ((e0), SCM_LIST2 ((e1), (e2)))
#define SCM_LIST4(e0, e1, e2, e3)\
     scm_cons2 ((e0), (e1), SCM_LIST2 ((e2), (e3)))
#define SCM_LIST5(e0, e1, e2, e3, e4)\
     scm_cons ((e0), SCM_LIST4 ((e1), (e2), (e3), (e4)))
#define SCM_LIST6(e0, e1, e2, e3, e4, e5)\
     scm_cons2 ((e0), (e1), SCM_LIST4 ((e2), (e3), (e4), (e5)))
#define SCM_LIST7(e0, e1, e2, e3, e4, e5, e6)\
     scm_cons ((e0), SCM_LIST6 ((e1), (e2), (e3), (e4), (e5), (e6)))
#define SCM_LIST8(e0, e1, e2, e3, e4, e5, e6, e7)\
     scm_cons2 ((e0), (e1), SCM_LIST6 ((e2), (e3), (e4), (e5), (e6), (e7)))
#define SCM_LIST9(e0, e1, e2, e3, e4, e5, e6, e7, e8)\
     scm_cons ((e0),\
	       SCM_LIST8 ((e1), (e2), (e3), (e4), (e5), (e6), (e7), (e8)))

#define scm_listify scm_list_n

SCM_API SCM scm_sloppy_memq (SCM x, SCM lst);
SCM_API SCM scm_sloppy_memv (SCM x, SCM lst);
SCM_API SCM scm_sloppy_member (SCM x, SCM lst);

SCM_API SCM scm_read_and_eval_x (SCM port);

#define scm_subr_entry scm_t_subr_entry

#define SCM_SUBR_DOC(x) SCM_BOOL_F

SCM_API SCM scm_make_subr (const char *name, int type, SCM (*fcn) ());
SCM_API SCM scm_make_subr_with_generic (const char *name,
					int type,
					SCM (*fcn) (),
					SCM *gf);
SCM_API SCM scm_make_subr_opt (const char *name,
			       int type,
			       SCM (*fcn) (),
			       int set);

SCM_API SCM scm_call_catching_errors (SCM (*thunk)(), SCM (*err_filter)(),
				      void * closure);

SCM_API long scm_make_smob_type_mfpe (char *name, size_t size,
				      SCM (*mark) (SCM),
				      size_t (*free) (SCM),
				      int (*print) (SCM, SCM,
						    scm_print_state*),
				      SCM (*equalp) (SCM, SCM));

SCM_API void scm_set_smob_mfpe (long tc,
				SCM (*mark) (SCM),
				size_t (*free) (SCM),
				int (*print) (SCM, SCM, scm_print_state*),
				SCM (*equalp) (SCM, SCM));

SCM_API SCM scm_strprint_obj (SCM obj);
SCM_API SCM scm_read_0str (char *expr);
SCM_API SCM scm_eval_0str (const char *expr);

SCM_API char *scm_i_object_chars (SCM);

#define SCM_CHARS(x)   scm_i_object_chars(x)
#define SCM_UCHARS(x)  ((unsigned char *)SCM_CHARS(x))

SCM_API long scm_i_object_length (SCM);

#define SCM_LENGTH(x) scm_i_object_length(x)

#define scm_strhash(str, len, n) (scm_string_hash ((str), (len)) % (n))

SCM_API SCM scm_sym2ovcell_soft (SCM sym, SCM obarray);
SCM_API SCM scm_sym2ovcell (SCM sym, SCM obarray);
SCM_API SCM scm_intern_obarray_soft (const char *name, size_t len,
				     SCM obarray, unsigned int softness);
SCM_API SCM scm_intern_obarray (const char *name, size_t len, SCM obarray);
SCM_API SCM scm_symbol_value0 (const char *name);

SCM_API SCM scm_string_to_obarray_symbol (SCM o, SCM s, SCM softp);
SCM_API SCM scm_intern_symbol (SCM o, SCM s);
SCM_API SCM scm_unintern_symbol (SCM o, SCM s);
SCM_API SCM scm_symbol_binding (SCM o, SCM s);
#if 0
/* This name has been reused for real uninterned symbols. */
SCM_API SCM scm_symbol_interned_p (SCM o, SCM s);
#endif
SCM_API SCM scm_symbol_bound_p (SCM o, SCM s);
SCM_API SCM scm_symbol_set_x (SCM o, SCM s, SCM v);

SCM_API SCM scm_gentemp (SCM prefix, SCM obarray);

#define SCM_OPDIRP(x) (SCM_DIRP (x) && (SCM_DIR_OPEN_P (x)))
#define scm_fport scm_t_fport
#define scm_option scm_t_option
#define scm_srcprops scm_t_srcprops
#define scm_srcprops_chunk scm_t_srcprops_chunk
#define scm_info_frame scm_t_info_frame
#define scm_stack scm_t_stack
#define scm_array scm_t_array
#define scm_array_dim scm_t_array_dim
#define SCM_ARRAY_CONTIGUOUS SCM_ARRAY_FLAG_CONTIGUOUS
#define SCM_FUNC_NAME (scm_makfrom0str (FUNC_NAME))

#define SCM_WTA(pos, scm) \
  do { scm_wta (scm, (char *) pos, FUNC_NAME); } while (0)

#define RETURN_SCM_WTA(pos, scm) \
  do { return scm_wta (scm, (char *) pos, FUNC_NAME); } while (0)

#define SCM_VALIDATE_NUMBER_COPY(pos, z, cvar)	\
  do {						\
    if (SCM_I_INUMP (z))				\
      cvar = (double) SCM_I_INUM (z);		\
    else if (SCM_REALP (z))			\
      cvar = SCM_REAL_VALUE (z);		\
    else if (SCM_BIGP (z))			\
      cvar = scm_i_big2dbl (z);			\
    else					\
      {						\
	cvar = 0.0;				\
        SCM_WRONG_TYPE_ARG (pos, z);		\
      }						\
  } while (0)

#define SCM_VALIDATE_NUMBER_DEF_COPY(pos, number, def, cvar)	\
  do {								\
    if (SCM_UNBNDP (number))					\
      cvar = def;						\
    else							\
      SCM_VALIDATE_NUMBER_COPY(pos, number, cvar);		\
  } while (0)

#define SCM_VALIDATE_OPDIR(pos, port) SCM_MAKE_VALIDATE (pos, port, OPDIRP)

/* Deprecated because we can not safely cast a SCM* to a scm_t_bits*
 */

#define SCM_CELL_WORD_LOC(x, n)   ((scm_t_bits*)SCM_CELL_OBJECT_LOC((x),(n)))

/* Users shouldn't know about INUMs.
 */

SCM_API SCM scm_i_makinum (scm_t_signed_bits val);
SCM_API int scm_i_inump (SCM obj);
SCM_API scm_t_signed_bits scm_i_inum (SCM obj);

#define SCM_MAKINUM(x)   scm_i_makinum(x)
#define SCM_INUM(x)      scm_i_inum(x)
#define SCM_INUMP(x)     scm_i_inump(x)
#define SCM_NINUMP(x)    (!SCM_INUMP(x))

#define SCM_VALIDATE_INUM(pos, k) SCM_MAKE_VALIDATE_MSG (pos, k, INUMP, "exact integer")

#define SCM_VALIDATE_INUM_COPY(pos, k, cvar) \
  do { \
    SCM_ASSERT (SCM_I_INUMP (k), k, pos, FUNC_NAME); \
    cvar = SCM_I_INUM (k); \
  } while (0)

#define SCM_VALIDATE_BIGINT(pos, k) SCM_MAKE_VALIDATE_MSG (pos, k, BIGP, "bignum")

#define SCM_VALIDATE_INUM_MIN(pos, k, min) \
  do { \
    SCM_ASSERT (SCM_I_INUMP(k), k, pos, FUNC_NAME); \
    SCM_ASSERT_RANGE (pos, k, (SCM_I_INUM (k) >= min)); \
  } while (0)

#define SCM_VALIDATE_INUM_MIN_COPY(pos, k, min, cvar) \
  do { \
    SCM_ASSERT (SCM_I_INUMP (k), k, pos, FUNC_NAME); \
    SCM_ASSERT_RANGE (pos, k, (SCM_I_INUM (k) >= min)); \
    cvar = SCM_INUM (k); \
  } while (0)

#define SCM_VALIDATE_INUM_MIN_DEF_COPY(pos, k, min, default, cvar) \
  do { \
    if (SCM_UNBNDP (k)) \
      k = SCM_I_MAKINUM (default); \
    SCM_ASSERT (SCM_I_INUMP (k), k, pos, FUNC_NAME); \
    SCM_ASSERT_RANGE (pos, k, (SCM_I_INUM (k) >= min)); \
    cvar = SCM_INUM (k); \
  } while (0)

#define SCM_VALIDATE_INUM_DEF(pos, k, default) \
  do { \
    if (SCM_UNBNDP (k)) \
      k = SCM_I_MAKINUM (default); \
    else SCM_ASSERT (SCM_I_INUMP (k), k, pos, FUNC_NAME); \
  } while (0)

#define SCM_VALIDATE_INUM_DEF_COPY(pos, k, default, cvar) \
  do { \
    if (SCM_UNBNDP (k)) \
      { \
        k = SCM_I_MAKINUM (default); \
        cvar = default; \
      } \
    else \
      { \
        SCM_ASSERT (SCM_I_INUMP (k), k, pos, FUNC_NAME); \
        cvar = SCM_INUM (k); \
      } \
  } while (0)

/* [low, high) */
#define SCM_VALIDATE_INUM_RANGE(pos, k, low, high) \
  do { SCM_ASSERT(SCM_I_INUMP(k), k, pos, FUNC_NAME); \
       SCM_ASSERT_RANGE(pos, k, \
                        (SCM_I_INUM (k) >= low && \
                         SCM_I_INUM (k) < high)); \
     } while (0)

#define SCM_VALIDATE_INUM_RANGE_COPY(pos, k, low, high, cvar) \
  do { \
    SCM_ASSERT (SCM_INUMP (k), k, pos, FUNC_NAME); \
    SCM_ASSERT_RANGE (pos, k, low <= SCM_INUM (k) && SCM_INUM (k) < high); \
    cvar = SCM_INUM (k); \
  } while (0)

#define SCM_STRING_COERCE_0TERMINATION_X(x) (x)

/* XXX - buggy interface, STR might not be large enough.

   Converts the given Scheme string OBJ into a C string, containing a copy
   of OBJ's content with a trailing null byte.  If LENP is non-NULL, set
   *LENP to the string's length.

   When STR is non-NULL it receives the copy and is returned by the function,
   otherwise new memory is allocated and the caller is responsible for
   freeing it via free().  If out of memory, NULL is returned.

   Note that Scheme strings may contain arbitrary data, including null
   characters.  This means that null termination is not a reliable way to
   determine the length of the returned value.  However, the function always
   copies the complete contents of OBJ, and sets *LENP to the length of the
   scheme string (if LENP is non-null).
*/
SCM_API char *scm_c_string2str (SCM obj, char *str, size_t *lenp);

/* XXX - buggy interface, you don't know how many bytes have been copied.

   Copy LEN characters at START from the Scheme string OBJ to memory
   at STR.  START is an index into OBJ; zero means the beginning of
   the string.  STR has already been allocated by the caller.

   If START + LEN is off the end of OBJ, silently truncate the source
   region to fit the string.  If truncation occurs, the corresponding
   area of STR is left unchanged.
*/
SCM_API char *scm_c_substring2str (SCM obj, char *str, size_t start, size_t len);

SCM_API char *scm_c_symbol2str (SCM obj, char *str, size_t *lenp);

/* Deprecated because the names belong to what is now
   scm_truncate_number and scm_round_number.
*/
SCM_API double scm_truncate (double x);
SCM_API double scm_round (double x);

/* Deprecated because we don't want people to access the internal
   representation of strings directly.
*/

#define SCM_VALIDATE_STRING_COPY(pos, str, cvar) \
  do { \
    SCM_ASSERT (SCM_STRINGP (str), str, pos, FUNC_NAME); \
    cvar = SCM_STRING_CHARS(str); \
  } while (0)

/* validate a string and optional start/end arguments which default to
   0/string-len.  this is unrelated to the old shared substring
   support, so please do not deprecate it :) */
#define SCM_VALIDATE_SUBSTRING_SPEC_COPY(pos_str, str, c_str, \
                                         pos_start, start, c_start,\
                                         pos_end, end, c_end) \
  do {\
    SCM_VALIDATE_STRING_COPY (pos_str, str, c_str);\
    c_start = SCM_UNBNDP(start)? 0 : scm_to_size_t (start);\
    c_end = SCM_UNBNDP(end)? SCM_STRING_LENGTH(str) : scm_to_size_t (end);\
    SCM_ASSERT_RANGE (pos_start, start,\
                      0 <= c_start \
                      && (size_t) c_start <= SCM_STRING_LENGTH (str));\
    SCM_ASSERT_RANGE (pos_end, end,\
		      c_start <= c_end \
                      && (size_t) c_end <= SCM_STRING_LENGTH (str));\
  } while (0)

/* Deprecated because we don't want people to access the internals of
   symbols directly.
*/

SCM_API char *scm_i_deprecated_symbol_chars (SCM sym);
SCM_API size_t scm_i_deprecated_symbol_length (SCM sym);

#define SCM_SYMBOL_CHARS(x)  scm_i_deprecated_symbol_chars(x)
#define SCM_SYMBOL_LENGTH(x) scm_i_deprecated_symbol_length(x)

/* Deprecated because the macros used to evaluate the arguments more
   than once and because the symbol of a keyword now has no dash.
*/

SCM_API int scm_i_keywordp (SCM obj);
SCM_API SCM scm_i_keywordsym (SCM keyword);

#define SCM_KEYWORDP(x)   scm_i_keywordp(x)
#define SCM_KEYWORDSYM(x) scm_i_keywordsym(x)

/* Deprecated because we don't want to hand out unprotected pointers
   to arrays, vectors, etc. */

#define SCM_VECTOR_MAX_LENGTH ((1L << 24) - 1)

SCM_API int scm_i_vectorp (SCM x);
SCM_API unsigned long scm_i_vector_length (SCM x);
SCM_API const SCM *scm_i_velts (SCM x);
SCM_API SCM *scm_i_writable_velts (SCM x);
SCM_API SCM scm_i_vector_ref (SCM x, size_t idx);
SCM_API void scm_i_vector_set (SCM x, size_t idx, SCM val);
SCM_API SCM scm_vector_equal_p (SCM x, SCM y);

#define SCM_VECTORP(x)         scm_i_vectorp(x)
#define SCM_VECTOR_LENGTH(x)   scm_i_vector_length(x)
#define SCM_VELTS(x)           scm_i_velts(x)
#define SCM_WRITABLE_VELTS(x)  scm_i_writable_velts(x)
#define SCM_VECTOR_REF(x,y)    scm_i_vector_ref(x,y)
#define SCM_VECTOR_SET(x,y,z)  scm_i_vector_set(x,y,z)

typedef scm_i_t_array scm_t_array;

SCM_API int scm_i_arrayp (SCM a);
SCM_API size_t scm_i_array_ndim (SCM a);
SCM_API int scm_i_array_contp (SCM a);
SCM_API scm_t_array *scm_i_array_mem (SCM a);
SCM_API SCM scm_i_array_v (SCM a);
SCM_API size_t scm_i_array_base (SCM a);
SCM_API scm_t_array_dim *scm_i_array_dims (SCM a);

#define SCM_ARRAYP(a)      scm_i_arrayp(a)
#define SCM_ARRAY_NDIM(a)  scm_i_array_ndim(a)
#define SCM_ARRAY_CONTP(a) scm_i_array_contp(a)
#define SCM_ARRAY_MEM(a)   scm_i_array_mem(a)
#define SCM_ARRAY_V(a)     scm_i_array_v(a)
#define SCM_ARRAY_BASE(a)  scm_i_array_base(a)
#define SCM_ARRAY_DIMS(a)  scm_i_array_dims(a)

/* Deprecated because they should not be lvalues and we want people to
   use the official interfaces.
 */

#define scm_cur_inp           scm_i_cur_inp ()
#define scm_cur_outp          scm_i_cur_outp ()
#define scm_cur_errp          scm_i_cur_errp ()
#define scm_cur_loadp         scm_i_cur_loadp ()
#define scm_progargs          scm_i_progargs ()
#define scm_dynwinds          scm_i_deprecated_dynwinds ()
#define scm_last_debug_frame  scm_i_deprecated_last_debug_frame ()
#define scm_stack_base        scm_i_stack_base ()

SCM_API SCM scm_i_cur_inp (void);
SCM_API SCM scm_i_cur_outp (void);
SCM_API SCM scm_i_cur_errp (void);
SCM_API SCM scm_i_cur_loadp (void);
SCM_API SCM scm_i_progargs (void);
SCM_API SCM scm_i_deprecated_dynwinds (void);
SCM_API scm_t_debug_frame *scm_i_deprecated_last_debug_frame (void);
SCM_API SCM_STACKITEM *scm_i_stack_base (void);

/* Deprecated because it evaluates its argument twice.
 */
#define SCM_FLUIDP(x) scm_i_fluidp (x)
SCM_API int scm_i_fluidp (SCM x);

/* In the old days, SCM_CRITICAL_SECTION_START stopped signal handlers
   from running, since in those days the handler directly ran scheme
   code, and that had to be avoided when the heap was not in a
   consistent state etc.  And since the scheme code could do a stack
   swapping new continuation etc, signals had to be deferred around
   various C library functions which were not safe or not known to be
   safe to swap away, which was a lot of stuff.

   These days signals are implemented with asyncs and don't directly
   run scheme code in the handler, but hold it until an SCM_TICK etc
   where it will be safe.  This means interrupt protection is not
   needed and SCM_CRITICAL_SECTION_START / SCM_CRITICAL_SECTION_END is
   something of an anachronism.

   What past SCM_CRITICAL_SECTION_START usage also did though was
   indicate code that was not reentrant, ie. could not be reentered by
   signal handler code.  The present definitions are a mutex lock,
   affording that reentrancy protection against the new guile 1.8
   free-running posix threads.

   One big problem with the present defintions though is that code which
   throws an error from within a DEFER/ALLOW region will leave the
   defer_mutex locked and hence hang other threads that attempt to enter a
   similar DEFER/ALLOW region.
*/

SCM_API void scm_i_defer_ints_etc (void);
#define SCM_DEFER_INTS scm_i_defer_ints_etc ()
#define SCM_ALLOW_INTS scm_i_defer_ints_etc ()
#define SCM_REDEFER_INTS scm_i_defer_ints_etc ()
#define SCM_REALLOW_INTS scm_i_defer_ints_etc ()

/* Deprecated since they are unnecessary and had not been documented.
 */
SCM_API SCM scm_guard (SCM guardian, SCM obj, int throw_p);
SCM_API SCM scm_get_one_zombie (SCM guardian);

/* Deprecated since guardians no longer have these special features.
 */
SCM_API SCM scm_destroy_guardian_x (SCM guardian);
SCM_API SCM scm_guardian_greedy_p (SCM guardian);
SCM_API SCM scm_guardian_destroyed_p (SCM guardian);

void scm_i_init_deprecated (void);

#endif

#endif /* SCM_DEPRECATED_H */

license: unknown


code:
/* Copyright (C) 2001, 2006, 2009 Free Software Foundation, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <stdio.h>
#include <string.h>
#include <stdarg.h>

#include "libguile/_scm.h"

#include "libguile/deprecation.h"
#include "libguile/strings.h"
#include "libguile/ports.h"

/* Windows defines. */
#ifdef __MINGW32__
# define vsnprintf _vsnprintf
#elif !HAVE_DECL_VSNPRINTF
extern int vsnprintf (char *, size_t, const char *, va_list);
#endif

struct issued_warning {
  struct issued_warning *prev;
  const char *message;
};

static struct issued_warning *issued_warnings;
static int print_summary = 0;

void
scm_c_issue_deprecation_warning (const char *msg)
{
  if (!SCM_WARN_DEPRECATED)
    print_summary = 1;
  else
    {
      struct issued_warning *iw;
      for (iw = issued_warnings; iw; iw = iw->prev)
	if (!strcmp (iw->message, msg))
	  return;
      if (scm_gc_running_p)
	fprintf (stderr, "%s\n", msg);
      else
	{
	  scm_puts (msg, scm_current_error_port ());
	  scm_newline (scm_current_error_port ());
	}
      msg = strdup (msg);
      iw = malloc (sizeof (struct issued_warning));
      if (msg == NULL || iw == NULL)
	return;
      iw->message = msg;
      iw->prev = issued_warnings;
      issued_warnings = iw;
    }
}

void
scm_c_issue_deprecation_warning_fmt (const char *msg, ...)
{
  va_list ap;
  char buf[512];

  va_start (ap, msg);
  vsnprintf (buf, 511, msg, ap);
  va_end (ap);
  buf[511] = '\0';
  scm_c_issue_deprecation_warning (buf);
}

SCM_DEFINE(scm_issue_deprecation_warning,
	   "issue-deprecation-warning", 0, 0, 1,
	   (SCM msgs),
	   "Output @var{msgs} to @code{(current-error-port)} when this "
	   "is the first call to @code{issue-deprecation-warning} with "
	   "this specific @var{msgs}.  Do nothing otherwise. "
	   "The argument @var{msgs} should be a list of strings; "
	   "they are printed in turn, each one followed by a newline.")
#define FUNC_NAME s_scm_issue_deprecation_warning
{
  if (!SCM_WARN_DEPRECATED)
    print_summary = 1;
  else
    {
      SCM nl = scm_from_locale_string ("\n");
      SCM msgs_nl = SCM_EOL;
      char *c_msgs;
      while (scm_is_pair (msgs))
	{
	  if (msgs_nl != SCM_EOL)
	    msgs_nl = scm_cons (nl, msgs_nl);
	  msgs_nl = scm_cons (SCM_CAR (msgs), msgs_nl);
	  msgs = SCM_CDR (msgs);
	}
      msgs_nl = scm_string_append (scm_reverse_x (msgs_nl, SCM_EOL));
      c_msgs = scm_to_locale_string (msgs_nl);
      scm_c_issue_deprecation_warning (c_msgs);
      free (c_msgs);
    }
  return SCM_UNSPECIFIED;
}
#undef FUNC_NAME

static void
print_deprecation_summary (void)
{
  if (print_summary)
    {
      fputs ("\n"
	     "Some deprecated features have been used.  Set the environment\n"
             "variable GUILE_WARN_DEPRECATED to \"detailed\" and rerun the\n"
	     "program to get more information.  Set it to \"no\" to suppress\n"
	     "this message.\n", stderr);
    }
}

SCM_DEFINE(scm_include_deprecated_features,
	   "include-deprecated-features", 0, 0, 0,
	   (),
	   "Return @code{#t} iff deprecated features should be included "
           "in public interfaces.")
#define FUNC_NAME s_scm_include_deprecated_features
{
  return scm_from_bool (SCM_ENABLE_DEPRECATED == 1);
}
#undef FUNC_NAME

void
scm_init_deprecation ()
{
  const char *level = getenv ("GUILE_WARN_DEPRECATED");
  if (level == NULL)
    level = SCM_WARN_DEPRECATED_DEFAULT;
  if (!strcmp (level, "detailed"))
    SCM_WARN_DEPRECATED = 1;
  else if (!strcmp (level, "no"))
    SCM_WARN_DEPRECATED = 0;
  else
    {
      SCM_WARN_DEPRECATED = 0;
      atexit (print_deprecation_summary);
    }
#include "libguile/deprecation.x"
}

/*
  Local Variables:
  c-file-style: "gnu"
  End: */


code:
/* classes: h_files */

#ifndef SCM_DEPRECATION_H
#define SCM_DEPRECATION_H

/* Copyright (C) 2001, 2006, 2009 Free Software Foundation, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include "libguile/__scm.h"

/* These functions are a possibly useful part of the API and not only used
   internally, thus they are exported always, not depending on
   SCM_ENABLE_DEPRECATED.  */

SCM_API void scm_c_issue_deprecation_warning (const char *msg);
SCM_API void scm_c_issue_deprecation_warning_fmt (const char *msg, ...);
SCM_API SCM scm_issue_deprecation_warning (SCM msgs);

SCM_API SCM scm_include_deprecated_features (void);
SCM_API void scm_init_deprecation (void);

#endif  /* SCM_DEPRECATION_H */

/*
  Local Variables:
  c-file-style: "gnu"
  End:
*/


code:
/* This file contains definitions for discouraged features.  When you
   discourage something, move it here when that is feasible.
*/

/* Copyright (C) 2003, 2004, 2006, 2008 Free Software Foundation, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <libguile.h>

#if (SCM_ENABLE_DISCOURAGED == 1)

SCM
scm_short2num (short x)
{
  return scm_from_short (x);
}

SCM
scm_ushort2num (unsigned short x)
{
  return scm_from_ushort (x);
}

SCM
scm_int2num (int x)
{
  return scm_from_int (x);
}

SCM
scm_uint2num (unsigned int x)
{
  return scm_from_uint (x);
}

SCM
scm_long2num (long x)
{
  return scm_from_long (x);
}

SCM
scm_ulong2num (unsigned long x)
{
  return scm_from_ulong (x);
}

SCM
scm_size2num (size_t x)
{
  return scm_from_size_t (x);
}

SCM
scm_ptrdiff2num (ptrdiff_t x)
{
  return scm_from_ssize_t (x);
}

short
scm_num2short (SCM x, unsigned long pos, const char *s_caller)
{
  return scm_to_short (x);
}

unsigned short
scm_num2ushort (SCM x, unsigned long pos, const char *s_caller)
{
  return scm_to_ushort (x);
}

int
scm_num2int (SCM x, unsigned long pos, const char *s_caller)
{
  return scm_to_int (x);
}

unsigned int
scm_num2uint (SCM x, unsigned long pos, const char *s_caller)
{
  return scm_to_uint (x);
}

long
scm_num2long (SCM x, unsigned long pos, const char *s_caller)
{
  return scm_to_long (x);
}

unsigned long
scm_num2ulong (SCM x, unsigned long pos, const char *s_caller)
{
  return scm_to_ulong (x);
}

size_t
scm_num2size (SCM x, unsigned long pos, const char *s_caller)
{
  return scm_to_size_t (x);
}

ptrdiff_t
scm_num2ptrdiff (SCM x, unsigned long pos, const char *s_caller)
{
  return scm_to_ssize_t (x);
}

#if SCM_SIZEOF_LONG_LONG != 0

SCM
scm_long_long2num (long long x)
{
  return scm_from_long_long (x);
}

SCM
scm_ulong_long2num (unsigned long long x)
{
  return scm_from_ulong_long (x);
}

long long
scm_num2long_long (SCM x, unsigned long pos, const char *s_caller)
{
  return scm_to_long_long (x);
}

unsigned long long
scm_num2ulong_long (SCM x, unsigned long pos, const char *s_caller)
{
  return scm_to_ulong_long (x);
}

#endif

SCM
scm_make_real (double x)
{
  return scm_from_double (x);
}

double
scm_num2dbl (SCM a, const char *why)
{
  return scm_to_double (a);
}

SCM
scm_float2num (float n)
{
  return scm_from_double ((double) n);
}

SCM
scm_double2num (double n)
{
  return scm_from_double (n);
}

SCM
scm_make_complex (double x, double y)
{
  return scm_c_make_rectangular (x, y);
}

SCM
scm_mem2symbol (const char *mem, size_t len)
{
  return scm_from_locale_symboln (mem, len);
}

SCM
scm_mem2uninterned_symbol (const char *mem, size_t len)
{
  return scm_make_symbol (scm_from_locale_stringn (mem, len));
}

SCM
scm_str2symbol (const char *str)
{
  return scm_from_locale_symbol (str);
}

/* This function must only be applied to memory obtained via malloc,
   since the GC is going to apply `free' to it when the string is
   dropped.

   Also, s[len] must be `\0', since we promise that strings are
   null-terminated.  Perhaps we could handle non-null-terminated
   strings by claiming they're shared substrings of a string we just
   made up.  */
SCM
scm_take_str (char *s, size_t len)
{
  SCM answer = scm_from_locale_stringn (s, len);
  free (s);
  return answer;
}

/* `s' must be a malloc'd string.  See scm_take_str.  */
SCM
scm_take0str (char *s)
{
  return scm_take_locale_string (s);
}

SCM
scm_mem2string (const char *src, size_t len)
{
  return scm_from_locale_stringn (src, len);
}

SCM
scm_str2string (const char *src)
{
  return scm_from_locale_string (src);
}

SCM
scm_makfrom0str (const char *src)
{
  if (!src) return SCM_BOOL_F;
  return scm_from_locale_string (src);
}

SCM
scm_makfrom0str_opt (const char *src)
{
  return scm_makfrom0str (src);
}

SCM
scm_allocate_string (size_t len)
{
  return scm_i_make_string (len, NULL);
}

SCM_DEFINE (scm_make_keyword_from_dash_symbol, "make-keyword-from-dash-symbol", 1, 0, 0,
            (SCM symbol),
            "Make a keyword object from a @var{symbol} that starts with a dash.")
#define FUNC_NAME s_scm_make_keyword_from_dash_symbol
{
  SCM dash_string, non_dash_symbol;

  SCM_ASSERT (scm_is_symbol (symbol)
	      && ('-' == scm_i_symbol_chars(symbol)[0]),
	      symbol, SCM_ARG1, FUNC_NAME);

  dash_string = scm_symbol_to_string (symbol);
  non_dash_symbol =
    scm_string_to_symbol (scm_c_substring (dash_string,
					   1,
					   scm_c_string_length (dash_string)));

  return scm_symbol_to_keyword (non_dash_symbol);
}
#undef FUNC_NAME

SCM_DEFINE (scm_keyword_dash_symbol, "keyword-dash-symbol", 1, 0, 0,
            (SCM keyword),
	    "Return the dash symbol for @var{keyword}.\n"
	    "This is the inverse of @code{make-keyword-from-dash-symbol}.")
#define FUNC_NAME s_scm_keyword_dash_symbol
{
  SCM symbol = scm_keyword_to_symbol (keyword);
  SCM parts = scm_list_2 (scm_from_locale_string ("-"),
			  scm_symbol_to_string (symbol));
  return scm_string_to_symbol (scm_string_append (parts));
}
#undef FUNC_NAME

SCM
scm_c_make_keyword (const char *s)
{
  return scm_from_locale_keyword (s);
}

void
scm_i_init_discouraged (void)
{
#include "libguile/discouraged.x"
}

#endif


code:
/* This file contains definitions for discouraged features.  When you
   discourage something, move it here when that is feasible.

   A discouraged feature is one that shouldn't be used in new code
   since we have a better alternative now.  However, there is nothing
   wrong with using the old feature, so it is OK to continue to use
   it.

   Eventually, discouraged features can be deprecated since removing
   them will make Guile simpler.
*/

#ifndef SCM_DISCOURAGED_H
#define SCM_DISCOURAGED_H

/* Copyright (C) 2004, 2006 Free Software Foundation, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include "libguile/__scm.h"

#if SCM_ENABLE_DISCOURAGED == 1

/* Discouraged because they do not follow the naming convention.  That
   is, they end in "P" but return a C boolean.  Also, SCM_BOOLP
   evaluates its argument twice.
*/

#define SCM_FALSEP		scm_is_false
#define SCM_NFALSEP		scm_is_true
#define SCM_BOOLP               scm_is_bool
#define SCM_EQ_P                scm_is_eq

/* Convert from a C boolean to a SCM boolean value */
#define SCM_BOOL		scm_from_bool

/* Convert from a C boolean to a SCM boolean value and negate it */
#define SCM_NEGATE_BOOL(f)	scm_from_bool(!(f))

/* SCM_BOOL_NOT returns the other boolean.
 * The order of ^s here is important for Borland C++ (!?!?!)
 */
#define SCM_BOOL_NOT(x)		(SCM_PACK (SCM_UNPACK (x) \
					   ^ (SCM_UNPACK (SCM_BOOL_T) \
					      ^ SCM_UNPACK (SCM_BOOL_F))))

/* scm_to_int, scm_from_int are the official functions to do the job,
   but there is nothing wrong with using scm_num2int, etc.

   These could be trivially defined via macros, but we leave them as
   functions since existing code may take their addresses.
*/

SCM_API SCM scm_short2num (short n);
SCM_API SCM scm_ushort2num (unsigned short n);
SCM_API SCM scm_int2num (int n);
SCM_API SCM scm_uint2num (unsigned int n);
SCM_API SCM scm_long2num (long n);
SCM_API SCM scm_ulong2num (unsigned long n);
SCM_API SCM scm_size2num (size_t n);
SCM_API SCM scm_ptrdiff2num (scm_t_ptrdiff n);
SCM_API short scm_num2short (SCM num, unsigned long int pos,
			     const char *s_caller);
SCM_API unsigned short scm_num2ushort (SCM num, unsigned long int pos,
				       const char *s_caller);
SCM_API int scm_num2int (SCM num, unsigned long int pos,
			 const char *s_caller);
SCM_API unsigned int scm_num2uint (SCM num, unsigned long int pos,
				   const char *s_caller);
SCM_API long scm_num2long (SCM num, unsigned long int pos,
			   const char *s_caller);
SCM_API unsigned long scm_num2ulong (SCM num, unsigned long int pos,
				     const char *s_caller);
SCM_API scm_t_ptrdiff scm_num2ptrdiff (SCM num, unsigned long int pos,
                                       const char *s_caller);
SCM_API size_t scm_num2size (SCM num, unsigned long int pos,
			     const char *s_caller);
#if SCM_SIZEOF_LONG_LONG != 0
SCM_API SCM scm_long_long2num (long long sl);
SCM_API SCM scm_ulong_long2num (unsigned long long sl);
SCM_API long long scm_num2long_long (SCM num, unsigned long int pos,
				     const char *s_caller);
SCM_API unsigned long long scm_num2ulong_long (SCM num, unsigned long int pos,
					       const char *s_caller);
#endif

SCM_API SCM scm_make_real (double x);
SCM_API double scm_num2dbl (SCM a, const char * why);
SCM_API SCM scm_float2num (float n);
SCM_API SCM scm_double2num (double n);

/* The next two are implemented in numbers.c since they use features
   only available there.
*/
SCM_API float scm_num2float (SCM num, unsigned long int pos,
			     const char *s_caller);
SCM_API double scm_num2double (SCM num, unsigned long int pos,
			       const char *s_caller);

SCM_API SCM scm_make_complex (double x, double y);

/* Discouraged because they don't make the encoding explicit.
 */

SCM_API SCM scm_mem2symbol (const char *mem, size_t len);
SCM_API SCM scm_mem2uninterned_symbol (const char *mem, size_t len);
SCM_API SCM scm_str2symbol (const char *str);

SCM_API SCM scm_take_str (char *s, size_t len);
SCM_API SCM scm_take0str (char *s);
SCM_API SCM scm_mem2string (const char *src, size_t len);
SCM_API SCM scm_str2string (const char *src);
SCM_API SCM scm_makfrom0str (const char *src);
SCM_API SCM scm_makfrom0str_opt (const char *src);

/* Discouraged because scm_c_make_string has a better name and is more
   consistent with make-string.
 */
SCM_API SCM scm_allocate_string (size_t len);

/* Discouraged because scm_is_symbol has a better name,
 */
#define SCM_SYMBOLP scm_is_symbol

/* Discouraged because the alternatives have the better names.
 */
#define SCM_SYMBOL_FUNC	            scm_symbol_fref
#define SCM_SET_SYMBOL_FUNC         scm_symbol_fset_x
#define SCM_SYMBOL_PROPS	    scm_symbol_pref
#define SCM_SET_SYMBOL_PROPS        scm_symbol_pset_x

/* Discouraged because there are better ways.
 */
#define SCM_SYMBOL_HASH             scm_i_symbol_hash
#define SCM_SYMBOL_INTERNED_P(X)    scm_i_symbol_is_interned

/* Discouraged because they evaluated their arguments twice and/or
   don't fit the naming scheme.
*/

#define SCM_CONSP(x)            (scm_is_pair (x))
#define SCM_NCONSP(x)           (!SCM_CONSP (x))
#define SCM_NULLP(x)		(scm_is_null (x))
#define SCM_NNULLP(x)		(!scm_is_null (x))

/* Discouraged because they are just strange.
 */

SCM_API SCM scm_make_keyword_from_dash_symbol (SCM symbol);
SCM_API SCM scm_keyword_dash_symbol (SCM keyword);

/* Discouraged because it does not state what encoding S is in.
 */

SCM_API SCM scm_c_make_keyword (const char *s);

/* Discouraged because the 'internal' and 'thread' moniker is
   confusing.
 */

#define scm_internal_select scm_std_select
#define scm_thread_sleep    scm_std_sleep
#define scm_thread_usleep   scm_std_usleep

void scm_i_init_discouraged (void);

#endif /* SCM_ENABLE_DISCOURAGED == 1 */

#endif /* SCM_DISCOURAGED_H */


code:
/* dynl.c - dynamic linking
 *
 * Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 2001, 2002,
 * 2003, 2008 Free Software Foundation, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

/* "dynl.c" dynamically link&load object files.
   Author: Aubrey Jaffer
   Modified for libguile by Marius Vollmer */

#if 0 /* Disabled until we know for sure that it isn't needed */
/* XXX - This is only here to drag in a definition of __eprintf. This
   is needed for proper operation of dynamic linking. The real
   solution would probably be a shared libgcc. */

#undef NDEBUG
#include <assert.h>

static void
maybe_drag_in_eprintf ()
{
  assert (!maybe_drag_in_eprintf);
}
#endif

#include <stdio.h>
#include <string.h>

#include "libguile/_scm.h"
#include "libguile/dynl.h"
#include "libguile/smob.h"
#include "libguile/keywords.h"
#include "libguile/ports.h"
#include "libguile/strings.h"
#include "libguile/deprecation.h"
#include "libguile/lang.h"
#include "libguile/validate.h"
#include "libguile/dynwind.h"

#include <ltdl.h>

/*
  From the libtool manual: "Note that libltdl is not threadsafe,
  i.e. a multithreaded application has to use a mutex for libltdl.".

  Guile does not currently support pre-emptive threads, so there is no
  mutex.  Previously SCM_CRITICAL_SECTION_START and
  SCM_CRITICAL_SECTION_END were used: they are mentioned here in case
  somebody is grepping for thread problems ;)
*/
/* njrev: not threadsafe, protection needed as described above */

static void *
sysdep_dynl_link (const char *fname, const char *subr)
{
  lt_dlhandle handle;
  handle = lt_dlopenext (fname);
  if (NULL == handle)
    {
      SCM fn;
      SCM msg;

      fn = scm_from_locale_string (fname);
      msg = scm_from_locale_string (lt_dlerror ());
      scm_misc_error (subr, "file: ~S, message: ~S", scm_list_2 (fn, msg));
    }
  return (void *) handle;
}

static void
sysdep_dynl_unlink (void *handle, const char *subr)
{
  if (lt_dlclose ((lt_dlhandle) handle))
    {
      scm_misc_error (subr, (char *) lt_dlerror (), SCM_EOL);
    }
}

static void *
sysdep_dynl_func (const char *symb, void *handle, const char *subr)
{
  void *fptr;

  fptr = lt_dlsym ((lt_dlhandle) handle, symb);
  if (!fptr)
    {
      scm_misc_error (subr, (char *) lt_dlerror (), SCM_EOL);
    }
  return fptr;
}

static void
sysdep_dynl_init ()
{
  lt_dlinit ();
}

scm_t_bits scm_tc16_dynamic_obj;

#define DYNL_FILENAME         SCM_SMOB_OBJECT
#define DYNL_HANDLE(x)        ((void *) SCM_SMOB_DATA_2 (x))
#define SET_DYNL_HANDLE(x, v) (SCM_SET_SMOB_DATA_2 ((x), (scm_t_bits) (v)))

static SCM
dynl_obj_mark (SCM ptr)
{
  return DYNL_FILENAME (ptr);
}

static int
dynl_obj_print (SCM exp, SCM port, scm_print_state *pstate)
{
  scm_puts ("#<dynamic-object ", port);
  scm_iprin1 (DYNL_FILENAME (exp), port, pstate);
  if (DYNL_HANDLE (exp) == NULL)
    scm_puts (" (unlinked)", port);
  scm_putc ('>', port);
  return 1;
}

SCM_DEFINE (scm_dynamic_link, "dynamic-link", 1, 0, 0,
            (SCM filename),
	    "Find the shared object (shared library) denoted by\n"
	    "@var{filename} and link it into the running Guile\n"
	    "application.  The returned\n"
	    "scheme object is a ``handle'' for the library which can\n"
	    "be passed to @code{dynamic-func}, @code{dynamic-call} etc.\n\n"
	    "Searching for object files is system dependent.  Normally,\n"
	    "if @var{filename} does have an explicit directory it will\n"
	    "be searched for in locations\n"
	    "such as @file{/usr/lib} and @file{/usr/local/lib}.")
#define FUNC_NAME s_scm_dynamic_link
{
  void *handle;
  char *file;

  scm_dynwind_begin (0);
  file = scm_to_locale_string (filename);
  scm_dynwind_free (file);
  handle = sysdep_dynl_link (file, FUNC_NAME);
  scm_dynwind_end ();
  SCM_RETURN_NEWSMOB2 (scm_tc16_dynamic_obj, SCM_UNPACK (filename), handle);
}
#undef FUNC_NAME

SCM_DEFINE (scm_dynamic_object_p, "dynamic-object?", 1, 0, 0,
            (SCM obj),
	    "Return @code{#t} if @var{obj} is a dynamic object handle,\n"
	    "or @code{#f} otherwise.")
#define FUNC_NAME s_scm_dynamic_object_p
{
  return scm_from_bool (SCM_TYP16_PREDICATE (scm_tc16_dynamic_obj, obj));
}
#undef FUNC_NAME

SCM_DEFINE (scm_dynamic_unlink, "dynamic-unlink", 1, 0, 0,
            (SCM dobj),
	    "Unlink a dynamic object from the application, if possible.  The\n"
	    "object must have been linked by @code{dynamic-link}, with \n"
	    "@var{dobj} the corresponding handle.  After this procedure\n"
	    "is called, the handle can no longer be used to access the\n"
	    "object.")
#define FUNC_NAME s_scm_dynamic_unlink
{
  /*fixme* GC-problem */
  SCM_VALIDATE_SMOB (SCM_ARG1, dobj, dynamic_obj);
  if (DYNL_HANDLE (dobj) == NULL) {
    SCM_MISC_ERROR ("Already unlinked: ~S", scm_list_1 (dobj));
  } else {
    sysdep_dynl_unlink (DYNL_HANDLE (dobj), FUNC_NAME);
    SET_DYNL_HANDLE (dobj, NULL);
    return SCM_UNSPECIFIED;
  }
}
#undef FUNC_NAME

SCM_DEFINE (scm_dynamic_func, "dynamic-func", 2, 0, 0,
            (SCM name, SCM dobj),
	    "Return a ``handle'' for the function @var{name} in the\n"
	    "shared object referred to by @var{dobj}.  The handle\n"
	    "can be passed to @code{dynamic-call} to actually\n"
	    "call the function.\n\n"
	    "Regardless whether your C compiler prepends an underscore\n"
	    "@samp{_} to the global names in a program, you should\n"
	    "@strong{not} include this underscore in @var{name}\n"
	    "since it will be added automatically when necessary.")
#define FUNC_NAME s_scm_dynamic_func
{
  /* The returned handle is formed by casting the address of the function to a
   * long value and converting this to a scheme number
   */

  void (*func) ();

  SCM_VALIDATE_STRING (1, name);
  /*fixme* GC-problem */
  SCM_VALIDATE_SMOB (SCM_ARG2, dobj, dynamic_obj);
  if (DYNL_HANDLE (dobj) == NULL) {
    SCM_MISC_ERROR ("Already unlinked: ~S", dobj);
  } else {
    char *chars;

    scm_dynwind_begin (0);
    chars = scm_to_locale_string (name);
    scm_dynwind_free (chars);
    func = (void (*) ()) sysdep_dynl_func (chars, DYNL_HANDLE (dobj),
					   FUNC_NAME);
    scm_dynwind_end ();
    return scm_from_ulong ((unsigned long) func);
  }
}
#undef FUNC_NAME

SCM_DEFINE (scm_dynamic_call, "dynamic-call", 2, 0, 0,
            (SCM func, SCM dobj),
	    "Call a C function in a dynamic object.  Two styles of\n"
	    "invocation are supported:\n\n"
	    "@itemize @bullet\n"
	    "@item @var{func} can be a function handle returned by\n"
	    "@code{dynamic-func}.  In this case @var{dobj} is\n"
	    "ignored\n"
	    "@item @var{func} can be a string with the name of the\n"
	    "function to call, with @var{dobj} the handle of the\n"
	    "dynamic object in which to find the function.\n"
	    "This is equivalent to\n"
	    "@smallexample\n\n"
	    "(dynamic-call (dynamic-func @var{func} @var{dobj}) #f)\n"
	    "@end smallexample\n"
	    "@end itemize\n\n"
	    "In either case, the function is passed no arguments\n"
	    "and its return value is ignored.")
#define FUNC_NAME s_scm_dynamic_call
{
  void (*fptr) ();

  if (scm_is_string (func))
    func = scm_dynamic_func (func, dobj);
  fptr = (void (*) ()) scm_to_ulong (func);
  fptr ();
  return SCM_UNSPECIFIED;
}
#undef FUNC_NAME

static void
free_string_pointers (void *data)
{
  scm_i_free_string_pointers ((char **)data);
}

SCM_DEFINE (scm_dynamic_args_call, "dynamic-args-call", 3, 0, 0,
            (SCM func, SCM dobj, SCM args),
	    "Call the C function indicated by @var{func} and @var{dobj},\n"
	    "just like @code{dynamic-call}, but pass it some arguments and\n"
	    "return its return value.  The C function is expected to take\n"
	    "two arguments and return an @code{int}, just like @code{main}:\n"
	    "@smallexample\n"
	    "int c_func (int argc, char **argv);\n"
	    "@end smallexample\n\n"
	    "The parameter @var{args} must be a list of strings and is\n"
	    "converted into an array of @code{char *}.  The array is passed\n"
	    "in @var{argv} and its size in @var{argc}.  The return value is\n"
	    "converted to a Scheme number and returned from the call to\n"
	    "@code{dynamic-args-call}.")
#define FUNC_NAME s_scm_dynamic_args_call
{
  int (*fptr) (int argc, char **argv);
  int result, argc;
  char **argv;

  scm_dynwind_begin (0);

  if (scm_is_string (func))
    func = scm_dynamic_func (func, dobj);

  fptr = (int (*) (int, char **)) scm_to_ulong (func);

  argv = scm_i_allocate_string_pointers (args);
  scm_dynwind_unwind_handler (free_string_pointers, argv,
			      SCM_F_WIND_EXPLICITLY);
  for (argc = 0; argv[argc]; argc++)
    ;
  result = (*fptr) (argc, argv);

  scm_dynwind_end ();
  return scm_from_int (result);
}
#undef FUNC_NAME

void
scm_init_dynamic_linking ()
{
  scm_tc16_dynamic_obj = scm_make_smob_type ("dynamic-object", 0);
  scm_set_smob_mark (scm_tc16_dynamic_obj, dynl_obj_mark);
  scm_set_smob_print (scm_tc16_dynamic_obj, dynl_obj_print);
  sysdep_dynl_init ();
#include "libguile/dynl.x"
}

/*
  Local Variables:
  c-file-style: "gnu"
  End:
*/


code:
/* classes: h_files */

#ifndef SCM_DYNL_H
#define SCM_DYNL_H

/* Copyright (C) 1996,1998,2000,2001, 2006 Free Software Foundation, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include "libguile/__scm.h"

SCM_API SCM scm_dynamic_link (SCM fname);
SCM_API SCM scm_dynamic_unlink (SCM dobj);
SCM_API SCM scm_dynamic_object_p (SCM obj);
SCM_API SCM scm_dynamic_func (SCM symb, SCM dobj);
SCM_API SCM scm_dynamic_call (SCM symb, SCM dobj);
SCM_API SCM scm_dynamic_args_call (SCM symb, SCM dobj, SCM args);

SCM_API void scm_init_dynamic_linking (void);

#endif  /* SCM_DYNL_H */

/*
  Local Variables:
  c-file-style: "gnu"
  End:
*/