unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* [PATCH] more descriptive error for dynamic-pointer
@ 2011-03-31  3:51 Mike Gran
  2011-03-31 10:28 ` Andy Wingo
  2011-03-31 14:32 ` Ludovic Courtès
  0 siblings, 2 replies; 4+ messages in thread
From: Mike Gran @ 2011-03-31  3:51 UTC (permalink / raw)
  To: guile-devel

[-- Attachment #1: Type: text/plain, Size: 244 bytes --]

Hi-

dynamic-pointer relies on lt_dlerror for its error message, and that
procedure can return the unhelpful string "No Error" when lt_dlsym
fails to find a symbol.  You might fix it like I did in the following
patch.

Thanks,

Mike   

[-- Attachment #2: 0001-More-descriptive-error-for-dynamic-pointer.patch --]
[-- Type: application/octet-stream, Size: 1285 bytes --]

From a5d7eb5892cb02d988c492dd5726eada8198a799 Mon Sep 17 00:00:00 2001
From: Michael Gran <spk121@yahoo.com>
Date: Wed, 30 Mar 2011 20:42:37 -0700
Subject: [PATCH] More descriptive error for dynamic-pointer

If a symbol is not found, the cryptic "No Error" can be returned.

* libguile/dynl.c (sysdep_dynl_value): modify error message
---
 libguile/dynl.c |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/libguile/dynl.c b/libguile/dynl.c
index 2484dda..2630098 100644
--- a/libguile/dynl.c
+++ b/libguile/dynl.c
@@ -116,7 +116,22 @@ sysdep_dynl_value (const char *symb, void *handle, const char *subr)
   fptr = lt_dlsym ((lt_dlhandle) handle, symb);
   if (!fptr)
     {
-      scm_misc_error (subr, (char *) lt_dlerror (), SCM_EOL);
+      const char *lt_err = lt_dlerror ();
+      if (lt_err == (const char *) NULL || strncmp (lt_err, "No Error", strlen ("No Error")))
+	{
+	  char *msg;
+	  int ret;
+	  ret = asprintf (&msg, "symbol \"%s\" not found", symb);
+	  if (ret != -1)
+	    {
+	      scm_misc_error (subr, msg, SCM_EOL);
+	      free (msg);
+	    }
+	  else
+	    scm_misc_error (subr, "symbol not found", SCM_EOL);
+	}
+      else
+	scm_misc_error (subr, (char *) lt_dlerror (), SCM_EOL);
     }
   return fptr;
 }
-- 
1.7.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] more descriptive error for dynamic-pointer
  2011-03-31  3:51 [PATCH] more descriptive error for dynamic-pointer Mike Gran
@ 2011-03-31 10:28 ` Andy Wingo
  2011-03-31 14:32 ` Ludovic Courtès
  1 sibling, 0 replies; 4+ messages in thread
From: Andy Wingo @ 2011-03-31 10:28 UTC (permalink / raw)
  To: Mike Gran; +Cc: guile-devel

On Thu 31 Mar 2011 05:51, Mike Gran <spk121@yahoo.com> writes:

> dynamic-pointer relies on lt_dlerror for its error message, and that
> procedure can return the unhelpful string "No Error" when lt_dlsym
> fails to find a symbol.  You might fix it like I did in the following
> patch.

Cool.  Applied something similar.

Thanks,

Andy
-- 
http://wingolog.org/



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] more descriptive error for dynamic-pointer
  2011-03-31  3:51 [PATCH] more descriptive error for dynamic-pointer Mike Gran
  2011-03-31 10:28 ` Andy Wingo
@ 2011-03-31 14:32 ` Ludovic Courtès
  2011-03-31 14:56   ` Andy Wingo
  1 sibling, 1 reply; 4+ messages in thread
From: Ludovic Courtès @ 2011-03-31 14:32 UTC (permalink / raw)
  To: guile-devel

Hello,

Mike Gran <spk121@yahoo.com> writes:

> +      const char *lt_err = lt_dlerror ();
> +      if (lt_err == (const char *) NULL || strncmp (lt_err, "No Error", strlen ("No Error")))
> +	{
> +	  char *msg;
> +	  int ret;
> +	  ret = asprintf (&msg, "symbol \"%s\" not found", symb);
> +	  if (ret != -1)
> +	    {
> +	      scm_misc_error (subr, msg, SCM_EOL);
> +	      free (msg);
> +	    }
> +	  else
> +	    scm_misc_error (subr, "symbol not found", SCM_EOL);
> +	}
> +      else
> +	scm_misc_error (subr, (char *) lt_dlerror (), SCM_EOL);

Two things:

  1. the bottom-most ‘scm_misc_error’ call should use ‘lt_err’.

  2. ‘asprintf’ is a GNU extension so can’t be used here (unless we use
     the right Gnulib module.)

Thanks,
Ludo’.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] more descriptive error for dynamic-pointer
  2011-03-31 14:32 ` Ludovic Courtès
@ 2011-03-31 14:56   ` Andy Wingo
  0 siblings, 0 replies; 4+ messages in thread
From: Andy Wingo @ 2011-03-31 14:56 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guile-devel

On Thu 31 Mar 2011 16:32, ludo@gnu.org (Ludovic Courtès) writes:

> Hello,
>
> Mike Gran <spk121@yahoo.com> writes:
>
>> +      const char *lt_err = lt_dlerror ();
>> +      if (lt_err == (const char *) NULL || strncmp (lt_err, "No Error", strlen ("No Error")))
>> +	{
>> +	  char *msg;
>> +	  int ret;
>> +	  ret = asprintf (&msg, "symbol \"%s\" not found", symb);
>> +	  if (ret != -1)
>> +	    {
>> +	      scm_misc_error (subr, msg, SCM_EOL);
>> +	      free (msg);
>> +	    }
>> +	  else
>> +	    scm_misc_error (subr, "symbol not found", SCM_EOL);
>> +	}
>> +      else
>> +	scm_misc_error (subr, (char *) lt_dlerror (), SCM_EOL);
>
> Two things:
>
>   1. the bottom-most ‘scm_misc_error’ call should use ‘lt_err’.
>
>   2. ‘asprintf’ is a GNU extension so can’t be used here (unless we use
>      the right Gnulib module.)

There were more things: no need to asprintf, as you could just pass a
format string to scm_misc_error; and it's not actually an error to get
NULL from lt_dlsym, so you shouldn't call lt_dlerror there.

Andy
-- 
http://wingolog.org/



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-03-31 14:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-31  3:51 [PATCH] more descriptive error for dynamic-pointer Mike Gran
2011-03-31 10:28 ` Andy Wingo
2011-03-31 14:32 ` Ludovic Courtès
2011-03-31 14:56   ` Andy Wingo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).