[C++-sig] Arrays and Boost.Python
Patrick Hartling
patrick at vrac.iastate.edu
Sun Mar 30 07:54:10 CEST 2003
David Abrahams wrote:
> Patrick Hartling <patrick at vrac.iastate.edu> writes:
>
>
>>Does Boost.Python (from Boost 1.30.0 or the Boost CVS trunk) provide
>>handling of arrays as public data members in a C++ class? Using
>>Boost.Python from Boost 1.30.0, I get an error from GCC 3.2 about line
>>68 of boost/python/data_members.hpp stating that "ISO C++ forbids
>>assignment of arrays." If I change the array definition in my
>>Boost.Python code so that the data member is read-only instead of
>>read/write, that gets rid of the error.
>
>
> But I doubt it will do anything other than raise an exception when
> you try to use it from Python.
That is true. I hadn't actually tested it prior to reading your
response. Oh well.
>>I don't mind doing that in this case--really I am just curious about
>>how Boost.Python handles C++ arrays.
>
>
> So far, it doesn't. If you can write down precisely what semantics
> you'd like to see, considering what would constitute an argument match
> for overloaded functions, we might be able to do something about it.
I hadn't really thought about it much so far. It was one of those
things I was hoping would "just work." The fact that it is not handled
right now is not a big problem for me personally.
What I see as a problem is that arrays in C/C++ are just syntactic sugar
for accessing a block of memory. In languages such as Java and C# (and
even Managed C++ from what I have seen so far), their handling is more
formalized. In other words, there is no question that a function with a
signature such as 'void f(int[] intList)' takes an array of integers.
In the land of C/C++, we have to deal with the uncertainty of 'void
f(int* intList)'. Is it a pointer to a single integer, an array, or a
pointer into the middle of an array? All that is certain is that it
points to four bytes of memory (for ILP32, anyway).
Honestly, I don't feel too strongly about seeing support for arrays in
Boost.Python. Considering that neither lists nor tuples in Python
provide quite the right semantics for a C-style array, the concept may
just not map into the world of Python very well. Of course, I could be
wrong about all of this--I'm just a user, not an expert. :)
-Patrick
--
Patrick L. Hartling | Research Assistant, VRAC
patrick at vrac.iastate.edu | 2624 Howe Hall: 1.515.294.4916
http://www.137.org/patrick/ | http://www.vrac.iastate.edu/
More information about the Cplusplus-sig
mailing list