[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #55599] print_usage() within subfunction resul
From: |
anonymous |
Subject: |
[Octave-bug-tracker] [bug #55599] print_usage() within subfunction results error |
Date: |
Tue, 29 Jan 2019 03:00:18 -0500 (EST) |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0 |
URL:
<https://savannah.gnu.org/bugs/?55599>
Summary: print_usage() within subfunction results error
Project: GNU Octave
Submitted by: None
Submitted on: Tue 29 Jan 2019 08:00:17 AM UTC
Category: Octave Function
Severity: 3 - Normal
Priority: 5 - Normal
Item Group: Unexpected Error
Status: None
Assigned to: None
Originator Name:
Originator Email: address@hidden
Open/Closed: Open
Discussion Lock: Any
Release: 4.4.1
Operating System: Any
_______________________________________________________
Details:
Here is how to produce this error:
octave:1> gradient (ones (4,5,3), 1, 1)
error: 'fullname' undefined near line 55 column 33
error: called from
print_usage at line 55 column 16
gradient>matrix_gradient at line 102 column 5
gradient at line 74 column 35
and here is another simpler example:
first, create an Octave function file named "tmp.m":
$ cat tmp.m
function tmp
## print_usage()
tmp1
end
function tmp1
print_usage()
end
then, invoke this function "tmp" in Octave:
octave:2> tmp
error: 'fullname' undefined near line 55 column 33
error: called from
print_usage at line 55 column 16
tmp>tmp1 at line 7 column 2
tmp at line 3 column 2
The reason is that there is an useless variable named "fullpath",
and the variable "fullname" may be undefined if the line 41 in "print_usage.m"
has a false value:
$ grep fullpath -w -C3 -n /usr/share/octave/4.4.1/m/help/print_usage.m
37- else
38- error ("Octave:invalid-context", "print_usage: invalid function\n");
39- endif
40: fullpath = evalin ("caller", 'mfilename ("fullpath")');
41: if (strcmp (fullpath(end-length(name)+1:end), name))
42: fullname = [fullpath ".m"];
43- endif
44- elseif (! ischar (name))
45- error ("Octave:invalid-input-arg",
Here is a possible patch for this bug:
--- a/scripts/help/print_usage.m
+++ b/scripts/help/print_usage.m
@@ -37,9 +37,9 @@
else
error ("Octave:invalid-context", "print_usage: invalid function\n");
endif
- fullpath = evalin ("caller", 'mfilename ("fullpath")');
- if (strcmp (fullpath(end-length(name)+1:end), name))
- fullname = [fullpath ".m"];
+ fullname = evalin ("caller", 'mfilename ("fullpath")');
+ if (strcmp (fullname(end-length(name)+1:end), name))
+ fullname = [fullname ".m"];
endif
elseif (! ischar (name))
error ("Octave:invalid-input-arg",
After applying the above patch, the "undefined variable" error disappears, but
it would print some less useful information:
octave:4> gradient (ones (4,5,3), 1, 1)
error: print_usage: 'matrix_gradient' not found
octave:4> tmp
error: print_usage: 'tmp1' not found
This is because these subfunctions do not have their own docstrings.
Therefore, it seems that in this case it would better to invoke "print_usage"
with the corresponding "main function" name, just like "plotmatrix.m":
$ grep print_usage -w -C2 -n
/usr/share/octave/4.4.1/m/plot/draw/plotmatrix.m
73-
74- if (nargin > 3 || nargin < 1)
75: print_usage ();
76- endif
77-
--
147- break;
148- else
149: print_usage ("plotmatrix");
150- endif
151- endif
--
160- Y = varargin{2};
161- else
162: print_usage ("plotmatrix");
163- endif
164-
Below is some more possible patch:
diff -ur a/scripts/general/gradient.m b/scripts/general/gradient.m
--- a/scripts/general/gradient.m
+++ b/scripts/general/gradient.m
@@ -99,7 +99,7 @@
endif
if (nargin > 2 && nargin != nd + 1)
- print_usage ();
+ print_usage ("gradient");
endif
## cell d stores a spacing vector for each dimension
diff -ur a/scripts/plot/draw/reducepatch.m b/scripts/plot/draw/reducepatch.m
--- a/scripts/plot/draw/reducepatch.m
+++ b/scripts/plot/draw/reducepatch.m
@@ -197,7 +197,7 @@
"FACES, second argument must be a matrix containing
VERTICES"]);
endif
else
- print_usage ();
+ print_usage ("reducepatch");
endif
## get reduction_factor
diff -ur a/scripts/statistics/quantile.m b/scripts/statistics/quantile.m
--- a/scripts/statistics/quantile.m
+++ b/scripts/statistics/quantile.m
@@ -406,7 +406,7 @@
function inv = __quantile__ (x, p, method = 5)
if (nargin < 2 || nargin > 3)
- print_usage ();
+ print_usage ("quantile");
endif
if (isinteger (x) || islogical (x))
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?55599>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
- [Octave-bug-tracker] [bug #55599] print_usage() within subfunction results error,
anonymous <=