diff mbox

Sync up loadmsgcat.c with gettext

Message ID 20140702194959.GS20796@spoyarek.pnq.redhat.com
State New
Headers show

Commit Message

Siddhesh Poyarekar July 2, 2014, 7:50 p.m. UTC
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.

Comments

Roland McGrath July 2, 2014, 7:55 p.m. UTC | #1
> +#ifdef _LIBC
> +# ifndef PRI_MACROS_BROKEN
> +#  define PRI_MACROS_BROKEN 0
> +# endif
>  #endif

Nothing in libc defines this or ever will (or should).
So drop the ifndef.

Looks fine with that change.


Thanks,
Roland
diff mbox

Patch

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 <alloca.h>
+# ifdef _MSC_VER
+#  include <malloc.h>
+#  define alloca _alloca
 # else
-#  ifdef _AIX
- #pragma alloca
+#  if defined HAVE_ALLOCA_H || defined _LIBC
+#   include <alloca.h>
 #  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 <not-cancel.h>
+#endif
+
+/* Handle multi-threaded applications.  */
+#ifdef _LIBC
 # include <bits/libc-lock.h>
+#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 <inttypes.h>.
@@ -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 <fcntl.h>. */
+#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);
 }