On Wednesday 25 May 2011 15:16:38 John Cummings wrote:
> > Any function that gets arrays on their arguments must be treated as
> > special cases, because there's no way to create a heuristic that will do
> > the right thing in all cases :-/
> > 
> > What you really need to do to fix your function depends on the semantics
> > of your function and how you want to export it to Python.
> 
> I understand the need and semantics for changing the handling of arrays
> for function arguments. However, I am not trying to change the behavior
> for a function argument in this case. I am trying to access a member (or
> class static) variable that happens to be an array. The example I gave
> is roughly as follows:
> 
> class Foo
> {
> public:
>     // constructor, other methods, etc.
>     size_t scalar;
>     size_t array[2];
> }
> 
> As you suggested, adding a primitive-type tag like this:
> 
> <primitive-type name="size_t" default-constructor="0"
> target-lang-api-name="PyLong" />
> 
> 
> works great for the member variable "scalar" above. It does not handle
> the member variable "array" above. It really can just become either a
> Python tuple or a list, with a slight preference for a tuple in the case
> of a static const class variable that happens to be an array.
> 
> Have I missed something?

Oh, sorry now I see, it's a public attribute of your class, you are right 
there's no special semantics in this case, is clear what should be exported to 
Python.

But there are some problems...

We can't export if as a tuple because tuples are immutable objects in Python, 
so we need to export this attribute as a list, however we need to forbidden 
the user to do some constructs like:

foo = Foo()
foo.array.append(2);

Because the size of array must be constant.

There is another problem regarding to the sync between Python and C++, if the 
user do:

foo.array[0] = 3

The array gets modified by him, ok, but how C++ will knows that the list was 
modified? C++ need to knows it to proper copy the values back to the C++ Foo 
instance that lies behind the Pyhton object.

The problem is that the Python list is another thing, different from the C++ 
array and we can't tell the Python list to point to the C++ address of 
Foo.array, so we need to copy some data to Python but we never know when to 
copy this values back to C++.

However I think all these problems could be addressed if we create a new 
object to deal with this, this object would hold a pointer to the C++ array 
it's mapping and direct change it when necessary, but this rises a new set of 
minor problems, e.g. we would need different objects for different C++ types, 
etc..

> Thank you for your help
> John Cummings

-- 
Hugo Parente Lima
INdT - Instituto Nokia de Tecnologia

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
PySide mailing list
[email protected]
http://lists.pyside.org/listinfo/pyside

Reply via email to