fix std::vector<A*>
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5840 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
f9d781feee
commit
bf5c37390a
1 changed files with 26 additions and 3 deletions
|
|
@ -156,7 +156,9 @@ namespace swigpy {
|
||||||
int res = (SWIG_ConvertPtr(obj, (void**)&p, type_info<Type>(), 0) != -1)
|
int res = (SWIG_ConvertPtr(obj, (void**)&p, type_info<Type>(), 0) != -1)
|
||||||
? SWIG_OLDOBJ : 0;
|
? SWIG_OLDOBJ : 0;
|
||||||
if (res) {
|
if (res) {
|
||||||
if (val) *val = p;
|
if (val) {
|
||||||
|
*val = p;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
PyErr_Format(PyExc_TypeError, "a '%s *' is expected",
|
PyErr_Format(PyExc_TypeError, "a '%s *' is expected",
|
||||||
type_name<Type>());
|
type_name<Type>());
|
||||||
|
|
@ -247,7 +249,7 @@ namespace swigpy {
|
||||||
struct traits_as<Type, pointer_category> {
|
struct traits_as<Type, pointer_category> {
|
||||||
static Type as(PyObject *obj, bool throw_error) {
|
static Type as(PyObject *obj, bool throw_error) {
|
||||||
Type *v = 0;
|
Type *v = 0;
|
||||||
int res = (obj ? asptr(obj, &v) : 0) && v;
|
int res = (obj ? traits_asptr<Type>::asptr(obj, &v) : 0) && v;
|
||||||
if (res) {
|
if (res) {
|
||||||
if (res == SWIG_NEWOBJ) {
|
if (res == SWIG_NEWOBJ) {
|
||||||
Type r(*v);
|
Type r(*v);
|
||||||
|
|
@ -271,6 +273,27 @@ namespace swigpy {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <class Type>
|
||||||
|
struct traits_as<Type*, pointer_category> {
|
||||||
|
static Type* as(PyObject *obj, bool throw_error) {
|
||||||
|
Type *v = 0;
|
||||||
|
int res = (obj ? traits_asptr<Type>::asptr(obj, &v) : 0) && v;
|
||||||
|
if (res) {
|
||||||
|
return v;
|
||||||
|
} else {
|
||||||
|
// Uninitialized return value, no Type() constructor required.
|
||||||
|
std::string msg = "a value of type '";
|
||||||
|
msg += swigpy::type_name<Type>();
|
||||||
|
msg += "' is expected";
|
||||||
|
if (!PyErr_Occurred()) {
|
||||||
|
PyErr_SetString(PyExc_TypeError, msg.c_str());
|
||||||
|
}
|
||||||
|
if (throw_error) throw std::invalid_argument(msg);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template <class Type>
|
template <class Type>
|
||||||
inline Type as(PyObject *obj, bool te = false) {
|
inline Type as(PyObject *obj, bool te = false) {
|
||||||
return traits_as<Type, typename traits<Type>::category>::as(obj, te);
|
return traits_as<Type, typename traits<Type>::category>::as(obj, te);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue