Re: [C++-sig] shared_ptr and register_ptr_to_python

2010-10-25 Thread Marek Denis
On 11.10.2010 22:01, Jim Bosch wrote: A couple of notes: - I have not tested this. Likely there are some typos, and possibly even a bit of forgotten syntax - hopefully it's easy to correct. - Note that there's no need to re-wrap the methods that B inherits from A, but you do have create both

[C++-sig] Wrapping method that returns const int& (boost::python)

2010-10-25 Thread Panos
I have a simple test case: class Foo { public: const int& getX() const {return x;} void setX(const int& x_) {x = x_;} private: int x; }; BOOST_PYTHON_MODULE(module) { class_("Foo") .def("getX", &Foo::getX) ; } The problem is that I cannot wrap getX and I get a compile

Re: [C++-sig] Wrapping method that returns const int& (boost::python)

2010-10-25 Thread Erik Tuerke
Panos wrote: I have a simple test case: class Foo { public: const int& getX() const {return x;} void setX(const int& x_) {x = x_;} private: int x; }; BOOST_PYTHON_MODULE(module) { class_("Foo") .def("getX", &Foo::getX) ; } The problem is that I cannot wrap getX and

Re: [C++-sig] Delete objects, remove from dict

2010-10-25 Thread Simon W
Hey and thanks for the answer! Unfortunately that doesn't seem to work. I'm using boost.python for Python 3 ( boost python 1.44? ) error C2039: 'del' : is not a member of 'boost::python::api::object' I've had a look on the reference manual but I don't understand if it's a free function or an meth

Re: [C++-sig] Delete objects, remove from dict

2010-10-25 Thread Ralf W. Grosse-Kunstleve
I've only tried it with Python 2; I'm not setup for working with Python 3. Try boost::python::api::delitem(target, key); and if that fails too PyObject_DelItem(target.ptr(), key.ptr()); Ralf > >From: Simon W >To: Development of Python/C++ integration >Sent: Mon, October 25, 2010 8:48:2

Re: [C++-sig] Delete objects, remove from dict

2010-10-25 Thread Ralf W. Grosse-Kunstleve
Oh, at second glance... > > object obj = mMainNamespace[ name.c_str() ]; > >obj.del(); This cannot work! You need to do it the way I showed before. mMainNamespace[ name.c_str() ].del(); The [] operator returns a proxy object which supports the del since it still know

Re: [C++-sig] Delete objects, remove from dict

2010-10-25 Thread Simon W
Thanks that did the trick! On Mon, Oct 25, 2010 at 7:07 PM, Ralf W. Grosse-Kunstleve wrote: > Oh, at second glance... > > > > > > object obj = mMainNamespace[ name.c_str() ]; > > >obj.del(); > > This cannot work! > You need to do it the way I showed before. > > mMainNames

[C++-sig] Reference count on class object and import()

2010-10-25 Thread Simon W
Hey again, I'm trying to implement a load / unload module functionallity. When I delete the module in the __main__ dict the module's reference count is still > 1. I've been trying to find if I reference it anywhere else in my code but I can't find anything! When I did a check in vc++ debugger foun

[C++-sig] Mapping RAW memory data into Python

2010-10-25 Thread Marek Denis
Hi, While I had some questions concerning accessing objects in Python, that were previously created in C++ now I'd like to know whether it's possible to get access to the raw memory from Python layer. Let's suppose I have the char* ptr pointer that points to the memory chunk with IPv4 packet. I

Re: [C++-sig] Wrapping method that returns const int& (boost::python)

2010-10-25 Thread Abhishek Srivastava
Does this works for you?? class Foo { public: const int& getX() const {return x;} void setX(const int& x_) {x = x_;} private: int x; }; BOOST_PYTHON_MODULE(module) { class_("Foo") .def("getX", &Foo::getX, return_value_policy()) ; } With Regards, Abhishek Srivastava

Re: [C++-sig] Mapping RAW memory data into Python

2010-10-25 Thread Jim Bosch
On 10/25/2010 10:51 AM, Marek Denis wrote: Hi, While I had some questions concerning accessing objects in Python, that were previously created in C++ now I'd like to know whether it's possible to get access to the raw memory from Python layer. Let's suppose I have the char* ptr pointer that point

Re: [C++-sig] Wrapping method that returns const int& (boost::python)

2010-10-25 Thread Stefan Seefeld
Panos, Erik, the issue here is likely that Python's "int" objects are immutable. Therefore, you can't pass around ints by reference, only by-value. If the compiler is confused, perhaps you need to explicitly set a return-value policy that makes this clear ? Stefan -- ...ich hab'