public inbox for insight@sourceware.org
 help / color / mirror / Atom feed
* [RFC] setting proper result codes
@ 2001-10-25 16:00 Martin M. Hunt
  2001-10-26  9:05 ` Keith Seitz
  0 siblings, 1 reply; 2+ messages in thread
From: Martin M. Hunt @ 2001-10-25 16:00 UTC (permalink / raw)
  To: Insight Mailing List

Due to some changes made some time ago, most C functions are incorrectly setting error messages.  For example:

  Tcl_SetStringObj (result_ptr->obj_ptr, "type must be \"temp\" or \"normal\"", -1);

- or - 

  {
      char *err_buf;
      xasprintf (&err_buf, "Breakpoint #%d does not exist.", bpnum);
      Tcl_SetStringObj (result_ptr->obj_ptr, err_buf, -1);
      free(err_buf);
      return TCL_ERROR;
    }

The above examples do not actually cause an error message to be displayed.  
Using Tcl_SetObjResult() fixes this, but is a bit awkward.  For example, the first
example needs to be:

Tcl_SetObjResult (interp, Tcl_NewStringObj ("type must be \"temp\" or \"normal\"", -1));

The second example is even worse.  So I am proposing using the following for all error messages
in our C tcl functions:

void
set_result (Tcl_Interp *interp, const char *fmt,...)
{
  va_list args;
  char *buf;

  va_start (args, fmt);
  xvasprintf (&buf, fmt, args);
  va_end (args);
  Tcl_SetObjResult (interp, Tcl_NewStringObj (buf, -1));
  free(buf);
}

so in each function, you just do something like:
  set_result (interp, "the line number %d is invalid.", line_number);

This seems obvious. Am I understanding the problem fully?  Any objections or suggestions?

-- 
Martin Hunt
GDB Engineer
Red Hat, Inc.

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

* Re: [RFC] setting proper result codes
  2001-10-25 16:00 [RFC] setting proper result codes Martin M. Hunt
@ 2001-10-26  9:05 ` Keith Seitz
  0 siblings, 0 replies; 2+ messages in thread
From: Keith Seitz @ 2001-10-26  9:05 UTC (permalink / raw)
  To: Martin M. Hunt; +Cc: Insight Mailing List

On Thu, 25 Oct 2001, Martin M. Hunt wrote:

> void
> set_result (Tcl_Interp *interp, const char *fmt,...)
> {
>   va_list args;
>   char *buf;
>
>   va_start (args, fmt);
>   xvasprintf (&buf, fmt, args);
>   va_end (args);
>   Tcl_SetObjResult (interp, Tcl_NewStringObj (buf, -1));
>   free(buf);
> }

Yes, I think this is pretty obviously needed, too. Developers simply need
to remember that tcl commands in the interpreter are tcl commands: if they
return TCL_ERROR, they should leave an error message in the interpreter,
not in result_ptr. (Thanks to Tom Tromey for clarifying this some time
ago.)

Other than using "free" (should be "xfree"), I don't see a problem with
the code, and I think it would be a good addition.

Now let's talk about the name... :-)

I have been sporadically attempting to define interfaces into our C code
that others can tap. The most immediate group of developers that come to
mind: plugin writers. Ok, there aren't any, but there could be one day
before this project dies.

Unfortunately, I've only started down this road, and haven't made a whole
lot of headroom... But, gdbtk-cmds.h does exist and contain some useful
functions, although they all suffer from severe namespace problems.

What I think I would like to do is have all the really external functions
(like our call wrapper) begin with "insight_". Right now, nothing does
that, but your result-setting thingy could be the first! (Anyone have a
problem with this?)

Keith

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

end of thread, other threads:[~2001-10-26  9:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-25 16:00 [RFC] setting proper result codes Martin M. Hunt
2001-10-26  9:05 ` Keith Seitz

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).