logo       

Re: bug while wrapping const char arrays without an explicitly defined size: msg#00173

programming.swig

Subject: Re: bug while wrapping const char arrays without an explicitly defined size

David Beazley wrote:

Marcelo Matus writes:
> >Where is SWIG_FromCharArray() coming from? I don't remember that
> >function being part of the SWIG API (I sure didn't write it anyways).
> >
> >SWIG developers: Is there some reason the normal PyObject API
> >functions are not being used here???
> >
> > > >
> > Most of the PyObject API functions don't check for NULL pointers, and
> if you pass one, python crashes. Also, internally python uses
> 'int' for size, which means if you have a very large binary string
> python can't handle it.
> > The extra SWIG_XXX methods check for null when needed and
> return you a plain pointer (not a python string) if the array size
> is larger than INT_MAX.
>
IMHO, both of these problems sound like issues that can be resolved
using user-defined typemaps and are not necessary for SWIG's default
behavior.



probably the very large strings could have special typemaps,
but the checking of NULL should be there since is not uncommon
to pass or return a NULL value for char*.

In fact, the NULL check is in the 1.3.21, but is inside the typemaps, in
some cases, in other cases the check was missing.

The other thing I forgot, if you get a swig pointer, like

_012234_p_char

that you create using carrays (or other form), then in

void test_case(char * in);

the old 1.3.21 passes you the string "_012234_p_char", and not
the pointer 0x01234.

all these little differences or features of C++/python/swig
can be added to the typemaps, or in the SWIG_XXX methods.
I like the later better since the code generated is shorter
and more consistent (you are sure the same checks are performed
in the in,out,varin,directorout,... typemaps where you use
the SWIG_XXX methods).

Marcelo

PS: Anyway, the reported problem was not related to the SWIG_XXX
methods, but to the fact that I added the 'char [ANY]' forms, but
I forgot to add the 'char []' form to the typemaps.


-- Dave
_______________________________________________
Swig maillist - Swig@xxxxxxxxxxxxxxx
http://mailman.cs.uchicago.edu/mailman/listinfo/swig


_______________________________________________
Swig maillist - Swig@xxxxxxxxxxxxxxx
http://mailman.cs.uchicago.edu/mailman/listinfo/swig



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise