From owner-freebsd-python@FreeBSD.ORG Thu Jan 26 11:34:06 2012 Return-Path: Delivered-To: python@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9076E1065672; Thu, 26 Jan 2012 11:34:06 +0000 (UTC) (envelope-from theraven@freebsd.org) Received: from theravensnest.org (theravensnest.org [109.169.23.128]) by mx1.freebsd.org (Postfix) with ESMTP id 1A45D8FC14; Thu, 26 Jan 2012 11:34:05 +0000 (UTC) Received: from [192.168.0.2] (cpc1-cwma8-2-0-cust257.7-3.cable.virginmedia.com [82.20.153.2]) (authenticated bits=0) by theravensnest.org (8.14.4/8.14.4) with ESMTP id q0QBXvcv058372 (version=TLSv1/SSLv3 cipher=DHE-DSS-AES128-SHA bits=128 verify=NO); Thu, 26 Jan 2012 11:33:57 GMT (envelope-from theraven@freebsd.org) Mime-Version: 1.0 (Apple Message framework v1251.1) Content-Type: text/plain; charset=us-ascii From: David Chisnall In-Reply-To: Date: Thu, 26 Jan 2012 11:34:00 +0000 Content-Transfer-Encoding: quoted-printable Message-Id: <3B3BEEED-D1E4-4329-BE34-5CFF5CABB52C@freebsd.org> References: <4F1AAA75.5050500@FreeBSD.org> <20120122192526.GA52071@zim.MIT.EDU> <9F9CC3ED-0686-4BC5-BF01-1839A30ABA9C@FreeBSD.ORG> <4F206B5D.3080302@FreeBSD.org> To: Eitan Adler X-Mailer: Apple Mail (2.1251.1) Cc: David Schultz , freebsd-standards@freebsd.org, python@freebsd.org, Andriy Gapon , gogo@cs.uni-sb.de Subject: Re: pyconfig.h and freebsd10: _POSIX_C_SOURCE and _XOPEN_SOURCE X-BeenThere: freebsd-python@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD-specific Python issues List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Jan 2012 11:34:06 -0000 On 26 Jan 2012, at 04:47, Eitan Adler wrote: > On Wed, Jan 25, 2012 at 3:51 PM, Andriy Gapon wrote: >> on 25/01/2012 15:23 David Chisnall said the following: >>> On 22 Jan 2012, at 19:25, David Schultz wrote: >>>> Technically it's a problem with python. If you ask for a strict >>>> POSIX environment (doesn't matter what version) and also #include >>>> a non-POSIX header, there's no guarantee about what you'll get. >>>> I've CC'd the xlocale author in case he wants to comment or >>>> voluntarily make xlocale work in an otherwise strict POSIX >>>> environment, but that's not officially supported. >>>=20 >>> The problem is really with glibc, which uses these macros in the = opposite way to everyone else (glibc thinks defining these macros means = expose functionality from this standard, don't expose it otherwise, = everyone else thinks they mean expose only the things defined by this = standard). This makes writing portable code a pain and, while I'd = usually be keen to blame Python for everything, in this case I = sympathise with their problem. >>=20 >> Thank you for the insights. >>=20 >>> Would defining locale_t and the related functions in xlocale.h if we = are in a mode where they are not normally exposed fix the problem? >>=20 >> I think that this should work. >=20 > What about patching python to only define the POSIX macros iff glibc > is being used (and getting this upstreamed) ? That would be ideal, but I'd prefer that we did anything that we can = within the standard to ensure that people who do silly thing that work = on other platforms don't end up saying 'FreeBSD sucks!' because of their = code. Please can you someone verify that this patch fixes the problem? =20= David Index: include/locale.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- include/locale.h (revision 230510) +++ include/locale.h (working copy) @@ -79,7 +79,8 @@ char *setlocale(int, const char *); __END_DECLS =20 -#if __POSIX_VISIBLE >=3D 200809 +#if __POSIX_VISIBLE >=3D 200809 && !defined(__X_LOCALE_DEFINED) +#define __X_LOCALE_DEFINED =20 #define LC_COLLATE_MASK (1<<0) #define LC_CTYPE_MASK (1<<1) Index: include/xlocale.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- include/xlocale.h (revision 230510) +++ include/xlocale.h (working copy) @@ -35,7 +35,33 @@ #include =20 __BEGIN_DECLS +/* + * If people turned off POSIX2008 stuff, but still explicitly included = the + * xlocale.h header, then assume that they actually do want these = functions and + * define them. + */ +#ifndef __X_LOCALE_DEFINED +#define __X_LOCALE_DEFINED =20 +#define LC_COLLATE_MASK (1<<0) +#define LC_CTYPE_MASK (1<<1) +#define LC_MESSAGES_MASK (1<<2) +#define LC_MONETARY_MASK (1<<3) +#define LC_NUMERIC_MASK (1<<4) +#define LC_TIME_MASK (1<<5) +#define LC_ALL_MASK (LC_COLLATE_MASK | LC_CTYPE_MASK | = LC_MESSAGES_MASK | \ + LC_MONETARY_MASK | LC_NUMERIC_MASK | LC_TIME_MASK) +#define LC_GLOBAL_LOCALE ((locale_t)-1) + +typedef struct _xlocale *locale_t; +locale_t newlocale(int mask, const char *locale, locale_t base); +locale_t duplocale(locale_t base); +int freelocale(locale_t loc); +const char *querylocale(int mask, locale_t loc); +locale_t uselocale(locale_t loc); + +#endif /* __X_LOCALE_DEFINED */ + /* * Extended locale versions of the locale-aware functions from = string.h. *