fix to avoid copies when the wrapper class exists
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@8293 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
e8d67c80f3
commit
972974c0e3
2 changed files with 46 additions and 31 deletions
|
|
@ -4,9 +4,10 @@ import std_containers
|
|||
|
||||
cube = (((1, 2), (3, 4)), ((5, 6), (7, 8)))
|
||||
|
||||
|
||||
if cube != std_containers.cident(cube):
|
||||
raise RuntimeError, "bad cident"
|
||||
icube = std_containers.cident(cube)
|
||||
for i in range(0,len(cube)):
|
||||
if cube[i] != icube[i]:
|
||||
raise RuntimeError, "bad cident"
|
||||
|
||||
|
||||
p = (1,2)
|
||||
|
|
@ -14,13 +15,18 @@ if p != std_containers.pident(p):
|
|||
raise RuntimeError, "bad pident"
|
||||
|
||||
v = (1,2,3,4,5,6)
|
||||
|
||||
if v != std_containers.vident(v):
|
||||
raise RuntimeError, "bad pident"
|
||||
iv = std_containers.vident(v)
|
||||
for i in range(0,len(v)):
|
||||
if v[i] != iv[i]:
|
||||
raise RuntimeError, "bad vident"
|
||||
|
||||
|
||||
if v != std_containers.videntu(v):
|
||||
raise RuntimeError, "bad videntu"
|
||||
|
||||
iv = std_containers.videntu(v)
|
||||
for i in range(0,len(v)):
|
||||
if v[i] != iv[i]:
|
||||
raise RuntimeError, "bad videntu"
|
||||
|
||||
|
||||
vu = std_containers.vector_ui(v)
|
||||
if vu[2] != std_containers.videntu(vu)[2]:
|
||||
|
|
@ -33,12 +39,19 @@ if v[0:3][1] != vu[0:3][1]:
|
|||
|
||||
|
||||
m = ((1,2,3),(2,3),(3,4))
|
||||
if m != std_containers.midenti(m):
|
||||
raise RuntimeError, "bad getslice"
|
||||
im = std_containers.midenti(m)
|
||||
|
||||
mb = ((1,0,1),(1,1),(1,1))
|
||||
if mb != std_containers.midentb(mb):
|
||||
raise RuntimeError, "bad getslice"
|
||||
for i in range(0,len(m)):
|
||||
for j in range(0,len(m[i])):
|
||||
if m[i][j] != im[i][j]:
|
||||
raise RuntimeError, "bad getslice"
|
||||
|
||||
m = ((1,0,1),(1,1),(1,1))
|
||||
im = std_containers.midentb(m)
|
||||
for i in range(0,len(m)):
|
||||
for j in range(0,len(m[i])):
|
||||
if m[i][j] != im[i][j]:
|
||||
raise RuntimeError, "bad getslice"
|
||||
|
||||
|
||||
mi = std_containers.imatrix(m)
|
||||
|
|
@ -52,8 +65,10 @@ map['hello'] = 1
|
|||
map['hi'] = 2
|
||||
map['3'] = 2
|
||||
|
||||
if map != std_containers.mapident(map):
|
||||
raise RuntimeError, "bad map"
|
||||
imap = std_containers.mapident(map)
|
||||
for k in map:
|
||||
if map[k] != imap[k]:
|
||||
raise RuntimeError, "bad map"
|
||||
|
||||
|
||||
mapc ={}
|
||||
|
|
|
|||
|
|
@ -717,10 +717,6 @@ namespace swig {
|
|||
return SWIG_OLDOBJ;
|
||||
}
|
||||
}
|
||||
if (seq) {
|
||||
PyErr_Format(PyExc_TypeError, "a %s is expected",
|
||||
swig::type_name<sequence>());
|
||||
}
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
};
|
||||
|
|
@ -733,19 +729,23 @@ namespace swig {
|
|||
typedef typename sequence::const_iterator const_iterator;
|
||||
|
||||
static PyObject *from(const sequence& seq) {
|
||||
size_type size = seq.size();
|
||||
if (size <= (size_type)INT_MAX) {
|
||||
PyObject *obj = PyTuple_New((int)size);
|
||||
int i = 0;
|
||||
for (const_iterator it = seq.begin();
|
||||
it != seq.end(); ++it, ++i) {
|
||||
PyTuple_SetItem(obj,i,swig::from<value_type>(*it));
|
||||
}
|
||||
return obj;
|
||||
swig_type_info *desc = swig::type_info<sequence>();
|
||||
if (desc && desc->clientdata) {
|
||||
return SWIG_NewPointerObj(new sequence(seq), desc, SWIG_POINTER_OWN);
|
||||
} else {
|
||||
PyErr_SetString(PyExc_OverflowError,
|
||||
"sequence size not valid in python");
|
||||
return NULL;
|
||||
size_type size = seq.size();
|
||||
if (size <= (size_type)INT_MAX) {
|
||||
PyObject *obj = PyTuple_New((int)size);
|
||||
int i = 0;
|
||||
for (const_iterator it = seq.begin();
|
||||
it != seq.end(); ++it, ++i) {
|
||||
PyTuple_SetItem(obj,i,swig::from<value_type>(*it));
|
||||
}
|
||||
return obj;
|
||||
} else {
|
||||
PyErr_SetString(PyExc_OverflowError,"sequence size not valid in python");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue