UTL STL container descriptor checks
The vector of pointers (just fixed) were not working correctly because the
descriptors returned from swig::type_info() were sometimes returning
zero. Zero should only be used for void * as the subsequent call to
SWIG_ConvertPtr will blindly cast the pointer without checking
descriptor.
std::vector<void *> does not work and will require further changes:
specializing traits_info<void *> to return 0 and traits_asptr<void *>.
I tried this and traits_asptr<void> also needs to be added in which
seems odd and requires further investigation...
Lib/python/pystdcommon.swg:
template <> struct traits_info<void *> {
static swig_type_info *type_info() {
static swig_type_info *info = 0;
}
};
Lib/std/std_common.i:
template <>
struct traits_asptr<void *> {
static int asptr(PyObject *obj, void ***val) {
void **p;
swig_type_info *descriptor = 0;
int res = SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0);
if (SWIG_IsOK(res)) {
if (val) *val = p;
}
return res;
}
};
// this is needed, but am not sure this is expected
template <>
struct traits_asptr<void> {
static int asptr(PyObject *obj, void **val) {
void **p;
swig_type_info *descriptor = 0;
int res = SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0);
if (SWIG_IsOK(res)) {
if (val) *val = p;
}
return res;
}
};
This commit is contained in:
parent
6e9184b6f8
commit
91aba9f719
18 changed files with 53 additions and 41 deletions
|
|
@ -464,8 +464,7 @@ namespace swig
|
|||
%typemap(in,noblock=1,fragment="RubySequence_Cont")
|
||||
const_iterator(swig::ConstIterator *iter = 0, int res),
|
||||
const_reverse_iterator(swig::ConstIterator *iter = 0, int res) {
|
||||
res = SWIG_ConvertPtr($input, %as_voidptrptr(&iter),
|
||||
swig::ConstIterator::descriptor(), 0);
|
||||
res = SWIG_ConvertPtr($input, %as_voidptrptr(&iter), swig::ConstIterator::descriptor(), 0);
|
||||
if (!SWIG_IsOK(res) || !iter) {
|
||||
%argument_fail(SWIG_TypeError, "$type", $symname, $argnum);
|
||||
} else {
|
||||
|
|
@ -497,16 +496,14 @@ namespace swig
|
|||
%typecheck(%checkcode(ITERATOR),noblock=1,fragment="RubySequence_Cont")
|
||||
const_iterator, const_reverse_iterator {
|
||||
swig::ConstIterator *iter = 0;
|
||||
int res = SWIG_ConvertPtr($input, %as_voidptrptr(&iter),
|
||||
swig::ConstIterator::descriptor(), 0);
|
||||
int res = SWIG_ConvertPtr($input, %as_voidptrptr(&iter), swig::ConstIterator::descriptor(), 0);
|
||||
$1 = (SWIG_IsOK(res) && iter && (dynamic_cast<swig::ConstIterator_T<$type > *>(iter) != 0));
|
||||
}
|
||||
|
||||
%typecheck(%checkcode(ITERATOR),noblock=1,fragment="RubySequence_Cont")
|
||||
iterator, reverse_iterator {
|
||||
swig::ConstIterator *iter = 0;
|
||||
int res = SWIG_ConvertPtr($input, %as_voidptrptr(&iter),
|
||||
swig::Iterator::descriptor(), 0);
|
||||
int res = SWIG_ConvertPtr($input, %as_voidptrptr(&iter), swig::Iterator::descriptor(), 0);
|
||||
$1 = (SWIG_IsOK(res) && iter && (dynamic_cast<swig::Iterator_T<$type > *>(iter) != 0));
|
||||
}
|
||||
|
||||
|
|
@ -1037,8 +1034,8 @@ namespace swig {
|
|||
}
|
||||
} else {
|
||||
sequence *p;
|
||||
if (SWIG_ConvertPtr(obj,(void**)&p,
|
||||
swig::type_info<sequence>(),0) == SWIG_OK) {
|
||||
swig_type_info *descriptor = swig::type_info<sequence>();
|
||||
if (descriptor && SWIG_IsOK(SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0))) {
|
||||
if (seq) *seq = p;
|
||||
return SWIG_OLDOBJ;
|
||||
}
|
||||
|
|
@ -1077,8 +1074,8 @@ namespace swig {
|
|||
}
|
||||
} else {
|
||||
sequence *p;
|
||||
if (SWIG_ConvertPtr(obj,(void**)&p,
|
||||
swig::type_info<sequence>(),0) == SWIG_OK) {
|
||||
swig_type_info *descriptor = swig::type_info<sequence>();
|
||||
if (descriptor && SWIG_IsOK(SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0))) {
|
||||
if (seq) *seq = p;
|
||||
return SWIG_OLDOBJ;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,7 +53,8 @@ namespace swig {
|
|||
struct traits_asptr {
|
||||
static int asptr(VALUE obj, Type **val) {
|
||||
Type *p;
|
||||
int res = SWIG_ConvertPtr(obj, (void**)&p, type_info<Type>(), 0);
|
||||
swig_type_info *descriptor = type_info<Type>();
|
||||
int res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
|
||||
if (SWIG_IsOK(res)) {
|
||||
if (val) *val = p;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,7 +100,8 @@
|
|||
res = traits_asptr_stdseq<std::map<K,T>, std::pair<K, T> >::asptr(items, val);
|
||||
} else {
|
||||
map_type *p;
|
||||
res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info<map_type>(),0);
|
||||
swig_type_info *descriptor = swig::type_info<map_type>();
|
||||
res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
|
||||
if (SWIG_IsOK(res) && val) *val = p;
|
||||
}
|
||||
return res;
|
||||
|
|
|
|||
|
|
@ -44,8 +44,8 @@
|
|||
}
|
||||
} else {
|
||||
value_type *p;
|
||||
res = SWIG_ConvertPtr(obj,(void**)&p,
|
||||
swig::type_info<value_type>(),0);
|
||||
swig_type_info *descriptor = swig::type_info<value_type>();
|
||||
res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
|
||||
if (SWIG_IsOK(res) && val) *val = *p;
|
||||
}
|
||||
return res;
|
||||
|
|
@ -90,8 +90,8 @@
|
|||
}
|
||||
} else {
|
||||
value_type *p;
|
||||
res = SWIG_ConvertPtr(obj,(void**)&p,
|
||||
swig::type_info<value_type>(),0);
|
||||
swig_type_info *descriptor = swig::type_info<value_type>();
|
||||
res = descriptor ? SWIG_ConvertPtr(obj, (void **)&p, descriptor, 0) : SWIG_ERROR;
|
||||
if (SWIG_IsOK(res) && val) *val = p;
|
||||
}
|
||||
return res;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue