This is the mail archive of the
insight@sources.redhat.com
mailing list for the Insight project.
[RFC] setting proper result codes
- To: Insight Mailing List <insight at sources dot redhat dot com>
- Subject: [RFC] setting proper result codes
- From: "Martin M. Hunt" <hunt at redhat dot com>
- Date: Thu, 25 Oct 2001 15:58:49 -0700
- Organization: Red Hat Inc
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.