Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ssl_options: use std::vector<unsigned char> for the ALPN protocol list in wire format#544

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fpagliughi merged 1 commit intoeclipse-paho:developfromfrwilckens:master
May 15, 2025

Conversation

@frwilckens
Copy link
Contributor

@frwilckensfrwilckens commentedMar 15, 2025
edited
Loading

This change is needed to compile the library with clang/libc++ since version 19.

The library usedstd::basic_string<unsigned char> which requiresstd::char_traits<unsigned char> and is technically not defined by the standard. libc++ no longer supports it as of LLVM 19.

RankoR and benjiwolff reacted with heart emojisikmir reacted with rocket emoji
@frwilckensfrwilckens changed the base branch frommaster todevelopMarch 16, 2025 17:07
…t in wire formatThe library used std::basic_string<unsigned char> which requires std::char_traits<unsigned char> and is technically not defined by the standard. libc++ no longer supports it as of LLVM 19.Signed-off-by: Friedrich Wilckens <frwilckens@gmail.com>

opts_.protos = protos_.data();
opts_.protos_len =unsigned(protos_.length());
opts_.protos_len =unsigned(protos_.size());
Copy link

@RankoRRankoRMar 26, 2025
edited
Loading

Choose a reason for hiding this comment

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

Wouldn'tstatic_cast<unsigned> be better than a C-style cast?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. But in@frwilckens 's defense, this was taken from my code!

Choose a reason for hiding this comment

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

Yep, but I thought it would be good to fix it if we're already changing that lines :)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I agree, this should be changed. I just did not want to distract from the main point.

@fpagliughi
Copy link
Contributor

Argh. This is unfortunate. It's always pained me that the signed-ness ofchar was left undefined.

This is a little painful, as I have often usedbasic_string as a container for binary data. I have a lot of code in a lot of projects that will need to be updated!

The methods for find and replace in the string class are often useful for binary data as well. That probably isn't too helpful for a field or two in the option classes in this library, but I will consider the best thing to do. Using avector is fine for this specific case, but I wonder if it would be useful to just define achar_traits<unsigned char>.

@strega-nil-re
Copy link

Using a vector is fine for this specific case, but I wonder if it would be useful to just define achar_traits<unsigned char>.

This woulddefinitely break user code, I think, and even if it wouldn't it would certainly break the standard library's API.

@frwilckens
Copy link
ContributorAuthor

frwilckens commentedApr 2, 2025
edited
Loading

I'm not a language lawyer but as far as I know a user-defined specializationstd::char_traits<unsigned char> is undefined behavior since it's an explicit specialization of a template defined in namespace std for a type that's not user-defined. You have to use a custom character type likestruct MyChar { unsigned char c_; } if you want to use the benefits of the basic_string template for binary data. See the (rather old) requestn1985 for a discussion of the details involved andhttps://reviews.llvm.org/D138307 for why it is removed from libc++.

strega-nil-re reacted with thumbs up emoji

@fpagliughi
Copy link
Contributor

Hey. Apologies that I'm slammed at work and haven't had much time to jump on this.

I also want to make it clear that the proposed PR, and any number of other solutions would be perfectly adequate to fix the ALPN field inssl_options. I'm just thinking out loud because I have consistently, and successfully, usedbasic_string<unsigned char> as a binary contained in any number of other proprietary and open-source projects. And would like to continue to do so.

First, it always seemed idiotic to me that C++ hassigned char. And thatchar is platform specific. Seriously? I know it was done for performance reasons around computers from the 1970's, but that was 50 years ago!

And now,unsigned char is a valid, standard, C++ character type, but is not supported in the primary character collection?!?!

Ugh.

After looking at a few things, I agree that actuallydefiningstd::char_traits<unsigned char> in a library could be problematic. But you you need to? Or can you just define something that conforms to it? The std one is just the default in thebasic_string template:

template<    class CharT,    class Traits = std::char_traits<CharT>,    class Allocator = std::allocator<CharT>> class basic_string;

Couldn't I just define amy_uchar_traits and use that?

using binary_blob = std::basic_string<unsigned char, my_uchar_traits>;

@laltenlalten mentioned this pull requestApr 5, 2025
@strega-nil-re
Copy link

@fpagliughi

Couldn't I just define a my_uchar_traits and use that?

using binary_blob = std::basic_string<unsigned char, my_uchar_traits>;

You absolutely can, and it's a reasonable thing to do.

@frwilckens
Copy link
ContributorAuthor

I agree, that would work. There is even more wonky stuff written about this topic inp0551r3.pdf, where it says that for a template specialization in namespace std to be fine it needs to have at least one template parameter depend on a user-defined type.

The libc++ authors argue that they can't provide a base implementation of template char_traits because there is none that would work for all parameters. That makes sense but I still don't see a good reason to remove the explicit specialization for unsigned char. I think they could have offered it as a vendor extension, even in light of the above-mentioned paper.

@kuroneko
Copy link

This is now a pressing matter as Apple recently updated XCode and the new release has a clang and libc++ version that barfs on this issue.

@fpagliughifpagliughi merged commit4c7f15d intoeclipse-paho:developMay 15, 2025
1 check passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fpagliughifpagliughifpagliughi left review comments

+1 more reviewer

@RankoRRankoRRankoR left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

5 participants

@frwilckens@fpagliughi@strega-nil-re@kuroneko@RankoR

[8]ページ先頭

©2009-2025 Movatter.jp