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
This commit is contained in:
parent
0cfccf817f
commit
93f0390322
10 changed files with 75 additions and 5 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ CPP_TEST_BROKEN += \
|
|||
cpp_broken \
|
||||
exception_partial_info \
|
||||
extend_variable \
|
||||
li_std_vector_ptr \
|
||||
namespace_union \
|
||||
nested_comment \
|
||||
overload_complicated \
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
%module keyword_rename
|
||||
|
||||
#pragma SWIG nowarn=SWIGWARN_PARSE_KEYWORD
|
||||
//#pragma SWIG nowarn=SWIGWARN_PARSE_KEYWORD
|
||||
|
||||
%inline %{
|
||||
|
||||
|
|
|
|||
|
|
@ -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 %{
|
||||
|
|
|
|||
29
Examples/test-suite/li_std_vector_ptr.i
Normal file
29
Examples/test-suite/li_std_vector_ptr.i
Normal file
|
|
@ -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;
|
||||
}
|
||||
%}
|
||||
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
8
Examples/test-suite/python/li_std_vector_ptr_runme.py
Normal file
8
Examples/test-suite/python/li_std_vector_ptr_runme.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
from li_std_vector_ptr import *
|
||||
|
||||
ip1 = makeIntPtr(11)
|
||||
ip2 = makeIntPtr(22)
|
||||
|
||||
vi = IntPtrVector((ip1, ip2))
|
||||
displayVector(vi)
|
||||
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue