X-Git-Url: http://git.hcoop.net/bpt/guile.git/blobdiff_plain/5f236208d0d864546e59afa0f5a11c9b3ba14b10..521c542199afa4f199746d5bbffc18a988cb30bc:/libguile/deprecation.c diff --git a/libguile/deprecation.c b/libguile/deprecation.c index af8b93610..1be3aea7e 100644 --- a/libguile/deprecation.c +++ b/libguile/deprecation.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2001, 2006 Free Software Foundation, Inc. +/* Copyright (C) 2001, 2006, 2010, 2011 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 @@ -34,12 +34,6 @@ #include "libguile/private-options.h" - -/* Windows defines. */ -#ifdef __MINGW32__ -#define vsnprintf _vsnprintf -#endif - struct issued_warning { @@ -47,6 +41,7 @@ struct issued_warning { const char *message; }; +static scm_i_pthread_mutex_t warn_lock = SCM_I_PTHREAD_MUTEX_INITIALIZER; static struct issued_warning *issued_warnings; static int print_summary = 0; @@ -58,23 +53,40 @@ scm_c_issue_deprecation_warning (const char *msg) else { struct issued_warning *iw; + + scm_i_pthread_mutex_lock (&warn_lock); 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; + { + msg = NULL; + break; + } + if (msg) + { + msg = strdup (msg); + iw = malloc (sizeof (struct issued_warning)); + if (msg == NULL || iw == NULL) + /* Nothing sensible to do if you can't allocate this small + amount of memory. */ + abort (); + iw->message = msg; + iw->prev = issued_warnings; + issued_warnings = iw; + } + scm_i_pthread_mutex_unlock (&warn_lock); + + /* All this dance is to avoid printing to a port inside a mutex, + which could recurse and deadlock. */ + if (msg) + { + if (scm_gc_running_p) + fprintf (stderr, "%s\n", msg); + else + { + scm_puts_unlocked (msg, scm_current_warning_port ()); + scm_newline (scm_current_warning_port ()); + } + } } } @@ -110,7 +122,7 @@ SCM_DEFINE(scm_issue_deprecation_warning, char *c_msgs; while (scm_is_pair (msgs)) { - if (msgs_nl != SCM_EOL) + if (!scm_is_null (msgs_nl)) msgs_nl = scm_cons (nl, msgs_nl); msgs_nl = scm_cons (SCM_CAR (msgs), msgs_nl); msgs = SCM_CDR (msgs);