Re: [C++-sig] boost::python handles boost::shared_ptr specially...

2012-02-11 Thread Neal Becker
Jim Bosch wrote:

> On 02/06/2012 11:33 AM, Neal Becker wrote:
>> Will std::shared_ptr just work also?
> 
> Just tried the experiment, albeit with slightly old versions.
> 
> As of gcc 4.4 (with -std=gnu++0x) and Boost 1.47, it looks like
> Boost.Python doesn't even recognize std::shared_ptr as any kind of smart
> pointer, let alone an equivalent to boost::shared_ptr.
> 
> That's definitely going to need fixing in the near future.
> 
> Jim

Thanks:
https://svn.boost.org/trac/boost/ticket/6545

___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] Crash at shutdown

2012-02-11 Thread Niall Douglas
On 10 Feb 2012 at 21:23, Jim Bosch wrote:

> > when I execute Boost.Python export statement in C it adds some records in
> > Boost.Python and Python interpreter. When C is unloaded from memory somehow
> > these records are not being cleaned up. By the time we get to clean this 
> > records
> > C is already unloaded from memory and either Boost.Python or Python 
> > interpreter
> > corrupt the memory.
> 
> I'm pretty sure there's no programmatic way to remove something from the 
> registry, and to add such a feature you'd have to modify the 
> Boost.Python sources and recompile the shared library.  If you're 
> willing to do that, that might be a way out.

I was about to say the same as Jim, except to add that this is really 
another example of why BPL lacks Py_Finalize() support if I remember 
correctly. BPL can set itself up, but it's a one way action - it 
cannot unwind itself.

> If it's at all possible, I think the safest bet would be to refactor 
> things so that everything that gets exported to Python happens within a 
> separate module that would be imported by the Python scripts, so you 
> only rely on Python's own dlopen calls when it involves Boost.Python 
> wrappers.  If that's not feasible, you might try putting the wrapper 
> code in a function in a library that never gets unloaded, even if that 
> function is called by some library that may be unloaded.

The other thing to try is to force an immediate exit without 
unwinding the DLL list :) e.g. TerminateProcess(self). Obviously, do 
this after all buffers and such have been flushed, but just before 
DLL unload.

The other thing, on Windows, is to manually hack increment the DLL 
reference count to ensure the DLL never gets kicked out :) This works 
well for this type of situation. Sometimes when working with other 
people's broken libraries it's just easiest.

BTW I agree that code which cannot shut itself down cleanly is broken 
and its authors should hang their heads appropriately and treat it as 
a bug to be fixed rather than a feature to be added. That said, it 
can be hard to anticipate every possible shutdown use case. I've 
certainly been wowed by some user reports regarding my own libraries 
coming in at times.

Niall

-- 
Technology & Consulting Services - ned Productions Limited.
http://www.nedproductions.biz/. VAT reg: IE 9708311Q. Company no: 
472909.



___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] How to define a Python metaclass with Boost.Python?

2012-02-11 Thread Paul-Cristian Manta
>
>
> This is indeed a perfectly valid way to make a metaclass, and it should
> definitely work to do the same thing in C++ using the C API and/or
> Boost.Python.
>
> The trouble is using that metaclass as the type of a Boost.Python-wrapped
> C++ class...that's what I think is basically impossible.
>
> Of course, if you just want to inject some attributes into a wrapped
> class, you can do that in Boost.Python without a metaclass.  You'd write a
> function that takes a boost::python::object and adds the attributes you
> want to it.  Calling that function with a boost::python::class_ object
> would then add the attribute, just like a metaclass would.
>
>
> Jim
>
>
I don't think it's impossible to set a metaclass of another class with
Boost.Python. The trick is actually pretty similar to the one above.

>>> class Foo:
...pass
...
>>> Foo = FooMeta(Foo.__name__, Foo.__bases__, dict(Foo.__dict__))

You first define the class in Boost.Python as you normally would, then do
the equivalent of the code above. This should work, unless, of course,
there's some subtle detail I'm not aware of.
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig

Re: [C++-sig] How to define a Python metaclass with Boost.Python?

2012-02-11 Thread Jim Bosch

On 02/11/2012 04:15 PM, Paul-Cristian Manta wrote:


I don't think it's impossible to set a metaclass of another class with
Boost.Python. The trick is actually pretty similar to the one above.

 >>> class Foo:
...pass
...
 >>> Foo = FooMeta(Foo.__name__, Foo.__bases__, dict(Foo.__dict__))

You first define the class in Boost.Python as you normally would, then
do the equivalent of the code above. This should work, unless, of
course, there's some subtle detail I'm not aware of.



Ah, yes.  I see what you're talking about now.  You'll probably need to 
have FooMeta inherit from the Boost.Python metaclass and delegate to its 
__call__ to make sure the Boost.Python metaclass gets to do its magic 
too.  But I think that ought to be enough to make it work.


Good thinking - glad you didn't get discouraged by my pessimism!

Jim

___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig