[C++-sig] destructor not called
Hi,
I've got problem with embedded python. When using some classes inside embedded
python, the the number of constructor/destructor doesn't match. I don't have
code because it is a big project. But the class I have problem with looks like
that:
class SessionImpl;
class Session
{
boost::shared_ptr m_pImpl;
...
};
So as you can see when the destructor is not called appropriate times, the
shared_ptr isn't destroyed. I've tried searching but no working solution was
found.
thanks
Trigve
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] destructor not called
Trigve yahoo.com> writes: > > Hi, > I've got problem with embedded python. When using some classes inside embedded > python... Sorry, It looks like it is not python fault. Trigve ___ Cplusplus-sig mailing list [email protected] http://mail.python.org/mailman/listinfo/cplusplus-sig
[C++-sig] multithreading and interpreters
Hi, I'm working on project where we used boost.python (embedded). In general I have the "modules" where each module is something like sandbox, is isolated from others modules and run in solo thread. I want to be able to use python (and boost python functions of course) from each module thread. Something like that each thread could have own interpreter without need to take care of GIL and like. Is it possible? I know there could be some problems with GIL and so. I've found in python C API docs Py_NewInterpreter() function which could be of help (or not?). So will this configuration work? Could be there some problems with boost.python when using multiple threads? Thanks Trigve ___ Cplusplus-sig mailing list [email protected] http://mail.python.org/mailman/listinfo/cplusplus-sig
[C++-sig] division operator in 3.1
Hi, I've found bug in boost python with division operator. Division operator with custom types doesn't work with python 3.1. It is because there were some changes in this regard in python 3. I've created ticket with patch https://svn.boost.org/trac/boost/ticket/4497 . Can somebody look at it? Thanks Trigve ___ Cplusplus-sig mailing list [email protected] http://mail.python.org/mailman/listinfo/cplusplus-sig
[C++-sig] [python] base::get_override() exception set
Hi, when calling get_override() method while trying to find python overload and overload is not found exception in python is set. This is because PyObject_GetAttrString() is used for retrieving the attribute. If attribute is not found, PyObject_GetAttrString() set the exception. This is using python 3.1. I've created ticket https://svn.boost.org/trac/boost/ticket/4701 with patch. Could anyone look at this? Thanks Trigve ___ Cplusplus-sig mailing list [email protected] http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Multiple calls to bp::detail::init_module() causing conflicts?
> From: Ralf W. Grosse-Kunstleve > To: Development of Python/C++ integration > Sent: Tue, December 21, 2010 12:48:35 AM > Subject: Re: [C++-sig] Multiple calls to bp::detail::init_module() causing >conflicts? > > Hi Austin, > Just a remark: the python3 support isn't routinely exercised. > Overlooked incompatibilities are possible. > I only have time to maintain the python2 support. We need a > volunteer to port the unit tests to python3. > Ralf > I'm testing release branch against python 3 (see Trigve in http://www.boost.org/development/tests/release/developer/summary.html). Adding trunk testing against python 3 would be also welcomed. Trigve ___ Cplusplus-sig mailing list [email protected] http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] [Boost-users] boost python & context manager/with statement
> From: Dave Abrahams > To: [email protected] > Cc: [email protected] > Sent: Tuesday, February 28, 2012 10:06 PM > Subject: Re: [Boost-users] boost python & context manager/with statement > > > on Sun Feb 12 2012, Avi Bahra wrote: > >> Does boost python support context management using the with >> statement? In my case I need to manage __enter__/__exit__ on >> the c++ side. Could not find any examples for this in the >> documentation. >> >> Any help appreciated. >> >> Best regards, >> Ta, >> Avi > > There's no explicit support for it, no. > > Sorry, But I think you could implement it like this: class_(...) .def("__enter__", &somefunc) .def("__exit__", &someotherfunc) ; Trigve ___ Cplusplus-sig mailing list [email protected] http://mail.python.org/mailman/listinfo/cplusplus-sig
[C++-sig] C++ clas with (*args, **kwargs) constructor
Hi,
I'm trying to find some solution to my problem but without succes. I need to be
able to export C++ class constructor that takes arbitraty arguments (as in
python __init__(self, *args, **kwargs). Is it possible to have this kind of
constructor? I've tried something like this:
BOOST_PYTHON_MODULE(main)
{ class_>("Form") ;
}
then in main:
...
try {
object main = import("__main__"); object global(main.attr("__dict__"));
boost::python::dict local;
exec( "import main\n" "class Form1(main.Form):\n"
" def __init__(self, A, *args, **kwargs):\n"
" super().__init__(*args, **kwargs)\n\n" , global, local); // Get class
object c_form1 = local["Form1"]; // Create instance
object form1_instance = object(handle<>(PyObject_CallObject(c_form1.ptr(), make_tuple(1, 2).ptr(;
}
catch(error_already_set &)
{ PyErr_Print();
}
But it prints:
Traceback (most recent call last):
File "", line 4, in __init__
Boost.Python.ArgumentError: Python argument types in
Form.__init__(Form1, int)
did not match C++ signature:
__init__(struct _object *)
Which is logical I think because it finds only default constructor. I've tried
also raw_constructor from
http://wiki.python.org/moin/boost.python/HowTo#A.22Raw.22_constructor but
without success.
Anyone know if it is somehow possible?
Thanks
Trigve
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] C++ clas with (*args, **kwargs) constructor
> From: Trigve Siver
> To: Development of Python/C++ integration
> Cc:
> Sent: Thursday, June 21, 2012 11:31 PM
> Subject: [C++-sig] C++ clas with (*args, **kwargs) constructor
>
> ...
> then in main:
> ...
> try {
> object main = import("__main__");
> object global(main.attr("__dict__")); boost::python::dict local;
> exec( "import main\n"
> "class Form1(main.Form):\n"
> " def __init__(self, A, *args, **kwargs):\n"
> " super().__init__(*args, **kwargs)\n\n" , global, local);
> // Get class object c_form1 = local["Form1"]; // Create instance
> object form1_instance = object(handle<>(PyObject_CallObject(c_form1.ptr(), make_tuple(1, 2).ptr(;
> }
> catch(error_already_set &)
> { PyErr_Print();
> }
Bad formatting, sorry:
try {
object main = import("__main__");
object global(main.attr("__dict__"));
boost::python::dict local;
exec("import main\n"
"class Form1(main.Form):\n"
" def __init__(self, A, *args, **kwargs):\n"
" super().__init__(*args, **kwargs)\n\n"
, global, local);
// Get class
object c_form1 = local["Form1"];
// Create instance
object form1_instance = object(handle<>(PyObject_CallObject(c_form1.ptr(), make_tuple(1, 2).ptr(;
}
catch(error_already_set &)
{
PyErr_Print();
}
>...
Trigve
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] C++ clas with (*args, **kwargs) constructor
> From: Jim Bosch > To: [email protected] > Cc: > Sent: Thursday, June 21, 2012 11:57 PM > Subject: Re: [C++-sig] C++ clas with (*args, **kwargs) constructor > > On 06/21/2012 05:31 PM, Trigve Siver wrote: >> >> >> Hi, >> I'm trying to find some solution to my problem but without succes. I > need to be able to export C++ class constructor that takes arbitraty > arguments > (as in python __init__(self, *args, **kwargs). Is it possible to have this > kind > of constructor? I've tried something like this: >> > > I believe this is not possible in Boost.Python. The closest approximations I > know of are: > > - Use a static method or free function instead of a constructor for this mode > of > construction in Python. You can wrap a non-constructor with *args, **kwds > using > boost::python::raw_function. > > - Inherit from the wrapped class at the Python layer; the derived class could > then have a constructor with *args, **kwds. > Thanks for reply :) Hmm I was trying with python::raw_function, but without success also. Ok I'm gonna try a bit more with raw_constructor once more. Thanks > > Jim Trigve ___ Cplusplus-sig mailing list [email protected] http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] C++ clas with (*args, **kwargs) constructor
> From: Holger Brandsmeier
> To: Trigve Siver ; Development of Python/C++ integration
>
> Cc:
> Sent: Thursday, June 21, 2012 11:58 PM
> Subject: Re: [C++-sig] C++ clas with (*args, **kwargs) constructor
>
>T rigve,
>
> 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. Try to
> get this working and tell us if this is how you want it to work, I
> have a feeling that you already might not like having to manually
> convert the PyObject* to the proper types. However, you can not avoid
> it, you can not expect boost::python to automatically call a
> constructor taking a single `int` if all that you export is a
> constructor taking one `PyObject`, you will have to do the proper
> conversions on the C++ side.
>
> Second if you want to work with many objects of type PyObject* or even
> `kwargs`, then
> http://wiki.python.org/moin/boost.python/HowTo#A.22Raw.22_constructor
> is one option. I didn't really do this myself, but what is your problem
> there?
Thanks for reply :)
Ok it looks like it is working now :) When I used raw_constructor I have set
min arguments to 2, like this:
...
boost::shared_ptr create(tuple, dict)
{
return boost::shared_ptr(new Form());
}
class_>("Form", no_init)
.def("__init__", raw_constructor(&create, 2))
...
But when *args or **kwargs was empty (or both of them), it was spoiling
errors. So I set min arguments to 0 (removed the parameter respectively). Hope
I'm doing it right way.
> ...
>
> -Holger
>
Thanks
Trigve
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] C++ clas with (*args, **kwargs) constructor
> From: Jim Bosch > To: [email protected] > Cc: > Sent: Friday, June 22, 2012 12:28 AM > Subject: Re: [C++-sig] C++ clas with (*args, **kwargs) constructor > > On 06/21/2012 06:07 PM, Trigve Siver wrote: >>> From: Jim Bosch >>> To: [email protected] >>> Cc: >>> Sent: Thursday, June 21, 2012 11:57 PM >>> Subject: Re: [C++-sig] C++ clas with (*args, **kwargs) constructor >>> >>> On 06/21/2012 05:31 PM, Trigve Siver wrote: >>>> >>>> >>>> Hi, >>>> I'm trying to find some solution to my problem but without > succes. I >>> need to be able to export C++ class constructor that takes arbitraty > arguments >>> (as in python __init__(self, *args, **kwargs). Is it possible to have > this kind >>> of constructor? I've tried something like this: >>>> >>> >>> I believe this is not possible in Boost.Python. The closest > approximations I >>> know of are: >>> >>> - Use a static method or free function instead of a constructor for > this mode of >>> construction in Python. You can wrap a non-constructor with *args, > **kwds using >>> boost::python::raw_function. >>> >>> - Inherit from the wrapped class at the Python layer; the derived class > could >>> then have a constructor with *args, **kwds. >>> >> >> Thanks for reply :) Hmm I was trying with python::raw_function, but without > success also. Ok I'm gonna try a bit more with raw_constructor once more. >> > > Heh, I didn't even know about raw_constructor, because it isn't in the > reference docs for some reason. If it exists, then your problem very > likely is solvable and my response was totally bogus. This raw_constructor isn't integrated in boost:python. It is from http://wiki.python.org/moin/boost.python/HowTo#A.22Raw.22_constructor as mentioned in previous mail. Maybe there is a little chance to make patch and add it to boost::python? :) > Glad I didn't discourage you. :) > > Jim Trigve ___ Cplusplus-sig mailing list [email protected] http://mail.python.org/mailman/listinfo/cplusplus-sig
[C++-sig] Member function of other class
Hi,
I'm curios, why this piece of code does compile?
struct BaseClass
{ void func() {}
}; struct Wrap
{ void func() {}
}; BOOST_PYTHON_MODULE(main)
{ class_("Base", no_init) .def("func", &Wrap::func) ;
}
I'm asking because a want to do something like this and want to know if it is
UB or not:
struct BaseClass
{ void func() {}
}; struct Wrap
{ static void func(BaseClass &Instance) { Instance.func(); }
}; BOOST_PYTHON_MODULE(main)
{ class_("Base", init<>()) .def("func", &Wrap::func) ;
}
then in python:
import main main.Base().func()
Thank you
Trigve
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Member function of other class
Code formatting went wrong
> ...
> struct BaseClass
> { void func() {}
> }; struct Wrap
> { void func() {}
> }; BOOST_PYTHON_MODULE(main)
> { class_("Base", no_init)
> .def("func", &Wrap::func) ;
> }
struct BaseClass
{
void func() {}
};
struct Wrap
{
void func() {}
};
BOOST_PYTHON_MODULE(main)
{
class_("Base", no_init)
.def("func", &Wrap::func) ;
}
> ...
> struct BaseClass
> { void func() {}
> }; struct Wrap
> { static void func(BaseClass &Instance) { Instance.func(); }
> }; BOOST_PYTHON_MODULE(main)
> { class_("Base", init<>())
> .def("func", &Wrap::func) ;
> }
struct BaseClass
{
void func() {}
};
struct Wrap
{
static void func(BaseClass &Instance)
{
Instance.func();
}
};
BOOST_PYTHON_MODULE(main)
{
class_("Base", init<>())
.def("func", &Wrap::func) ;
}
> ..
> import main main.Base().func()
>
import main
main.Base().func()
Trigve
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] issues with loading the boost_python dll on different computers
> From: Ronny Herzog > To: [email protected] > Cc: > Sent: Thursday, August 23, 2012 4:53 PM > Subject: [C++-sig] issues with loading the boost_python dll on different > computers > > Dear all, > > I installed and used boost (1.50.0) to build a python extension on my Windows > 7 > / 32 Bit. Everything worked fine. > > Now I tried the extension module on other Computers with Windows 7 and > Windows > XP and the same Python version and it gave me an error concerning the DLL: > > ** ImportError : DLL load failed: This application has failed to start > because the application configuration is incorrect. Reinstalling the > application may fix this problem. ** > > Would anyone have a hint on were this problem could come from. I am totally > clueless. Hi, two possible reason from top of my mind: * Is it possible that you are using debug version of your extension? * If you are using VS, have you installed VC redist of *your's VS version* on target PC? Also try depends.exe to find if you aren't missing any dependencies. > Thanks a lot, > Ronny Trigve ___ Cplusplus-sig mailing list [email protected] http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Returning values to Python in C++ reference arguments
- Original Message - > From: Jason Addison > To: [email protected] > Cc: > Sent: Saturday, May 23, 2015 6:05 PM > Subject: [C++-sig] Returning values to Python in C++ reference arguments > > How can results be returned in function arguments? > I don't think that you can return arguments by reference/pointers in python. You could theoretically pass a mutable sequence (list) and push the objects there. But the common approach is to return tuple. ___ Cplusplus-sig mailing list [email protected] https://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] C++ copy construction and Python object copies
> From: Stefan Seefeld > To: [email protected] > Cc: > Sent: Saturday, May 30, 2015 12:57 AM > Subject: Re: [C++-sig] C++ copy construction and Python object copies > > On 29/05/15 06:48 PM, Alex Mohr wrote: >> On 5/29/2015 7:28 AM, Stefan Seefeld wrote: >>> Python's copy module allows for objects to be copied. The protocol > for >>> this will look up special method __copy__. It seems to me that this >>> would trivially work for C++ objects providing a copy-constructor. >>> However, the copy-constructor isn't automatically bound to > __copy__. >>> While I can certainly add that in user-code, I wonder why this > isn't >>> done by Boost.Python itself. >>> Does anyone know the reasons for this ? Would it seem useful to add > that >>> feature ? >> >> The __copy__ method's intended semantics are to produce a > "shallow" >> copy while the __deepcopy__ method is meant to produce a "deep" > copy. >> Given a C++ class with a copy ctor, it's hard to know which is more >> appropriate. For instance, copying a shared_ptr is like a >> "shallow" copy but copying a vector> > is like a deep >> copy. On the other hand copying a vector> is > more like >> a shallow copy. >> >> I wouldn't mind an opt-in convenience utility that adds a __copy__ or >> __deepcopy__ method, but given the semantic subtlety, I think trying >> to do it automatically is dicey. > > That's a fair point. > I agree with Alex Mohr. Adding some mechanism of implementing the copy using copy constructor would be welcome. But doing it automatically wouldn't be ok. I think that explicit is better than implicit. Trigve ___ Cplusplus-sig mailing list [email protected] https://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Boost.Python C++ object reference in Python: unexpected behaviour.
> From: Christoff Kok >To: [email protected] >Sent: Tuesday, June 2, 2015 7:34 AM >Subject: Re: [C++-sig] Boost.Python C++ object reference in Python: >unexpected behaviour. > > > >Hi, > > >This looks like a bug in Boost.Python to me. > > >Could anyone confirm this? I provided a minimal, full working example. > > >I would like to make sure it is a bug before reporting it as one. > > >Christoff > What about making the Factory and Manufacturer class as noncopyable (and also exporting them to python as noncopyable)? Has something changed? Trigve ___ Cplusplus-sig mailing list [email protected] https://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Boost.Python docs update
> > From: Francesco Biscani >To: Development of Python/C++ integration >Sent: Thursday, August 6, 2015 4:00 PM >Subject: Re: [C++-sig] Boost.Python docs update > > > >Kudos and thanks a lot, that looks great! (and it must have taken a lot of >effort...) > > >Cheers, > > > Francesco. > > > > > >On 5 August 2015 at 14:23, Stefan Seefeld wrote: > >Hi all, >> >>I have updated the Boost.Python documentation. >> >>The new docs are available at http://boostorg.github.io/python. >>(For any issues you notice please submit a bug report at >>https://github.com/boostorg/python/issues. >> >>Thanks, >>Stefan >> Kudos to you from me, too ;) ___ Cplusplus-sig mailing list [email protected] https://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Returning C++ buffer to Python 2.7
> > From: Tony Cappellini >To: [email protected] >Sent: Thursday, October 15, 2015 10:27 PM >Subject: [C++-sig] Returning C++ buffer to Python 2.7 > > > > > >I've allocated memory in C++ and need to expose a function to Python >so that Python can read this memory as a sequence. > > > >I've found this example > > >http://pastebin.com/YGi61R4H > > > >from this URL >http://stackoverflow.com/questions/16232520/how-to-expose-raw-byte-buffers-with-boostpython > > > >which **looks** like it will do what I need, from the description of the code >and the request from the original author. > > >However, it looks incomplete to me. There is no code which defines, or >explains what >handle<> is/does, in this line of code > See http://www.boost.org/doc/libs/1_55_0/libs/python/doc/tutorial/doc/html/python/object.html#python.creating_python_objectfor explanation of handle<> ___ Cplusplus-sig mailing list [email protected] https://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] pybind11 -- alternative to Boost.Python
> > From: Wenzel Jakob >To: [email protected] >Sent: Sunday, October 18, 2015 2:56 PM >Subject: [C++-sig] pybind11 -- alternative to Boost.Python > > > >Hello all, > > >after being a long-time Boost.Python user, I’ve been working on an alternative >that makes more effective use of recent C++11-capable compilers. The overall >syntax and ideology are very similar to Boost.Python, but the implementation >only requires a few header files with a a vastly smaller amount of code thanks >to C++11 lambda functions, tuples and variadic templates. There is also >dedicated support for Python’s buffer protocol and NumPy arrays, which is >useful for scientific computing applications. > > >So far it’s only used by a few projects, but I think it could be useful to >this audience. > > >Code: https://github.com/wjakob/pybind11 >Documentation: http://pybind11.readthedocs.org/en/latest/ It looks good. Have you tried contacting the actual boost.python mantainer and maybe propose merge with the boost.python or make a boost.python3 from it? It would be shame not incorporate the useful stuff in boost.python. > >Best, >Wenzel >___ >Cplusplus-sig mailing list >[email protected] >https://mail.python.org/mailman/listinfo/cplusplus-sig > > -- Trigve ___ Cplusplus-sig mailing list [email protected] https://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] Problem with and fix for automatic pointer registration in Boost.Python 1.60
> > From: Stefan Seefeld >To: [email protected] >Sent: Sunday, March 6, 2016 7:03 PM >Subject: Re: [C++-sig] Problem with and fix for automatic pointer registration >in Boost.Python 1.60 > > >On 04.03.2016 13:45, Greg Falcon via Cplusplus-sig wrote: >> Boost.Python 1.60 has a bug, introducing an incompatibility from 1.59, >> and first noted on this mailing list on January 11. What has changed >> is that a class declaration of the form >> >> class_>("Foo"); >> >> will no longer automatically register a converter for the shared_ptr >> wrapper. >> >> This is not an intentional change, but a bug exposed by a change to >> Boost.MPL. The template metaprogramming in class_metadata.hpp makes >> assumptions about the types used in Boost.MPL that are no longer true. >> >> I have posted a fix to this issue >> at https://github.com/boostorg/python/pull/59/files, which at least >> solves the problem for us. This patch, when applied against 1.60, >> fixes pointer registration. It can also be applied to 1.59 without issue. >> >> If someone on this list could take a look at this change, I'd >> appreciate it. Let me know if you have any questions. > >I have merged the PR, and will try to get it into master for the 1.61 >release. Sorry this took so long. >Stefan > Shouldn't there be a note (+ a patch) in a release document (1.60), also? Because this bug looks like showstopper to me. Thanks -- Trigve ___ Cplusplus-sig mailing list [email protected] https://mail.python.org/mailman/listinfo/cplusplus-sig
[C++-sig] Re: Retiring the Python/C++-sig mailing list
Hello,just the last good bye to everyone ;) -- Trigve On Monday, June 2, 2025 at 07:19:35 PM GMT+2, Jim Bosch via Cplusplus-sig wrote: On Wed, May 28, 2025 at 9:23 AM Stefan Seefeld wrote: I agree, but leave it to the list maintainer(s) to take any final decision. I'll answer questions here should any be raised. Thanks for the input, Stefan (and for your many contributions over the years). I actually am the maintainer, so absent any other feedback on this, I've asked for the list to be retired. Jim ___ Cplusplus-sig mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/cplusplus-sig.python.org Member address: [email protected] ___ Cplusplus-sig mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/cplusplus-sig.python.org Member address: [email protected]
