[cfe-commits] [patch] Expect 16bit type for %S in NSStrings (was Re: r148324)

Jean-Daniel Dupas devlists at shadowlab.org
Tue Jan 31 06:50:17 PST 2012


No, there is not Obj-C equivalent of scanf. 

The main difference between of NSString and printf format is the support of "%@" which represents an Obj-C object.
While it's easy to get a string representation of an obj-c object (using -[NSObject description]), it's not possible to create any object from a string, so having a Obj-C scanf format would not be very useful anyway.

Le 31 janv. 2012 à 15:36, Hans Wennborg a écrit :

> Does ScanfSpecifier::getArgType need an update as well?
> 
> The rest looks good as far as I can tell.
> 
> On Tue, Jan 31, 2012 at 12:27 AM, Nico Weber <thakis at chromium.org> wrote:
>> Better?
>> 
>> On Mon, Jan 30, 2012 at 4:24 PM, Jean-Daniel Dupas
>> <devlists at shadowlab.org> wrote:
>>> 
>>> Le 31 janv. 2012 à 01:10, Nico Weber a écrit :
>>> 
>>>> On Mon, Jan 30, 2012 at 9:46 AM, Sebastian Redl
>>>> <sebastian.redl at getdesigned.at> wrote:
>>>>> 
>>>>> On 30.01.2012, at 18:37, Nico Weber wrote:
>>>>> 
>>>>>> 
>>>>>> The current %S warning implementation is wrong for just printf() as
>>>>>> well: It compares the argument to wchar_t, but if you build your
>>>>>> program with -fshort-wchar, clang won't warn (since your program uses
>>>>>> wchar_t) yet printf won't work (because libc was built without
>>>>>> -fshort-wchar). If you store your characters in an uint32* and pass
>>>>>> that to printf() and build your program with -fshort-wchar, clang will
>>>>>> warn (because uint32* doesn't match wchar_t* with -fshort-whar) yet
>>>>>> the program will work correctly.
>>>>> 
>>>>> And just to make things more fun, Microsoft's printf takes "%S" to mean "UCS-2 string" and wprintf interprets L"%S" as "narrow string".
>>>> 
>>>> wchar_t is always 2 byte in Microsoft land, so -fms-extensions should
>>>> implicitly enable -fshort-wchar, which would take care of the
>>>> Microsoft part.
>>>> 
>>>> The attached patch lets %S, %C, and %ls look for a 16bit type in
>>>> NSStrings as discussed. OK?
>>>> 
>>>> Nico
>>>> <clang-percent-S.patch>
>>> 
>>> 
>>> 
>>>> + // AppKit was built with -fshort-wchar, so passing in 4-byte wchars is a bug.
>>> 
>>> I don't think it is right to say that AppKit was built with "-fshort-wchar".
>>> This is just that the %S modifier is implemented to take a UTF-16 string and not a wchar_t as the lib C does.
>>> 
>>> -- Jean-Daniel
>>> 
>>> 
>>> 
>>> 
>> 
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>> 

-- Jean-Daniel








More information about the cfe-commits mailing list