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-12615: Add copy-constructors to astshim objects #38

Merged
merged 13 commits into from Jan 31, 2018
Merged

Conversation

r-owen
Copy link
Contributor

@r-owen r-owen commented Jan 24, 2018

No description provided.

*/
AstObject * getRawPtrCopy() const {
AstObject * rawPtrCopy = reinterpret_cast<AstObject *>(astCopy(getRawPtr()));
assertOK(rawPtrCopy);

Choose a reason for hiding this comment

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

I am not familiar with much of ast, will this nicely handle exceptions etc, if this assertion turns out to not be ok?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. If there is an error assertOK will annul rawPtrCopy and then raise an exception. This prevents memory leaks.

@@ -105,7 +105,7 @@ class FrameDict : public FrameSet {

@throws std::invalid_argument if two Frames in the FrameSet have the same non-empty domain.
*/
explicit FrameDict(FrameSet const &frameSet) : FrameSet(std::move(*frameSet.copy())), _domainIndexDict() {
explicit FrameDict(FrameSet const &frameSet) : FrameSet(frameSet), _domainIndexDict() {

Choose a reason for hiding this comment

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

It seems weird that this commit in history happens before the commit to add the copy constructor. In the end it wont matter much, just the timeline for things seems off to anyone reading git log

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added it after adding C++ copy constructor and before adding Python support for copy constructor. So it's reasonable, but I agree it would be clearer to swap the last two

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could combine the C++ and python copy constructor commits; I was basically waiting to see if there would be complaints about having the C++ copy constructors exposed to Python (but I prefer that if only to unit-test it!)

Choose a reason for hiding this comment

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

I am fine with it being exposed to python. Swap if you can, otherwise it is ok I guess

chan.write(obj)
ss.sinkToSource()
if channelType == FitsChan:

Choose a reason for hiding this comment

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

This should be:
if channelType is FitsChan:

and all properties are identical
(including whether set or defaulted).
"""
self.assertEqual(obj1.className, obj2.className)

Choose a reason for hiding this comment

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

Why are you checking types like this and not
self.assertIs(type(obj1), type(obj2))
it seems more idiomatic to use actual type checking

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Things can get a bit weird for astshim classes with no direct AST equivalent: FrameDict is a wrapper around FrameSet and SeriesMap and ParallelMap are both basically CmpMaps.

However, I decided you were right and I made the test picker while adding support for the type being something other than expected in checkPersistence.

This also prompted me to improve pickle support for FrameDict so it round-trips correctly instead of coming back as a FrameSet.

@@ -162,6 +162,13 @@ std::string Object::show(bool showComments) const {
return os.str();
}

Object::Object(AstObject *object) : _objPtr(object, &detail::annulAstObject) {

Choose a reason for hiding this comment

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

This seems to be the exact opposite of the commit message. If that was the intention, please change the message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. I fixed the message.

@r-owen r-owen force-pushed the tickets/DM-12615 branch 2 times, most recently from 22bb869 to c9ecffe Compare January 30, 2018 23:23
Make the FrameSet(frame, mapping, frame, options) constructor
call FrameSet(frame, options) constructor, to reduce repetition.
Add these for all AST wrapper objects except channels
(which cannot be copied)
Include Python wrappers for the copy constructors and python
unit tests.
This method was supposed to test persistence using three different
channel classes, but in fact was only testing ast.Channel.
and use it to reduce some code repetition
Make all astshim persistable objects pickleable in Python
by adding Object.__reduce__
Simplify test_object by using UnitMap's regular pickling
for the multiprocessing test
Make ObjectTestCase.checkPersistence support testing for other
types returned by a channel, as exptected for FrameDict.
Make ObjectTestCase.assertObjectsIdentical pickier, while supporting
the case just mentioned.
Use Channel instead of AST functions such as astChannel,
in order to make the code more robust and minimze direct use of
AST functions.
except the ones about defaulted functions which need a bigger fix
The documentation for CmpMap, SeriesMap and ParallelMap
was incorrect regarding the effects of the latter two
being a wrapper around the first.
@r-owen r-owen merged commit 777fb5e into master Jan 31, 2018
@ktlim ktlim deleted the tickets/DM-12615 branch August 25, 2018 04:30
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