logo       

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

programming.swig

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

David Beazley wrote:

Oren Miller writes:
> Using the latest CVS version:
> > If I have a char array defined like this:
> > const char BeginString_FIX44[8] = "FIX.4.4";
> > The wrapper for this is generated correctly like so:
> > static PyObject *_wrap_BeginString_FIX44_get() {
> PyObject *pyobj;
> > pyobj = SWIG_FromCharArray(FIX::BeginString_FIX44, 8);
> return pyobj;
> }
> > However, if it is defined like so:
> > const char BeginString_FIX44[] = "FIX.4.4";
> > This gets generated:
> > static PyObject *_wrap_BeginString_FIX44_get() {
> PyObject *pyobj;
> > pyobj = SWIG_FromCharArray(FIX::BeginString_FIX44, );
> return pyobj;
> }
> > As you can see the size is missing which of course results in > compilation errors. It would seem to me in this case Swig should count > up the characters in the string and place the value as the second > parameter to FromCharArray. I'd be happy to try to create a patch but > am not familiar with the source and would need someone to point me to > the module where this generation occurs. Thanks.
>
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.


-- 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