fix char* typemap in bug #1080514

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6856 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2004-12-11 08:30:40 +00:00
commit 988db075cb
4 changed files with 27 additions and 8 deletions

View file

@ -545,6 +545,19 @@ macro(size_t, pfx, sizet)
} }
%inline %{
const char* char_foo(float f, const char *s) {
return s;
}
int char_foo(double d, int i) {
return i;
}
%}
%apply SWIGTYPE* { char *}; %apply SWIGTYPE* { char *};
%include "carrays.i" %include "carrays.i"

View file

@ -344,3 +344,12 @@ f2 = fptr_ref(f)
if f1._a != f2._a: if f1._a != f2._a:
raise RuntimeError, "bad const ptr& typemap" raise RuntimeError, "bad const ptr& typemap"
v = char_foo(1,3)
if v !=3:
raise RuntimeError, "bad int typemap"
s = char_foo(1,"hello")
if s !="hello":
raise RuntimeError, "bad char* typemap"

View file

@ -40,12 +40,11 @@ SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize)
SWIGINTERNSHORT int SWIGINTERNSHORT int
SWIG_AsCharPtr(PyObject *obj, char **val) SWIG_AsCharPtr(PyObject *obj, char **val)
{ {
char* cptr = 0; if (SWIG_AsCharPtrAndSize(obj, val, (size_t*)(0))) {
if (SWIG_AsCharPtrAndSize(obj, &cptr, (size_t*)(0))) {
if (val) *val = cptr;
return 1; return 1;
} }
if (val) { if (val) {
PyErr_Clear();
SWIG_type_error("char *", obj); SWIG_type_error("char *", obj);
} }
return 0; return 0;

View file

@ -44,13 +44,11 @@ SWIG_AsWCharPtrAndSize(PyObject *obj, wchar_t **cptr, size_t *psize)
SWIGINTERN int SWIGINTERN int
SWIG_AsWCharPtr(PyObject *obj, wchar_t **val) SWIG_AsWCharPtr(PyObject *obj, wchar_t **val)
{ {
wchar_t * cptr = 0; if (SWIG_AsWCharPtrAndSize(obj, val, (size_t*)(0))) {
int res = 0; return 1;
if ((res = SWIG_AsWCharPtrAndSize(obj, &cptr, (size_t*)(0)))) {
if (val) *val = cptr;
return res;
} }
if (val) { if (val) {
PyErr_Clear();
SWIG_type_error("wchar_t *", obj); SWIG_type_error("wchar_t *", obj);
} }
return 0; return 0;