[C++-sig] extract<> with custom shared pointers

2011-08-05 Thread Holger Brandsmeier
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

[C++-sig] Dynamic Cast failed over multiple modules

2011-09-08 Thread Holger Brandsmeier
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

Re: [C++-sig] Dynamic Cast failed over multiple modules

2011-09-08 Thread Holger Brandsmeier
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,

Re: [C++-sig] [Boost.Python v3] Conversions and Registries

2011-09-19 Thread Holger Brandsmeier
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

[C++-sig] Custom smart pointer with const Types

2011-10-05 Thread Holger Brandsmeier
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

Re: [C++-sig] Custom smart pointer with const Types

2011-10-05 Thread Holger Brandsmeier
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, >

[C++-sig] two pitfals when extending c++ classes from python

2011-10-25 Thread Holger Brandsmeier
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

[C++-sig] make_constructor and BOOST_PYTHON_FUNCTION_OVERLOADS

2012-02-02 Thread Holger Brandsmeier
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

[C++-sig] storing weak_ptr to this in classes extended from python

2012-02-03 Thread Holger Brandsmeier
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

[C++-sig] make_constructor and extending from python

2012-02-03 Thread Holger Brandsmeier
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

Re: [C++-sig] Retaining a useful weak_ptr to a wrapped C++ interface implemented in Python

2012-03-06 Thread Holger Brandsmeier
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

Re: [C++-sig] Retaining a useful weak_ptr to a wrapped C++ interface implemented in Python

2012-03-06 Thread Holger Brandsmeier
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

[C++-sig] std::complex vs python complex

2012-04-10 Thread Holger Brandsmeier
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

[C++-sig] overloaded functions and order of arguments

2012-04-12 Thread Holger Brandsmeier
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

Re: [C++-sig] std::complex vs python complex

2012-04-12 Thread Holger Brandsmeier
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 &

Re: [C++-sig] overloaded functions and order of arguments

2012-04-12 Thread Holger Brandsmeier
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`

Re: [C++-sig] Re : boost::python: C++/Python function overload issue

2012-04-19 Thread Holger Brandsmeier
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

[C++-sig] weak_ptr to this in C++ classes extended from python

2012-04-22 Thread Holger Brandsmeier
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

Re: [C++-sig] weak_ptr to this in C++ classes extended from python

2012-04-23 Thread Holger Brandsmeier
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? >

Re: [C++-sig] weak_ptr to this in C++ classes extended from python

2012-04-23 Thread Holger Brandsmeier
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 >

Re: [C++-sig] weak_ptr to this in C++ classes extended from python

2012-04-25 Thread Holger Brandsmeier
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

Re: [C++-sig] weak_ptr to this in C++ classes extended from python

2012-04-26 Thread Holger Brandsmeier
; } ---  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

Re: [C++-sig] weak_ptr to this in C++ classes extended from python

2012-04-27 Thread Holger Brandsmeier
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

Re: [C++-sig] boost::python with virtual inheritance and g++ c++0x/11 (testcase attached)

2012-05-14 Thread Holger Brandsmeier
>>> 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

Re: [C++-sig] C++ clas with (*args, **kwargs) constructor

2012-06-21 Thread Holger Brandsmeier
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

Re: [C++-sig] Instance ownership transfer in constructor.

2012-07-05 Thread Holger Brandsmeier
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,

Re: [C++-sig] Instance ownership transfer in constructor.

2012-07-06 Thread Holger Brandsmeier
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

[C++-sig] `cout << tuple` is ambiguous

2012-08-26 Thread Holger Brandsmeier
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

Re: [C++-sig] boost-python: Passing an object held in a boost::shared_ptr from C++ to python to C++

2012-08-31 Thread Holger Brandsmeier
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

Re: [C++-sig] Inheriting static overloaded properties

2012-09-04 Thread Holger Brandsmeier
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

Re: [C++-sig] More inheritance problems

2012-09-04 Thread Holger Brandsmeier
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) ;

Re: [C++-sig] [boost.python] Register a Python-callable with C++ code and call it from C++ code?

2012-10-27 Thread Holger Brandsmeier
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

Re: [C++-sig] [boost.python] Register a Python-callable with C++ code and call it from C++ code?

2012-10-27 Thread Holger Brandsmeier
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

[C++-sig] boost numpy and boost python exported float128 / dd_real

2012-11-04 Thread Holger Brandsmeier
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:

[C++-sig] buildin converter for long double

2012-11-05 Thread Holger Brandsmeier
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

Re: [C++-sig] buildin converter for long double

2012-11-07 Thread Holger Brandsmeier
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

[C++-sig] From python converter for builtin types

2012-11-08 Thread Holger Brandsmeier
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

Re: [C++-sig] From python converter for builtin types

2012-11-09 Thread Holger Brandsmeier
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 > > >

Re: [C++-sig] a boost.python question about parameter that is a pointer of instance.

2012-11-17 Thread Holger Brandsmeier
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

Re: [C++-sig] a boost.python question about parameter that is a pointer of instance.

2012-11-17 Thread Holger Brandsmeier
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

Re: [C++-sig] Extending classes

2012-12-07 Thread Holger Brandsmeier
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

Re: [C++-sig] Exposing c++ class template to Python (known template instances)

2013-03-17 Thread Holger Brandsmeier
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

Re: [C++-sig] Exposing c++ class template to Python (known template instances)

2013-03-17 Thread Holger Brandsmeier
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 >>

Re: [C++-sig] Alternate locations for BOOST_PYTHON_MODULE

2013-06-12 Thread Holger Brandsmeier
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

Re: [C++-sig] Alternate locations for BOOST_PYTHON_MODULE

2013-06-12 Thread Holger Brandsmeier
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 >

Re: [C++-sig] Exposing a C-style array data member to Python via Boost.Python

2013-07-27 Thread Holger Brandsmeier
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

Re: [C++-sig] fault core dump error

2013-09-30 Thread Holger Brandsmeier
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