Skip to content

Commit b88fe49

Browse files
committed
Fix argcargv.i in Perl5, Tcl, PHP
Add missing type map for type check. Add testing of argcargv.i for Perl5, Tcl, PHP and Ruby. Signed-off-by: Erez Geva <[email protected]>
1 parent 464d548 commit b88fe49

File tree

7 files changed

+123
-0
lines changed

7 files changed

+123
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use strict;
2+
use warnings;
3+
use Test::More tests => 8;
4+
BEGIN { use_ok('argcargvtest') }
5+
require_ok('argcargvtest');
6+
7+
my $largs = ["hi", "hola", "hello"];
8+
is(argcargvtest::mainc($largs), 3, "test main typemap 1");
9+
10+
my $targs = ["hi", "hola"];
11+
is(argcargvtest::mainv($targs, 1), "hola", "test main typemap 2");
12+
13+
my $errorVal = 0;
14+
my $ret = eval qq(argcargvtest::mainv("hello", 1); \$errorVal = 1;);
15+
is($ret, undef, "test main typemap 3");
16+
is($errorVal, 0, "test main typemap 4");
17+
18+
is(argcargvtest::initializeApp($largs), undef, "test main typemap 5");
19+
20+
ok(1, "done");
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
require "tests.php";
4+
5+
// New functions
6+
check::functions(array('mainc', 'mainv', 'initializeapp'));
7+
// New classes
8+
check::classes(array('argcargvtest'));
9+
// No new vars
10+
check::globals(array());
11+
12+
$largs = array('hi', 'hola', 'hello');
13+
check::equal(mainc($largs), 3, 'Test main typemap 1');
14+
15+
$targs = array('hi', 'hola');
16+
check::equal(mainv($targs, 1), 'hola', 'Test main typemap 2');
17+
18+
$error = 0;
19+
try {
20+
mainv('hello', 1);
21+
$error = 1;
22+
}
23+
catch (exception $e) {
24+
}
25+
check::equal($error, 0, 'Test main typemap 3');
26+
27+
initializeApp($largs);
28+
29+
check::done();
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'swig_assert'
4+
require 'argcargvtest'
5+
6+
include Argcargvtest
7+
8+
9+
$largs = ["hi", "hola", "hello"]
10+
if mainc($largs) != 3
11+
raise RuntimeError, "bad main typemap"
12+
end
13+
14+
$targs = ["hi", "hola"]
15+
if mainv($targs, 1) != "hola"
16+
raise RuntimeError, "bad main typemap"
17+
end
18+
19+
$error = 0
20+
$ret = 0
21+
begin
22+
mainv("hello", 1)
23+
$error = 1
24+
rescue => e
25+
$ret = 1
26+
end
27+
28+
if $error == 1 or $ret != 1
29+
raise RuntimeError, "bad main typemap"
30+
end
31+
32+
initializeApp($largs)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
if [ catch { load ./argcargvtest[info sharedlibextension] argcargvtest} err_msg ] {
2+
puts stderr "Could not load shared object:\n$err_msg"
3+
}
4+
5+
set largs {hi hola hello}
6+
if {[mainc $largs] != 3} {
7+
puts stderr "bad main typemap"
8+
exit 1
9+
}
10+
11+
set targs {hi hola}
12+
if {[mainv $targs 1] != "hola"} {
13+
puts stderr "bad main typemap"
14+
exit 1
15+
}
16+
17+
set targs " hi hola "
18+
if {[mainv $targs 1] != "hola"} {
19+
puts stderr "bad main typemap"
20+
exit 1
21+
}
22+
23+
if { ! [ catch { mainv("hello", 1) } ] } {
24+
puts stderr "bad main typemap"
25+
exit 1
26+
}
27+
28+
initializeApp $largs

Lib/perl5/argcargv.i

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
$2[i] = NULL;
2525
}
2626

27+
%typemap(typecheck, precedence=SWIG_TYPECHECK_STRING_ARRAY) (int ARGC, char **ARGV) {
28+
AV *av = (AV *)SvRV($input);
29+
$1 = SvTYPE(av) == SVt_PVAV;
30+
}
31+
2732
%typemap(freearg) (int ARGC, char **ARGV) {
2833
if ($2 != NULL) {
2934
free((void *)$2);

Lib/php/argcargv.i

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
$2[i] = NULL;
3434
}
3535

36+
%typemap(typecheck, precedence=SWIG_TYPECHECK_STRING_ARRAY) (int ARGC, char **ARGV) {
37+
$1 = Z_TYPE($input) == IS_ARRAY;
38+
}
39+
3640
%typemap(freearg) (int ARGC, char **ARGV) {
3741
if ($2 != NULL) {
3842
free((void *)$2);

Lib/tcl/argcargv.i

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
$2[i] = NULL;
2222
}
2323

24+
%typemap(typecheck, precedence=SWIG_TYPECHECK_STRING_ARRAY) (int ARGC, char **ARGV) {
25+
int len;
26+
$1 = Tcl_ListObjLength(interp, $input, &len) == TCL_OK;
27+
}
28+
2429
%typemap(freearg) (int ARGC, char **ARGV) {
2530
if ($2 != NULL) {
2631
free((void *)$2);

0 commit comments

Comments
 (0)