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

Fix yaml parser error when meets .nan #741

Closed
wants to merge 9 commits into from

Conversation

Ada-King
Copy link
Contributor

Related issue 555

The problem has examined on my host machine.

Signed-off-by: Ada-King Bingtao.Du@sony.com

Signed-off-by: Ada-King <Bingtao.Du@sony.com>
Signed-off-by: Ada-King <Bingtao.Du@sony.com>
Copy link
Contributor

@clalancette clalancette left a comment

Choose a reason for hiding this comment

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

Besides the inline comment, can you also please add a test for this case? Thanks.

rcl_yaml_param_parser/src/parser.c Outdated Show resolved Hide resolved
Signed-off-by: Ada-King <Bingtao.Du@sony.com>
@Ada-King
Copy link
Contributor Author

Besides the inline comment, can you also please add a test for this case? Thanks.

@Ada-King Ada-King closed this Aug 18, 2020
@Ada-King Ada-King reopened this Aug 18, 2020
@Ada-King
Copy link
Contributor Author

Besides the inline comment, can you also please add a test for this case? Thanks.

Close this by accident... never mind.
The code has been modified according to your suggestion. Please check :)

rcl_yaml_param_parser/src/parser.c Outdated Show resolved Hide resolved
rcl_yaml_param_parser/test/test_parse_yaml.cpp Outdated Show resolved Hide resolved
rcl_yaml_param_parser/test/test_parse_yaml.cpp Outdated Show resolved Hide resolved
rcl_yaml_param_parser/test/test_parse_yaml.cpp Outdated Show resolved Hide resolved
rcl_yaml_param_parser/test/special_float2.yaml Outdated Show resolved Hide resolved
Signed-off-by: Ada-King <Bingtao.Du@sony.com>
Copy link
Contributor

@clalancette clalancette left a comment

Choose a reason for hiding this comment

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

Thanks for iterating on this! This is exactly what I was looking for.

I have a few more minor comments inline, and this also needs to be rebased. Once that happens, I'll run CI on this.

rcl_yaml_param_parser/src/parser.c Outdated Show resolved Hide resolved
rcl_yaml_param_parser/test/special_float.yaml Outdated Show resolved Hide resolved
rcl_yaml_param_parser/test/test_parse_yaml.cpp Outdated Show resolved Hide resolved
rcl_yaml_param_parser/test/test_parse_yaml.cpp Outdated Show resolved Hide resolved
Copy link
Collaborator

@fujitatomoya fujitatomoya left a comment

Choose a reason for hiding this comment

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

LGTM with @clalancette 's comments.

Signed-off-by: Ada-King <Bingtao.Du@sony.com>
Signed-off-by: Ada-King <Bingtao.Du@sony.com>
@Ada-King
Copy link
Contributor Author

Thanks for iterating on this! This is exactly what I was looking for.

I have a few more minor comments inline, and this also needs to be rebased. Once that happens, I'll run CI on this.

I think this is ready to be merged, please has a re-review. Thanks.

Copy link
Contributor

@clalancette clalancette 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 to me. I'm going to approve and run CI on it. Note that this is going to cause merge conflicts with #754 . @brawner FYI, let me know how you'd like to proceed here.

@clalancette
Copy link
Contributor

CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@clalancette
Copy link
Contributor

So, Windows is failing because it doesn't like strcasecmp. I'm not entirely sure how to solve that, but it needs further looking into.

@fujitatomoya
Copy link
Collaborator

what about using stricmp with case insensitivity instead?

@brawner
Copy link
Contributor

brawner commented Aug 20, 2020

It sounds like this PR can be merged as soon as it passes CI. #754 is not blocking anything at the moment, so I'm happy to rebase it on top of this PR.

@clalancette
Copy link
Contributor

It sounds like this PR can be merged as soon as it passes CI. #754 is not blocking anything at the moment, so I'm happy to rebase it on top of this PR.

Sounds good, thanks @brawner

@Ada-King
Copy link
Contributor Author

@clalancette @fujitatomoya
Maybe we can define a macro for the windows platform at the beginning of the parser.c file

#ifdef _WIN32
#define strcasecmp stricmp
#endif

Signed-off-by: Ada-King <Bingtao.Du@sony.com>
Comment on lines 35 to 38
#ifdef _WIN32
#define strcasecmp stricmp
#endif

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that there is no standard case insensitive string compare in C. but I am negative on this, this will cause complication and dependency especially for maintenance. (at least i believe that this is not the right place.) Instead of this, we would create rcutils_strcasecmp based on strcasecmp and stricmp? Any thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I have to agree that it would be nicer to have a rcutils_strcasecmp, rather than putting the compatibility code in here. So I'll suggest a new PR to rcutils to do that (sorry that this is going to drag out a bit longer).

For what it is worth, there are 2 different ways we could go about this. One is that we could define rcutils_strcasecmp based on either strcasecmp or stricmp, as you mention above. The other way to do it is to just implement it ourselves, since it is a pretty easy function:

int rcutils_strcasecmp(const char *s1, const char *s2)
{
  const unsigned char *p1 = (const unsigned char *) s1;
  const unsigned char *p2 = (const unsigned char *) s2;
  int result;

  if (p1 == p2) {
    return 0;
  }

  while ((result = tolower(*p1) - tolower(*p2++)) == 0) {
    if (*p1++ == '\0') {
      break;
    }
  }

  return result;
}

(that code comes from glibc with some minor edits by me). I'm fine with either option, just thought I'd point out that both were available.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@Ada-King

Let's open new PR as discussed here and then get back on this!

One is that we could define rcutils_strcasecmp based on either strcasecmp or stricmp

I am good to with either way, but I personally would prefer this one.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ASSERT_EQ(9U, param_value->double_array_value->size);
EXPECT_TRUE(std::isnan(param_value->double_array_value->values[2]));
EXPECT_TRUE(std::isnan(param_value->double_array_value->values[3]));
EXPECT_TRUE(std::isinf(param_value->double_array_value->values[4]));
Copy link
Collaborator

Choose a reason for hiding this comment

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

@Ada-King

About inf, there are positive infinity and negative infinity.
isinf(x) returns 1 if x is positive infinity, and -1 if x is negative infinity.

Maybe it should be

EXPECT_TRUE(std::isinf(param_value->double_array_value->values[4]) == 1);
EXPECT_TRUE(std::isinf(param_value->double_array_value->values[5]) == -1);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, that make sense

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The type of return value in c++ is bool, so the current test is sufficient.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, It's my bad (not to check the c++ version).
I will use c version isinf to check the result accurately, anyway, it's up to you.

Signed-off-by: Ada-King <Bingtao.Du@sony.com>
@Ada-King
Copy link
Contributor Author

@fujitatomoya
Although the PR is not used here, but i think it's still worth doing.

@clalancette friendly ping
I have modified the code based on above comments, Can you help to merge this :) ?

Signed-off-by: Ada-King <Bingtao.Du@sony.com>
Comment on lines +1110 to +1121
if ((0 == strcmp(value, ".nan")) ||
(0 == strcmp(value, ".NaN")) ||
(0 == strcmp(value, ".NAN")) ||
(0 == strcmp(value, ".inf")) ||
(0 == strcmp(value, ".Inf")) ||
(0 == strcmp(value, ".INF")) ||
(0 == strcmp(value, "+.inf")) ||
(0 == strcmp(value, "+.Inf")) ||
(0 == strcmp(value, "+.INF")) ||
(0 == strcmp(value, "-.inf")) ||
(0 == strcmp(value, "-.Inf")) ||
(0 == strcmp(value, "-.INF")))
Copy link
Contributor

Choose a reason for hiding this comment

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

Once we get ros2/rcutils#280 in, we can change this code to use rcutils_strcasecmp.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Once we get ros2/rcutils#280 in, we can change this code to use rcutils_strcasecmp.

@clalancette
FYI (#741 (comment))
The yaml spec only allows specific formats.

Besides, the existed build error doesn't seem to be caused by this PR.

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 checked it, the build error result from #727, the rcutils dependency has been merged, but build system still based on ros-rolling-rcutils: 1.1.0, which is the problem.

Anyway, this has no effect on this merge process.

@clalancette
Copy link
Contributor

@ros-pull-request-builder retest this please

@brawner
Copy link
Contributor

brawner commented Sep 1, 2020

The refactoring PR #754 was merged in order to make progress on adding in coverage unit tests. Rebasing this PR on master should be fairly straightforward. The modified logic in parser.c has been moved to parse.c and everything else can remain the same. Here is a draft PR with this PR's commits squashed and rebased into a single commit on top of master. Feel free to cherry-pick that commit, or just use it as an example. This logic also passes all the unit tests I'm adding in #771, #766, and #772.

PR with squashed commits rebased onto master
#781

@fujitatomoya
Copy link
Collaborator

@brawner

thanks for opening and rebasing the PR, i will check #781 once again just in case.

@clalancette
Copy link
Contributor

I'm going to close this one out in favor of #781; we can continue the discussion over there.

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

5 participants