miscellaneous questions about boost.python

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

miscellaneous questions about boost.python

Wojciech Mamrak
I have a few doubts and questions I haven't found answer googling here
and there. I hope you can help me with them.

1. When exposing C++ objects to python using Boost, instance
dictionaries are created only "on demand", the first time the
instance's __dict__ attribute is accessed

Some Python scripts make use of __dict__, and here dicts are created
only after assigning a value to non-existent (non-c++-defined)
members. Is there any way to overcome this?

2. Is it possible to expose variadic functions to Python? Like: inline
int printInts(int num, ...);

3. Is there a way to pass a list or dict object with all the arguments
to a function as a single parameter? This is possible in Python C when
calling a function and might be sometimes very useful.

4. The docs regarding the mutable copying problem are very misleading.
Following Python and Boost scripts do not produce the same results:
b = a = []
c = list(a)
print a.count("s1"), b.count("s1"), c.count("s1") #1 1 0

list a, b, c;
b = a;
c = list(a);
list d = extract<list>(a);
printf("%i %i %i %i\n", a.count("s1"), b.count("s1"), c.count("s1"),
d.count("s1")); //1 1 1 1

expected 1 1 0 1 according to Pythonic behaviour. This is in confilct
with example provided in the tutorial.

5. BOOST_PYTHON_FUNCTION_OVERLOADS and friends on my MSVC10 produce
errors C2246 and C2892.

6. Is it ok to expose to Python just some properties/methods of a c++
class? As long as all classes, that the mentioned class inherits
after, are defined in boost python, I assume there is no risk that
objects created in Python are not complete and compatible (i.e. might
not work properly when extracted back to C++). Is this assumption
valid? I can provide an example if my intentions are not clear to you.

Cplusplus-sig mailing list
[hidden email]