From garyo at genarts.com Fri Jan 10 14:16:16 2014 From: garyo at genarts.com (Gary Oberbrunner) Date: Fri, 10 Jan 2014 08:16:16 -0500 (EST) Subject: [C++-sig] How to handle argument error exceptions in boost.python? In-Reply-To: <1623265129.4204769.1389359712843.JavaMail.root@genarts.com> Message-ID: <1279986594.4204774.1389359776309.JavaMail.root@genarts.com> [I posted this on StackOverflow yesterday, but got nothing. Hoping you will have some insight!] I'm writing a C++ python extension. I have a boost::python extension function static void EXTrender_effect(EffectGlobals_t *effect_handle, std::string preset, bp::object dest, int xdim, int ydim) { ... } that I export as usual in my boost.python extension: def("render_effect", EXTrender_effect); When I call that from python(2.7), I get a C++ exception boost::python::error_already_set. Tracing that down in Visual Studio, I can see it's coming from a boost::python::objects::function::argument_error. So OK, I have an argument error; I'm probably calling it with the wrong args. What I'd like to do is print or throw something sensible in my python extension when this happens, so users of my extension will see the nice message that I know is lurking in PyErr_Fetch. (I can see the message getting built in the boost.python argument_error code.) But I can't catch that error_already_set; boost.python does that internally around the funcall. And I can't check for python errors in my extension code, since my function never gets called (the argument error is detected by boost.python). What ends up happening is it just silently fails. What can I hook up so I (or my users) can see the argument error messages? And ideally convert those into python exceptions? This is all Win7, Python2.7. -- . . . . . . . . . . . . . . . . . . . . . . Gary Oberbrunner garyo at genarts.com VP Engineering Tel: 617-492-2888 GenArts, Inc. www.genarts.com From legordian at gmx.net Fri Jan 10 14:45:05 2014 From: legordian at gmx.net (Charly Bicker) Date: Fri, 10 Jan 2014 14:45:05 +0100 (CET) Subject: [C++-sig] How to handle argument error exceptions in boost.python? Message-ID: An HTML attachment was scrubbed... URL: From karl.bicker at gordiano.net Fri Jan 10 14:36:48 2014 From: karl.bicker at gordiano.net (Karl Bicker) Date: Fri, 10 Jan 2014 14:36:48 +0100 (CET) Subject: [C++-sig] How to handle argument error exceptions in boost.python? In-Reply-To: <1279986594.4204774.1389359776309.JavaMail.root@genarts.com> References: <1279986594.4204774.1389359776309.JavaMail.root@genarts.com> Message-ID: <992310155.9582115.1389361008183.JavaMail.zimbra@gordiano.net> Dear Gary, I am not sure if this is what you want, but what about writing a wrapper function around EXTrender_effect which takes boost::python::objects and then use boost::python::extract to check if you can convert the objects you got to what they should be (cf. https://wiki.python.org/moin/boost.python/extract)? Does this help? Regards, Charly ----- Original Message ----- From: "Gary Oberbrunner" To: "Development of Python/C++ integration" Sent: Friday, January 10, 2014 2:16:16 PM Subject: [C++-sig] How to handle argument error exceptions in boost.python? [I posted this on StackOverflow yesterday, but got nothing. Hoping you will have some insight!] I'm writing a C++ python extension. I have a boost::python extension function static void EXTrender_effect(EffectGlobals_t *effect_handle, std::string preset, bp::object dest, int xdim, int ydim) { ... } that I export as usual in my boost.python extension: def("render_effect", EXTrender_effect); When I call that from python(2.7), I get a C++ exception boost::python::error_already_set. Tracing that down in Visual Studio, I can see it's coming from a boost::python::objects::function::argument_error. So OK, I have an argument error; I'm probably calling it with the wrong args. What I'd like to do is print or throw something sensible in my python extension when this happens, so users of my extension will see the nice message that I know is lurking in PyErr_Fetch. (I can see the message getting built in the boost.python argument_error code.) But I can't catch that error_already_set; boost.python does that internally around the funcall. And I can't check for python errors in my extension code, since my function never gets called (the argument error is detected by boost.python). What ends up happening is it just silently fails. What can I hook up so I (or my users) can see the argument error messages? And ideally convert those into python exceptions? This is all Win7, Python2.7. -- . . . . . . . . . . . . . . . . . . . . . . Gary Oberbrunner garyo at genarts.com VP Engineering Tel: 617-492-2888 GenArts, Inc. www.genarts.com _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org https://mail.python.org/mailman/listinfo/cplusplus-sig From garyo at genarts.com Sat Jan 11 15:52:42 2014 From: garyo at genarts.com (Gary Oberbrunner) Date: Sat, 11 Jan 2014 09:52:42 -0500 (EST) Subject: [C++-sig] How to handle argument error exceptions in boost.python? In-Reply-To: <992310155.9582115.1389361008183.JavaMail.zimbra@gordiano.net> Message-ID: <2032874050.4226045.1389451962920.JavaMail.root@genarts.com> ----- Original Message ----- > From: "Karl Bicker" > To: "Development of Python/C++ integration" > Sent: Friday, January 10, 2014 8:36:48 AM > Subject: Re: [C++-sig] How to handle argument error exceptions in boost.python? > > Dear Gary, > > I am not sure if this is what you want, but what about writing a > wrapper function around EXTrender_effect which takes > boost::python::objects and then use boost::python::extract to check > if you can convert the objects you got to what they should be (cf. > https://wiki.python.org/moin/boost.python/extract)? Does this help? I suppose it might -- essentially what you're talking about is avoiding boost::python's overloading logic and putting in my own. Then I could handle arg errors any way I want, because my function would be guaranteed to be called no matter what. Right? It seems like a bad solution overall though, because it means most of the coolness of boost::python is gone. All my functions would just have to take a list of kw args and parse them out themselves, rather than boost::python doing that. Seems like there must be a better way! I mean, there is all this logic in the boost::python call framework to build nice error messages about which overloads were tried, but that message never comes out anywhere. -- Gary Oberbrunner From giuseppe.corbelli at copanitalia.com Tue Jan 14 09:04:14 2014 From: giuseppe.corbelli at copanitalia.com (Giuseppe Corbelli) Date: Tue, 14 Jan 2014 09:04:14 +0100 Subject: [C++-sig] How to handle argument error exceptions in boost.python? In-Reply-To: <1279986594.4204774.1389359776309.JavaMail.root@genarts.com> References: <1279986594.4204774.1389359776309.JavaMail.root@genarts.com> Message-ID: <52D4EF7E.6030604@copanitalia.com> On 10/01/2014 14:16, Gary Oberbrunner wrote: > [I posted this on StackOverflow yesterday, but got nothing. Hoping you will have some insight!] > > > I'm writing a C++ python extension. I have a boost::python extension function > > static void EXTrender_effect(EffectGlobals_t *effect_handle, > std::string preset, > bp::object dest, int xdim, int ydim) > { ... } > that I export as usual in my boost.python extension: > > def("render_effect", EXTrender_effect); > > When I call that from python(2.7), I get a C++ exception > boost::python::error_already_set. Tracing that down in Visual Studio, I can > see it's coming from a boost::python::objects::function::argument_error. So > OK, I have an argument error; I'm probably calling it with the wrong args. > What I'd like to do is print or throw something sensible in my python > extension when this happens, so users of my extension will see the nice > message that I know is lurking in PyErr_Fetch. (I can see the message getting > built in the boost.python argument_error code.) What is the exception you see from the python side? something like: ArgumentError: Python argument types in function_name(function_args) did not match C++ signature: cpp_function_name(cpp_args) -- Giuseppe Corbelli WASP Software Engineer, Copan Italia S.p.A Phone: +390303666318 Fax: +390302659932 E-mail: giuseppe.corbelli at copanitalia.com From garyo at genarts.com Tue Jan 14 12:45:07 2014 From: garyo at genarts.com (Gary Oberbrunner) Date: Tue, 14 Jan 2014 06:45:07 -0500 (EST) Subject: [C++-sig] How to handle argument error exceptions in boost.python? In-Reply-To: <52D4EF7E.6030604@copanitalia.com> Message-ID: <1031519715.4270700.1389699907378.JavaMail.root@genarts.com> ----- Original Message ----- > From: "Giuseppe Corbelli" ... > What is the exception you see from the python side? something like: > > ArgumentError: Python argument types in > function_name(function_args) > did not match C++ signature: > cpp_function_name(cpp_args) That's exactly what I'm trying to figure out! The c++ exception gets handled in handle_exception and it never gets turned into a python exception as far as I can tell. -- Gary Oberbrunner From herron at ELLINGTON.com Tue Jan 14 00:01:35 2014 From: herron at ELLINGTON.com (Liam Herron) Date: Mon, 13 Jan 2014 23:01:35 +0000 Subject: [C++-sig] BoostPython: C++ function with "non-const double reference" argument issue. Python looks for float causing argument mismatch. Message-ID: <96426055F003C542B3FB8A0928736DF90EEC37@ex0.ELLINGTON.com> Here is my example: ------------------------------------------------------------------------------------------- CPP Code: ------------------------------------------------------------------------------------------- #include using namespace boost::python; void updateDoubleReference(double& x) { x = x + 5.4321; } BOOST_PYTHON_MODULE(_testDR) { // Add regular functions to the module. def("updateDoubleReference", &updateDoubleReference ); } ------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------- PY Code: ------------------------------------------------------------------------------------------- #!/usr/bin/python # # from _testDR import * x = 3.0 updateDoubleReference(x) -------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------- ERROR OUTPUT ------------------------------------------------------------------------------------------- python2.5 testDR.py Traceback (most recent call last): File "testDR.py", line 8, in updateDoubleReference(x) Boost.Python.ArgumentError: Python argument types in _testDR.updateDoubleReference(float) did not match C++ signature: updateDoubleReference(double {lvalue}) ------------------------------------------------------------------------------------------- How do people typically handle this issue? Wrap the function with 'float' versions of the arguments? I tried to create a 'NativeDouble' struct that had a double member attribute but when exposed to python, it simply interprets this as a float and it still has a mismatch. Any help would be greatly appreciated. Thanks, Liam ============================================================================================= Email transmissions can not be guaranteed to be secure or error-free, as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of email transmission. In addition, the information contained in this email message is intended only for use of the individual or entity named above. If the reader of this message is not the intended recipient, or the employee or agent responsible to deliver it to the intended recipient, you are hereby notified that any dissemination, distribution,or copying of this communication, disclosure of the parties to it, or any action taken or omitted to be taken in reliance on it, is strictly prohibited, and may be unlawful. If you are not the intended recipient please delete this email message. ============================================================================================== -------------- next part -------------- An HTML attachment was scrubbed... URL: From talljimbo at gmail.com Tue Jan 14 15:08:21 2014 From: talljimbo at gmail.com (Jim Bosch) Date: Tue, 14 Jan 2014 09:08:21 -0500 Subject: [C++-sig] How to handle argument error exceptions in boost.python? In-Reply-To: <1031519715.4270700.1389699907378.JavaMail.root@genarts.com> References: <52D4EF7E.6030604@copanitalia.com> <1031519715.4270700.1389699907378.JavaMail.root@genarts.com> Message-ID: On Tue, Jan 14, 2014 at 6:45 AM, Gary Oberbrunner wrote: > > > ----- Original Message ----- >> From: "Giuseppe Corbelli" > ... >> What is the exception you see from the python side? something like: >> >> ArgumentError: Python argument types in >> function_name(function_args) >> did not match C++ signature: >> cpp_function_name(cpp_args) > > That's exactly what I'm trying to figure out! The c++ exception gets handled in handle_exception and it never gets turned into a python exception as far as I can tell. > My memory on this is a bit fuzzy, but I think it does get translated to a custom Boost.Python exception (it's either that or a built-in Python exception, which would make your task much more difficult, if not impossible). Unfortunately there's no clear-cut way to import that exception. You could try intentionally raising one in a Python try/except block when your module is imported, though, so you could store the exception type and reuse it later in subsequent try/except blocks. Jim From talljimbo at gmail.com Tue Jan 14 15:13:34 2014 From: talljimbo at gmail.com (Jim Bosch) Date: Tue, 14 Jan 2014 09:13:34 -0500 Subject: [C++-sig] BoostPython: C++ function with "non-const double reference" argument issue. Python looks for float causing argument mismatch. In-Reply-To: <96426055F003C542B3FB8A0928736DF90EEC37@ex0.ELLINGTON.com> References: <96426055F003C542B3FB8A0928736DF90EEC37@ex0.ELLINGTON.com> Message-ID: The problem here isn't a mismatch between double and float, it's that Python's float object is immutable, and hence there's no way to translate it into a C++ lvalue. You simply can't wrap a C++ function with a "double &" (or "int &" or "string &") argument to Python with the same signature, regardless of whether you're using Boost.Python or something else, because Python won't allow the argument you pass to be changed. You have two options: - Add an extra struct (similar to your NativeDouble idea) that is a wrapped class that only contains a double. But you'll need explicit get/set methods, not just a public data member, though you can add a Python property to make the get/set look like a data member. - Transform the function signature, by wrapping a new function that takes a non-reference double and returns the new one, delegating it's work to the original function. Jim From garyo at genarts.com Tue Jan 14 15:24:44 2014 From: garyo at genarts.com (Gary Oberbrunner) Date: Tue, 14 Jan 2014 09:24:44 -0500 (EST) Subject: [C++-sig] How to handle argument error exceptions in boost.python? In-Reply-To: Message-ID: <1062900681.4273373.1389709483992.JavaMail.root@genarts.com> ----- Original Message ----- > From: "Jim Bosch" ... > My memory on this is a bit fuzzy, but I think it does get translated > to a custom Boost.Python exception (it's either that or a built-in > Python exception, which would make your task much more difficult, if > not impossible). Unfortunately there's no clear-cut way to import > that exception. You could try intentionally raising one in a Python > try/except block when your module is imported, though, so you could > store the exception type and reuse it later in subsequent try/except > blocks. Thanks Jim; if that's happening, something on the python side must be eating that exception, because I don't see it there. Still, this is a complex piece of code so it's entirely possible it is being swallowed on the python side. I'll continue to track it down based on that theory. -- Gary Oberbrunner From giuseppe.corbelli at copanitalia.com Tue Jan 14 16:42:39 2014 From: giuseppe.corbelli at copanitalia.com (Giuseppe Corbelli) Date: Tue, 14 Jan 2014 16:42:39 +0100 Subject: [C++-sig] How to handle argument error exceptions in boost.python? In-Reply-To: <1031519715.4270700.1389699907378.JavaMail.root@genarts.com> References: <1031519715.4270700.1389699907378.JavaMail.root@genarts.com> Message-ID: <52D55AEF.404@copanitalia.com> On 14/01/2014 12:45, Gary Oberbrunner wrote: > ... >> What is the exception you see from the python side? something like: >> >> ArgumentError: Python argument types in >> function_name(function_args) >> did not match C++ signature: >> cpp_function_name(cpp_args) > > That's exactly what I'm trying to figure out! The c++ exception gets > handled in handle_exception and it never gets turned into a python exception as far as > I can tell. So, what you see in the python side? And what boost version? I've always seen an ArgumentError being raised when passing wrong argument types to the C++ code object and ValueError (I think) when the C++ code object raises an exception without a specific C++ to python exception translator installed. -- Giuseppe Corbelli WASP Software Engineer, Copan Italia S.p.A Phone: +390303666318 Fax: +390302659932 E-mail: giuseppe.corbelli at copanitalia.com From petr_aleksandrov at mail.ru Thu Jan 16 14:36:27 2014 From: petr_aleksandrov at mail.ru (=?UTF-8?B?0JDQu9C10LrRgdCw0L3QtNGA0L7QsiDQn9C10YLRgA==?=) Date: Thu, 16 Jan 2014 17:36:27 +0400 Subject: [C++-sig] Using Numpy C API with boost python numeric Message-ID: <52D7E05B.5060608@mail.ru> Is it safe to use direct Numpy C API in Boost Python module together with Boost Python numeric::array (also using numpy)? The function "import_array" must be called before using PyArray_SimpeNew. Will it cause problems if the function "import_array" will be called twice in one module? From talljimbo at gmail.com Fri Jan 17 14:49:34 2014 From: talljimbo at gmail.com (Jim Bosch) Date: Fri, 17 Jan 2014 08:49:34 -0500 Subject: [C++-sig] Using Numpy C API with boost python numeric In-Reply-To: <52D7E05B.5060608@mail.ru> References: <52D7E05B.5060608@mail.ru> Message-ID: I'm pretty sure the numeric::array stuff doesn't actually use the NumPy C API, and hence it doesn't call import_array. It just relies on the Python interface to NumPy objects, which is why it doesn't support things like accessing the raw data pointers. So there shouldn't be any problem with using the NumPy C API with it. That said, I think it's always good practice to follow the NumPy C API docs for multiple source files and define a unique preprocessor symbol to import the NumPy API with, i.e.: http://docs.scipy.org/doc/numpy/reference/c-api.array.html#miscellaneous You may also be interested in this project: https://github.com/ndarray/Boost.NumPy Jim From garyo at genarts.com Tue Jan 21 00:14:46 2014 From: garyo at genarts.com (Gary Oberbrunner) Date: Mon, 20 Jan 2014 18:14:46 -0500 (EST) Subject: [C++-sig] create a python object from scratch in boost.python? In-Reply-To: <367439895.4443291.1390259684599.JavaMail.root@genarts.com> Message-ID: <903128184.4443292.1390259686007.JavaMail.root@genarts.com> I'd like to create a python object with some attributes in C++, and return it to python. Something like this: Plugin_Info *pinfo = get_plugin_info_i(i); bp::object plugin; // this creates None; how can I make an empty class? plugin.attr("name") = std::string(pinfo->plugin_name); plugin.attr("category") = std::string(pinfo->category); plugin.attr("n_effects") = (int)pinfo->n_effects; plugin.attr("n_inputs") = (int)pinfo->n_inputs; plugin.attr("custom_p") = (int)pinfo->custom_p; effect_list.append(plugin); But this fails on the third line, because the "plugin" object is None, and None has no attributes. Instead of None, I'd like to create a simple empty python class I can add attributes to. How can I do that? (Yes, I could use a dict instead but the python side would like to see attributes with values rather than a dict.) -- . . . . . . . . . . . . . . . . . . . . . . Gary Oberbrunner garyo at genarts.com VP Engineering Tel: 617-492-2888 GenArts, Inc. www.genarts.com From ndbecker2 at gmail.com Tue Jan 21 02:39:55 2014 From: ndbecker2 at gmail.com (Neal Becker) Date: Mon, 20 Jan 2014 20:39:55 -0500 Subject: [C++-sig] create a python object from scratch in boost.python? References: <367439895.4443291.1390259684599.JavaMail.root@genarts.com> <903128184.4443292.1390259686007.JavaMail.root@genarts.com> Message-ID: Gary Oberbrunner wrote: > I'd like to create a python object with some attributes in C++, and return it > to python. Something like this: > > Plugin_Info *pinfo = get_plugin_info_i(i); > bp::object plugin; // this creates None; how can I make an empty class? > plugin.attr("name") = std::string(pinfo->plugin_name); > plugin.attr("category") = std::string(pinfo->category); > plugin.attr("n_effects") = (int)pinfo->n_effects; > plugin.attr("n_inputs") = (int)pinfo->n_inputs; > plugin.attr("custom_p") = (int)pinfo->custom_p; > effect_list.append(plugin); > > But this fails on the third line, because the "plugin" object is None, and > None has no attributes. Instead of None, I'd like to create a simple empty > python class I can add attributes to. How can I do that? (Yes, I could use a > dict instead but the python side would like to see attributes with values > rather than a dict.) > I think if you've exposed your c++ class, then there is a conversion from c++ object to python object. So bp::object plugin (Plugin_Info()); I believe would work. From garyo at genarts.com Tue Jan 21 14:29:48 2014 From: garyo at genarts.com (Gary Oberbrunner) Date: Tue, 21 Jan 2014 08:29:48 -0500 (EST) Subject: [C++-sig] create a python object from scratch in boost.python? In-Reply-To: Message-ID: <2086157964.4451583.1390310988666.JavaMail.root@genarts.com> ----- Original Message ----- > From: "Neal Becker" > To: cplusplus-sig at python.org > Sent: Monday, January 20, 2014 8:39:55 PM > Subject: Re: [C++-sig] create a python object from scratch in boost.python? > > Gary Oberbrunner wrote: > > > I'd like to create a python object with some attributes in C++, and > > return it > > to python. ... Instead of None, I'd like to create a > > simple empty > > python class I can add attributes to.... > > I think if you've exposed your c++ class, then there is a conversion > from c++ object to python object. So > > bp::object plugin (Plugin_Info()); Thanks -- I can indeed do that (or a proxy C++ class in any case). I was wondering though if it's possible to create an anonymous python class in BP, without a "starter" C++ class as it were. But I suppose that's mostly an academic question right now. -- Gary Oberbrunner From nikolay.mladenov at gmail.com Tue Jan 21 14:55:16 2014 From: nikolay.mladenov at gmail.com (Nikolay Mladenov) Date: Tue, 21 Jan 2014 08:55:16 -0500 Subject: [C++-sig] create a python object from scratch in boost.python? In-Reply-To: <2086157964.4451583.1390310988666.JavaMail.root@genarts.com> References: <2086157964.4451583.1390310988666.JavaMail.root@genarts.com> Message-ID: My be construct bp::object from the result of _PyObject_New? On Tue, Jan 21, 2014 at 8:29 AM, Gary Oberbrunner wrote: > > > ----- Original Message ----- > > From: "Neal Becker" > > To: cplusplus-sig at python.org > > Sent: Monday, January 20, 2014 8:39:55 PM > > Subject: Re: [C++-sig] create a python object from scratch in > boost.python? > > > > Gary Oberbrunner wrote: > > > > > I'd like to create a python object with some attributes in C++, and > > > return it > > > to python. ... Instead of None, I'd like to create a > > > simple empty > > > python class I can add attributes to.... > > > > I think if you've exposed your c++ class, then there is a conversion > > from c++ object to python object. So > > > > bp::object plugin (Plugin_Info()); > > Thanks -- I can indeed do that (or a proxy C++ class in any case). I was > wondering though if it's possible to create an anonymous python class in > BP, without a "starter" C++ class as it were. But I suppose that's mostly > an academic question right now. > > -- > Gary Oberbrunner > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > https://mail.python.org/mailman/listinfo/cplusplus-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From garyo at genarts.com Tue Jan 21 16:37:01 2014 From: garyo at genarts.com (Gary Oberbrunner) Date: Tue, 21 Jan 2014 10:37:01 -0500 (EST) Subject: [C++-sig] create a python object from scratch in boost.python? In-Reply-To: Message-ID: <2079615492.4456011.1390318621152.JavaMail.root@genarts.com> ... > > > > I think if you've exposed your c++ class, then there is a conversion > > > from c++ object to python object. So > > > bp::object plugin (Plugin_Info()); > > > Thanks -- I can indeed do that (or a proxy C++ class in any case). > > I > > was wondering though if it's possible to create an anonymous python > > class in BP, without a "starter" C++ class as it were. But I > > suppose that's mostly an academic question right now. Well, it turns out I really do want to do this without a predefined C++ class, or something like that. I want to have the C++ code be easily extensible, so I don't have to repeat myself too much when adding new attributes. I tried making the proxy C++ class and exposing it, but it's very verbose and hard to maintain. I switched to using a dict, and what I have now is almost there: static bp::list EXTget_effects() { bp::list effect_list; int n_effects = get_n_sapphire_effects(); for (int i = 0; i < n_effects; i++) { Plugin_Info *pinfo = get_plugin_info_i(i); bp::dict ppinfo; ppinfo["name"] = (std::string)pinfo->plugin_name; ppinfo["category"] = (std::string)pinfo->category; ppinfo["n_effects"] = (int)pinfo->n_effects; ppinfo["n_inputs"] = (int)pinfo->n_inputs; ppinfo["custom_p"] = (int)pinfo->custom_p; effect_list.append(ppinfo); } return effect_list; } So now it returns a python list of python dicts. All I want now is to override __getattr__ on each ppinfo dict so it returns the dict value as the attribute value, so in python I can reference effect_list[i].name instead of effect_list[i]['name']. Or any alternative way to get the same effect. Is that possible? -- Gary Oberbrunner From stefan at seefeld.name Tue Jan 21 16:45:52 2014 From: stefan at seefeld.name (Stefan Seefeld) Date: Tue, 21 Jan 2014 10:45:52 -0500 Subject: [C++-sig] create a python object from scratch in boost.python? In-Reply-To: <2079615492.4456011.1390318621152.JavaMail.root@genarts.com> References: <2079615492.4456011.1390318621152.JavaMail.root@genarts.com> Message-ID: <52DE9630.3010907@seefeld.name> On 01/21/2014 10:37 AM, Gary Oberbrunner wrote: > So now it returns a python list of python dicts. All I want now is to > override __getattr__ on each ppinfo dict so it returns the dict value > as the attribute value, so in python I can reference > effect_list[i].name instead of effect_list[i]['name']. Or any > alternative way to get the same effect. Is that possible? There are many ways to do that elegantly in Python. For example: class Effect: def __init__(self, mydict): self.__dict__.update(mydict) If you want to combine that with existing classes / APIs, you could also consider merging the new attributes in via metaclasses. Stefan -- ...ich hab' noch einen Koffer in Berlin... From garyo at genarts.com Tue Jan 21 17:03:48 2014 From: garyo at genarts.com (Gary Oberbrunner) Date: Tue, 21 Jan 2014 11:03:48 -0500 (EST) Subject: [C++-sig] create a python object from scratch in boost.python? In-Reply-To: <52DE9630.3010907@seefeld.name> Message-ID: <138792326.4456593.1390320228445.JavaMail.root@genarts.com> ----- Original Message ----- > From: "Stefan Seefeld" > To: "Development of Python/C++ integration" > Sent: Tuesday, January 21, 2014 10:45:52 AM > Subject: Re: [C++-sig] create a python object from scratch in boost.python? > > On 01/21/2014 10:37 AM, Gary Oberbrunner wrote: > > So now it returns a python list of python dicts. All I want now is > > to > > override __getattr__ on each ppinfo dict so it returns the dict > > value > > as the attribute value, so in python I can reference > > effect_list[i].name instead of effect_list[i]['name']. Or any > > alternative way to get the same effect. Is that possible? > There are many ways to do that elegantly in Python. For example: > > class Effect: > def __init__(self, mydict): > self.__dict__.update(mydict) I like the idea of using self.__dict__. If that's accessible from C++, then I suppose I could have an empty C++ class, export that as a simple container, and dynamically add attributes to it by manipulating its __dict__. Does that seem possible? -- Gary Oberbrunner From stefan at seefeld.name Tue Jan 21 17:35:20 2014 From: stefan at seefeld.name (Stefan Seefeld) Date: Tue, 21 Jan 2014 11:35:20 -0500 Subject: [C++-sig] create a python object from scratch in boost.python? In-Reply-To: <138792326.4456593.1390320228445.JavaMail.root@genarts.com> References: <138792326.4456593.1390320228445.JavaMail.root@genarts.com> Message-ID: <52DEA1C8.9040705@seefeld.name> On 01/21/2014 11:03 AM, Gary Oberbrunner wrote: > > ----- Original Message ----- >> From: "Stefan Seefeld" >> To: "Development of Python/C++ integration" >> Sent: Tuesday, January 21, 2014 10:45:52 AM >> Subject: Re: [C++-sig] create a python object from scratch in boost.python? >> >> On 01/21/2014 10:37 AM, Gary Oberbrunner wrote: >>> So now it returns a python list of python dicts. All I want now is >>> to >>> override __getattr__ on each ppinfo dict so it returns the dict >>> value >>> as the attribute value, so in python I can reference >>> effect_list[i].name instead of effect_list[i]['name']. Or any >>> alternative way to get the same effect. Is that possible? >> There are many ways to do that elegantly in Python. For example: >> >> class Effect: >> def __init__(self, mydict): >> self.__dict__.update(mydict) > I like the idea of using self.__dict__. If that's accessible from C++, then I suppose I could have an empty C++ class, export that as a simple container, and dynamically add attributes to it by manipulating its __dict__. Does that seem possible? > Why do you want to export an empty C++ class ? Do you have an API that would take that as argument or return type ? If not, I see no point in doing that, as all that does is provide implicit type conversion for you. It seems what you really want is a way for your C++ code to manipulate pure Python objects, without any automatic type conversion. So the cleanest way to do that would be to use the above definition of the "Effect" class (in Python), import that into your C++ runtime (via bpl::import()), and then instantiate an "Effect" object with your pre-defined dict object. bpl::object effect_type = bpl::import("Effect"); // Define Effect type in C++ runtime bpl::object effect = effect_type(ppinfo); // Instantiate Effect object with pre-defined attribute dictionary ... Stefan -- ...ich hab' noch einen Koffer in Berlin... From garyo at genarts.com Tue Jan 21 19:52:06 2014 From: garyo at genarts.com (Gary Oberbrunner) Date: Tue, 21 Jan 2014 13:52:06 -0500 (EST) Subject: [C++-sig] create a python object from scratch in boost.python? In-Reply-To: <52DEA1C8.9040705@seefeld.name> Message-ID: <1752024852.4460451.1390330326308.JavaMail.root@genarts.com> ----- Original Message ----- > From: "Stefan Seefeld" ... > It seems what you really want is a way for your C++ code to > manipulate pure Python objects, without any automatic type conversion. Yes! > So the cleanest way to do that would be to use the above definition of > the "Effect" class (in Python), import that into your C++ runtime > (via bpl::import()), and then instantiate an "Effect" object with your > pre-defined dict object. I'm trying to do this in a boost python extension, so it has to be all in C++. If I have to wrap some python around it, it'll become a bit too heavyweight. I'd love to do what you suggest above, if it can be done all in C++. I think all I need is a way to create, in C++, an empty Python class object with a __dict__. Then, as you say, I can add attributes to it (at least I think I should be able to - but I'm not sure how far the boost.python world goes). -- Gary Oberbrunner From stefan at seefeld.name Tue Jan 21 23:07:54 2014 From: stefan at seefeld.name (Stefan Seefeld) Date: Tue, 21 Jan 2014 17:07:54 -0500 Subject: [C++-sig] create a python object from scratch in boost.python? In-Reply-To: <1752024852.4460451.1390330326308.JavaMail.root@genarts.com> References: <1752024852.4460451.1390330326308.JavaMail.root@genarts.com> Message-ID: <52DEEFBA.9090601@seefeld.name> On 01/21/2014 01:52 PM, Gary Oberbrunner wrote: > > ----- Original Message ----- >> From: "Stefan Seefeld" > ... >> It seems what you really want is a way for your C++ code to >> manipulate pure Python objects, without any automatic type conversion. > Yes! > >> So the cleanest way to do that would be to use the above definition of >> the "Effect" class (in Python), import that into your C++ runtime >> (via bpl::import()), and then instantiate an "Effect" object with your >> pre-defined dict object. > I'm trying to do this in a boost python extension, so it has to be all in C++. If I have to wrap some python around it, it'll become a bit too heavyweight. Have a look at the attached code; I don't think that counts as heavy-weight. In particular, trying to do the same without embedding a little "script" would be just more cumbersome, if it worked at all. > I'd love to do what you suggest above, if it can be done all in C++. I think all I need is a way to create, in C++, an empty Python class object with a __dict__. Then, as you say, I can add attributes to it (at least I think I should be able to - but I'm not sure how far the boost.python world goes). Compile the attached as a stand-alone app. I think it demonstrates what you want, so you should be able to easily adjust it to your use-case. Stefan -- ...ich hab' noch einen Koffer in Berlin... -------------- next part -------------- A non-text attachment was scrubbed... Name: bpl2.cc Type: text/x-c++src Size: 889 bytes Desc: not available URL: From garyo at genarts.com Tue Jan 21 23:24:15 2014 From: garyo at genarts.com (Gary Oberbrunner) Date: Tue, 21 Jan 2014 17:24:15 -0500 (EST) Subject: [C++-sig] create a python object from scratch in boost.python? In-Reply-To: <52DEEFBA.9090601@seefeld.name> Message-ID: <831082552.4463977.1390343055177.JavaMail.root@genarts.com> ----- Original Message ----- > From: "Stefan Seefeld" > Have a look at the attached code; I don't think that counts as > heavy-weight. In particular, trying to do the same without embedding > a > little "script" would be just more cumbersome, if it worked at all. Whoa, that is cool! I had no idea boost python could do this. Thanks, Stefan! (It's like "python-ception": python calls C++ which calls python...) -- Gary Oberbrunner From stefan at seefeld.name Tue Jan 21 23:34:00 2014 From: stefan at seefeld.name (Stefan Seefeld) Date: Tue, 21 Jan 2014 17:34:00 -0500 Subject: [C++-sig] create a python object from scratch in boost.python? In-Reply-To: <831082552.4463977.1390343055177.JavaMail.root@genarts.com> References: <831082552.4463977.1390343055177.JavaMail.root@genarts.com> Message-ID: <52DEF5D8.6050808@seefeld.name> On 01/21/2014 05:24 PM, Gary Oberbrunner wrote: > > ----- Original Message ----- >> From: "Stefan Seefeld" >> Have a look at the attached code; I don't think that counts as >> heavy-weight. In particular, trying to do the same without embedding >> a >> little "script" would be just more cumbersome, if it worked at all. > Whoa, that is cool! I had no idea boost python could do this. Thanks, Stefan! > > (It's like "python-ception": python calls C++ which calls python...) Yeah, the boundary between the two languages really becomes blurry, precisely because the two really share the same runtime, so passing objects across the boundary becomes so seamless you can almost forget it's there. The beauty of hybrid programming... :-) Stefan -- ...ich hab' noch einen Koffer in Berlin... From arm at rfh-koeln.de Tue Jan 28 17:33:18 2014 From: arm at rfh-koeln.de (=?iso-8859-1?Q?Peter_Armbr=FCster?=) Date: Tue, 28 Jan 2014 17:33:18 +0100 Subject: [C++-sig] PhysX3.x Wrapping Problems Message-ID: <039301cf1c46$a6c0b7d0$f4422770$@rfh-koeln.de> Dear Boost.python, C++ and Py++ Experts, this is my first post in your excellent Forum. I have chosen as the wrapper software the boost.python/Py++ Package to write a physx 3.x Wrapper, because I think it is the best. Many many thanks to David Abrahams and Roman Yakovenko for the great Tools. The wrapping of old versions physx 2.x had made no problems. And now I come across a very big problem at the 3.x Versions. All wrappings of classes works very well. The problem only exists in the PhysX free functions, which are responsible for the initialization of PhysX. I try to explain with a reduced Example. The initialization of PhysX starts with create of foundation : 0 static PxFoundation *mFoundation = NULL; 1 static PxDefaultErrorCallback gDefaultErrorCallback; 2 static PxDefaultAllocator gDefaultAllocatorCallback; 3 mFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, gDefaultAllocatorCallback, gDefaultErrorCallback); 4 4 if(!mFoundation) 5 fatalError("PxCreateFoundation failed!"); The wrapped python program generate a runtime error at line 3: RuntimeError: Access violation - no RTTI data! Its impossible to get mFoundation. Notes: - physx comes as SDK: only Headers, libs and dlls. - PxFoundation is a Abstract class: class PX_FOUNDATION_API PxFoundation { public: virtual void release() = 0; virtual PxErrorCallback& getErrorCallback() const = 0; virtual void setErrorLevel(PxErrorCode::Enum mask = PxErrorCode::eMASK_ALL) = 0; virtual PxErrorCode::Enum getErrorLevel() const = 0; virtual PxBroadcastingAllocator& getAllocator() const = 0; virtual PxAllocatorCallback& getAllocatorCallback() const = 0; virtual bool getReportAllocationNames() const = 0; virtual void setReportAllocationNames(bool value) = 0; virtual ~PxFoundation() {} }; - The wrapping of PxFoundation makes no problem. To make sure that I made no mistake with the initialization of PhysX, I tried a different solution. A small function InitPhysX create the foundation, and GetFoundation get this. C++ Code: using namespace physx; PxU32 PHYSICS_VERSION = PX_PHYSICS_VERSION; static PxFoundation *mFoundation = NULL; static PxDefaultErrorCallback gDefaultErrorCallback; static PxDefaultAllocator gDefaultAllocatorCallback; PxFoundation* GetFoundation(){ return mFoundation; } void InitPhysX() { mFoundation = PxCreateFoundation( PX_PHYSICS_VERSION, gDefaultAllocatorCallback, gDefaultErrorCallback); if(!mFoundation) printf("ERROR: PxCreateFoundation failed!\n"); else printf("PxCreateFoundation created!\n"); } The wrapped python program: 1 import _physx324_d as PX 2 PX.InitPhysX() 3 foundation = PX.GetFoundation() I get on line 2 the message: "PxCreateFoundation created!" => OK! On Line 3 the same error RuntimeError: Access violation - no RTTI data! Now i check the wrappings of PxCreateFoundation in _physx324_d_free_functions.pypp.cpp void register_free_functions(){ . . . { //::GetFoundation typedef ::physx::PxFoundation * ( *GetFoundation_function_type )( ); bp::def( "GetFoundation" , GetFoundation_function_type( &::GetFoundation ) , bp::return_value_policy< bp::reference_existing_object >() ); } . . . I think: return_value_policy< bp::reference_existing_object > thats right!? Then a debug session with PTVS, start with a break point in InitPhysX and inspect the mFoundation after the successful generation. Its a vptr with 9 Entries => thats right, PxFoundation has 9 Methods. That's all what I can see, because I have no source code and no pdb (symbols). I place the next Breakpoint in PxFoundation* GetFoundation(){ return mFoundation; } to search the Error location. Then followed a trace trip through the code, for me is a journey through an unreadable jungles of wrapper C + + code. Unfortunately, I am not an C++Expert. The Error is not to find for me. The same problem occurs with PxCreatePhysics. My work enviroment: ? Windows 7 x64 ? Python 2.7 ? physxVersion 3.24 (i try: 3.01, 3.23, 3.3, same problem) ? visualStudioVersion 11 (i try: VS 9 and VS 10, same problem) ? PythonTools for Visual Studio (PTVS) ? Boost 1.55 (i try: 1.45, same problem) ? gccxml 0.9 ? pyplusplus 1.0 svn 1.5.1 ? pygccxml 1.0 svn 1.5.1 What is my mistake? I would be very grateful if someone could an expert help. Thanks for your response. Peter Armold -------------- next part -------------- An HTML attachment was scrubbed... URL: From niki at vintech.bg Wed Jan 29 09:19:59 2014 From: niki at vintech.bg (niki) Date: Wed, 29 Jan 2014 10:19:59 +0200 Subject: [C++-sig] PhysX3.x Wrapping Problems In-Reply-To: <039301cf1c46$a6c0b7d0$f4422770$@rfh-koeln.de> References: <039301cf1c46$a6c0b7d0$f4422770$@rfh-koeln.de> Message-ID: <52E8B9AF.4050602@vintech.bg> On 28.01.2014 18:33, Peter Armbr?ster wrote: > Dear Boost.python, C++ and Py++ Experts, > > this is my first post in your excellent Forum. > > I have chosen as the wrapper software the boost.python/Py++ Packageto > write a physx 3.x Wrapper, because I think it is the best. > > Many many thanks to David Abrahams and Roman Yakovenko for the great Tools. > > The wrapping of old versions physx 2.x had made no problems. > > And now I come across a very big problem at the 3.x Versions. > > All wrappings of classes works very well. > > The problem only exists in the PhysX free functions, which are > responsible for the initialization of PhysX. > > I try to explain with a reduced Example. > > The initialization of PhysX starts with create of foundation : > > *0 static*PxFoundation*mFoundation=NULL; > > *1 static*PxDefaultErrorCallbackgDefaultErrorCallback; > *2 static*PxDefaultAllocatorgDefaultAllocatorCallback; > 3 > mFoundation=PxCreateFoundation(PX_PHYSICS_VERSION,gDefaultAllocatorCallback,gDefaultErrorCallback);4 > *4 if*(!mFoundation) > > 5 fatalError("PxCreateFoundation failed!"); > > The wrapped python program generate a runtime error at line > 3:RuntimeError: Access violation - no RTTI data! Just wild guess: add compiler option to enable RTTI HTH Niki From giuseppe.corbelli at copanitalia.com Wed Jan 29 11:03:00 2014 From: giuseppe.corbelli at copanitalia.com (Giuseppe Corbelli) Date: Wed, 29 Jan 2014 11:03:00 +0100 Subject: [C++-sig] PhysX3.x Wrapping Problems In-Reply-To: <039301cf1c46$a6c0b7d0$f4422770$@rfh-koeln.de> References: <039301cf1c46$a6c0b7d0$f4422770$@rfh-koeln.de> Message-ID: <52E8D1D4.7060003@copanitalia.com> On 28/01/2014 17:33, Peter Armbr?ster wrote: > Dear Boost.python, C++ and Py++ Experts, > > this is my first post in your excellent Forum. > > I have chosen as the wrapper software the boost.python/Py++ Packageto write a > physx 3.x Wrapper, because I think it is the best. > > Many many thanks to David Abrahams and Roman Yakovenko for the great Tools. > > The wrapping of old versions physx 2.x had made no problems. > > And now I come across a very big problem at the 3.x Versions. > > All wrappings of classes works very well. > > The problem only exists in the PhysX free functions, which are responsible for > the initialization of PhysX. > > I try to explain with a reduced Example. > > The initialization of PhysX starts with create of foundation : > > *0 static*PxFoundation*mFoundation=NULL; > > *1 static*PxDefaultErrorCallbackgDefaultErrorCallback; > *2 static*PxDefaultAllocatorgDefaultAllocatorCallback; > 3 > mFoundation=PxCreateFoundation(PX_PHYSICS_VERSION,gDefaultAllocatorCallback,gDefaultErrorCallback);4 > *4 if*(!mFoundation) > > 5 fatalError("PxCreateFoundation failed!"); > > The wrapped python program generate a runtime error at line 3:RuntimeError: > Access violation - no RTTI data! > > Its impossible to get mFoundation. > > *Notes: * > > - physx comes as SDK: only Headers, libs and dlls. Before reading on I'd investigate the "no RTTI data" message. Make sure you're using the /GR compiler option. -- Giuseppe Corbelli WASP Software Engineer, Copan Italia S.p.A Phone: +390303666318 Fax: +390302659932 E-mail: giuseppe.corbelli at copanitalia.com From arm at rfh-koeln.de Wed Jan 29 12:26:18 2014 From: arm at rfh-koeln.de (=?iso-8859-1?Q?Peter_Armbr=FCster?=) Date: Wed, 29 Jan 2014 12:26:18 +0100 Subject: [C++-sig] Cplusplus-sig Digest, Vol 64, Issue 11 In-Reply-To: References: Message-ID: <03d701cf1ce4$ee69dc30$cb3d9490$@rfh-koeln.de> Hi Niki and Giuseppe, thanks for your answers, but once I had already considered . My compiler flags are: /DWIN32 /DDEBUG /GR /RTCsu /DPX_DEBUG I wish you a nice day. Peter -----Urspr?ngliche Nachricht----- Von: Cplusplus-sig [mailto:cplusplus-sig-bounces+arm=rfh-koeln.de at python.org] Im Auftrag von cplusplus-sig-request at python.org Gesendet: Mittwoch, 29. Januar 2014 12:00 An: cplusplus-sig at python.org Betreff: Cplusplus-sig Digest, Vol 64, Issue 11 Send Cplusplus-sig mailing list submissions to cplusplus-sig at python.org To subscribe or unsubscribe via the World Wide Web, visit https://mail.python.org/mailman/listinfo/cplusplus-sig or, via email, send a message with subject or body 'help' to cplusplus-sig-request at python.org You can reach the person managing the list at cplusplus-sig-owner at python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Cplusplus-sig digest..." Today's Topics: 1. Re: PhysX3.x Wrapping Problems (niki) 2. Re: PhysX3.x Wrapping Problems (Giuseppe Corbelli) ---------------------------------------------------------------------- Message: 1 Date: Wed, 29 Jan 2014 10:19:59 +0200 From: niki To: Development of Python/C++ integration Subject: Re: [C++-sig] PhysX3.x Wrapping Problems Message-ID: <52E8B9AF.4050602 at vintech.bg> Content-Type: text/plain; charset=UTF-8; format=flowed On 28.01.2014 18:33, Peter Armbr?ster wrote: > Dear Boost.python, C++ and Py++ Experts, > > this is my first post in your excellent Forum. > > I have chosen as the wrapper software the boost.python/Py++ Packageto > write a physx 3.x Wrapper, because I think it is the best. > > Many many thanks to David Abrahams and Roman Yakovenko for the great Tools. > > The wrapping of old versions physx 2.x had made no problems. > > And now I come across a very big problem at the 3.x Versions. > > All wrappings of classes works very well. > > The problem only exists in the PhysX free functions, which are > responsible for the initialization of PhysX. > > I try to explain with a reduced Example. > > The initialization of PhysX starts with create of foundation : > > *0 static*PxFoundation*mFoundation=NULL; > > *1 static*PxDefaultErrorCallbackgDefaultErrorCallback; > *2 static*PxDefaultAllocatorgDefaultAllocatorCallback; > 3 > mFoundation=PxCreateFoundation(PX_PHYSICS_VERSION,gDefaultAllocatorCal > lback,gDefaultErrorCallback);4 > *4 if*(!mFoundation) > > 5 fatalError("PxCreateFoundation failed!"); > > The wrapped python program generate a runtime error at line > 3:RuntimeError: Access violation - no RTTI data! Just wild guess: add compiler option to enable RTTI HTH Niki ------------------------------ Message: 2 Date: Wed, 29 Jan 2014 11:03:00 +0100 From: Giuseppe Corbelli To: Development of Python/C++ integration Subject: Re: [C++-sig] PhysX3.x Wrapping Problems Message-ID: <52E8D1D4.7060003 at copanitalia.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed On 28/01/2014 17:33, Peter Armbr?ster wrote: > Dear Boost.python, C++ and Py++ Experts, > > this is my first post in your excellent Forum. > > I have chosen as the wrapper software the boost.python/Py++ Packageto > write a physx 3.x Wrapper, because I think it is the best. > > Many many thanks to David Abrahams and Roman Yakovenko for the great Tools. > > The wrapping of old versions physx 2.x had made no problems. > > And now I come across a very big problem at the 3.x Versions. > > All wrappings of classes works very well. > > The problem only exists in the PhysX free functions, which are > responsible for the initialization of PhysX. > > I try to explain with a reduced Example. > > The initialization of PhysX starts with create of foundation : > > *0 static*PxFoundation*mFoundation=NULL; > > *1 static*PxDefaultErrorCallbackgDefaultErrorCallback; > *2 static*PxDefaultAllocatorgDefaultAllocatorCallback; > 3 > mFoundation=PxCreateFoundation(PX_PHYSICS_VERSION,gDefaultAllocatorCal > lback,gDefaultErrorCallback);4 > *4 if*(!mFoundation) > > 5 fatalError("PxCreateFoundation failed!"); > > The wrapped python program generate a runtime error at line 3:RuntimeError: > Access violation - no RTTI data! > > Its impossible to get mFoundation. > > *Notes: * > > - physx comes as SDK: only Headers, libs and dlls. Before reading on I'd investigate the "no RTTI data" message. Make sure you're using the /GR compiler option. -- Giuseppe Corbelli WASP Software Engineer, Copan Italia S.p.A Phone: +390303666318 Fax: +390302659932 E-mail: giuseppe.corbelli at copanitalia.com ------------------------------ Subject: Digest Footer _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org https://mail.python.org/mailman/listinfo/cplusplus-sig ------------------------------ End of Cplusplus-sig Digest, Vol 64, Issue 11 ********************************************* From nikolay.mladenov at gmail.com Wed Jan 29 16:21:50 2014 From: nikolay.mladenov at gmail.com (Nikolay Mladenov) Date: Wed, 29 Jan 2014 10:21:50 -0500 Subject: [C++-sig] PhysX3.x Wrapping Problems In-Reply-To: <039301cf1c46$a6c0b7d0$f4422770$@rfh-koeln.de> References: <039301cf1c46$a6c0b7d0$f4422770$@rfh-koeln.de> Message-ID: Recently I had such symptom - it went away when I turned "Whole Program Optimization" off On Tue, Jan 28, 2014 at 11:33 AM, Peter Armbr?ster wrote: > Dear Boost.python, C++ and Py++ Experts, > > > > this is my first post in your excellent Forum. > > > > I have chosen as the wrapper software the boost.python/Py++ Package to > write a physx 3.x Wrapper, because I think it is the best. > > Many many thanks to David Abrahams and Roman Yakovenko for the great Tools. > > > > The wrapping of old versions physx 2.x had made no problems. > > And now I come across a very big problem at the 3.x Versions. > > All wrappings of classes works very well. > > The problem only exists in the PhysX free functions, which are responsible > for the initialization of PhysX. > > > > I try to explain with a reduced Example. > > The initialization of PhysX starts with create of foundation : > > > > *0 static* PxFoundation *mFoundation = NULL; > > *1 static* PxDefaultErrorCallback gDefaultErrorCallback; > *2 static* PxDefaultAllocator gDefaultAllocatorCallback; > 3 mFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, > gDefaultAllocatorCallback, gDefaultErrorCallback); 4 > *4 if*(!mFoundation) > > 5 fatalError("PxCreateFoundation failed!"); > > > > The wrapped python program generate a runtime error at line 3:RuntimeError: Access violation - no RTTI data! > > Its impossible to get mFoundation. > > > > > > > > *Notes: * > > - physx comes as SDK: only Headers, libs and dlls. > > - PxFoundation is a Abstract class: > > > > *class* PX_FOUNDATION_API PxFoundation > { > *public*: > *virtual* *void* release() = 0; > *virtual* PxErrorCallback& getErrorCallback() *const* = 0; > *virtual* *void* setErrorLevel(PxErrorCode::Enum mask = > PxErrorCode::eMASK_ALL) = 0; > *virtual* PxErrorCode::Enum getErrorLevel() *const* = 0; > *virtual* PxBroadcastingAllocator& getAllocator() *const* = 0; > *virtual* PxAllocatorCallback& getAllocatorCallback() *const* = 0; > *virtual* *bool* getReportAllocationNames() *const* = 0; > *virtual* *void* setReportAllocationNames(*bool* value) = 0; > > *virtual* ~PxFoundation() {} > }; > > > > - The wrapping of PxFoundation makes no problem. > > > > > > To make sure that I made no mistake with the initialization of PhysX, I > tried a different solution. > > A small function InitPhysX create the foundation, and GetFoundation get > this. > > > > C++ Code: > > > *using* *namespace* physx; > > PxU32 PHYSICS_VERSION = PX_PHYSICS_VERSION; > *static* PxFoundation *mFoundation = NULL; > *static* PxDefaultErrorCallback gDefaultErrorCallback; > *static* PxDefaultAllocator gDefaultAllocatorCallback; > > > PxFoundation* GetFoundation(){ > *return* mFoundation; > } > > *void* InitPhysX() { > mFoundation = PxCreateFoundation( > PX_PHYSICS_VERSION, > gDefaultAllocatorCallback, > gDefaultErrorCallback); > > *if*(!mFoundation) > printf("ERROR: PxCreateFoundation failed!\n"); > > > *else* printf("PxCreateFoundation created!\n"); > } > > > > The wrapped python program: > > > > 1 import _physx324_d as PX > > 2 PX.InitPhysX() > > 3 foundation = PX.GetFoundation() > > > > I get on line 2 the message: "PxCreateFoundation created!" > => OK! > > > > On Line 3 the same error RuntimeError: Access violation - no RTTI data! > > > > Now i check the wrappings of PxCreateFoundation in > _physx324_d_free_functions.pypp.cpp > > > > void register_free_functions(){ > > . . . > > > > { //::GetFoundation > > typedef ::physx::PxFoundation * ( *GetFoundation_function_type )( > ); > > bp::def( > "GetFoundation" > , GetFoundation_function_type( &::GetFoundation ) > , bp::return_value_policy< bp::reference_existing_object >() ); > > } > > > > . . . > > > > > > I think: return_value_policy< bp::reference_existing_object > thats > right!? > > > > Then a debug session with PTVS, start with a break point in InitPhysX > > and inspect the mFoundation after the successful generation. > > Its a vptr with 9 Entries => thats right, PxFoundation has 9 Methods. > > That's all what I can see, because I have no source code and no pdb > (symbols). > > > > I place the next Breakpoint in > > PxFoundation* GetFoundation(){ > *return* mFoundation; > } > > > > to search the Error location. > > > > Then followed a trace trip through the code, for me is a journey through > an unreadable jungles of wrapper C + + code. > > Unfortunately, I am not an C++Expert. > > The Error is not to find for me. > > > > > > The same problem occurs with PxCreatePhysics. > > > > My work enviroment: > > ? Windows 7 x64 > > ? Python 2.7 > > ? physxVersion 3.24 (i try: 3.01, 3.23, 3.3, same problem) > > ? visualStudioVersion 11 (i try: VS 9 and VS 10, same problem) > > ? PythonTools for Visual Studio (PTVS) > > ? Boost 1.55 (i try: 1.45, same problem) > > ? gccxml 0.9 > > ? pyplusplus 1.0 svn 1.5.1 > > ? pygccxml 1.0 svn 1.5.1 > > > > > > > > What is my mistake? > > I would be very grateful if someone could an expert help. > > Thanks for your response. > > > > Peter Armold > > > > > > > > > > > > > > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > https://mail.python.org/mailman/listinfo/cplusplus-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From arm at rfh-koeln.de Thu Jan 30 16:28:59 2014 From: arm at rfh-koeln.de (=?iso-8859-1?Q?Peter_Armbr=FCster?=) Date: Thu, 30 Jan 2014 16:28:59 +0100 Subject: [C++-sig] PhysX3.x Wrapping Problems Message-ID: <03dc01cf1dd0$01ac35e0$0504a1a0$@rfh-koeln.de> Hi Nicolay, thanks for your Tip. I tested this, but same Error. I think that is the biggest sh... Error in my live. Maybe I would better become a musician. :-) Best Regards Peter -----Urspr?ngliche Nachricht----- Von: Cplusplus-sig [mailto:cplusplus-sig-bounces+arm=rfh-koeln.de at python.org] Im Auftrag von cplusplus-sig-request at python.org Gesendet: Mittwoch, 29. Januar 2014 16:22 An: cplusplus-sig at python.org Betreff: Cplusplus-sig Digest, Vol 64, Issue 12 Send Cplusplus-sig mailing list submissions to cplusplus-sig at python.org To subscribe or unsubscribe via the World Wide Web, visit https://mail.python.org/mailman/listinfo/cplusplus-sig or, via email, send a message with subject or body 'help' to cplusplus-sig-request at python.org You can reach the person managing the list at cplusplus-sig-owner at python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Cplusplus-sig digest..." Today's Topics: 1. Re: Cplusplus-sig Digest, Vol 64, Issue 11 (Peter Armbr?ster) 2. Re: PhysX3.x Wrapping Problems (Nikolay Mladenov) ---------------------------------------------------------------------- Message: 1 Date: Wed, 29 Jan 2014 12:26:18 +0100 From: Peter Armbr?ster To: Subject: Re: [C++-sig] Cplusplus-sig Digest, Vol 64, Issue 11 Message-ID: <03d701cf1ce4$ee69dc30$cb3d9490$@rfh-koeln.de> Content-Type: text/plain; charset="iso-8859-1" Hi Niki and Giuseppe, thanks for your answers, but once I had already considered . My compiler flags are: /DWIN32 /DDEBUG /GR /RTCsu /DPX_DEBUG I wish you a nice day. Peter -----Urspr?ngliche Nachricht----- Von: Cplusplus-sig [mailto:cplusplus-sig-bounces+arm=rfh-koeln.de at python.org] Im Auftrag von cplusplus-sig-request at python.org Gesendet: Mittwoch, 29. Januar 2014 12:00 An: cplusplus-sig at python.org Betreff: Cplusplus-sig Digest, Vol 64, Issue 11 Send Cplusplus-sig mailing list submissions to cplusplus-sig at python.org To subscribe or unsubscribe via the World Wide Web, visit https://mail.python.org/mailman/listinfo/cplusplus-sig or, via email, send a message with subject or body 'help' to cplusplus-sig-request at python.org You can reach the person managing the list at cplusplus-sig-owner at python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Cplusplus-sig digest..." Today's Topics: 1. Re: PhysX3.x Wrapping Problems (niki) 2. Re: PhysX3.x Wrapping Problems (Giuseppe Corbelli) ---------------------------------------------------------------------- Message: 1 Date: Wed, 29 Jan 2014 10:19:59 +0200 From: niki To: Development of Python/C++ integration Subject: Re: [C++-sig] PhysX3.x Wrapping Problems Message-ID: <52E8B9AF.4050602 at vintech.bg> Content-Type: text/plain; charset=UTF-8; format=flowed On 28.01.2014 18:33, Peter Armbr?ster wrote: > Dear Boost.python, C++ and Py++ Experts, > > this is my first post in your excellent Forum. > > I have chosen as the wrapper software the boost.python/Py++ Packageto > write a physx 3.x Wrapper, because I think it is the best. > > Many many thanks to David Abrahams and Roman Yakovenko for the great Tools. > > The wrapping of old versions physx 2.x had made no problems. > > And now I come across a very big problem at the 3.x Versions. > > All wrappings of classes works very well. > > The problem only exists in the PhysX free functions, which are > responsible for the initialization of PhysX. > > I try to explain with a reduced Example. > > The initialization of PhysX starts with create of foundation : > > *0 static*PxFoundation*mFoundation=NULL; > > *1 static*PxDefaultErrorCallbackgDefaultErrorCallback; > *2 static*PxDefaultAllocatorgDefaultAllocatorCallback; > 3 > mFoundation=PxCreateFoundation(PX_PHYSICS_VERSION,gDefaultAllocatorCal > lback,gDefaultErrorCallback);4 > *4 if*(!mFoundation) > > 5 fatalError("PxCreateFoundation failed!"); > > The wrapped python program generate a runtime error at line > 3:RuntimeError: Access violation - no RTTI data! Just wild guess: add compiler option to enable RTTI HTH Niki ------------------------------ Message: 2 Date: Wed, 29 Jan 2014 11:03:00 +0100 From: Giuseppe Corbelli To: Development of Python/C++ integration Subject: Re: [C++-sig] PhysX3.x Wrapping Problems Message-ID: <52E8D1D4.7060003 at copanitalia.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed On 28/01/2014 17:33, Peter Armbr?ster wrote: > Dear Boost.python, C++ and Py++ Experts, > > this is my first post in your excellent Forum. > > I have chosen as the wrapper software the boost.python/Py++ Packageto > write a physx 3.x Wrapper, because I think it is the best. > > Many many thanks to David Abrahams and Roman Yakovenko for the great Tools. > > The wrapping of old versions physx 2.x had made no problems. > > And now I come across a very big problem at the 3.x Versions. > > All wrappings of classes works very well. > > The problem only exists in the PhysX free functions, which are > responsible for the initialization of PhysX. > > I try to explain with a reduced Example. > > The initialization of PhysX starts with create of foundation : > > *0 static*PxFoundation*mFoundation=NULL; > > *1 static*PxDefaultErrorCallbackgDefaultErrorCallback; > *2 static*PxDefaultAllocatorgDefaultAllocatorCallback; > 3 > mFoundation=PxCreateFoundation(PX_PHYSICS_VERSION,gDefaultAllocatorCal > lback,gDefaultErrorCallback);4 > *4 if*(!mFoundation) > > 5 fatalError("PxCreateFoundation failed!"); > > The wrapped python program generate a runtime error at line 3:RuntimeError: > Access violation - no RTTI data! > > Its impossible to get mFoundation. > > *Notes: * > > - physx comes as SDK: only Headers, libs and dlls. Before reading on I'd investigate the "no RTTI data" message. Make sure you're using the /GR compiler option. -- Giuseppe Corbelli WASP Software Engineer, Copan Italia S.p.A Phone: +390303666318 Fax: +390302659932 E-mail: giuseppe.corbelli at copanitalia.com ------------------------------ Subject: Digest Footer _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org https://mail.python.org/mailman/listinfo/cplusplus-sig ------------------------------ End of Cplusplus-sig Digest, Vol 64, Issue 11 ********************************************* ------------------------------ Message: 2 Date: Wed, 29 Jan 2014 10:21:50 -0500 From: Nikolay Mladenov To: "Development of Python/C++ integration" Subject: Re: [C++-sig] PhysX3.x Wrapping Problems Message-ID: Content-Type: text/plain; charset="iso-8859-1" Recently I had such symptom - it went away when I turned "Whole Program Optimization" off On Tue, Jan 28, 2014 at 11:33 AM, Peter Armbr?ster wrote: > Dear Boost.python, C++ and Py++ Experts, > > > > this is my first post in your excellent Forum. > > > > I have chosen as the wrapper software the boost.python/Py++ Package to > write a physx 3.x Wrapper, because I think it is the best. > > Many many thanks to David Abrahams and Roman Yakovenko for the great Tools. > > > > The wrapping of old versions physx 2.x had made no problems. > > And now I come across a very big problem at the 3.x Versions. > > All wrappings of classes works very well. > > The problem only exists in the PhysX free functions, which are > responsible for the initialization of PhysX. > > > > I try to explain with a reduced Example. > > The initialization of PhysX starts with create of foundation : > > > > *0 static* PxFoundation *mFoundation = NULL; > > *1 static* PxDefaultErrorCallback gDefaultErrorCallback; > *2 static* PxDefaultAllocator gDefaultAllocatorCallback; > 3 mFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, > gDefaultAllocatorCallback, gDefaultErrorCallback); 4 > *4 if*(!mFoundation) > > 5 fatalError("PxCreateFoundation failed!"); > > > > The wrapped python program generate a runtime error at line 3:RuntimeError: Access violation - no RTTI data! > > Its impossible to get mFoundation. > > > > > > > > *Notes: * > > - physx comes as SDK: only Headers, libs and dlls. > > - PxFoundation is a Abstract class: > > > > *class* PX_FOUNDATION_API PxFoundation { > *public*: > *virtual* *void* release() = 0; > *virtual* PxErrorCallback& getErrorCallback() *const* = 0; > *virtual* *void* setErrorLevel(PxErrorCode::Enum mask = > PxErrorCode::eMASK_ALL) = 0; > *virtual* PxErrorCode::Enum getErrorLevel() *const* = 0; > *virtual* PxBroadcastingAllocator& getAllocator() *const* = 0; > *virtual* PxAllocatorCallback& getAllocatorCallback() *const* = 0; > *virtual* *bool* getReportAllocationNames() *const* = 0; > *virtual* *void* setReportAllocationNames(*bool* value) = 0; > > *virtual* ~PxFoundation() {} > }; > > > > - The wrapping of PxFoundation makes no problem. > > > > > > To make sure that I made no mistake with the initialization of PhysX, > I tried a different solution. > > A small function InitPhysX create the foundation, and GetFoundation > get this. > > > > C++ Code: > > > *using* *namespace* physx; > > PxU32 PHYSICS_VERSION = PX_PHYSICS_VERSION; > *static* PxFoundation *mFoundation = NULL; > *static* PxDefaultErrorCallback gDefaultErrorCallback; > *static* PxDefaultAllocator gDefaultAllocatorCallback; > > > PxFoundation* GetFoundation(){ > *return* mFoundation; > } > > *void* InitPhysX() { > mFoundation = PxCreateFoundation( > PX_PHYSICS_VERSION, > gDefaultAllocatorCallback, > gDefaultErrorCallback); > > *if*(!mFoundation) > printf("ERROR: PxCreateFoundation failed!\n"); > > > *else* printf("PxCreateFoundation created!\n"); > } > > > > The wrapped python program: > > > > 1 import _physx324_d as PX > > 2 PX.InitPhysX() > > 3 foundation = PX.GetFoundation() > > > > I get on line 2 the message: "PxCreateFoundation created!" > => OK! > > > > On Line 3 the same error RuntimeError: Access violation - no RTTI data! > > > > Now i check the wrappings of PxCreateFoundation in > _physx324_d_free_functions.pypp.cpp > > > > void register_free_functions(){ > > . . . > > > > { //::GetFoundation > > typedef ::physx::PxFoundation * ( *GetFoundation_function_type > )( ); > > bp::def( > "GetFoundation" > , GetFoundation_function_type( &::GetFoundation ) > , bp::return_value_policy< bp::reference_existing_object > >() ); > > } > > > > . . . > > > > > > I think: return_value_policy< bp::reference_existing_object > thats > right!? > > > > Then a debug session with PTVS, start with a break point in InitPhysX > > and inspect the mFoundation after the successful generation. > > Its a vptr with 9 Entries => thats right, PxFoundation has 9 Methods. > > That's all what I can see, because I have no source code and no pdb > (symbols). > > > > I place the next Breakpoint in > > PxFoundation* GetFoundation(){ > *return* mFoundation; > } > > > > to search the Error location. > > > > Then followed a trace trip through the code, for me is a journey > through an unreadable jungles of wrapper C + + code. > > Unfortunately, I am not an C++Expert. > > The Error is not to find for me. > > > > > > The same problem occurs with PxCreatePhysics. > > > > My work enviroment: > > ? Windows 7 x64 > > ? Python 2.7 > > ? physxVersion 3.24 (i try: 3.01, 3.23, 3.3, same problem) > > ? visualStudioVersion 11 (i try: VS 9 and VS 10, same problem) > > ? PythonTools for Visual Studio (PTVS) > > ? Boost 1.55 (i try: 1.45, same problem) > > ? gccxml 0.9 > > ? pyplusplus 1.0 svn 1.5.1 > > ? pygccxml 1.0 svn 1.5.1 > > > > > > > > What is my mistake? > > I would be very grateful if someone could an expert help. > > Thanks for your response. > > > > Peter Armold > > > > > > > > > > > > > > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > https://mail.python.org/mailman/listinfo/cplusplus-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: ------------------------------ Subject: Digest Footer _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig at python.org https://mail.python.org/mailman/listinfo/cplusplus-sig ------------------------------ End of Cplusplus-sig Digest, Vol 64, Issue 12 *********************************************