discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug in +[NSError _lastError] ?


From: Eric Wasylishen
Subject: Re: Bug in +[NSError _lastError] ?
Date: Wed, 29 Feb 2012 11:12:38 -0700

Sounds to me like the mistake is that we define _GNU_SOURCE globally in 
Source/config.h, activating the standards-breaking definitions of some posix 
functions such as this one.

On 2012-02-29, at 3:38 AM, David Chisnall wrote:

> Note that this will break on any non-GNU platform, where the standards are 
> actually implemented even if _GNU_SOURCE is defined.  The correct test is 
> probably #if __GNU__ or __glibc__.  I think in Étoilé we have a 
> __drepper_can_not_read_standards__ macro for cases like this.
> 
> David
> 
> On 29 Feb 2012, at 00:56, Jens Alfke wrote:
> 
>> 
>> On Feb 28, 2012, at 4:43 PM, I wrote:
>> 
>>> I’m not sure what the best way is to fix this. It looks like one could 
>>> either add
>>>     #undef _GNU_SOURCE
>>> near the top of the file where it defines _XOPEN_SOURCE; or one could use 
>>> an #if around the call to strerror_r to call either version depending on 
>>> which one is available.
>>> 
>>> For now I’m going to try the first option since it’s simpler.
>> 
>> That didn’t work, because “common.h” both defines _GNU_SOURCE and ends up 
>> including <string.h> so the GNU version of strerror_r is already declared. 
>> So I went with the second option, which was pretty easy.
>> 
>> I’ll get around to formally submitting a patch once I’ve got more stuff 
>> working, but here’s a diff showing what I did:
>> 
>> Index: Source/Additions/NSError+GNUstepBase.m
>> ===================================================================
>> --- Source/Additions/NSError+GNUstepBase.m   (revision 34837)
>> +++ Source/Additions/NSError+GNUstepBase.m   (working copy)
>> @@ -130,12 +130,17 @@
>> 
>>  /* FIXME ... not all are POSIX, should we use NSMachErrorDomain for some? */
>>  domain = NSPOSIXErrorDomain;
>> +#if _GNU_SOURCE
>> +  message = [NSString stringWithCString: strerror_r(code, buf, BUFSIZ)
>> +                           encoding: [NSString defaultCStringEncoding]];
>> +#else
>>  if (strerror_r(code, buf, BUFSIZ) < 0)
>>    {
>>      snprintf(buf, sizeof(buf), "%ld", code);
>>    }
>>  message = [NSString stringWithCString: buf
>>                             encoding: [NSString defaultCStringEncoding]];
>> +#endif
>>  /* FIXME ... can we do better localisation? */
>>  info = [NSMutableDictionary dictionaryWithObjectsAndKeys:
>>    message, NSLocalizedDescriptionKey,
>> 
>> 
>> 
>> _______________________________________________
>> Discuss-gnustep mailing list
>> Discuss-gnustep@gnu.org
>> https://lists.gnu.org/mailman/listinfo/discuss-gnustep
> 
> -- Send from my Jacquard Loom
> 
> 
> _______________________________________________
> Discuss-gnustep mailing list
> Discuss-gnustep@gnu.org
> https://lists.gnu.org/mailman/listinfo/discuss-gnustep




reply via email to

[Prev in Thread] Current Thread [Next in Thread]