more typemaps unification and fixes for valgrind
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7684 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
036c081066
commit
aadff06f45
26 changed files with 484 additions and 74 deletions
|
|
@ -65,7 +65,7 @@ SWIG_AsArgcArgv(PyObject* input,
|
|||
}
|
||||
}
|
||||
|
||||
%typemap(freearg) (int ARGC, char **ARGV) {
|
||||
%typemap(freearg,noblock=1) (int ARGC, char **ARGV) {
|
||||
if (owner$argnum) {
|
||||
size_t i = argc$argnum;
|
||||
while (i) {
|
||||
|
|
|
|||
2
Lib/python/carrays.i
Normal file
2
Lib/python/carrays.i
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
%include <typemaps/carrays.swg>
|
||||
|
||||
1
Lib/python/cmalloc.i
Normal file
1
Lib/python/cmalloc.i
Normal file
|
|
@ -0,0 +1 @@
|
|||
%include <typemaps/cmalloc.swg>
|
||||
1
Lib/python/cpointer.i
Normal file
1
Lib/python/cpointer.i
Normal file
|
|
@ -0,0 +1 @@
|
|||
%include <typemaps/cpointer.swg>
|
||||
|
|
@ -338,10 +338,10 @@ namespace swig
|
|||
snprintf(msg, sizeof(msg), "in sequence element %d of type %s", i, swig::type_name<value_type>());
|
||||
SWIG_set_errmsg(SWIG_TypeError, msg);
|
||||
}
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
@ -488,7 +488,7 @@ namespace swig
|
|||
if (SWIG_ConvertPtr(obj,(void**)&p,
|
||||
swig::type_info<sequence>(),0) == SWIG_OK) {
|
||||
if (seq) *seq = p;
|
||||
return 1;
|
||||
return SWIG_OLDOBJ;
|
||||
}
|
||||
}
|
||||
if (seq) {
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ namespace swig {
|
|||
|
||||
template <class Type>
|
||||
struct traits_asval {
|
||||
static bool asval(PyObject *obj, Type *val) {
|
||||
static int asval(PyObject *obj, Type *val) {
|
||||
if (val) {
|
||||
Type *p = 0;
|
||||
int res = traits_asptr<Type>::asptr(obj, &p);
|
||||
|
|
@ -75,12 +75,12 @@ namespace swig {
|
|||
typedef typename noconst_traits<Type>::noconst_type noconst_type;
|
||||
*(const_cast<noconst_type*>(val)) = *p;
|
||||
if (res == SWIG_NEWOBJ) SWIG_delete(p);
|
||||
return true;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
return false;
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
} else {
|
||||
return traits_asptr<Type>::asptr(obj, (Type **)(0)) ? true : false;
|
||||
return traits_asptr<Type>::asptr(obj, (Type **)(0)) ? SWIG_OK : SWIG_ERROR;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -93,26 +93,26 @@ namespace swig {
|
|||
int res = traits_asptr<noconst_type>::asptr(obj, &p);
|
||||
if (res) {
|
||||
*(const_cast<noconst_type**>(val)) = p;
|
||||
return true;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
return false;
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
} else {
|
||||
return traits_asptr<Type>::asptr(obj, (Type **)(0)) ? true : false;
|
||||
return traits_asptr<Type>::asptr(obj, (Type **)(0)) ? SWIG_OK : SWIG_ERROR;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <class Type>
|
||||
inline bool asval(PyObject *obj, Type *val) {
|
||||
return traits_asval<Type>::asval(obj, val) ? true : false;
|
||||
inline int asval(PyObject *obj, Type *val) {
|
||||
return traits_asval<Type>::asval(obj, val);
|
||||
}
|
||||
|
||||
template <class Type>
|
||||
struct traits_as<Type, value_category> {
|
||||
static Type as(PyObject *obj, bool throw_error) {
|
||||
Type v;
|
||||
if (!obj || !asval(obj, &v)) {
|
||||
if (!obj || (asval(obj, &v) != SWIG_OK)) {
|
||||
if (!PyErr_Occurred()) {
|
||||
SWIG_Python_SetErrorMsg(SWIG_Python_ErrorType(SWIG_TypeError), swig::type_name<Type>());
|
||||
}
|
||||
|
|
@ -173,7 +173,7 @@ namespace swig {
|
|||
template <class Type>
|
||||
struct traits_check<Type, value_category> {
|
||||
static bool check(PyObject *obj) {
|
||||
return obj && asval(obj, (Type *)(0));
|
||||
return obj && (asval(obj, (Type *)(0)) == SWIG_OK);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -229,9 +229,9 @@ namespace swig {
|
|||
static int asval(PyObject *obj, value_type *val) {
|
||||
if (Check(obj)) {
|
||||
*val = As(obj);
|
||||
return 1;
|
||||
return SWIG_OK;
|
||||
}
|
||||
return 0;
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
};
|
||||
template <> struct traits_from<Type > {
|
||||
|
|
|
|||
|
|
@ -20,12 +20,30 @@ SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc)
|
|||
PyString_AsStringAndSize(obj, &cstr, &len);
|
||||
if (cptr) {
|
||||
if (alloc) {
|
||||
if (*alloc == SWIG_NEWOBJ) {
|
||||
*cptr = SWIG_new_copy_array(cstr, len + 1, char);
|
||||
} else {
|
||||
/*
|
||||
In python the user should not be able to modify the inner
|
||||
string representation, so, by default we return a copy of
|
||||
the buffer, as in the wstring case.
|
||||
|
||||
But, if you use the -DSWIG_PYTHON_UNSAFE_CSTR at
|
||||
compilation time, you will get, at your own risk, the
|
||||
inner string pointer instead, when possible.
|
||||
*/
|
||||
#ifndef SWIG_PYTHON_UNSAFE_CSTR
|
||||
if (*alloc != SWIG_OLDOBJ)
|
||||
#else
|
||||
if (*alloc == SWIG_NEWOBJ)
|
||||
#endif
|
||||
{
|
||||
*cptr = SWIG_new_copy_array(cstr, len + 1, char);
|
||||
*alloc = SWIG_NEWOBJ;
|
||||
}
|
||||
else {
|
||||
*cptr = cstr;
|
||||
*alloc = SWIG_OLDOBJ;
|
||||
}
|
||||
} else {
|
||||
*cptr = cstr;
|
||||
}
|
||||
}
|
||||
if (psize) *psize = len + 1;
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ SWIG_AsWCharPtrAndSize(PyObject *obj, wchar_t **cptr, size_t *psize, int *alloc)
|
|||
int len = PyUnicode_GetSize(obj);
|
||||
if (cptr) {
|
||||
*cptr = SWIG_new_array(len + 1, wchar_t);
|
||||
memset(*cptr, 0, (len + 1)*sizeof(wchar_t));
|
||||
PyUnicode_AsWideChar((PyUnicodeObject *)obj, *cptr, len);
|
||||
(*cptr)[len] = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
pfirst = &((*val)->first);
|
||||
psecond = &((*val)->second);
|
||||
}
|
||||
if (swig::asval(first,pfirst) && swig::asval(second,psecond)) {
|
||||
if ((swig::asval(first,pfirst) == SWIG_OK) && (swig::asval(second,psecond) == SWIG_OK)) {
|
||||
return SWIG_NEWOBJ;
|
||||
} else {
|
||||
SWIG_delete(*val);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue