[Libwebsockets] wide strings and _lws_log

Andy Green andy at warmcat.com
Tue May 15 01:57:46 CEST 2018



On 05/15/2018 07:33 AM, Andy Green wrote:
> 
> 
> On 05/15/2018 07:21 AM, Alexander Bruines wrote:
>> Hello Andy,
>>
>> Congratulations on the 3.0 release of libwebsockets!
>>
>> I may have discovered a minor issue with _lws_log() when using C++. It 
>> produces errors when printing a std::wstring.
> 
> ... okay... personally I only use utf-8.

Wow this wide char stuff is completely insane :-)

All the apis around character handling get duplicated and you are either 
wholly in the "wide world" or in a NUL-terminated 1-byte char world. 
UTF-8 doesn't need any of that it's firmly in the latter world, even 
though one printable char may consist of multiple in-memory chars 
sequentially.

>> Please consider the following code snippet and the output that 
>> valgrind produces:

What you are actually saying is lws doesn't support wide chars... 
nothing is broken except the crazy wide char ecosystem itself.

If we wanted to support wide char logging, the relevant ingredient is 
"vswprintf_s()" from c11 that produces and consumes wide chars while 
trying to make the result NUL-terminated.

But lws is just C, and just 1-byte char.

If you want to provide patches for an _lws_logw() and a way to select 
that at runtime so it can support wide chars, I'll he happy to look at 
them.  Otherwise, vsnprintf() simply doesn't handle wide chars, so lws 
doesn't.

-Andy



More information about the Libwebsockets mailing list