Dear Boost::python experts,
I am trying to use a custom shared pointer type instead of
boost::shared_pointer, in my case Teuchos::RCP from the Trilinos
project. The details of Teuchos::RCP should not matter much here. In
any case there is a Doxygen documentation on the Trilinos webpage.
For compl
Dear List,
when I use dynamic cast from two boost modules on a class with "vague
linkage", in my real use case a template in the simplified example I
show you a class which is declared inline, then the dynamic cast fails
in the second module.
So when I call the code from python from the first mod
Mathieu,
thank you very much. This is exactly what I was still missing.
-Holger
On Thu, Sep 8, 2011 at 12:00, Mathieu Malaterre
wrote:
> On Thu, Sep 8, 2011 at 11:56 AM, Holger Brandsmeier
> wrote:
> [...]
>> CMAKE_SHARED_LINKER_FLAGS. About the RTLD_GLOBAL flag for dlopen,
Jim,
My answer for 1), 2) for module specific behavior would be that I
would probably not use module specific behavior. In my current project
I separate the code into multiple BOOST_PYTHON_MODULE. So I would want
to use project specific behavior and not behavior specific to the
BOOST_PYTHON_MODULE
Dear list,
how should I export functions to python which return smart pointers to
const-pointers, e.g. shared_ptr?
For my own classes I always tried to avoid this problem by always
providing a methods which returns shared_ptr.
Now I need to export the following method in a class provided by some
t away the constness and use the above implementation.
This seems to be working so far. Did you provide a smarter
implementation for shared_ptr?
-Holger
On Wed, Oct 5, 2011 at 15:44, Jim Bosch wrote:
> On 10/05/2011 03:08 AM, Holger Brandsmeier wrote:
>>
>> Dear list,
>
rted as "noncopyable" and "no_init".
Admittedly the problem here is how to handle the lifetime of the
object and after thinking about it I fully why boost::python has a
problem here. My solution was then to pass a smart pointer instance.
I just wanted to point
Dear list,
how can I combine make_constructor() and BOOST_PYTHON_FUNCTION_OVERLOADS()?
I have a static member function in a class that "acts like a
constructors", in the sense that it returns a shared pointer to the
class. The function has default arguments, thats why I was thinking of
using BOOS
Dear list,
Note: I am actually using Teuchos::RCP instead of boost::shared_ptr
and boost::weak_ptr, but I already mirrored almost all the special
treatments in boost::python, and have been successfully using this for
a while. Everything that I write should actually apply to both
implementations in
Dear list,
how can I have a static member function that acts like a constructor
in a Wrapper, i.e. I have a class that I want to extend from python?
I have a wrapper class around a class (PfemSpace) that has this static
member functions:
static RCP create( ... )
{
RCP ret(new PfemSpaceWr
Adam,
you probably run into a similar problem that I ran into (not with
boost::shared_ptr but with our custom implementation which strongly
mimics boost::shared_ptr). I wanted to have a class in C++ that is
extended in python, and it should store a weak_ptr to itself.
Unfortunately I didn't solve
Adam,
>> So, before the function exits your object `arg` exists at least in three
>> places:
>> 1) somewhere in C++ where it was created
>> 2) in the python context
>> 3) in the context of addCallback
>>
>
> Technically, it was declared and constructed from Python, but everything you
> say is a
not
cooperate nicely with boost::python and std::complex<> but how did
python/boost::python end up converting the result of the addition to
`complex`?
I am using:
Python 2.7.2
boost-1.46.1
Best regards,
Holger Brandsmeier
___
Cplusplus-sig mailin
Dear list,
I exported the C++ function `sin` both for real and complex numbers
(`float` and `complex` in python / `double` and `std::complex` in C++)
and I noticed that calling `sin(2.3)` gives `(0.7457052121767203-0j)`
so a complex number. Why is that? In which order does boost python
handle over
n.
-Holger
On Tue, Apr 10, 2012 at 17:37, Jim Bosch wrote:
> On 04/10/2012 06:58 AM, Holger Brandsmeier wrote:
>>
>> Dear list,
>>
>> I exported a wrapper for std::complex to python and I am
>> willing to always use this class in python and I never want to use
&
rst match" approach, I think trying bottom up
> for functions and member functions, top down for constructors (for weird
> reasons).
>
> On Thu, Apr 12, 2012 at 9:48 AM, Holger Brandsmeier
> wrote:
>>
>> Dear list,
>>
>> I exported the C++ function `sin`
Christophe,
You need to work with Wrappers when you export the class A to python.
This wrapper will make sure that when C++ calls a class that you
overloaded in python that then the correct python implementation is
called.
See also the sections:
Class Virtual Functions
Virtual Functions with Def
Dear list,
how is it possible to have a class in C++ that can be extended from
python and that stores a weak_ptr to itself?
The reason why I want to do this:
- using a weak_ptr to itself does not introduce a memory leak.
- from a C++-member of that class I can call other functions that
expect a
eas?
-Holger
On Mon, Apr 23, 2012 at 18:01, Dave Abrahams wrote:
>
> on Sun Apr 22 2012, Holger Brandsmeier wrote:
>
>> Dear list,
>>
>> how is it possible to have a class in C++ that can be extended from
>> python and that stores a weak_ptr to itself?
>
Dave,
Here is the reduced example with only the
`boost::enable_shared_from_this` variant. The issues are all as
reported before.
-Holger
On Mon, Apr 23, 2012 at 22:25, Dave Abrahams wrote:
>
> on Mon Apr 23 2012, Holger Brandsmeier wrote:
>
>> In fact the statement
>
lease post the complete, correct example that you tried?
>
> on Mon Apr 23 2012, Holger Brandsmeier wrote:
>
>> Dave,
>>
>> Here is the reduced example with only the
>> `boost::enable_shared_from_this` variant. The issues are all as
>> reported befor
;
}
---
foo.py
import foo
class ExtendedA(foo.A):
def foo(self):
return 33;
a0 = foo.A()
a = ExtendedA()
aa = a.ptr();
print a.foo()
del a
print aa.foo()
---
Do you have any suggestion how to get thi
n Mon, Apr 23, 2012 at 20:48, Holger Brandsmeier wrote:
> In the meantime I figured out a different way of doing the shared
> pointer from this in python. Namely, to just make getThisRCP() a
> virtual function, add it to the Wrapper and to implement it in the
> python by implementing it as
>>> Clang doesn't compile boost python 1.49 at all. Sadly.
> Sure, you're right. Sorry, it was my fault in reading clang's error
> messages. It chockes on the c++ stl bits, not on boost, but they're
> included from boost, so the first thing I read was “boost”.
> Well, I cannot tell if it would chok
Trigve,
with the line
class_>("Form") ;
you declare Form to have a default constructor (you didn't use any
init<> struct. That is why you can not pass anything to the
constructor. If you want to use a constructor with a single (but
arbitrary) type, then you should use PyObject on the C++ side. T
Jani,
ok what you want to do is quite a lot more intrusive, so you need some
more involved methods, but it should be possible. I would do it by
noting the following
- data_1 is published to python as a boost::shared_ptr (default
holder type)
- usually it is difficult for a class member function,
emory corruption.
>
> I've tried to make usage of shared_ptr but no luck and I didn't understood
> how to apply shared_ptr_for_this.
>
> (NOTE: in my case all classes are from 3rd party library that I have no
> control over)
>
> 5.7.2012 20:44, Holger Brandsmeier kir
leans? And how can I output tuples?
Btw. the compiler that I used is `clang version 3.1 (trunk 154212)`
Best regards,
Holger Brandsmeier
___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig
Dear Phil,
the problem you are phasing is because you use a weak pointer. I had a
very similar problem in April, you may read it up here
http://mail.python.org/pipermail/cplusplus-sig/2012-April/016524.html
There I also tried to explain why this happens, I'm not sure if I did
a good job, just as
Dear Karl,
your problem does not occur if you do the following,
bp::class_("Base")
.add_static_property("debug", &Base::debug, &Base::setDebug);
bp::class_ >("Derived")
.add_static_property("debug2", &Derived::debug, &Derived::setDebug);
Note that I called the property "d
Dear Karl,
the problem is fixed if you do the following:
bp::class_("Base", bp::no_init)
.def("do_stuff", bp::pure_virtual(&BaseWrapper::do_stuff))
.def("name", &BaseWrapper::name, &BaseWrapper::default_name)
.def("name", &Base::name)
;
Paul,
if I see this correctly, then you are trying to register a function to
python in
.def( "register_tau4ehS", register_tau4ehS)
which is expecting a pointer to a function to python. You can not do
that. Python can not pass function pointers as arguments, and so can't
boost::python.
When
e wich is called
> before/after the call into cpp.
>
> Tanks
> Paul
>
>
> Holger Brandsmeier wrote:
>
>> Paul,
>>
>> if I see this correctly, then you are trying to register a function to
>> python in
>> .def( "register_tau4ehS", regis
Dear list,
there is a C++ library that supports 128bit (and 256bit) floats:
libqd. In C++ that data type is called dd_real and I exported dd_real
to python via boost python.
Sometimes I send the same `dd_real` to python via a boost numpy by
creating and ndarray with the dtype given by
`np::dtype:
Dear list,
the boost python buildin converter for long double:
BOOST_PYTHON_TO_PYTHON_BY_VALUE(long double,
::PyFloat_FromDouble(x), &PyFloat_Type)
converter/builtin_converters.hpp
identifies long double, which on my system is a 128bit float, with a
64bit float in python. I would like to ident
ot useful, it's slow. and in most case, change
> algorithm to avoid precision problem is another *better* approach.
>
>
> Changsheng Jiang
>
>
> On Mon, Nov 5, 2012 at 6:27 PM, Holger Brandsmeier
> wrote:
>&g
Dear list,
where does boost python define the from python converters for buildin
types such as double / PyLong_Type?
With the help of Changsheng Jiang I was able to modify
builtin_converters.hpp and was able to change a to python converter
for long double to produce numpy.float128. I do not find
gt; builtin_converters.cpp:
>
> slot_rvalue_from_python();
>
> Boost/Python using global registration only according type saw in C++, I
> don't known is it possible to overrides these.
>
> Changsheng Jiang
>
>
>
Have a look at
http://stackoverflow.com/questions/4331599/calling-python-functions-from-c
On Sat, Nov 17, 2012 at 4:25 PM, simon zhang wrote:
> This is a complex problem. I provide some code.
>
> c++
> ===
> #include
> #include
> #include
>
> class Rectangle
That error has nothing to do with boost python. Apparently you did not
link against the definition for the class Rectangle. You need to link
against the object file generated from the definiton of Rectangle,
usually you would have a Rectangle.cpp and generate a Rectangle.o.
Your python module needs
Dear Karl,
I have one idea that may help you.
Say you have a class `MyClass` with a method `func` where you want
extra code to be excecuted when that function is called from python. I
would add a function `MyClass_func` which is a function outside a
class that has the same return code as `func` a
Dotan,
in
>>> barPolicy = GetBarWithPolic(Io)
>>> barPolicy = GetBarWithPolic(File)
what type of object would you imaginge `Io` and `File` to be?
You already exported the functions as `GetBarWithPolicIo` and
`GetBarWithPolicFile` and then you could implement in python
`GetBarWithPolic(str)` a
hat I mean is this : I
> would like to have some generic pointer that can either point to
> BarWithPolicy nor to BarWithPolicy ?
>
>
> thanks
> -Dotan
>
> On Sun, Mar 17, 2013 at 9:36 AM, Holger Brandsmeier
> wrote:
>>
>> Dotan,
>>
>> in
>>
Trevor,
that is certainly possible, all my python exports look like this:
#include "pfemPy.inl"
BOOST_PYTHON_MODULE(pfemPy)
{
PfemInst::call();
} // boost module
Then e.g. in "pfemPy.inl" I wrap and export the C++ classes. The file
"pfemPy.inl" in turn includes the header of the required sour
w are you compiling your python extension modules?
> Can you point me to some information about it?
>
> Thanks for your help,
> Trevor
>
> -Original Message-----
> From: Cplusplus-sig
> [mailto:cplusplus-sig-bounces+trevor.haba=logmein@python.org] On Behalf
>
Ashish,
if you really need it to be a `list` in python, then there is no way
around it, you have to copy it. If you just need it to behave like a
list, then that is possible. Just export your struct to python and
implement methods such as __get__(), __set__(), __len()__, __eq__(),
...
You may al
Sam,
this looks really awful:
double **array1; array1 [HEIGHT][WIDTH];
do you mean:
double **array1; //array1 [HEIGHT][WIDTH];
But this might not be your probablem. You say " folder which has about
200 text files", but your code is treating this as "exactly 200 text
files", you need to do som
47 matches
Mail list logo