[git] GnuPG - branch, master, updated. gnupg-2.1.0beta3-399-g8416c87

by Werner Koch cvs at cvs.gnupg.org
Wed Apr 30 21:14:20 CEST 2014


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU Privacy Guard".

The branch, master has been updated
       via  8416c875a729426eae05ed1ca9f1ebcb933c246a (commit)
       via  ecea94461ed40f3f6ef662c2501e1d56ec284022 (commit)
       via  aeb81727c77dfea3bf5d2d689ffbdc897f2938a7 (commit)
       via  39e91a5f0a666aad2fef7a840b2cd03949bb1be4 (commit)
       via  7296ccf3d51a5672708a43923b0bf71871c04bd6 (commit)
       via  7adeae3ba3488a9ada6caab17572f0ac6a639c6e (commit)
      from  21dab64030c95a909767bf6d8f99e8476f9df8a2 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 8416c875a729426eae05ed1ca9f1ebcb933c246a
Author: Werner Koch <wk at gnupg.org>
Date:   Tue Apr 15 16:40:48 2014 +0200

    estream: Implement "samethread" mode keyword.
    
    * src/estream.c (estream_internal): Add field SAMETHREAD.
    (init_stream_lock, lock_stream, trylock_stream, unlock_stream): Use it.
    (parse_mode): Add arg SAMETHREAD and parse that keyword.
    (es_initialize): Rename to ...
    (init_stream_obj): this.  Add arg SAMETHREAD.
    (es_create): Add arg SAMETHREAD.  Call init_stream_lock after
    init_stream_obj.
    (doreadline): Call es_create with samethread flag.
    (es_fopen, es_mopen, es_fopenmem, es_fopencookie, do_fdopen)
    (do_fpopen, do_w32open): Implement "samethread" keyword.
    (es_freopen): Take samthread flag from old stream.
    (es_tmpfile): Call es)_create w/o samethread.
    --
    
    Note: Unfortunately es_tmpfile has no mode arg so that we can't use
    samethread.

diff --git a/common/estream.c b/common/estream.c
index a20d6d4..34726a3 100644
--- a/common/estream.c
+++ b/common/estream.c
@@ -1,5 +1,6 @@
 /* estream.c - Extended Stream I/O Library
- * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2011 g10 Code GmbH
+ * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2011,
+ *               2014 g10 Code GmbH
  *
  * This file is part of Libestream.
  *
@@ -221,6 +222,7 @@ struct estream_internal
   unsigned int is_stdstream:1;   /* This is a standard stream.  */
   unsigned int stdstream_fd:2;   /* 0, 1 or 2 for a standard stream.  */
   unsigned int printable_fname_inuse: 1;  /* es_fname_get has been used.  */
+  unsigned int samethread: 1;    /* The "samethread" mode keyword.  */
   size_t print_ntotal;           /* Bytes written from in print_writer. */
   notify_list_t onclose;         /* On close notify function list.  */
 };
@@ -359,9 +361,14 @@ init_stream_lock (estream_t ES__RESTRICT stream)
 #ifdef HAVE_NPTH
   int rc;
 
-  dbg_lock_1 ("enter init_stream_lock for %p\n", stream);
-  rc = npth_mutex_init (&stream->intern->lock, NULL);
-  dbg_lock_2 ("leave init_stream_lock for %p: rc=%d\n", stream, rc);
+  if (!stream->intern->samethread)
+    {
+      dbg_lock_1 ("enter init_stream_lock for %p\n", stream);
+      rc = npth_mutex_init (&stream->intern->lock, NULL);
+      dbg_lock_2 ("leave init_stream_lock for %p: rc=%d\n", stream, rc);
+    }
+  else
+    rc = 0;
   return rc;
 #else
   (void)stream;
@@ -374,9 +381,12 @@ static void
 lock_stream (estream_t ES__RESTRICT stream)
 {
 #ifdef HAVE_NPTH
-  dbg_lock_1 ("enter lock_stream for %p\n", stream);
-  npth_mutex_lock (&stream->intern->lock);
-  dbg_lock_1 ("leave lock_stream for %p\n", stream);
+  if (!stream->intern->samethread)
+    {
+      dbg_lock_1 ("enter lock_stream for %p\n", stream);
+      npth_mutex_lock (&stream->intern->lock);
+      dbg_lock_1 ("leave lock_stream for %p\n", stream);
+    }
 #else
   (void)stream;
 #endif
@@ -389,9 +399,14 @@ trylock_stream (estream_t ES__RESTRICT stream)
 #ifdef HAVE_NPTH
   int rc;
 
-  dbg_lock_1 ("enter trylock_stream for %p\n", stream);
-  rc = npth_mutex_trylock (&stream->intern->lock)? 0 : -1;
-  dbg_lock_2 ("leave trylock_stream for %p: rc=%d\n", stream, rc);
+  if (!stream->intern->samethread)
+    {
+      dbg_lock_1 ("enter trylock_stream for %p\n", stream);
+      rc = npth_mutex_trylock (&stream->intern->lock)? 0 : -1;
+      dbg_lock_2 ("leave trylock_stream for %p: rc=%d\n", stream, rc);
+    }
+  else
+    rc = 0;
   return rc;
 #else
   (void)stream;
@@ -404,9 +419,12 @@ static void
 unlock_stream (estream_t ES__RESTRICT stream)
 {
 #ifdef HAVE_NPTH
-  dbg_lock_1 ("enter unlock_stream for %p\n", stream);
-  npth_mutex_unlock (&stream->intern->lock);
-  dbg_lock_1 ("leave unlock_stream for %p\n", stream);
+  if (!stream->intern->samethread)
+    {
+      dbg_lock_1 ("enter unlock_stream for %p\n", stream);
+      npth_mutex_unlock (&stream->intern->lock);
+      dbg_lock_1 ("leave unlock_stream for %p\n", stream);
+    }
 #else
   (void)stream;
 #endif
@@ -1478,29 +1496,40 @@ func_file_create (void **cookie, int *filedes,
    defined mode flags keyword parameters are supported.  These are
    key/value pairs delimited by comma and optional white spaces.
    Keywords and values may not contain a comma or white space; unknown
-   keyword are skipped.  The only supported keyword is mode; for
-   example:
+   keywords are skipped. Supported keywords are:
+
+   mode=<string>
+
+      Creates a file and gives the new file read and write permissions
+      for the user and read permission for the group.  The format of
+      the string is the same as shown by the -l option of the ls(1)
+      command.  However the first letter must be a dash and it is
+      allowed to leave out trailing dashes.  If this keyword parameter
+      is not given the default mode for creating files is "-rw-rw-r--"
+      (664).  Note that the system still applies the current umask to
+      the mode when crating a file.  Example:
+
+         "wb,mode=-rw-r--"
+
+   samethread
 
-     "wb,mode=-rw-r--"
+      Assumes that the object is only used by the creating thread and
+      disables any internal locking.  This keyword is also found on
+      IBM systems.
 
-   Creates a file and gives the new file read and write permissions
-   for the user and read permission for the group.  The format of the
-   string is the same as shown by the -l option of the ls(1) command.
-   However the first letter must be a dash and it is allowed to leave
-   out trailing dashes.  If this keyword parameter is not given the
-   default mode for creating files is "-rw-rw-r--" (664).  Note that
-   the system still applies the current umask to the mode when crating
-   a file.
 
    Note: R_CMODE is optional because is only required by functions
    which are able to creat a file.  */
 static int
 parse_mode (const char *modestr,
-            unsigned int *modeflags, unsigned int *r_cmode)
+            unsigned int *modeflags, int *samethread,
+            unsigned int *r_cmode)
 {
   unsigned int omode, oflags, cmode;
   int got_cmode = 0;
 
+  *samethread = 0;
+
   switch (*modestr)
     {
     case 'r':
@@ -1573,6 +1602,16 @@ parse_mode (const char *modestr,
               return -1;
             }
         }
+      else if (!strncmp (modestr, "samethread", 10))
+        {
+          modestr += 10;
+          if (*modestr && !strchr (" \t,", *modestr))
+            {
+              _set_errno (EINVAL);
+              return -1;
+            }
+          *samethread = 1;
+        }
     }
   if (!got_cmode)
     cmode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
@@ -1712,10 +1751,10 @@ es_empty (estream_t stream)
 
 /* Initialize STREAM.  */
 static void
-es_initialize (estream_t stream,
-	       void *cookie, es_syshd_t *syshd,
-               es_cookie_io_functions_t functions,
-               unsigned int modeflags)
+init_stream_obj (estream_t stream,
+                 void *cookie, es_syshd_t *syshd,
+                 es_cookie_io_functions_t functions,
+                 unsigned int modeflags, int samethread)
 {
   stream->intern->cookie = cookie;
   stream->intern->opaque = NULL;
@@ -1735,6 +1774,7 @@ es_initialize (estream_t stream,
   stream->intern->deallocate_buffer = 0;
   stream->intern->printable_fname = NULL;
   stream->intern->printable_fname_inuse = 0;
+  stream->intern->samethread = !!samethread;
   stream->intern->onclose = NULL;
 
   stream->data_len = 0;
@@ -1784,7 +1824,7 @@ es_deinitialize (estream_t stream)
 static int
 es_create (estream_t *stream, void *cookie, es_syshd_t *syshd,
 	   es_cookie_io_functions_t functions, unsigned int modeflags,
-           int with_locked_list)
+           int samethread, int with_locked_list)
 {
   estream_internal_t stream_internal_new;
   estream_t stream_new;
@@ -1813,8 +1853,8 @@ es_create (estream_t *stream, void *cookie, es_syshd_t *syshd,
   stream_new->unread_buffer_size = sizeof (stream_internal_new->unread_buffer);
   stream_new->intern = stream_internal_new;
 
+  init_stream_obj (stream_new, cookie, syshd, functions, modeflags, samethread);
   init_stream_lock (stream_new);
-  es_initialize (stream_new, cookie, syshd, functions, modeflags);
 
   err = do_list_add (stream_new, with_locked_list);
   if (err)
@@ -2406,7 +2446,7 @@ doreadline (estream_t ES__RESTRICT stream, size_t max_length,
 
   memset (&syshd, 0, sizeof syshd);
   err = es_create (&line_stream, line_stream_cookie, &syshd,
-		   estream_functions_mem, O_RDWR, 0);
+		   estream_functions_mem, O_RDWR, 1, 0);
   if (err)
     goto out;
 
@@ -2667,7 +2707,7 @@ estream_t
 es_fopen (const char *ES__RESTRICT path, const char *ES__RESTRICT mode)
 {
   unsigned int modeflags, cmode;
-  int create_called;
+  int samethread, create_called;
   estream_t stream;
   void *cookie;
   int err;
@@ -2678,7 +2718,7 @@ es_fopen (const char *ES__RESTRICT path, const char *ES__RESTRICT mode)
   cookie = NULL;
   create_called = 0;
 
-  err = parse_mode (mode, &modeflags, &cmode);
+  err = parse_mode (mode, &modeflags, &samethread, &cmode);
   if (err)
     goto out;
 
@@ -2690,7 +2730,8 @@ es_fopen (const char *ES__RESTRICT path, const char *ES__RESTRICT mode)
   syshd.u.fd = fd;
 
   create_called = 1;
-  err = es_create (&stream, cookie, &syshd, estream_functions_fd, modeflags, 0);
+  err = es_create (&stream, cookie, &syshd, estream_functions_fd, modeflags,
+                   samethread, 0);
   if (err)
     goto out;
 
@@ -2731,10 +2772,11 @@ es_mopen (void *ES__RESTRICT data, size_t data_n, size_t data_len,
   estream_t stream = NULL;
   void *cookie = NULL;
   unsigned int modeflags;
+  int samethread;
   int err;
   es_syshd_t syshd;
 
-  err = parse_mode (mode, &modeflags, NULL);
+  err = parse_mode (mode, &modeflags, &samethread, NULL);
   if (err)
     goto out;
 
@@ -2747,7 +2789,7 @@ es_mopen (void *ES__RESTRICT data, size_t data_n, size_t data_len,
   memset (&syshd, 0, sizeof syshd);
   create_called = 1;
   err = es_create (&stream, cookie, &syshd,
-                   estream_functions_mem, modeflags, 0);
+                   estream_functions_mem, modeflags, samethread, 0);
 
  out:
 
@@ -2763,13 +2805,14 @@ estream_t
 es_fopenmem (size_t memlimit, const char *ES__RESTRICT mode)
 {
   unsigned int modeflags;
+  int samethread;
   estream_t stream = NULL;
   void *cookie = NULL;
   es_syshd_t syshd;
 
   /* Memory streams are always read/write.  We use MODE only to get
      the append flag.  */
-  if (parse_mode (mode, &modeflags, NULL))
+  if (parse_mode (mode, &modeflags, &samethread, NULL))
     return NULL;
   modeflags |= O_RDWR;
 
@@ -2780,7 +2823,8 @@ es_fopenmem (size_t memlimit, const char *ES__RESTRICT mode)
     return NULL;
 
   memset (&syshd, 0, sizeof syshd);
-  if (es_create (&stream, cookie, &syshd, estream_functions_mem, modeflags, 0))
+  if (es_create (&stream, cookie, &syshd, estream_functions_mem, modeflags,
+                 samethread, 0))
     (*estream_functions_mem.func_close) (cookie);
 
   if (stream)
@@ -2830,6 +2874,7 @@ es_fopencookie (void *ES__RESTRICT cookie,
 		es_cookie_io_functions_t functions)
 {
   unsigned int modeflags;
+  int samethread;
   estream_t stream;
   int err;
   es_syshd_t syshd;
@@ -2837,12 +2882,13 @@ es_fopencookie (void *ES__RESTRICT cookie,
   stream = NULL;
   modeflags = 0;
 
-  err = parse_mode (mode, &modeflags, NULL);
+  err = parse_mode (mode, &modeflags, &samethread, NULL);
   if (err)
     goto out;
 
   memset (&syshd, 0, sizeof syshd);
-  err = es_create (&stream, cookie, &syshd, functions, modeflags, 0);
+  err = es_create (&stream, cookie, &syshd, functions, modeflags,
+                   samethread, 0);
   if (err)
     goto out;
 
@@ -2856,7 +2902,7 @@ estream_t
 do_fdopen (int filedes, const char *mode, int no_close, int with_locked_list)
 {
   unsigned int modeflags;
-  int create_called;
+  int samethread, create_called;
   estream_t stream;
   void *cookie;
   int err;
@@ -2866,7 +2912,7 @@ do_fdopen (int filedes, const char *mode, int no_close, int with_locked_list)
   cookie = NULL;
   create_called = 0;
 
-  err = parse_mode (mode, &modeflags, NULL);
+  err = parse_mode (mode, &modeflags, &samethread, NULL);
   if (err)
     goto out;
 
@@ -2878,7 +2924,7 @@ do_fdopen (int filedes, const char *mode, int no_close, int with_locked_list)
   syshd.u.fd = filedes;
   create_called = 1;
   err = es_create (&stream, cookie, &syshd, estream_functions_fd,
-                   modeflags, with_locked_list);
+                   modeflags, samethread, with_locked_list);
 
  out:
   if (err && create_called)
@@ -2906,7 +2952,7 @@ estream_t
 do_fpopen (FILE *fp, const char *mode, int no_close, int with_locked_list)
 {
   unsigned int modeflags, cmode;
-  int create_called;
+  int samethread, create_called;
   estream_t stream;
   void *cookie;
   int err;
@@ -2916,7 +2962,7 @@ do_fpopen (FILE *fp, const char *mode, int no_close, int with_locked_list)
   cookie = NULL;
   create_called = 0;
 
-  err = parse_mode (mode, &modeflags, &cmode);
+  err = parse_mode (mode, &modeflags, &samethread, &cmode);
   if (err)
     goto out;
 
@@ -2930,7 +2976,7 @@ do_fpopen (FILE *fp, const char *mode, int no_close, int with_locked_list)
   syshd.u.fd = fp? fileno (fp): -1;
   create_called = 1;
   err = es_create (&stream, cookie, &syshd, estream_functions_fp,
-                   modeflags, with_locked_list);
+                   modeflags, samethread, with_locked_list);
 
  out:
 
@@ -2971,13 +3017,14 @@ do_w32open (HANDLE hd, const char *mode,
             int no_close, int with_locked_list)
 {
   unsigned int modeflags, cmode;
+  int samethread;
   int create_called = 0;
   estream_t stream = NULL;
   void *cookie = NULL;
   int err;
   es_syshd_t syshd;
 
-  err = parse_mode (mode, &modeflags, &cmode);
+  err = parse_mode (mode, &modeflags, &samethread, &cmode);
   if (err)
     goto leave;
 
@@ -2989,7 +3036,7 @@ do_w32open (HANDLE hd, const char *mode,
   syshd.u.handle = hd;
   create_called = 1;
   err = es_create (&stream, cookie, &syshd, estream_functions_w32,
-                   modeflags, with_locked_list);
+                   modeflags, samethread, with_locked_list);
 
  leave:
   if (err && create_called)
@@ -3127,7 +3174,8 @@ _es_get_std_stream (int fd)
   return stream;
 }
 
-
+/* Note: A "samethread" keyword given in "mode" is ignored and the
+   value used by STREAM is used instead. */
 estream_t
 es_freopen (const char *ES__RESTRICT path, const char *ES__RESTRICT mode,
 	    estream_t ES__RESTRICT stream)
@@ -3137,7 +3185,7 @@ es_freopen (const char *ES__RESTRICT path, const char *ES__RESTRICT mode,
   if (path)
     {
       unsigned int modeflags, cmode;
-      int create_called;
+      int dummy, samethread, create_called;
       void *cookie;
       int fd;
       es_syshd_t syshd;
@@ -3145,13 +3193,16 @@ es_freopen (const char *ES__RESTRICT path, const char *ES__RESTRICT mode,
       cookie = NULL;
       create_called = 0;
 
+      samethread = stream->intern->samethread;
+
       lock_stream (stream);
 
       es_deinitialize (stream);
 
-      err = parse_mode (mode, &modeflags, &cmode);
+      err = parse_mode (mode, &modeflags, &dummy, &cmode);
       if (err)
 	goto leave;
+      (void)dummy;
 
       err = func_file_create (&cookie, &fd, path, modeflags, cmode);
       if (err)
@@ -3160,7 +3211,8 @@ es_freopen (const char *ES__RESTRICT path, const char *ES__RESTRICT mode,
       syshd.type = ES_SYSHD_FD;
       syshd.u.fd = fd;
       create_called = 1;
-      es_initialize (stream, cookie, &syshd, estream_functions_fd, modeflags);
+      init_stream_obj (stream, cookie, &syshd, estream_functions_fd,
+                       modeflags, samethread);
 
     leave:
 
@@ -4186,7 +4238,8 @@ es_tmpfile (void)
   syshd.type = ES_SYSHD_FD;
   syshd.u.fd = fd;
   create_called = 1;
-  err = es_create (&stream, cookie, &syshd, estream_functions_fd, modeflags, 0);
+  err = es_create (&stream, cookie, &syshd, estream_functions_fd, modeflags,
+                   0, 0);
 
  out:
   if (err)

commit ecea94461ed40f3f6ef662c2501e1d56ec284022
Author: Werner Koch <wk at gnupg.org>
Date:   Tue Apr 15 16:40:48 2014 +0200

    estream: Fix deadlock in es_fileno.
    
    * src/estream.c (es_fileno_unlocked): Call the unlocked functions.

diff --git a/common/estream.c b/common/estream.c
index 33195b7..a20d6d4 100644
--- a/common/estream.c
+++ b/common/estream.c
@@ -3300,7 +3300,7 @@ es_fileno_unlocked (estream_t stream)
 {
   es_syshd_t syshd;
 
-  if (es_syshd (stream, &syshd))
+  if (es_syshd_unlocked (stream, &syshd))
     return -1;
   switch (syshd.type)
     {

commit aeb81727c77dfea3bf5d2d689ffbdc897f2938a7
Author: Werner Koch <wk at gnupg.org>
Date:   Tue Apr 15 16:40:48 2014 +0200

    estream: Add debug code to the lock functions.
    
    * common/estream.c (dbg_lock_0, dbg_lock_1, dbg_lock_1): New.

diff --git a/common/estream.c b/common/estream.c
index eb68572..33195b7 100644
--- a/common/estream.c
+++ b/common/estream.c
@@ -343,12 +343,26 @@ map_w32_to_errno (DWORD w32_err)
 /*
  * Lock wrappers
  */
+#if 0
+# define dbg_lock_0(f)        fprintf (stderr, "estream: " f);
+# define dbg_lock_1(f, a)     fprintf (stderr, "estream: " f, (a));
+# define dbg_lock_2(f, a, b)  fprintf (stderr, "estream: " f, (a), (b));
+#else
+# define dbg_lock_0(f)
+# define dbg_lock_1(f, a)
+# define dbg_lock_2(f, a, b)
+#endif
 
 static int
 init_stream_lock (estream_t ES__RESTRICT stream)
 {
 #ifdef HAVE_NPTH
-  return npth_mutex_init (&stream->intern->lock, NULL);
+  int rc;
+
+  dbg_lock_1 ("enter init_stream_lock for %p\n", stream);
+  rc = npth_mutex_init (&stream->intern->lock, NULL);
+  dbg_lock_2 ("leave init_stream_lock for %p: rc=%d\n", stream, rc);
+  return rc;
 #else
   (void)stream;
   return 0;
@@ -360,7 +374,9 @@ static void
 lock_stream (estream_t ES__RESTRICT stream)
 {
 #ifdef HAVE_NPTH
+  dbg_lock_1 ("enter lock_stream for %p\n", stream);
   npth_mutex_lock (&stream->intern->lock);
+  dbg_lock_1 ("leave lock_stream for %p\n", stream);
 #else
   (void)stream;
 #endif
@@ -371,7 +387,12 @@ static int
 trylock_stream (estream_t ES__RESTRICT stream)
 {
 #ifdef HAVE_NPTH
-  return npth_mutex_trylock (&stream->intern->lock)? 0 : -1;
+  int rc;
+
+  dbg_lock_1 ("enter trylock_stream for %p\n", stream);
+  rc = npth_mutex_trylock (&stream->intern->lock)? 0 : -1;
+  dbg_lock_2 ("leave trylock_stream for %p: rc=%d\n", stream, rc);
+  return rc;
 #else
   (void)stream;
   return 0;
@@ -383,7 +404,9 @@ static void
 unlock_stream (estream_t ES__RESTRICT stream)
 {
 #ifdef HAVE_NPTH
+  dbg_lock_1 ("enter unlock_stream for %p\n", stream);
   npth_mutex_unlock (&stream->intern->lock);
+  dbg_lock_1 ("leave unlock_stream for %p\n", stream);
 #else
   (void)stream;
 #endif
@@ -394,7 +417,12 @@ static int
 init_list_lock (void)
 {
 #ifdef HAVE_NPTH
-  return npth_mutex_init (&estream_list_lock, NULL);
+  int rc;
+
+  dbg_lock_0 ("enter init_list_lock\n");
+  rc = npth_mutex_init (&estream_list_lock, NULL);
+  dbg_lock_1 ("leave init_list_lock: rc=%d\n", rc);
+  return rc;
 #else
   return 0;
 #endif
@@ -405,7 +433,9 @@ static void
 lock_list (void)
 {
 #ifdef HAVE_NPTH
+  dbg_lock_0 ("enter lock_list\n");
   npth_mutex_lock (&estream_list_lock);
+  dbg_lock_0 ("leave lock_list\n");
 #endif
 }
 
@@ -414,11 +444,17 @@ static void
 unlock_list (void)
 {
 #ifdef HAVE_NPTH
+  dbg_lock_0 ("enter unlock_list\n");
   npth_mutex_unlock (&estream_list_lock);
+  dbg_lock_0 ("leave unlock_list\n");
 #endif
 }
 
 
+#undef dbg_lock_0
+#undef dbg_lock_1
+#undef dbg_lock_2
+
 
 

 /*

commit 39e91a5f0a666aad2fef7a840b2cd03949bb1be4
Author: Werner Koch <wk at gnupg.org>
Date:   Tue Apr 15 16:40:48 2014 +0200

    estream: Replace locking macros by functions.
    
    * common/estream.c: Replace most macros.
    --
    
    The macros were too hard to read and actually blew up the source.

diff --git a/common/estream.c b/common/estream.c
index d26a914..eb68572 100644
--- a/common/estream.c
+++ b/common/estream.c
@@ -159,47 +159,6 @@ typedef void (*func_free_t) (void *mem);
 #define BUFFER_UNREAD_SIZE 16
 
 

-
-/* Locking.  */
-
-#ifdef HAVE_NPTH
-
-typedef npth_mutex_t estream_mutex_t;
-# define ESTREAM_MUTEX_INITIALIZER NPTH_MUTEX_INIT
-# define ESTREAM_MUTEX_LOCK(mutex)        \
-  npth_mutex_lock (&(mutex))
-# define ESTREAM_MUTEX_UNLOCK(mutex)      \
-  npth_mutex_unlock (&(mutex))
-# define ESTREAM_MUTEX_TRYLOCK(mutex)     \
-  (npth_mutex_trylock (&(mutex))? 0 : -1)
-# define ESTREAM_MUTEX_INITIALIZE(mutex)  \
-  npth_mutex_init (&(mutex), NULL)
-
-#else /*!HAVE_NPTH*/
-
-typedef void *estream_mutex_t;
-
-static inline void
-dummy_mutex_call_void (estream_mutex_t mutex)
-{
-  (void)mutex;
-}
-
-static inline int
-dummy_mutex_call_int (estream_mutex_t mutex)
-{
-  (void)mutex;
-  return 0;
-}
-
-# define ESTREAM_MUTEX_INITIALIZER NULL
-# define ESTREAM_MUTEX_LOCK(mutex) dummy_mutex_call_void ((mutex))
-# define ESTREAM_MUTEX_UNLOCK(mutex) dummy_mutex_call_int ((mutex))
-# define ESTREAM_MUTEX_TRYLOCK(mutex) dummy_mutex_call_int ((mutex))
-# define ESTREAM_MUTEX_INITIALIZE(mutex) dummy_mutex_call_int ((mutex))
-
-#endif /*!HAVE_NPTH*/
-
 /* Primitive system I/O.  */
 
 #ifdef HAVE_NPTH
@@ -231,14 +190,16 @@ typedef int (*cookie_ioctl_function_t) (void *cookie, int cmd,
 #define COOKIE_IOCTL_SNATCH_BUFFER 1
 
 
-
-
-/* An internal stream object.  */
+/* The internal stream object.  */
 struct estream_internal
 {
   unsigned char buffer[BUFFER_BLOCK_SIZE];
   unsigned char unread_buffer[BUFFER_UNREAD_SIZE];
-  estream_mutex_t lock;		 /* Lock. */
+
+#ifdef HAVE_NPTH
+  npth_mutex_t lock;		 /* Lock. */
+#endif
+
   void *cookie;			 /* Cookie.                */
   void *opaque;			 /* Opaque data.           */
   unsigned int modeflags;	 /* Flags for the backend. */
@@ -263,14 +224,8 @@ struct estream_internal
   size_t print_ntotal;           /* Bytes written from in print_writer. */
   notify_list_t onclose;         /* On close notify function list.  */
 };
-
-
 typedef struct estream_internal *estream_internal_t;
 
-#define ESTREAM_LOCK(stream) ESTREAM_MUTEX_LOCK (stream->intern->lock)
-#define ESTREAM_UNLOCK(stream) ESTREAM_MUTEX_UNLOCK (stream->intern->lock)
-#define ESTREAM_TRYLOCK(stream) ESTREAM_MUTEX_TRYLOCK (stream->intern->lock)
-
 /* A linked list to hold active stream objects.   */
 struct estream_list_s
 {
@@ -285,9 +240,9 @@ static int custom_std_fds[3];
 static unsigned char custom_std_fds_valid[3];
 
 /* A lock object for the estream list and the custom_std_fds array.  */
-static estream_mutex_t estream_list_lock;
-#define ESTREAM_LIST_LOCK   ESTREAM_MUTEX_LOCK   (estream_list_lock)
-#define ESTREAM_LIST_UNLOCK ESTREAM_MUTEX_UNLOCK (estream_list_lock)
+#ifdef HAVE_NPTH
+static npth_mutex_t estream_list_lock;
+#endif
 
 
 /* Error code replacements.  */
@@ -324,6 +279,7 @@ static void fname_set_internal (estream_t stream, const char *fname, int quote);
   while (0)
 
 
+

 /* Malloc wrappers to overcome problems on some older OSes.  */
 static void *
 mem_alloc (size_t n)
@@ -382,6 +338,89 @@ map_w32_to_errno (DWORD w32_err)
 }
 #endif /*HAVE_W32_SYSTEM*/
 
+
+

+/*
+ * Lock wrappers
+ */
+
+static int
+init_stream_lock (estream_t ES__RESTRICT stream)
+{
+#ifdef HAVE_NPTH
+  return npth_mutex_init (&stream->intern->lock, NULL);
+#else
+  (void)stream;
+  return 0;
+#endif
+}
+
+
+static void
+lock_stream (estream_t ES__RESTRICT stream)
+{
+#ifdef HAVE_NPTH
+  npth_mutex_lock (&stream->intern->lock);
+#else
+  (void)stream;
+#endif
+}
+
+
+static int
+trylock_stream (estream_t ES__RESTRICT stream)
+{
+#ifdef HAVE_NPTH
+  return npth_mutex_trylock (&stream->intern->lock)? 0 : -1;
+#else
+  (void)stream;
+  return 0;
+#endif
+}
+
+
+static void
+unlock_stream (estream_t ES__RESTRICT stream)
+{
+#ifdef HAVE_NPTH
+  npth_mutex_unlock (&stream->intern->lock);
+#else
+  (void)stream;
+#endif
+}
+
+
+static int
+init_list_lock (void)
+{
+#ifdef HAVE_NPTH
+  return npth_mutex_init (&estream_list_lock, NULL);
+#else
+  return 0;
+#endif
+}
+
+
+static void
+lock_list (void)
+{
+#ifdef HAVE_NPTH
+  npth_mutex_lock (&estream_list_lock);
+#endif
+}
+
+
+static void
+unlock_list (void)
+{
+#ifdef HAVE_NPTH
+  npth_mutex_unlock (&estream_list_lock);
+#endif
+}
+
+
+
+

 /*
  * List manipulation.
  */
@@ -402,7 +441,7 @@ do_list_add (estream_t stream, int with_locked_list)
   estream_list_t item;
 
   if (!with_locked_list)
-    ESTREAM_LIST_LOCK;
+    lock_list ();
 
   for (item = estream_list; item && item->stream; item = item->next)
     ;
@@ -419,7 +458,7 @@ do_list_add (estream_t stream, int with_locked_list)
     item->stream = stream;
 
   if (!with_locked_list)
-    ESTREAM_LIST_UNLOCK;
+    unlock_list ();
 
   return item? 0 : -1;
 }
@@ -431,7 +470,7 @@ do_list_remove (estream_t stream, int with_locked_list)
   estream_list_t item;
 
   if (!with_locked_list)
-    ESTREAM_LIST_LOCK;
+    lock_list ();
 
   for (item = estream_list; item; item = item->next)
     if (item->stream == stream)
@@ -441,7 +480,7 @@ do_list_remove (estream_t stream, int with_locked_list)
       }
 
   if (!with_locked_list)
-    ESTREAM_LIST_UNLOCK;
+    unlock_list ();
 }
 
 
@@ -512,12 +551,8 @@ do_init (void)
 
   if (!initialized)
     {
-#ifdef HAVE_NPTH
-      if (npth_mutex_init (&estream_list_lock, NULL))
+      if (!init_list_lock ())
         initialized = 1;
-#else
-      initialized = 1;
-#endif
       atexit (do_deinit);
     }
   return 0;
@@ -1742,7 +1777,7 @@ es_create (estream_t *stream, void *cookie, es_syshd_t *syshd,
   stream_new->unread_buffer_size = sizeof (stream_internal_new->unread_buffer);
   stream_new->intern = stream_internal_new;
 
-  ESTREAM_MUTEX_INITIALIZE (stream_new->intern->lock);
+  init_stream_lock (stream_new);
   es_initialize (stream_new, cookie, syshd, functions, modeflags);
 
   err = do_list_add (stream_new, with_locked_list);
@@ -2981,13 +3016,13 @@ void
 _es_set_std_fd (int no, int fd)
 {
   /* fprintf (stderr, "es_set_std_fd(%d, %d)\n", no, fd); */
-  ESTREAM_LIST_LOCK;
+  lock_list ();
   if (no >= 0 && no < 3 && !custom_std_fds_valid[no])
     {
       custom_std_fds[no] = fd;
       custom_std_fds_valid[no] = 1;
     }
-  ESTREAM_LIST_UNLOCK;
+  unlock_list ();
 }
 
 
@@ -2999,7 +3034,9 @@ _es_get_std_stream (int fd)
   estream_t stream = NULL;
 
   fd %= 3; /* We only allow 0, 1 or 2 but we don't want to return an error. */
-  ESTREAM_LIST_LOCK;
+
+  lock_list ();
+
   for (list_obj = estream_list; list_obj; list_obj = list_obj->next)
     if (list_obj->stream && list_obj->stream->intern->is_stdstream
         && list_obj->stream->intern->stdstream_fd == fd)
@@ -3049,7 +3086,8 @@ _es_get_std_stream (int fd)
                           fd == 0? "[stdin]" :
                           fd == 1? "[stdout]" : "[stderr]", 0);
     }
-  ESTREAM_LIST_UNLOCK;
+
+  unlock_list ();
   return stream;
 }
 
@@ -3071,7 +3109,7 @@ es_freopen (const char *ES__RESTRICT path, const char *ES__RESTRICT mode,
       cookie = NULL;
       create_called = 0;
 
-      ESTREAM_LOCK (stream);
+      lock_stream (stream);
 
       es_deinitialize (stream);
 
@@ -3102,7 +3140,7 @@ es_freopen (const char *ES__RESTRICT path, const char *ES__RESTRICT mode,
         {
           if (path)
             fname_set_internal (stream, path, 1);
-          ESTREAM_UNLOCK (stream);
+          unlock_stream (stream);
         }
     }
   else
@@ -3213,9 +3251,9 @@ es_onclose (estream_t stream, int mode,
 {
   int err;
 
-  ESTREAM_LOCK (stream);
+  lock_stream (stream);
   err = do_onclose (stream, mode, fnc, fnc_value);
-  ESTREAM_UNLOCK (stream);
+  unlock_stream (stream);
 
   return err;
 }
@@ -3262,21 +3300,21 @@ es_syshd_unlocked (estream_t stream, es_syshd_t *syshd)
 void
 es_flockfile (estream_t stream)
 {
-  ESTREAM_LOCK (stream);
+  lock_stream (stream);
 }
 
 
 int
 es_ftrylockfile (estream_t stream)
 {
-  return ESTREAM_TRYLOCK (stream);
+  return trylock_stream (stream);
 }
 
 
 void
 es_funlockfile (estream_t stream)
 {
-  ESTREAM_UNLOCK (stream);
+  unlock_stream (stream);
 }
 
 
@@ -3285,9 +3323,9 @@ es_fileno (estream_t stream)
 {
   int ret;
 
-  ESTREAM_LOCK (stream);
+  lock_stream (stream);
   ret = es_fileno_unlocked (stream);
-  ESTREAM_UNLOCK (stream);
+  unlock_stream (stream);
 
   return ret;
 }
@@ -3302,9 +3340,9 @@ es_syshd (estream_t stream, es_syshd_t *syshd)
 {
   int ret;
 
-  ESTREAM_LOCK (stream);
+  lock_stream (stream);
   ret = es_syshd_unlocked (stream, syshd);
-  ESTREAM_UNLOCK (stream);
+  unlock_stream (stream);
 
   return ret;
 }
@@ -3322,9 +3360,9 @@ es_feof (estream_t stream)
 {
   int ret;
 
-  ESTREAM_LOCK (stream);
+  lock_stream (stream);
   ret = es_feof_unlocked (stream);
-  ESTREAM_UNLOCK (stream);
+  unlock_stream (stream);
 
   return ret;
 }
@@ -3342,9 +3380,9 @@ es_ferror (estream_t stream)
 {
   int ret;
 
-  ESTREAM_LOCK (stream);
+  lock_stream (stream);
   ret = es_ferror_unlocked (stream);
-  ESTREAM_UNLOCK (stream);
+  unlock_stream (stream);
 
   return ret;
 }
@@ -3360,9 +3398,9 @@ es_clearerr_unlocked (estream_t stream)
 void
 es_clearerr (estream_t stream)
 {
-  ESTREAM_LOCK (stream);
+  lock_stream (stream);
   es_clearerr_unlocked (stream);
-  ESTREAM_UNLOCK (stream);
+  unlock_stream (stream);
 }
 
 
@@ -3390,24 +3428,24 @@ es_fflush (estream_t stream)
 
   if (stream)
     {
-      ESTREAM_LOCK (stream);
+      lock_stream (stream);
       err = do_fflush (stream);
-      ESTREAM_UNLOCK (stream);
+      unlock_stream (stream);
     }
   else
     {
       estream_list_t item;
 
       err = 0;
-      ESTREAM_LIST_LOCK;
+      lock_list ();
       for (item = estream_list; item; item = item->next)
         if (item->stream)
           {
-            ESTREAM_LOCK (item->stream);
+            lock_stream (item->stream);
             err |= do_fflush (item->stream);
-            ESTREAM_UNLOCK (item->stream);
+            unlock_stream (item->stream);
           }
-      ESTREAM_LIST_UNLOCK;
+      unlock_list ();
     }
   return err ? EOF : 0;
 }
@@ -3418,9 +3456,9 @@ es_fseek (estream_t stream, long int offset, int whence)
 {
   int err;
 
-  ESTREAM_LOCK (stream);
+  lock_stream (stream);
   err = es_seek (stream, offset, whence, NULL);
-  ESTREAM_UNLOCK (stream);
+  unlock_stream (stream);
 
   return err;
 }
@@ -3431,9 +3469,9 @@ es_fseeko (estream_t stream, off_t offset, int whence)
 {
   int err;
 
-  ESTREAM_LOCK (stream);
+  lock_stream (stream);
   err = es_seek (stream, offset, whence, NULL);
-  ESTREAM_UNLOCK (stream);
+  unlock_stream (stream);
 
   return err;
 }
@@ -3444,9 +3482,9 @@ es_ftell (estream_t stream)
 {
   long int ret;
 
-  ESTREAM_LOCK (stream);
+  lock_stream (stream);
   ret = es_offset_calculate (stream);
-  ESTREAM_UNLOCK (stream);
+  unlock_stream (stream);
 
   return ret;
 }
@@ -3457,9 +3495,9 @@ es_ftello (estream_t stream)
 {
   off_t ret = -1;
 
-  ESTREAM_LOCK (stream);
+  lock_stream (stream);
   ret = es_offset_calculate (stream);
-  ESTREAM_UNLOCK (stream);
+  unlock_stream (stream);
 
   return ret;
 }
@@ -3468,10 +3506,10 @@ es_ftello (estream_t stream)
 void
 es_rewind (estream_t stream)
 {
-  ESTREAM_LOCK (stream);
+  lock_stream (stream);
   es_seek (stream, 0L, SEEK_SET, NULL);
   es_set_indicators (stream, 0, -1);
-  ESTREAM_UNLOCK (stream);
+  unlock_stream (stream);
 }
 
 
@@ -3505,9 +3543,9 @@ es_fgetc (estream_t stream)
 {
   int ret;
 
-  ESTREAM_LOCK (stream);
+  lock_stream (stream);
   ret = es_getc_unlocked (stream);
-  ESTREAM_UNLOCK (stream);
+  unlock_stream (stream);
 
   return ret;
 }
@@ -3518,9 +3556,9 @@ es_fputc (int c, estream_t stream)
 {
   int ret;
 
-  ESTREAM_LOCK (stream);
+  lock_stream (stream);
   ret = es_putc_unlocked (c, stream);
-  ESTREAM_UNLOCK (stream);
+  unlock_stream (stream);
 
   return ret;
 }
@@ -3532,9 +3570,9 @@ es_ungetc (int c, estream_t stream)
   unsigned char data = (unsigned char) c;
   size_t data_unread;
 
-  ESTREAM_LOCK (stream);
+  lock_stream (stream);
   es_unreadn (stream, &data, 1, &data_unread);
-  ESTREAM_UNLOCK (stream);
+  unlock_stream (stream);
 
   return data_unread ? c : EOF;
 }
@@ -3549,9 +3587,9 @@ es_read (estream_t ES__RESTRICT stream,
 
   if (bytes_to_read)
     {
-      ESTREAM_LOCK (stream);
+      lock_stream (stream);
       err = es_readn (stream, buffer, bytes_to_read, bytes_read);
-      ESTREAM_UNLOCK (stream);
+      unlock_stream (stream);
     }
   else
     err = 0;
@@ -3569,9 +3607,9 @@ es_write (estream_t ES__RESTRICT stream,
 
   if (bytes_to_write)
     {
-      ESTREAM_LOCK (stream);
+      lock_stream (stream);
       err = es_writen (stream, buffer, bytes_to_write, bytes_written);
-      ESTREAM_UNLOCK (stream);
+      unlock_stream (stream);
     }
   else
     err = 0;
@@ -3588,9 +3626,9 @@ es_fread (void *ES__RESTRICT ptr, size_t size, size_t nitems,
 
   if (size * nitems)
     {
-      ESTREAM_LOCK (stream);
+      lock_stream (stream);
       es_readn (stream, ptr, size * nitems, &bytes);
-      ESTREAM_UNLOCK (stream);
+      unlock_stream (stream);
 
       ret = bytes / size;
     }
@@ -3609,9 +3647,9 @@ es_fwrite (const void *ES__RESTRICT ptr, size_t size, size_t nitems,
 
   if (size * nitems)
     {
-      ESTREAM_LOCK (stream);
+      lock_stream (stream);
       es_writen (stream, ptr, size * nitems, &bytes);
-      ESTREAM_UNLOCK (stream);
+      unlock_stream (stream);
 
       ret = bytes / size;
     }
@@ -3632,13 +3670,13 @@ es_fgets (char *ES__RESTRICT buffer, int length, estream_t ES__RESTRICT stream)
     return NULL;
 
   c = EOF;
-  ESTREAM_LOCK (stream);
+  lock_stream (stream);
   while (length > 1 && (c = es_getc_unlocked (stream)) != EOF && c != '\n')
     {
       *s++ = c;
       length--;
     }
-  ESTREAM_UNLOCK (stream);
+  unlock_stream (stream);
 
   if (c == EOF && s == (unsigned char*)buffer)
     return NULL; /* Nothing read.  */
@@ -3669,9 +3707,9 @@ es_fputs (const char *ES__RESTRICT s, estream_t ES__RESTRICT stream)
   int err;
 
   length = strlen (s);
-  ESTREAM_LOCK (stream);
+  lock_stream (stream);
   err = es_writen (stream, s, length, NULL);
-  ESTREAM_UNLOCK (stream);
+  unlock_stream (stream);
 
   return err ? EOF : 0;
 }
@@ -3685,9 +3723,9 @@ es_getline (char *ES__RESTRICT *ES__RESTRICT lineptr, size_t *ES__RESTRICT n,
   size_t line_n = 0;
   int err;
 
-  ESTREAM_LOCK (stream);
+  lock_stream (stream);
   err = doreadline (stream, 0, &line, &line_n);
-  ESTREAM_UNLOCK (stream);
+  unlock_stream (stream);
   if (err)
     goto out;
 
@@ -3798,7 +3836,7 @@ es_read_line (estream_t stream,
     }
   length -= 3; /* Reserve 3 bytes for CR,LF,EOL. */
 
-  ESTREAM_LOCK (stream);
+  lock_stream (stream);
   p = buffer;
   while  ((c = es_getc_unlocked (stream)) != EOF)
     {
@@ -3826,7 +3864,7 @@ es_read_line (estream_t stream,
               *length_of_buffer = 0;
               if (max_length)
                 *max_length = 0;
-              ESTREAM_UNLOCK (stream);
+              unlock_stream (stream);
               _set_errno (save_errno);
               return -1;
             }
@@ -3841,7 +3879,7 @@ es_read_line (estream_t stream,
         break;
     }
   *p = 0; /* Make sure the line is a string. */
-  ESTREAM_UNLOCK (stream);
+  unlock_stream (stream);
 
   return nbytes;
 }
@@ -3871,9 +3909,9 @@ es_vfprintf (estream_t ES__RESTRICT stream, const char *ES__RESTRICT format,
 {
   int ret;
 
-  ESTREAM_LOCK (stream);
+  lock_stream (stream);
   ret = es_print (stream, format, ap);
-  ESTREAM_UNLOCK (stream);
+  unlock_stream (stream);
 
   return ret;
 }
@@ -3902,9 +3940,9 @@ es_fprintf (estream_t ES__RESTRICT stream,
 
   va_list ap;
   va_start (ap, format);
-  ESTREAM_LOCK (stream);
+  lock_stream (stream);
   ret = es_print (stream, format, ap);
-  ESTREAM_UNLOCK (stream);
+  unlock_stream (stream);
   va_end (ap);
 
   return ret;
@@ -3933,9 +3971,9 @@ es_printf (const char *ES__RESTRICT format, ...)
 
   va_list ap;
   va_start (ap, format);
-  ESTREAM_LOCK (stream);
+  lock_stream (stream);
   ret = es_print (stream, format, ap);
-  ESTREAM_UNLOCK (stream);
+  unlock_stream (stream);
   va_end (ap);
 
   return ret;
@@ -4137,9 +4175,9 @@ es_setvbuf (estream_t ES__RESTRICT stream,
   if ((type == _IOFBF || type == _IOLBF || type == _IONBF)
       && (!buf || size || type == _IONBF))
     {
-      ESTREAM_LOCK (stream);
+      lock_stream (stream);
       err = es_set_buffering (stream, buf, type, size);
-      ESTREAM_UNLOCK (stream);
+      unlock_stream (stream);
     }
   else
     {
@@ -4154,9 +4192,9 @@ es_setvbuf (estream_t ES__RESTRICT stream,
 void
 es_setbuf (estream_t ES__RESTRICT stream, char *ES__RESTRICT buf)
 {
-  ESTREAM_LOCK (stream);
+  lock_stream (stream);
   es_set_buffering (stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
-  ESTREAM_UNLOCK (stream);
+  unlock_stream (stream);
 }
 
 
@@ -4167,7 +4205,7 @@ es_setbuf (estream_t ES__RESTRICT stream, char *ES__RESTRICT buf)
 void
 es_set_binary (estream_t stream)
 {
-  ESTREAM_LOCK (stream);
+  lock_stream (stream);
   if (!(stream->intern->modeflags & O_BINARY))
     {
       stream->intern->modeflags |= O_BINARY;
@@ -4188,16 +4226,16 @@ es_set_binary (estream_t stream)
         }
 #endif
     }
-  ESTREAM_UNLOCK (stream);
+  unlock_stream (stream);
 }
 
 
 void
 es_opaque_set (estream_t stream, void *opaque)
 {
-  ESTREAM_LOCK (stream);
+  lock_stream (stream);
   es_opaque_ctrl (stream, opaque, NULL);
-  ESTREAM_UNLOCK (stream);
+  unlock_stream (stream);
 }
 
 
@@ -4206,9 +4244,9 @@ es_opaque_get (estream_t stream)
 {
   void *opaque;
 
-  ESTREAM_LOCK (stream);
+  lock_stream (stream);
   es_opaque_ctrl (stream, NULL, &opaque);
-  ESTREAM_UNLOCK (stream);
+  unlock_stream (stream);
 
   return opaque;
 }
@@ -4249,9 +4287,9 @@ es_fname_set (estream_t stream, const char *fname)
 {
   if (fname)
     {
-      ESTREAM_LOCK (stream);
+      lock_stream (stream);
       fname_set_internal (stream, fname, 1);
-      ESTREAM_UNLOCK (stream);
+      unlock_stream (stream);
     }
 }
 
@@ -4264,11 +4302,11 @@ es_fname_get (estream_t stream)
 {
   const char *fname;
 
-  ESTREAM_LOCK (stream);
+  lock_stream (stream);
   fname = stream->intern->printable_fname;
   if (fname)
     stream->intern->printable_fname_inuse = 1;
-  ESTREAM_UNLOCK (stream);
+  unlock_stream (stream);
   if (!fname)
     fname = "[?]";
   return fname;
@@ -4290,7 +4328,7 @@ es_write_sanitized (estream_t ES__RESTRICT stream,
   size_t count = 0;
   int ret;
 
-  ESTREAM_LOCK (stream);
+  lock_stream (stream);
   for (; length; length--, p++, count++)
     {
       if (*p < 0x20
@@ -4346,7 +4384,7 @@ es_write_sanitized (estream_t ES__RESTRICT stream,
   if (bytes_written)
     *bytes_written = count;
   ret =  es_ferror_unlocked (stream)? -1 : 0;
-  ESTREAM_UNLOCK (stream);
+  unlock_stream (stream);
 
   return ret;
 }
@@ -4372,7 +4410,7 @@ es_write_hexstring (estream_t ES__RESTRICT stream,
   if (!length)
     return 0;
 
-  ESTREAM_LOCK (stream);
+  lock_stream (stream);
 
   for (s = buffer; length; s++, length--)
     {
@@ -4385,7 +4423,7 @@ es_write_hexstring (estream_t ES__RESTRICT stream,
     *bytes_written = count;
   ret = es_ferror_unlocked (stream)? -1 : 0;
 
-  ESTREAM_UNLOCK (stream);
+  unlock_stream (stream);
 
   return ret;
 

commit 7296ccf3d51a5672708a43923b0bf71871c04bd6
Author: Werner Koch <wk at gnupg.org>
Date:   Tue Apr 15 16:40:48 2014 +0200

    estream: Migrate from Pth to nPth.
    
    --
    
    Actually the mutex stuff was never used since we switched to nPth.

diff --git a/common/estream.c b/common/estream.c
index 6272c81..d26a914 100644
--- a/common/estream.c
+++ b/common/estream.c
@@ -164,16 +164,16 @@ typedef void (*func_free_t) (void *mem);
 
 #ifdef HAVE_NPTH
 
-typedef pth_mutex_t estream_mutex_t;
-# define ESTREAM_MUTEX_INITIALIZER PTH_MUTEX_INIT
+typedef npth_mutex_t estream_mutex_t;
+# define ESTREAM_MUTEX_INITIALIZER NPTH_MUTEX_INIT
 # define ESTREAM_MUTEX_LOCK(mutex)        \
-  pth_mutex_acquire (&(mutex), 0, NULL)
+  npth_mutex_lock (&(mutex))
 # define ESTREAM_MUTEX_UNLOCK(mutex)      \
-  pth_mutex_release (&(mutex))
+  npth_mutex_unlock (&(mutex))
 # define ESTREAM_MUTEX_TRYLOCK(mutex)     \
-  ((pth_mutex_acquire (&(mutex), 1, NULL) == TRUE) ? 0 : -1)
+  (npth_mutex_trylock (&(mutex))? 0 : -1)
 # define ESTREAM_MUTEX_INITIALIZE(mutex)  \
-  pth_mutex_init    (&(mutex))
+  npth_mutex_init (&(mutex), NULL)
 
 #else /*!HAVE_NPTH*/
 
@@ -203,9 +203,9 @@ dummy_mutex_call_int (estream_mutex_t mutex)
 /* Primitive system I/O.  */
 
 #ifdef HAVE_NPTH
-# define ESTREAM_SYS_READ  do_pth_read
-# define ESTREAM_SYS_WRITE do_pth_write
-# define ESTREAM_SYS_YIELD() pth_yield (NULL)
+# define ESTREAM_SYS_READ  do_npth_read
+# define ESTREAM_SYS_WRITE do_npth_write
+# define ESTREAM_SYS_YIELD() npth_usleep (0)
 #else
 # define ESTREAM_SYS_READ  read
 # define ESTREAM_SYS_WRITE write
@@ -450,35 +450,35 @@ do_list_remove (estream_t stream, int with_locked_list)
  * I/O Helper
  *
  * Unfortunately our Pth emulation for Windows expects system handles
- * for pth_read and pth_write.  We use a simple approach to fix this:
+ * for npth_read and npth_write.  We use a simple approach to fix this:
  * If the function returns an error we fall back to a vanilla read or
  * write, assuming that we do I/O on a plain file where the operation
- * can't block.
+ * can't block.  FIXME:  Is this still needed for npth?
  */
 #ifdef HAVE_NPTH
 static int
-do_pth_read (int fd, void *buffer, size_t size)
+do_npth_read (int fd, void *buffer, size_t size)
 {
 # ifdef HAVE_W32_SYSTEM
-  int rc = pth_read (fd, buffer, size);
+  int rc = npth_read (fd, buffer, size);
   if (rc == -1 && errno == EINVAL)
     rc = read (fd, buffer, size);
   return rc;
 # else /*!HAVE_W32_SYSTEM*/
-  return pth_read (fd, buffer, size);
+  return npth_read (fd, buffer, size);
 # endif /* !HAVE_W32_SYSTEM*/
 }
 
 static int
-do_pth_write (int fd, const void *buffer, size_t size)
+do_npth_write (int fd, const void *buffer, size_t size)
 {
 # ifdef HAVE_W32_SYSTEM
-  int rc = pth_write (fd, buffer, size);
+  int rc = npth_write (fd, buffer, size);
   if (rc == -1 && errno == EINVAL)
     rc = write (fd, buffer, size);
   return rc;
 # else /*!HAVE_W32_SYSTEM*/
-  return pth_write (fd, buffer, size);
+  return npth_write (fd, buffer, size);
 # endif /* !HAVE_W32_SYSTEM*/
 }
 #endif /*HAVE_NPTH*/
@@ -513,9 +513,7 @@ do_init (void)
   if (!initialized)
     {
 #ifdef HAVE_NPTH
-      if (!pth_init () && errno != EPERM )
-        return -1;
-      if (pth_mutex_init (&estream_list_lock))
+      if (npth_mutex_init (&estream_list_lock, NULL))
         initialized = 1;
 #else
       initialized = 1;
@@ -1039,8 +1037,9 @@ es_func_w32_read (void *cookie, void *buffer, size_t size)
       do
         {
 #ifdef HAVE_NPTH
-          /* Note: Our pth_read actually uses HANDLE! */
-          bytes_read = pth_read ((int)w32_cookie->hd, buffer, size);
+          /* Note: Our pth_read actually uses HANDLE!
+             FIXME: Check  whether this is the case for npth. */
+          bytes_read = npth_read ((int)w32_cookie->hd, buffer, size);
 #else
           DWORD nread, ec;
 
@@ -1085,7 +1084,7 @@ es_func_w32_write (void *cookie, const void *buffer, size_t size)
         {
 #ifdef HAVE_NPTH
           /* Note: Our pth_write actually uses HANDLE! */
-          bytes_written = pth_write ((int)w32_cookie->hd, buffer, size);
+          bytes_written = npth_write ((int)w32_cookie->hd, buffer, size);
 #else
           DWORD nwritten;
 

commit 7adeae3ba3488a9ada6caab17572f0ac6a639c6e
Author: Werner Koch <wk at gnupg.org>
Date:   Tue Apr 15 16:40:48 2014 +0200

    gpg: Minor doc enhancement
    
    --

diff --git a/doc/gpg.texi b/doc/gpg.texi
index f72775e..1a81010 100644
--- a/doc/gpg.texi
+++ b/doc/gpg.texi
@@ -1449,7 +1449,9 @@ Set what trust model GnuPG should follow. The models are:
   trusted. You generally won't use this unless you are using some
   external validation scheme. This option also suppresses the
   "[uncertain]" tag printed with signature checks when there is no
-  evidence that the user ID is bound to the key.
+  evidence that the user ID is bound to the key.  Note that this
+  trust model still does not allow the use of expired, revoked, or
+  disabled keys.
 
   @item auto
   @opindex trust-mode:auto

-----------------------------------------------------------------------

Summary of changes:
 common/estream.c |  540 +++++++++++++++++++++++++++++++++---------------------
 doc/gpg.texi     |    4 +-
 2 files changed, 336 insertions(+), 208 deletions(-)


hooks/post-receive
-- 
The GNU Privacy Guard
http://git.gnupg.org




More information about the Gnupg-commits mailing list