1 /* Copyright (C) 2001, 2006, 2010, 2011 Free Software Foundation, Inc.
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public License
5 * as published by the Free Software Foundation; either version 3 of
6 * the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
29 #include "libguile/_scm.h"
31 #include "libguile/deprecation.h"
32 #include "libguile/strings.h"
33 #include "libguile/ports.h"
35 #include "libguile/private-options.h"
39 struct issued_warning
{
40 struct issued_warning
*prev
;
44 static scm_i_pthread_mutex_t warn_lock
= SCM_I_PTHREAD_MUTEX_INITIALIZER
;
45 static struct issued_warning
*issued_warnings
;
46 static int print_summary
= 0;
49 scm_c_issue_deprecation_warning (const char *msg
)
51 if (!SCM_WARN_DEPRECATED
)
55 struct issued_warning
*iw
;
57 scm_i_pthread_mutex_lock (&warn_lock
);
58 for (iw
= issued_warnings
; iw
; iw
= iw
->prev
)
59 if (!strcmp (iw
->message
, msg
))
67 iw
= malloc (sizeof (struct issued_warning
));
68 if (msg
== NULL
|| iw
== NULL
)
69 /* Nothing sensible to do if you can't allocate this small
73 iw
->prev
= issued_warnings
;
76 scm_i_pthread_mutex_unlock (&warn_lock
);
78 /* All this dance is to avoid printing to a port inside a mutex,
79 which could recurse and deadlock. */
83 fprintf (stderr
, "%s\n", msg
);
86 scm_puts (msg
, scm_current_warning_port ());
87 scm_newline (scm_current_warning_port ());
94 scm_c_issue_deprecation_warning_fmt (const char *msg
, ...)
100 vsnprintf (buf
, 511, msg
, ap
);
103 scm_c_issue_deprecation_warning (buf
);
106 SCM_DEFINE(scm_issue_deprecation_warning
,
107 "issue-deprecation-warning", 0, 0, 1,
109 "Output @var{msgs} to @code{(current-error-port)} when this "
110 "is the first call to @code{issue-deprecation-warning} with "
111 "this specific @var{msgs}. Do nothing otherwise. "
112 "The argument @var{msgs} should be a list of strings; "
113 "they are printed in turn, each one followed by a newline.")
114 #define FUNC_NAME s_scm_issue_deprecation_warning
116 if (!SCM_WARN_DEPRECATED
)
120 SCM nl
= scm_from_locale_string ("\n");
121 SCM msgs_nl
= SCM_EOL
;
123 while (scm_is_pair (msgs
))
125 if (!scm_is_null (msgs_nl
))
126 msgs_nl
= scm_cons (nl
, msgs_nl
);
127 msgs_nl
= scm_cons (SCM_CAR (msgs
), msgs_nl
);
128 msgs
= SCM_CDR (msgs
);
130 msgs_nl
= scm_string_append (scm_reverse_x (msgs_nl
, SCM_EOL
));
131 c_msgs
= scm_to_locale_string (msgs_nl
);
132 scm_c_issue_deprecation_warning (c_msgs
);
135 return SCM_UNSPECIFIED
;
140 print_deprecation_summary (void)
145 "Some deprecated features have been used. Set the environment\n"
146 "variable GUILE_WARN_DEPRECATED to \"detailed\" and rerun the\n"
147 "program to get more information. Set it to \"no\" to suppress\n"
148 "this message.\n", stderr
);
152 SCM_DEFINE(scm_include_deprecated_features
,
153 "include-deprecated-features", 0, 0, 0,
155 "Return @code{#t} iff deprecated features should be included "
156 "in public interfaces.")
157 #define FUNC_NAME s_scm_include_deprecated_features
159 return scm_from_bool (SCM_ENABLE_DEPRECATED
== 1);
167 scm_init_deprecation ()
169 const char *level
= getenv ("GUILE_WARN_DEPRECATED");
171 level
= SCM_WARN_DEPRECATED_DEFAULT
;
172 if (!strcmp (level
, "detailed"))
173 SCM_WARN_DEPRECATED
= 1;
174 else if (!strcmp (level
, "no"))
175 SCM_WARN_DEPRECATED
= 0;
178 SCM_WARN_DEPRECATED
= 0;
179 atexit (print_deprecation_summary
);
181 #include "libguile/deprecation.x"