Skip to content

Commit c359f57

Browse files
committed
Better Octave typecheck for argc argv typemaps
1 parent 34221f2 commit c359f57

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

Lib/octave/argcargv.i

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
%typemap(in) (int ARGC, char **ARGV) {
66
if ($input.is_scalar_type()) {
7-
$1 = 0; $2 = NULL;
8-
%argument_fail(SWIG_TypeError, "'int ARGC, char **ARGV' is not a list", $symname, $argnum);
7+
$1 = 0; $2 = NULL;
8+
%argument_fail(SWIG_TypeError, "'int ARGC, char **ARGV' is not a list", $symname, $argnum);
99
}
1010
octave_value_list list = $input.list_value();
1111
int i, len = list.length();
1212
$1 = ($1_ltype) len;
1313
$2 = (char **) malloc((len+1)*sizeof(char *));
1414
for (i = 0; i < len; i++) {
15-
if(!list(i).is_string()) {
15+
if (!list(i).is_string()) {
1616
$1 = 0;
1717
%argument_fail(SWIG_TypeError, "'int ARGC, char **ARGV' use a non-string", $symname, $argnum);
1818
}
@@ -22,8 +22,19 @@
2222
}
2323

2424
%typemap(typecheck, precedence=SWIG_TYPECHECK_STRING_ARRAY) (int ARGC, char **ARGV) {
25+
$1 = 0;
2526
const octave_value& ov = $input;
26-
$1 = !ov.is_scalar_type();
27+
if (!ov.is_scalar_type()) {
28+
octave_value_list list = ov.list_value();
29+
int i, len = list.length();
30+
$1 = 1;
31+
for (i = 0; i < len; i++) {
32+
if (!list(i).is_string()) {
33+
$1 = 0;
34+
break;
35+
}
36+
}
37+
}
2738
}
2839

2940
%typemap(freearg) (int ARGC, char **ARGV) {

0 commit comments

Comments
 (0)