Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Refactoring of create_* and destroy_* functions - #45

Merged
wjwwood merged 1 commit into
masterfrom
memory_audit
Jul 15, 2015
Merged

wjwwood merged 1 commit into
masterfrom
memory_audit

Conversation

@wjwwood

@wjwwood wjwwood commented Jun 29, 2015

Copy link
Copy Markdown
Member

This has been done to resolve some teardown related errors and generally to improve the state of memory management in these implementations.

I've done several things here:

  • Implemented destroy functions where they were missing before.
  • Refactored create functions to properly unroll actions which had already been made in the event of an error later in the create function. This uses the "goto fail" pattern that is popular in the Linux kernel.
  • Wrapped C++ constructor and destructor calls in try-catch cases to prevent escalation of exceptions through the C api.
  • Replaced use of new and delete where ever possible with rmw_allocate to allow us more control over allocation in the future.
  • Other minor improvements.

Things that are yet to be done (covered by TODO's):

  • Some error propagation is not possible in the current setup (or error strings may get overwritten by other errors before returning).
  • I think we might be leaking calls to register_type on the participant, but it's not clear if we must unregister them or if so, when we should unregister them.
  • Servers and clients new more, msg specific, refactoring to replace use of new and (currently missing) delete calls to create "repliers" and "requesters".

Connects ros2/ros2#69

@wjwwood wjwwood added the in progress Actively being worked on (Kanban column) label Jun 29, 2015
@wjwwood

wjwwood commented Jun 29, 2015

Copy link
Copy Markdown
Member Author

Working on a similar pr for opensplice now.

@esteve

esteve commented Jun 29, 2015

Copy link
Copy Markdown
Member

+1

@tfoote

tfoote commented Jun 30, 2015

Copy link
Copy Markdown
Contributor

Overall it looks good. I think all the goto fail calls could be replaced with lambda functions for cleanlyness.

@wjwwood

wjwwood commented Jun 30, 2015

Copy link
Copy Markdown
Member Author

Maybe the lambda would be cleaner, but I'm not convinced of that since you'd have to capture all of the variables, not sure if a catch all capture would work. Either way, this is like my 16th iteration on this change set and I'm not particularly motivated to make such an intrusive non-functional change 😄.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seeing the dangling dereference arrow as input to the TRY_DESTRUCTOR macros is jarring for me. Are trying to leave the option open for another dereference operator besides ->?

Answered my own question, looks like you use operator . at later points in the code

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Answered my own question, looks like you use operator . at later points in the code

^, I didn't want to make two, really long named macros, but we could do that too. Also I could just put the whole destructor statement in there, but this is where I ended up.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ok, I moved the macros to a common header in rmw and I changed them such that they pass the entire destructor statement (no dangling -> or .).

@wjwwood

wjwwood commented Jul 2, 2015

Copy link
Copy Markdown
Member Author

I've addressed all of the comments, pending the decision about goto fail.

@wjwwood
wjwwood force-pushed the memory_audit branch 2 times, most recently from 6b03a0c to d131871 Compare July 15, 2015 01:16
Comment thread rmw_connext_cpp/src/functions.cpp Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Wrong indent.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I ran uncrustify over this already and I wouldn't call that indent wrong, but it is an alternative indent that we don't usually use. In this case I think it looks fine, in other cases like this:

  some_really_long_named_function_that_does_stuff(arg1,
                                                  arg2,
                                                  arg3);

I think that style doesn't make sense, but there has to be some room for developer discretion in these types of things.

@dirk-thomas

Copy link
Copy Markdown
Member

All tests related to staticarrayprimitives and dynamicarrayprimitives fail. Looking at one of them (publisher_subscriber_cpp__staticarrayprimitives__rmw_connext_dynamic_cpp) it fails with the following error:

DDS_DynamicDataTypeSupport_initialize:typecode error 5 on content_type
raising: could not create subscription: failed to register type

Therefore I looked at the type creation function - especially for arrays. For the subscriber: https://github.com/ros2/rmw_connext/blob/962fe936019c0fa081cb3c0d08661b85edb3502b/rmw_connext_dynamic_cpp/src/functions.cpp#L302-L360

The code first create the type support for the base type and then if it is an array creates the type support for the array / sequence which is based on the base type. But the PR removes the base type support which is required for the array / sequence type support: 5e7236f#diff-d8fc519447c043a7165e1ff89d1c2088R325

I have fixed the type support in commit 6cf72f33f898dffe5c2614ebc72a0153170cd54d.

@wjwwood

wjwwood commented Jul 15, 2015

Copy link
Copy Markdown
Member Author

@jackieokay

Copy link
Copy Markdown
Contributor

Jenkins looks great... +1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is destroy_type_code invoked for every type code which is being created? If yes, I would assume that should be sufficient.

Or are there currently cases where it not invoked yet?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think I just forgot to remove this after a refactoring (hidden due to the squash). I removed it in de87fd8

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants