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

Attempt to eliminate some MSVC /W build warnings. #28

Merged
merged 1 commit into from
Oct 9, 2019

Conversation

KineticTheory
Copy link
Contributor

Summary:

  • Mark some functions inline to avoid multiple definitions error.
  • Change some function signatures to use size_t instead of int
  • Change how escape some codes are represented to avoid build warnings.
  • Be more explicit about casting between different char types.
  • Fixes Fix the links #1

Comments:

  • You might still need to mark more functions inline. When I import your files into my project, I am moving many function implementations into a .cpp file.
  • It looks like my editor re-indented print_rect for me. Sorry about that style change. Have you considered using a .clang-format file to enforce formatting choices?

* Mark some functions `inline` to avoid multiple definitions error.
* Change some function signatures to use `size_t` instead of `int`
* Change how escape some codes are represented to avoid build warnings.
* Be more explicit about casting between different `char` types.
* Fixes jupyter-xeus#1
@KineticTheory KineticTheory added the enhancement New feature or request label Oct 9, 2019
@KineticTheory KineticTheory requested a review from certik October 9, 2019 21:12
@KineticTheory KineticTheory self-assigned this Oct 9, 2019
Copy link
Collaborator

@certik certik left a comment

Choose a reason for hiding this comment

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

Thank you for your fixes. I tested this in Ubuntu and it compiles and the Unicode still works. So I am going to merge this, and I'll send separate PRs trying to tidy that code up a bit per my comments below.

@@ -504,7 +503,7 @@ void codepoint_to_utf8(std::string &s, char32_t c) {
} else {
throw std::runtime_error("Invalid UTF32 codepoint.");
}
char u1, u2, u3, u4;
char32_t u1('x'), u2('x'), u3('x'), u4('x');
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 these need to be char8_t, which should be the same as char.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like 'char` is the correct type. This allows me to remove all of the static_casts. BTW - it looks like char8_t is a C++20 feature and so not available to my project yet.

@@ -513,18 +512,33 @@ void codepoint_to_utf8(std::string &s, char32_t c) {
case 1: u1 = (c | mask[nbytes-1]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

In here we can type it directly to char if it fixes the warnings.

s.push_back(static_cast<char>(u2));
s.push_back(static_cast<char>(u3));
s.push_back(static_cast<char>(u4));
break;
Copy link
Collaborator

@certik certik Oct 9, 2019

Choose a reason for hiding this comment

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

And in here we just need to take the u1, u2, ... and concatenate them at the end of the string s.

I don't like this code, but I couldn't figure out how to do it better. I just got an idea, something like:

idx = s.size();
s.append(std::string(nbytes, "X"))
s[idx] = u1; idx++;
if (nbytes >= 2) { s[idx] = u2; idx++; }
if (nbytes >= 3) { s[idx] = u3; idx++; }
if (nbytes == 4) { s[idx] = u4; }

It still feels ugly, but better than the current version. I'll send a separate PR with this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changing the type of u1,u2,u3,u4 to char allows me to remove all of these casts.

@certik certik merged commit 9042360 into jupyter-xeus:master Oct 9, 2019
@certik
Copy link
Collaborator

certik commented Oct 9, 2019

@KineticTheory I think this fixes #24, not #1, correct?

@certik
Copy link
Collaborator

certik commented Oct 9, 2019

I opened #29 and #30 for the other issues you found.

@KineticTheory
Copy link
Contributor Author

I should have linked to #24 not #1. Sorry. I'll put in another PR with the suggestions you mentioned.

@certik
Copy link
Collaborator

certik commented Oct 10, 2019

Perfect. I also opened #33 to ensure we catch any future warnings regressions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants