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:ythonExtension<Point> ...
class Bbox: public Py:ythonExtension<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
defines two new types, Point and Bbox. The Bbox is constructed with 2
Point instances
class Point: public Py:ythonExtension<Point> ...
class Bbox: public Py:ythonExtension<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