summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Wang <joequant@gmail.com>2009-01-11 00:08:37 +0000
committerJoseph Wang <joequant@gmail.com>2009-01-11 00:08:37 +0000
commit4b5c817793380cc6692d7abebffd664682788808 (patch)
treefc494a18a329da336471d35485ffe5352d1fb659
parent98f992e7040d5d0291e94166f44e68d9ed680a07 (diff)
downloadswig-4b5c817793380cc6692d7abebffd664682788808.tar.gz
Fix integer handling in r. unsigned values where getting handled
incorrected as reals leading to crashes git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11052 626c5289-ae23-0410-ae9c-e8d60b6d4f22
-rw-r--r--CHANGES.current4
-rw-r--r--Lib/r/r.swg22
-rw-r--r--Lib/r/rtype.swg73
3 files changed, 33 insertions, 66 deletions
diff --git a/CHANGES.current b/CHANGES.current
index 0124e6e76..bd4aa7b8b 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -1,6 +1,10 @@
Version 1.3.37 (30 December 2008)
=================================
+2009-01-10: drjoe
+ Fix integer handling in r to deal correctly with signed
+ and unsigned issues
+
2009-01-10: wsfulton
Patch #1992756 from Colin McDonald - %contract not working for classes
in namespace
diff --git a/Lib/r/r.swg b/Lib/r/r.swg
index 0a4d0c36e..d7dc04f15 100644
--- a/Lib/r/r.swg
+++ b/Lib/r/r.swg
@@ -55,7 +55,8 @@ SWIG_InitializeModule(0);
%typemap(out) void "";
-%typemap(in) int *, int[ANY] %{
+%typemap(in) int *, int[ANY],
+ long *, long[ANY] %{
$1 = INTEGER($input);
%}
@@ -77,7 +78,7 @@ SWIG_InitializeModule(0);
%}
-%typemap(scheck) int %{
+%typemap(scheck) int, long %{
if(length($input) > 1) {
warning("using only the first element of $input")
}
@@ -157,11 +158,12 @@ $1 = %static_cast(CHAR(STRING_ELT($input, 0))[0],$1_ltype);
}
-%typemap(in,noblock=1) int {
+%typemap(in,noblock=1) int, long
+{
$1 = %static_cast(INTEGER($input)[0], $1_ltype);
}
-%typemap(out,noblock=1) int
+%typemap(out,noblock=1) int, long
"$result = Rf_ScalarInteger($1);";
@@ -172,18 +174,16 @@ $1 = %static_cast(CHAR(STRING_ELT($input, 0))[0],$1_ltype);
%typemap(out,noblock=1) bool
"$result = Rf_ScalarLogical($1);";
-%typemap(in,noblock=1) unsigned int,
- unsigned long,
+%typemap(in,noblock=1)
float,
- double,
- long
+ double
{
$1 = %static_cast(REAL($input)[0], $1_ltype);
}
-
-%typemap(out,noblock=1) unsigned int *
- "$result = ScalarReal(*($1));";
+/* Why is this here ? */
+/* %typemap(out,noblock=1) unsigned int *
+ "$result = ScalarReal(*($1));"; */
%Rruntime %{
setMethod('[', "ExternalReference",
diff --git a/Lib/r/rtype.swg b/Lib/r/rtype.swg
index 043b7487d..504e7cd04 100644
--- a/Lib/r/rtype.swg
+++ b/Lib/r/rtype.swg
@@ -8,12 +8,18 @@
%apply int {std::size_t}
%apply int {ptrdiff_t}
%apply int {std::ptrdiff_t}
+%apply int {signed int}
+%apply int {unsigned int}
+%apply int {short}
+%apply int {unsigned short}
+
+%typemap("rtype") long, long *, long & "numeric";
+%apply long {long long}
+%apply long {signed long long}
+%apply long {unsigned long long}
+%apply long {unsigned long}
+%apply long {unsigned long}
-%typemap("rtype") long, long * "numeric";
-%typemap("rtype") unsigned long,
- unsigned long * "numeric";
-%typemap("rtype") unsigned int,
- unsigned int * "numeric";
%typemap("rtype") double, double*, double & "numeric";
%typemap("rtype") float, float *, float & "numeric";
%typemap("rtype") char *, char ** "character";
@@ -41,11 +47,7 @@
%typemap(scoercein) int, int *, int &
%{ $input = as.integer($input); %}
-%typemap(scoercein) ptrdiff_t, ptrdiff_t *, ptrdiff_t &
- %{ $input = as.integer($input); %}
-%typemap(scoercein) unsigned long, unsigned long *, unsigned long &
- %{ $input = as.integer($input); %}
-%typemap(scoercein) unsigned int, unsigned int *, unsigned int &
+%typemap(scoercein) long, long *, long &
%{ $input = as.integer($input); %}
%typemap(scoercein) double, double *, double &
%{ %}
@@ -90,45 +92,16 @@
%typemap(scoercein) bool, bool *, bool &
"$input = as.logical($input) ";
-/*
%typemap(scoercein) int,
int *,
int &,
int[ANY],
- size_t,
- std::size_t,
- size_t &,
- std::size_t &
+ long,
+ long *,
+ long &,
+ long[ANY]
"$input = as.integer($input) ";
-
-%typemap(scoercein) unsigned int,
- unsigned long,
- double,
- float,
- long,
- long long,
- unsigned int[],
- unsigned long[],
- double[],
- float[],
- long[],
- long long[],
- unsigned int[ANY],
- unsigned long[ANY],
- double[ANY],
- float[ANY],
- long[ANY],
- long long[ANY],
- unsigned int *,
- unsigned long *,
- double*,
- float*,
- long*,
- long long *
-%{ $input = as.numeric($input) %}
-*/
-
%typemap(scoercein) char *, string, std::string,
string &, std::string &
%{ $input = as($input, "character") %}
@@ -156,30 +129,20 @@ string &, std::string &
%typemap(scoerceout) char,
char *,
char &,
- unsigned int,
- unsigned int &,
- unsigned long,
- unsigned long &,
double,
double &,
float,
float &,
- long,
- long &,
- long long,
- long long &,
int,
int &,
+ long,
+ long &,
bool,
bool &,
string,
std::string,
string &,
std::string &,
- size_t,
- std::size_t,
- size_t &,
- std::size_t &,
void
%{ %}