pycxx and multiple new types

J

John Hunter

I have been using pycxx 5.2.2 to write an extension module which
defines two new types, Point and Bbox. The Bbox is constructed with 2
Point instances

class Point: public Py::pythonExtension<Point> ...

class Bbox: public Py::pythonExtension<Bbox> {
public:
Bbox(Point& ll, Point& ur) : _ll(ll), _ur(ur) {};
static void init_type(void);

// return lower left point
Py::Object ll(const Py::Tuple &args) { return Py::Object(&_ll); }

// return upper right point
Py::Object ur(const Py::Tuple &args) { return Py::Object(&_ur); }

private:
Point& _ll, _ur;
};


The problem I am having is that if I instantiate a Bbox from 2 point
instances, my python test code hangs after the last line of the script
and doesn't return the shell prompt until I hit CTRL-C.

ll = Point(10, 10)
ur = Point(20, 20)
bbox = Bbox(ll, ur) # this line causes the hang.

I think this is because I am not handling the ref count of the Point
objects properly.

My new_bbox function looks like


Py::Object _transforms_module::new_bbox (const Py::Tuple &args)
{

args.verify_length(2);

Point::check(args[0]);
Point::check(args[1]);

Point* ll = (Point*)(args[0].ptr());
Point* ur = (Point*)(args[1].ptr());
return Py::asObject(new Bbox(*ll, *ur) );
}

Do you have any thoughts on what I am doing wrong?

Thanks,
John Hunter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,197
Messages
2,571,040
Members
47,634
Latest member
RonnyBoelk

Latest Threads

Top