Re: [C++-sig] Segfault with keyword arguments and overloads.

2013-08-08 Thread Alex Leach
Hi Alex, On Wed, 07 Aug 2013 18:06:24 +0100, Alex Mohr wrote: Thanks for your response. I've responded to your comments in-line below. After further investigation, I believe this can be fixed by simply checking for None when we get 'kv' from f->m_arg_names while resolving keywords. If w

Re: [C++-sig] Segfault with keyword arguments and overloads.

2013-08-07 Thread Alex Leach
Hi, On Wed, 07 Aug 2013 01:35:54 +0100, Alex Mohr wrote: I'm hitting a repeatable segfault trying to upgrade our boost version. I believe there may be a bug with overload resolution in the presence of keyword arguments. Here's a minimal example that crashes for me. // C++ #include stat

Re: [C++-sig] return boost::shared_ptr

2013-06-14 Thread Alex Leach
On Fri, 14 Jun 2013 12:57:48 +0100, Neal Becker wrote: I have a class that has a member something like this: class A { boost::shared_ptr b; }; boost::shared_ptr get_b (A const& ...) { return A.b; } where class B is already exposed to python in a different module. I think this depe

Re: [C++-sig] How can I have a global C/C++ variable that is shared between Python C/C++ extensions?

2013-06-13 Thread Alex Leach
I had a similar problem when testing my extensions on OSX. I guess you're not on OSX, but if you test out on it, I'm sure you'd find even more linking problems.. Problem is that the bundle format - the default Python extension format, on OSX - doesn't allow compile-time linking, only run-time dyna

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

2013-06-12 Thread Alex Leach
On Wed, 12 Jun 2013 11:34:24 +0100, Holger Brandsmeier wrote: Trevor, ok, so I misunderstood your question. If what you want to do is this: myclass.h class MyClass { [...] }; pythonFile.cpp #include "myclass.h" [...] BOOST_PYTHON_MODULE(...) { [...] } That is certainly possible

Re: [C++-sig] Handling a custom C++ exception from Python

2013-06-02 Thread Alex Leach
On Sun, 02 Jun 2013 21:04:51 +0100, Александров Петр wrote: 02.06.2013 13:14, Alex Leach пишет: 1. Boost Python has a dedicated exception handling API[1] that doesn't require you to wrap the exception in a class_<> template. The class_ template is a bit heavy duty for

Re: [C++-sig] Handling a custom C++ exception from Python

2013-06-02 Thread Alex Leach
On Sat, 01 Jun 2013 23:50:40 +0100, Александров Петр wrote: I want to catch a custom C++ exception in Python. I have described my custom exception class as usual: class_(...); and created a translator: void translate(CMyException const &e) { object o(e); PyErr_SetObject(PyExc_E

Re: [C++-sig] Type converter not found for property

2013-05-09 Thread Alex Leach
On Thu, 09 May 2013 07:41:49 +0100, Wichert Akkerman wrote: If I try to do that by adding this: to_python_converter(); to_python_converter() I get a compile error: /opt/local/include/boost/python/converter/as_to_python_function.hpp:21:84: error: 'type name' declared as a pointer to a

Re: [C++-sig] Type converter not found for property

2013-05-09 Thread Alex Leach
On Thu, 09 May 2013 07:55:07 +0100, Wichert Akkerman wrote:On May 8, 2013, at 23:31 , "Alex Leach" <beamesle...@gmail.com> wrote:That error means the type_id of uuid is not in the bp registry.I think you can fix this by deriving uuid_to_python from to_python_converter, as dem

Re: [C++-sig] Type converter not found for property

2013-05-08 Thread Alex Leach
That error means the type_id of uuid is not in the bp registry.I think you can fix this by deriving uuid_to_python from to_python_converter, as demonstrated in the pytype_function example[1]. This will add the get_pytype function call, and on initialisation, should hopefully add what's missing: a

Re: [C++-sig] Custom PyTypeObjects

2013-04-29 Thread Alex Leach
Dear list, A thread I started was originally meant to discuss how to use C++ memory management methods (operator new, delete etc.) with a boost python instance. Rather than dwelling on the concern, I've been (successfully) wrapping other code since, but have now arrived at a separate conund

Re: [C++-sig] Tips for exposing classes with own memory management model

2013-04-19 Thread Alex Leach
Hi again, Whilst hoping for a reply, I thought I'd add some further insights I've learnt about the current PyTypeObject scheme. On Thu, 18 Apr 2013 17:14:05 +0100, Jim Bosch wrote: I was originally thinking that maybe you could get away with essentially wrapping your own classes just using

Re: [C++-sig] Tips for exposing classes with own memory management model

2013-04-18 Thread Alex Leach
Hi, Thanks again for the fast response! On Thu, 18 Apr 2013 17:14:05 +0100, Jim Bosch wrote: You can't really register the types themselves. All you can do is register custom converters for them, i.e. You'll need to read the code and comments in the "converter" subdirectories of the B

Re: [C++-sig] Tips for exposing classes with own memory management model

2013-04-18 Thread Alex Leach
Thank you for the quick response!On Thu, 18 Apr 2013 15:24:09 +0100, Jim Bosch wrote:If you go with writing your own PyTypeObject, you will indeed have a lot more control, but it will greatly limit how much Boost.Python you can use (no class_, for instance, at least), and you'll need to dive deep

[C++-sig] Tips for exposing classes with own memory management model

2013-04-18 Thread Alex Leach
Dear list, Apologies if this has been asked before, but I'm struggling to find anything strictly related.. Background -- This library I'm trying to wrap uses its own memory management model, where almost every class derives from an object with loads of memory management-related m

Re: [C++-sig] const_iterator type

2013-03-29 Thread Alex Leach
The iterator I'm wrapping comes from a 3rd party library, over which I have no control. However, I have been able to add those missing types to the derived inheritor class, by also inheriting from 'iterator_facade', as per a suggestion on StackOverflow. Thanks for the reply btw; I have no clue when

Re: [C++-sig] const_iterator type

2013-03-27 Thread Alex Leach
On Wed, 27 Mar 2013 11:36:47 -, Alex Leach wrote: I'm trying to wrap an iterable class, which returns a custom iterator typedef'd as const_iterator, from its begin and end methods. In case any of you like answering these types of questions on StackExchange sites, I'

[C++-sig] const_iterator type

2013-03-27 Thread Alex Leach
Hi, I'm trying to wrap an iterable class, which returns a custom iterator typedef'd as const_iterator, from its begin and end methods. When using boost::python::(iterator|iterators|range) to create an iterator in the exposed __iter__ function in the exposed class_ def, I get a load of com

Re: [C++-sig] Segfaults in object deallocation

2013-03-24 Thread Alex Leach
Thanks for the reply, and apologies for the delay in mine; I've been struggling with classes having protected destructors. Sorted now though.. On Sat, 23 Mar 2013 03:02:58 -, Niall Douglas wrote: Separate C++ objects from their python wrappers. Have C++ objects held by shared_ptr. H

Re: [C++-sig] Segfaults in object deallocation

2013-03-22 Thread Alex Leach
On Wed, 20 Mar 2013 15:52:52 -, Jim Bosch wrote: http://www.boost.org/doc/libs/1_53_0/libs/python/doc/v2/faq.html#threadsupport There are other people on this list who know a lot more about this than I do, but my understanding has always been that it you use Boost.Python with threadin

Re: [C++-sig] Segfaults in object deallocation

2013-03-21 Thread Alex Leach
On Wed, 20 Mar 2013 19:28:35 -, Jeffrey Van Voorst wrote: In short, the boost smart pointers, boost spirit, etc. implementations vary depending on the compile time options. I don't know if boost.python has options. Hi again, So I've just rebuilt everything to be compatible with Pyt

Re: [C++-sig] Segfaults in object deallocation

2013-03-20 Thread Alex Leach
On Wed, 20 Mar 2013 19:28:35 -, Jeffrey Van Voorst wrote: This could be misinformation, but some of the boost libraries have compile time flags that depend on whether or not threading is enabled. As an example, I was running into issues with an invalid free() with respect to shared_

Re: [C++-sig] Segfaults in object deallocation

2013-03-20 Thread Alex Leach
On Wed, 20 Mar 2013 19:27:34 -, Jim Bosch wrote: (btw, this reply seemed to only go to me rather than the list) oh, sorry... Need to get into a habit of double-checking the reply address.. On 03/20/2013 02:16 PM, Alex Leach wrote: void PyEnv::ResetPyList(const boost::python::list

Re: [C++-sig] Segfaults in object deallocation

2013-03-20 Thread Alex Leach
On Wed, 20 Mar 2013 15:52:52 -, Jim Bosch wrote: http://www.boost.org/doc/libs/1_53_0/libs/python/doc/v2/faq.html#threadsupport Thanks for that link. I checked out the tnfox library, which the FAQ refers to as having a thread-safe implementation of invoke.hpp. tnfox, whatever it is,

Re: [C++-sig] Segfaults in object deallocation

2013-03-20 Thread Alex Leach
On Wed, 20 Mar 2013 16:53:55 -, Alex Leach wrote: I've put it in a "boost_helpers" folder in my own project, but I'd be perfectly happy if someone wanted to put it in mainline boost. I attach it here, if you're interested in having it ;) Sorry, forgot t

Re: [C++-sig] Segfaults in object deallocation

2013-03-20 Thread Alex Leach
Thanks for your replies! On Wed, 20 Mar 2013 16:34:00 -, Jim Bosch wrote: I don't think shared_ptr would help here (and you almost certainly don't want to inherit from it), though I'm curious what you're using to wrap std::list, as you clearly have methods that return std::list, and t

Re: [C++-sig] Segfaults in object deallocation

2013-03-20 Thread Alex Leach
On Wed, 20 Mar 2013 15:54:45 -, Jaedyn K. Draper wrote: Can you send the C++ code of MyObj? Kind of hard to diagnose a C++-side crash without any C++ code. Sure. Sorry, thought previous email was getting long and it might have been an obvious fix for someone... Just writing a

[C++-sig] Extracting constant pointer to char* array from list

2013-03-20 Thread Alex Leach
Hi, I was wondering the best way to solve this problem:- void WrapperClass::parse_args(boost::python::list argv) { int argc = boost::python::len(argv); const char* const* pargv = boost::python::extractconst*>(argv); /// < WrappedClass::parse_args(argc, pargv); } This doesn't wo

[C++-sig] Segfaults in object deallocation

2013-03-20 Thread Alex Leach
Dear list, I've started using Boost.Python to wrap a 3rd party C++ library, and whilst running my unit tests, the Python interpreter segfault's during garbage collection. With explicit object deletion: $ gdb -q --args python -c 'import mylib; obj = mylib.MyObj(); del(obj)' ... *** Error in