Skip to content
This repository was archived by the owner on May 31, 2025. It is now read-only.

Use functions instead of macros where possible to avoid leaking variables - #835

Merged
dirk-thomas merged 1 commit into
ros:kinetic-develfrom
ksperling:leaking-variables
Jan 27, 2017
Merged

dirk-thomas merged 1 commit into
ros:kinetic-develfrom
ksperling:leaking-variables

Conversation

@ksperling

Copy link
Copy Markdown
Contributor

My primary reason for this PR is the first commit that makes list_insert_in_workspace_order a function, as it leaks a variable called cmd which triggers a bug in ExternalProject_Add (the value of the cmd variable becomes the default BUILD and INSTALL command for the external project, so order_paths.py just gets run a couple more times instead of actually building anything).

I filed a PR for CMake to fix this (https://gitlab.kitware.com/cmake/cmake/merge_requests/264), but I think it would be good to also fix this on the catkin side regardless. In general it seems to me using functions instead of macros wherever possible is desirable to avoid polluting the caller's variable namespace, but I'm by no means a CMake expert.

All tests still seem to pass (and my projects still build, and ExternalProject_Add works as expected)

@ksperling

Copy link
Copy Markdown
Contributor Author

Bump?

@dirk-thomas

Copy link
Copy Markdown
Member

Sorry for not responding on this before. I currently have to focus on ROS 2 related tasks. Hopefully I will have time to look at this in the next weeks.

@ksperling

Copy link
Copy Markdown
Contributor Author

Thanks for the update :)

Comment thread cmake/catkin_libraries.cmake Outdated
math(EXPR _index "${_index} + 1")
endwhile()
set(${VAR} "${result}" PARENT_SCOPE)
debug_message(10 "catkin_filter_libraries_for_build_configuration(${VAR} ${ARG_UNPARSED_ARGUMENTS} BUILD_TYPE ${ARG_BUILD_TYPE}) ${${VAR}}")

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.

Does ${${VAR}} work in this context? Does it get the updated value set in the parent scope in the line above?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Indeed it doesn't see the updated value, good catch. Seems like the child scope starts out with a copy of the parent scope at the start of the function, rather than dynamically inheriting any variables not present locally.

Comment thread cmake/catkin_libraries.cmake Outdated
set(result "")
foreach(lib ${ARGN})
string(REGEX REPLACE "^(debug|optimized|general)${CATKIN_BUILD_CONFIGURATION_KEYWORD_SEPARATOR}(.+)$" "\\1;\\2" lib "${lib}")
list(APPEND ${VAR} "${lib}")

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.

This should append to result.

@ksperling

Copy link
Copy Markdown
Contributor Author

Thanks for the review, I've addressed those two issues in the last commit. Let me know if you want me to squash everything into 1 commit.

Comment thread cmake/catkin_libraries.cmake Outdated
math(EXPR _index "${_index} + 1")
endwhile()
set(${VAR} "${result}" PARENT_SCOPE)
#debug_message(10 "catkin_pack_libraries_with_build_configuration(${VAR} ${_argn}) ${${VAR}}")

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.

Just to be safe if someone enables this line in the future can you also update it to use ${result} instead of ${${VAR}}.

Comment thread cmake/catkin_libraries.cmake Outdated
endforeach()
set(${VAR} "${result}" PARENT_SCOPE)
#set(_argn ${ARGN})
#debug_message(10 "catkin_replace_imported_library_targets(${VAR} ${_argn}) ${${VAR}}")

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.

Just to be safe if someone enables this line in the future can you also update it to use ${result} instead of ${${VAR}}.

@dirk-thomas

Copy link
Copy Markdown
Member

Thanks for iterating on this. I added two more comments inline.

If you can squash the commits afterwards that would be great. Otherwise I can take care of it during the merge.

…al variables.

The leaked 'cmd' variable in particular triggers a bug in cmake's ExternalProject_Add,
see https://gitlab.kitware.com/cmake/cmake/merge_requests/264

Also replace other macros with functions where possible.
@ksperling

Copy link
Copy Markdown
Contributor Author

Should all be tidied up now.

@dirk-thomas

dirk-thomas commented Jan 26, 2017 •

Copy link
Copy Markdown
Member

Thanks for the update. It looks good to me. I ran a prerelease test locally with 100+ packages to convince myself that the chance for regressions is minimal. Lets hope the next release builds "agree" with that 😉

@ros/ros_team Please review.

@wjwwood wjwwood left a comment

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.

lgtm

@dirk-thomas
dirk-thomas merged commit 5cd8c81 into ros:kinetic-devel Jan 27, 2017
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.

3 participants