Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-33519: Add non-shared_ptr overloads to various FITS I/O functions. #632

Merged
merged 2 commits into from Mar 29, 2022

Conversation

TallJimbo
Copy link
Member

No description provided.

@TallJimbo TallJimbo force-pushed the tickets/DM-33519 branch 5 times, most recently from a354832 to 9715b4d Compare March 25, 2022 16:45
Copy link
Member

@kfindeisen kfindeisen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but the deprecated versions of these methods aren't backwards-compatible with the originals (missing defaults).

include/lsst/afw/fits.h Outdated Show resolved Hide resolved
template <typename T>
[[deprecated("Replaced by a non-shared_ptr overload. Will be removed after v24.")]]
ImageScale determine(image::ImageBase<T> const& image,
std::shared_ptr<image::Mask<image::MaskPixel> const> mask) const {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original method had a nullptr default for mask; removing the default is a breaking change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is, except maybe in some edge case involving member function pointers: the new overload is identical with this one up to this argument, and we now want that new one to be the one invoked when the defaulted argument is not provided by the caller. And if we did leave this argument defaulted as well, calls that do not pass at least one defaulted argument would be ambiguous (as the compiler reminded me after my first attempt left the defaults in).

std::string const& mode = "w") const;
[[deprecated("Replaced by a non-shared_ptr overload. Will be removed after v24.")]]
void writeFits(std::string const& fileName,
std::shared_ptr<daf::base::PropertySet const> metadata,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

metadata originally had a nullptr default (same below).

[[deprecated("Replaced by a non-shared_ptr overload. Will be removed after v24.")]]
void writeFits(std::string const& filename, fits::ImageWriteOptions const& options,
std::string const& mode,
std::shared_ptr<daf::base::PropertySet const> header,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

header originally had a nullptr default (same below).

std::string const& mode = "w") const;
[[deprecated("Replaced by a non-shared_ptr overload. Will be removed after v24.")]]
void writeFits(std::string const& fileName,
std::shared_ptr<daf::base::PropertySet const> metadata,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

metadata originally had a nullptr default (same below).

[[deprecated("Replaced by a non-shared_ptr overload. Will be removed after v24.")]]
void writeFits(std::string const& filename, fits::ImageWriteOptions const& options,
std::string const& mode,
std::shared_ptr<daf::base::PropertySet const> header) const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

header originally had a nullptr default (same below).

},
"image"_a,
"mask"_a=nullptr
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this lambda necessary, instead of using py::overload_cast to disambiguate which determine this is?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure; I tried the overload_cast version first (and I'm pretty sure I had it all right, including the easy-to-forget py::const_ argument), and it didn't work. I'll add a comment to that effect - I confess I do not have a good sense for which cases overload_cast can handle and which it cannot.

src/fits.cc Outdated Show resolved Hide resolved
The original versions of these functions violate rule 5-24b of the
LSST C++ style guide and/or rule F7 of the C++ Core Guidelines: they
take a smart pointer argument but don't actually need to, because they
don't take ownership of the object or otherwise manipulate the
object's lifetime.  This is a viral problem, because it tempts
downstream code to use smart pointers unnecessarily in arguments that
will be forwarded to these.

There are many more examples of this, but they'll be easier to resolve
with or after RFC-840.
@TallJimbo TallJimbo merged commit 648ecf2 into main Mar 29, 2022
@TallJimbo TallJimbo deleted the tickets/DM-33519 branch March 29, 2022 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants