diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2008-11-28 23:35:46 +0000 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2008-11-28 23:35:46 +0000 |
commit | 93f039032204821d4fc363346587c90f640a1109 (patch) | |
tree | e6d0a9d8e8728fd22750e1ef2c9b515463f3cf39 | |
parent | 0cfccf817f766757ce0311c8d59b89247059ff47 (diff) | |
download | swig-93f039032204821d4fc363346587c90f640a1109.tar.gz |
UTL - Fix some incorrect acceptance of types in the STL, eg a double * element passed into a vector<int *> constructor would be accepted, but the ensuing behaviour was undefined. Now the type conversion correctly raises an exception
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10958 626c5289-ae23-0410-ae9c-e8d60b6d4f22
-rw-r--r-- | CHANGES.current | 5 | ||||
-rw-r--r-- | Examples/test-suite/common.mk | 1 | ||||
-rw-r--r-- | Examples/test-suite/keyword_rename.i | 2 | ||||
-rw-r--r-- | Examples/test-suite/li_std_vector_extra.i | 8 | ||||
-rw-r--r-- | Examples/test-suite/li_std_vector_ptr.i | 29 | ||||
-rw-r--r-- | Examples/test-suite/python/li_std_vector_extra_runme.py | 21 | ||||
-rw-r--r-- | Examples/test-suite/python/li_std_vector_ptr_runme.py | 8 | ||||
-rw-r--r-- | Lib/octave/octstdcommon.swg | 2 | ||||
-rw-r--r-- | Lib/python/pystdcommon.swg | 2 | ||||
-rw-r--r-- | Lib/r/rstdcommon.swg | 2 |
10 files changed, 75 insertions, 5 deletions
diff --git a/CHANGES.current b/CHANGES.current index 0b7a1e079..c00ae694c 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,11 @@ Version 1.3.37 (in progress) ============================ +2008-11-28: wsfulton + [UTL] Fix some incorrect acceptance of types in the STL, eg a double * element passed + into a vector<int *> constructor would be accepted, but the ensuing behaviour was + undefined. Now the type conversion correctly raises an exception. + 2008-11-24: wsfulton Add -outcurrentdir option. This sets the default output directory to the current directory instead of the path specified by the input file. This option enables diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 4bfd53aba..3848601bc 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -77,6 +77,7 @@ CPP_TEST_BROKEN += \ cpp_broken \ exception_partial_info \ extend_variable \ + li_std_vector_ptr \ namespace_union \ nested_comment \ overload_complicated \ diff --git a/Examples/test-suite/keyword_rename.i b/Examples/test-suite/keyword_rename.i index da9328868..244410d60 100644 --- a/Examples/test-suite/keyword_rename.i +++ b/Examples/test-suite/keyword_rename.i @@ -4,7 +4,7 @@ %module keyword_rename -#pragma SWIG nowarn=SWIGWARN_PARSE_KEYWORD +//#pragma SWIG nowarn=SWIGWARN_PARSE_KEYWORD %inline %{ diff --git a/Examples/test-suite/li_std_vector_extra.i b/Examples/test-suite/li_std_vector_extra.i index 17baffe04..5aeb403be 100644 --- a/Examples/test-suite/li_std_vector_extra.i +++ b/Examples/test-suite/li_std_vector_extra.i @@ -123,11 +123,17 @@ std::vector<std::string> vecStr(std::vector<std::string> v) { %pointer_class(int,PtrInt) %array_functions(int,ArrInt) +%inline %{ + int *makeIntPtr(int v) { return new int(v); } + double *makeDoublePtr(double v) { return new double(v); } + int extractInt(int *p) { return *p; } +%} %template(pyvector) std::vector<swig::PyObject_ptr>; namespace std { - %template(ConstIntVector) vector<const int *>; + %template(ConstShortVector) vector<const short *>; +// %template(ConstIntVector) vector<const int *>; // interferes with vector<int *>... see new testcase li_std_vector_ptr } %inline %{ diff --git a/Examples/test-suite/li_std_vector_ptr.i b/Examples/test-suite/li_std_vector_ptr.i new file mode 100644 index 000000000..688cbdd54 --- /dev/null +++ b/Examples/test-suite/li_std_vector_ptr.i @@ -0,0 +1,29 @@ +%module li_std_vector_ptr + +%include "std_vector.i" + +%template(IntPtrVector) std::vector<int *>; + +%inline %{ +#include <iostream> +using namespace std; +int* makeIntPtr(int v) { + return new int(v); +} +double* makeDoublePtr(double v) { + return new double(v); +} + +#if 1 +int** makeIntPtrPtr(int* v) { + return new int*(v); +} +#endif + +void displayVector(std::vector<int *> vpi) { + cout << "displayVector..." << endl; + for (int i=0; i<vpi.size(); ++i) + cout << *vpi[i] << endl; +} +%} + diff --git a/Examples/test-suite/python/li_std_vector_extra_runme.py b/Examples/test-suite/python/li_std_vector_extra_runme.py index ce7b0c737..776eacfb3 100644 --- a/Examples/test-suite/python/li_std_vector_extra_runme.py +++ b/Examples/test-suite/python/li_std_vector_extra_runme.py @@ -133,3 +133,24 @@ if overloaded3(None) != "vector<int> *": if overloaded3(100) != "int": raise RuntimeError + +# vector pointer checks +ip = makeIntPtr(11) +dp = makeDoublePtr(33.3) +error = 0 +try: + vi = IntPtrVector((ip, dp)) # check vector<int *> does not accept double * element + error = 1 +except: + pass + +if error: + raise RuntimeError + +vi = IntPtrVector((ip, makeIntPtr(22))) +if extractInt(vi[0]) != 11: + raise RuntimeError + +if extractInt(vi[1]) != 22: + raise RuntimeError + diff --git a/Examples/test-suite/python/li_std_vector_ptr_runme.py b/Examples/test-suite/python/li_std_vector_ptr_runme.py new file mode 100644 index 000000000..c5f72fde4 --- /dev/null +++ b/Examples/test-suite/python/li_std_vector_ptr_runme.py @@ -0,0 +1,8 @@ +from li_std_vector_ptr import * + +ip1 = makeIntPtr(11) +ip2 = makeIntPtr(22) + +vi = IntPtrVector((ip1, ip2)) +displayVector(vi) + diff --git a/Lib/octave/octstdcommon.swg b/Lib/octave/octstdcommon.swg index e69c7e629..96923f40a 100644 --- a/Lib/octave/octstdcommon.swg +++ b/Lib/octave/octstdcommon.swg @@ -42,7 +42,7 @@ namespace swig { struct traits_asptr { static int asptr(const octave_value& obj, Type **val) { Type *p; - int res = (SWIG_ConvertPtr(obj, (void**)&p, type_info<Type>(), 0) == SWIG_OK) ? SWIG_OLDOBJ : 0; + int res = SWIG_ConvertPtr(obj, (void**)&p, type_info<Type>(), 0); if (SWIG_IsOK(res)) { if (val) *val = p; } diff --git a/Lib/python/pystdcommon.swg b/Lib/python/pystdcommon.swg index 48b1fdcd5..7e9720cc0 100644 --- a/Lib/python/pystdcommon.swg +++ b/Lib/python/pystdcommon.swg @@ -46,7 +46,7 @@ namespace swig { struct traits_asptr { static int asptr(PyObject *obj, Type **val) { Type *p; - int res = (SWIG_ConvertPtr(obj, (void**)&p, type_info<Type>(), 0) == SWIG_OK) ? SWIG_OLDOBJ : 0; + int res = SWIG_ConvertPtr(obj, (void**)&p, type_info<Type>(), 0); if (SWIG_IsOK(res)) { if (val) *val = p; } diff --git a/Lib/r/rstdcommon.swg b/Lib/r/rstdcommon.swg index 223203773..56cbe2cdd 100644 --- a/Lib/r/rstdcommon.swg +++ b/Lib/r/rstdcommon.swg @@ -40,7 +40,7 @@ namespace swig { struct traits_asptr { static int asptr(SWIG_Object obj, Type **val) { Type *p; - int res = (SWIG_ConvertPtr(obj, (void**)&p, type_info<Type>(), 0) == SWIG_OK) ? SWIG_OLDOBJ : 0; + int res = SWIG_ConvertPtr(obj, (void**)&p, type_info<Type>(), 0); if (SWIG_IsOK(res)) { if (val) *val = p; } |