Thu 24 Jun 2010 10:08:27 PM UTC, comment #8:
The problem with print_usage (caller) in _plt_ is that it doesn't give the same result as print_usage () in the calling function. You get a traceback message, even when the calling function is executed at the top level. Results like that can be confusing, which is I think part of the reason for this bug report in the first place.
|
Thu 24 Jun 2010 07:23:57 PM UTC, comment #6:
I think JWE's approach is probably the way to go, although there was still a bit more work to be done. All of the plot commands accept the same sorts of arguments so it had been convenient to have the error message in one place. When we rely on print_usage back in the 6 .m files then we also need to update their documentation.
For example, semilogx says the calling convention is just 'semilogx (ARGS)' whereas it really accepts around 6 different calling conventions.
I have updated the documentation and checked in a change here.
http://hg.savannah.gnu.org/hgweb/octave/rev/390d93e20531
|
Wed 23 Jun 2010 03:29:51 PM UTC, comment #3:
What Rik suggests will help with the quadl function, but it won't help for the plot function... The way the print_usage function works is that it calls dbstack, then counts the depth of the function stack. From that it can figure out if the offending function was called from the top-level or not... We could change the error line in _plt_.m to
evalin ("caller", "print_usage()")
but then the caller stack would be
plot
_plt_
plot
print_usage
and the print_usage function would think that plot wasn't called from the toplevel.. The only way I see to really fix this is to have _plt_ return with a flag that the call was invalid that have the six functions that called _plt_ then call print_usage(), though this is ugly as it means more code than is strictly needed just to get rid of a trivial error message. Attached is a patch that would make this change. More code is not a great thing and so I hesitate to make such change, but will with a little convincing
D.
(file #20796)
|
Fri 11 Jun 2010 10:03:56 PM UTC, comment #2:
In general, functions should thoroughly check their input arguments before proceeding with calculation in order to avoid Garbage In, Garbage Out.
Octave over time has grown to have 830 m-files and, unfortunately, not all of them have been coded with input validation checks.
The case of plot.m is a little more obscure so I will put it aside for the moment.
For quadl, however, the fix is very simple. Take a look at legendre.m from the Mercurial repository where I recently added better input validation. These lines should be at the beginning of every m-file.
if (nargin < 2 || nargin > 3)
print_usage ();
endif
where the exact number of acceptable arguments varies between functions. I might slowly work through the m-files some time adding validation, but if you have patches for any favorites like quadl I can apply them now. Just attach to this bug report.
|
Sat 29 May 2010 12:41:44 AM UTC, original submission:
octave:1> plot
usage: plot (y)
plot (x, y, ...)
plot (x, y, fmt, ...) plot (x, y, property, value, ...)
error: /usr/local/share/octave/3.2.4/m/plot/__plt__.m at line 116, column 5
error: /usr/local/share/octave/3.2.4/m/plot/plot.m at line 186, column 5
octave:1>
I looked at the m files in question and I'm scratching my head because I don't know why those lines would throw errors.
The line in plot.m is "axes (oldh)", where oldh is set to gca(). "axes(gca())" doesn't seem to throw an error. The line in _plt_.m is "usage(msg)", where msg is the usage message you see above.
The only thing I noticed right off-hand is that line 114 of _plt_.m "msg = sprintf ("%s %s (x, y, fmt, ...)", msg, caller);" is missing the trailing newline character. Of course that wouldn't make it throw an error, but that's why the last usage line is on the same line as previous.
Anyway, I'm sure it'll be super obvious to someone else as to why the errors are appearing and not just the usage message.
|