Skip to content

Commit

Permalink
Move Background dtor to public, use shared_ptr for pybind11
Browse files Browse the repository at this point in the history
  • Loading branch information
brianv0 committed Nov 2, 2020
1 parent 24b9b38 commit c90daf1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
4 changes: 2 additions & 2 deletions include/lsst/afw/math/Background.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,14 @@ class Background {
* is mostly used to implement persistence.
*/
explicit Background(lsst::geom::Box2I const imageBBox, int const nx, int const ny);
/// dtor
virtual ~Background() = default;

public:
typedef float InternalPixelT; ///< type used for any internal images, and returned by getApproximate

Background(Background const&) = delete;
Background(Background&&) = delete;
/// dtor
virtual ~Background() = default;
Background& operator=(Background const&) = delete;
Background& operator=(Background&&) = delete;

Expand Down
10 changes: 2 additions & 8 deletions python/lsst/afw/math/background/background.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,7 @@ PYBIND11_MODULE(background, mod) {
(std::shared_ptr<ApproximateControl> (BackgroundControl::*)()) &
BackgroundControl::getApproximateControl);

/* Note that, in this case, the holder type must be unique_ptr to enable usage
* of py::nodelete, which in turn is needed because Background has a protected
* destructor. Adding py::nodelete prevents pybind11 from calling the destructor
* when the pointer is destroyed. Thus care needs to be taken to prevent leaks.
* Basically Background should only ever be used as a base class (without data
* members). */
py::class_<Background, std::unique_ptr<Background, py::nodelete>> clsBackground(mod, "Background");
py::class_<Background, std::shared_ptr<Background>> clsBackground(mod, "Background");

/* Members */
declareGetImage<float>(clsBackground, "F");
Expand Down Expand Up @@ -179,4 +173,4 @@ PYBIND11_MODULE(background, mod) {
}
}
}
} // lsst::afw::math
} // lsst::afw::math

0 comments on commit c90daf1

Please sign in to comment.