From patchwork Wed Jul 2 19:50:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 1859 Received: (qmail 14061 invoked by alias); 2 Jul 2014 19:48:51 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 13976 invoked by uid 89); 2 Jul 2014 19:48:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.5 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Date: Thu, 3 Jul 2014 01:20:00 +0530 From: Siddhesh Poyarekar To: libc-alpha@sourceware.org Subject: [PATCH] Sync up loadmsgcat.c with gettext Message-ID: <20140702194959.GS20796@spoyarek.pnq.redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.22.1-rc1 (2013-10-16) Hi, This patch is one part of the sync-up of loadmsgcat.c between gettext and glibc. I have posted the other part (i.e. changes to the gettext version) on the bug-gettext mailing list, but it is not showing up in the archives yet. The changes in this sync up are: - Bunch of macro jugglery does not affect glibc - Definition of PRI_MACROS_BROKEN that fixes its Wundef warning - Open domain_file in binary mode - Avoid use of the GNU-specific TEMP_FAILURE_RETRY. This was a deliberate change in glibc, but I thought reverting it here would be a good idea to keep these sources free of GNU extensions. - Cast alloca return to build with C++ compilers I have done a build and check run on x86_64 to verify that this does not break anything. I will follow up with the gettext folks on their end of the changes. Siddhesh Sync up with gettext. * intl/loadmsgcat.c: Define O_BINARY if not defined. [_MSC_VER]: Include malloc.h [_LIBC]: Define PRI_MACROS_BROKEN if it is not defined. (get_sysdep_segment_value) [!__UCLIBC__]: Return "I" flag. (_nl_load_domain): Open DOMAIN_FILE in binary mode. Don't use TEMP_FAILURE_RETRY. Cast return of alloca. [!_LIBC] Call gl_rwlock_init. [IN_LIBGLOCALE]: Call _nl_find_msg with one less argument. diff --git a/intl/loadmsgcat.c b/intl/loadmsgcat.c index 7497172..cce55b6 100644 --- a/intl/loadmsgcat.c +++ b/intl/loadmsgcat.c @@ -39,14 +39,19 @@ # define alloca __builtin_alloca # define HAVE_ALLOCA 1 #else -# if defined HAVE_ALLOCA_H || defined _LIBC -# include +# ifdef _MSC_VER +# include +# define alloca _alloca # else -# ifdef _AIX - #pragma alloca +# if defined HAVE_ALLOCA_H || defined _LIBC +# include # else -# ifndef alloca +# ifdef _AIX + #pragma alloca +# else +# ifndef alloca char *alloca (); +# endif # endif # endif # endif @@ -88,7 +93,19 @@ char *alloca (); #ifdef _LIBC # include "../locale/localeinfo.h" # include +#endif + +/* Handle multi-threaded applications. */ +#ifdef _LIBC # include +#else +# include "lock.h" +#endif + +#ifdef _LIBC +# ifndef PRI_MACROS_BROKEN +# define PRI_MACROS_BROKEN 0 +# endif #endif /* Provide fallback values for macros that ought to be defined in . @@ -472,6 +489,24 @@ char *alloca (); # define freea(p) free (p) #endif +/* For systems that distinguish between text and binary I/O. + O_BINARY is usually declared in . */ +#if !defined O_BINARY && defined _O_BINARY + /* For MSC-compatible compilers. */ +# define O_BINARY _O_BINARY +# define O_TEXT _O_TEXT +#endif +#ifdef __BEOS__ + /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect. */ +# undef O_BINARY +# undef O_TEXT +#endif +/* On reasonable systems, binary I/O is the default. */ +#ifndef O_BINARY +# define O_BINARY 0 +#endif + + /* We need a sign, whether a new catalog was loaded, which can be associated with all translations. This is important if the translations are cached by one of GCC's features. */ @@ -732,10 +767,12 @@ get_sysdep_segment_value (const char *name) /* Test for a glibc specific printf() format directive flag. */ if (name[0] == 'I' && name[1] == '\0') { -#if defined _LIBC || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) +#if defined _LIBC \ + || ((__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)) \ + && !defined __UCLIBC__) /* The 'I' flag, in numeric format directives, replaces ASCII digits with the 'outdigits' defined in the LC_CTYPE locale facet. This is - used for Farsi (Persian) and maybe Arabic. */ + used for Farsi (Persian), some Indic languages, and maybe Arabic. */ return "I"; #else return ""; @@ -779,8 +816,7 @@ _nl_load_domain (struct loaded_l10nfile *domain_file, Not necessary anymore since if the lock is available this is finished. */ - __libc_lock_unlock_recursive (lock); - return; + goto done; } domain_file->decided = -1; @@ -798,7 +834,7 @@ _nl_load_domain (struct loaded_l10nfile *domain_file, goto out; /* Try to open the addressed file. */ - fd = open (domain_file->filename, O_RDONLY); + fd = open (domain_file->filename, O_RDONLY | O_BINARY); if (fd == -1) goto out; @@ -846,11 +882,15 @@ _nl_load_domain (struct loaded_l10nfile *domain_file, read_ptr = (char *) data; do { - long int nb = (long int) TEMP_FAILURE_RETRY (read (fd, read_ptr, - to_read)); + long int nb = (long int) read (fd, read_ptr, to_read); if (nb <= 0) - goto out; - + { +#ifdef EINTR + if (nb == -1 && errno == EINTR) + continue; +#endif + goto out; + } read_ptr += nb; to_read -= nb; } @@ -947,6 +987,7 @@ _nl_load_domain (struct loaded_l10nfile *domain_file, ((char *) data + W (domain->must_swap, data->sysdep_segments_offset)); sysdep_segment_values = + (const char **) alloca (n_sysdep_segments * sizeof (const char *)); for (i = 0; i < n_sysdep_segments; i++) { @@ -1244,13 +1285,24 @@ _nl_load_domain (struct loaded_l10nfile *domain_file, /* No caches of converted translations so far. */ domain->conversions = NULL; domain->nconversions = 0; +#ifdef _LIBC __libc_rwlock_init (domain->conversions_lock); +#else + gl_rwlock_init (domain->conversions_lock); +#endif /* Get the header entry and look for a plural specification. */ +#ifdef IN_LIBGLOCALE + nullentry = + _nl_find_msg (domain_file, domainbinding, NULL, "", &nullentrylen); +#else nullentry = _nl_find_msg (domain_file, domainbinding, "", 0, &nullentrylen); +#endif if (__builtin_expect (nullentry == (char *) -1, 0)) { +#ifdef _LIBC __libc_rwlock_fini (domain->conversions_lock); +#endif goto invalid; } EXTRACT_PLURAL_EXPRESSION (nullentry, &domain->plural, &domain->nplurals); @@ -1261,6 +1313,7 @@ _nl_load_domain (struct loaded_l10nfile *domain_file, domain_file->decided = 1; + done: __libc_lock_unlock_recursive (lock); }