lost patch: errno shield ?

Arend-jan Wytzes <[email protected]>
Newsgroups gmane.linux.ngpt.devel
Message-ID <[email protected]>
Dear developers,

Back in December, I posted a patch to this mailinglist concerning the handeling
of errno. This patch consisted of two changes: the introduction of an errno 
per nativive and a replacement for the macro 'errno_shield'.

The errno per native was accepted and applied, but the errno_shield was not.
However, I still believe that the current (1.2.2) errno_shield macro is faulty,
because it uses a global variable for temporary storage. 
I tested the current stable (1.2.2) with the test program that was supplied 
with the patches in December, and it seems to confirm this on an SMP machine.

I hereby resent the errno_shield patch that should apply cleanly to 1.2.2-5.
If I'm wrong about this macro, please explain why =)

Regards,
aj
patch-errno-shield.diff (text/plain, 6.5 KB)
diff -r -u ngpt-1.2.2/pth_debug.c ngpt-1.2.2-6/pth_debug.c
--- ngpt-1.2.2/pth_debug.c	Mon Dec 17 15:29:24 2001
+++ ngpt-1.2.2-6/pth_debug.c	Wed Jun  5 13:12:48 2002
@@ -63,7 +63,7 @@
     char *debug_file_path = NULL;
     size_t n;
 
-    errno_shield {
+    errno_shield (
 	pid_t tid = gettid();
 	_pth_acquire_lock(&debug_lock, tid);
         va_start(ap, fmt);
@@ -92,7 +92,7 @@
 	/* now do the write... */
 	pth_sc(write)(debug_fd, str, n);
 	_pth_release_lock(&debug_lock, tid);
-    }
+    )
     return;
 }
 
diff -r -u ngpt-1.2.2/pth_errno.c ngpt-1.2.2-6/pth_errno.c
--- ngpt-1.2.2/pth_errno.c	Sat Jan 19 15:17:20 2002
+++ ngpt-1.2.2-6/pth_errno.c	Wed Jun  5 13:11:50 2002
@@ -31,12 +31,12 @@
 #if cpp
 
 /* enclose errno in a block */
-#define errno_shield \
-        for ( pth_errno_storage = errno, \
-              pth_errno_flag = TRUE; \
-              pth_errno_flag; \
-              errno = pth_errno_storage, \
-              pth_errno_flag = FALSE )
+#define errno_shield(___x) \
+    { \
+        int __saved_errno = errno; \
+        ___x \
+        errno = __saved_errno; \
+    }
 
 /* return plus setting an errno value */
 #if defined(PTH_DEBUG)
@@ -58,5 +58,5 @@
 #endif /* cpp */
 
 intern int pth_errno_storage = 0;
-intern int pth_errno_flag    = 0;
+/* intern int pth_errno_flag    = 0; */
 
diff -r -u ngpt-1.2.2/pth_high.c ngpt-1.2.2-6/pth_high.c
--- ngpt-1.2.2/pth_high.c	Wed Jun  5 13:17:09 2002
+++ ngpt-1.2.2-6/pth_high.c	Wed Jun  5 13:13:50 2002
@@ -481,7 +481,7 @@
         ;
 
     /* restore filedescriptor mode */
-    errno_shield { pth_fdmode(s, fdmode); }
+    errno_shield ( pth_fdmode(s, fdmode); )
 
     /* when it is still on progress wait until socket is really writeable */
     if (rv == -1 && errno == EINPROGRESS) {
@@ -550,11 +550,11 @@
     }
 
     /* restore filedescriptor mode */
-    errno_shield {
+    errno_shield (
         pth_fdmode(s, fdmode);
         if (rv != -1)
             pth_fdmode(rv, fdmode);
-    }
+    )
 
     pth_debug2("pth_accept_ev: leave to thread \"%s\"", CURRENT_NAME());
     return rv;
@@ -662,7 +662,7 @@
     if (fdmode != PTH_FDMODE_NONBLOCK && rv == -1 && errno == EAGAIN) {
 
 	/* restore filedescriptor mode */
-	errno_shield { pth_fdmode(fd, fdmode); }
+	errno_shield ( pth_fdmode(fd, fdmode); )
 
         /* now directly poll filedescriptor for writeability
            to avoid unneccessary (and resource consuming because of context
@@ -717,7 +717,7 @@
         }
     } else
 	/* restore filedescriptor mode */
-	errno_shield { pth_fdmode(fd, fdmode); }
+	errno_shield ( pth_fdmode(fd, fdmode); )
 
     pth_debug3("pth_write_ev: leave to thread \"%s\" returns %d", CURRENT_NAME(), rv);
     return rv;
@@ -909,7 +909,7 @@
     if (fdmode != PTH_FDMODE_NONBLOCK && rv == -1 && errno == EAGAIN) {
 
 	/* restore filedescriptor mode */
-	errno_shield { pth_fdmode(fd, fdmode); }
+	errno_shield ( pth_fdmode(fd, fdmode); )
 
         /* init return value and number of bytes to write */
         rv      = 0;
@@ -977,7 +977,7 @@
         }
     } else
 	/* restore filedescriptor mode */
-	errno_shield { pth_fdmode(fd, fdmode); }
+	errno_shield ( pth_fdmode(fd, fdmode); )
 
     pth_debug2("pth_writev_ev: leave to thread \"%s\"", CURRENT_NAME());
     return rv;
@@ -1103,7 +1103,7 @@
     rc = pth_read(fd, buf, nbytes);
 
     /* restore the old offset situation */
-    errno_shield { lseek(fd, old_offset, SEEK_SET); }
+    errno_shield ( lseek(fd, old_offset, SEEK_SET); )
 
     /* unprotect and return result of read */
     pth_mutex_release(&mutex);
@@ -1136,7 +1136,7 @@
     rc = pth_write(fd, buf, nbytes);
 
     /* restore the old offset situation */
-    errno_shield { lseek(fd, old_offset, SEEK_SET); }
+    errno_shield ( lseek(fd, old_offset, SEEK_SET); )
 
     /* unprotect and return result of write */
     pth_mutex_release(&mutex);
@@ -1169,7 +1169,7 @@
     rc = pth_read(fd, buf, nbytes);
 
     /* restore the old offset situation */
-    errno_shield { lseek64(fd, old_offset, SEEK_SET); }
+    errno_shield ( lseek64(fd, old_offset, SEEK_SET); )
 
     /* unprotect and return result of read */
     pth_mutex_release(&mutex);
@@ -1202,7 +1202,7 @@
     rc = pth_write(fd, buf, nbytes);
 
     /* restore the old offset situation */
-    errno_shield { lseek64(fd, old_offset, SEEK_SET); }
+    errno_shield ( lseek64(fd, old_offset, SEEK_SET); )
 
     /* unprotect and return result of write */
     pth_mutex_release(&mutex);
diff -r -u ngpt-1.2.2/pth_lib.c ngpt-1.2.2-6/pth_lib.c
--- ngpt-1.2.2/pth_lib.c	Wed Jun  5 13:17:09 2002
+++ ngpt-1.2.2-6/pth_lib.c	Wed Jun  5 13:14:09 2002
@@ -54,12 +54,12 @@
 intern void *pth_malloc(size_t sz)
 {
     void *memptr = NULL;
-    errno_shield {
+    errno_shield (
 	memptr = mmap(NULL, sz,
 		  PROT_READ | PROT_WRITE | PROT_EXEC,
 		  MAP_PRIVATE | MAP_ANONYMOUS,
 		  -1, 0);
-    }
+    )
     if (memptr == MAP_FAILED) 
 	return NULL;
 
@@ -77,7 +77,7 @@
 /* special version of free that do munmap instead... */
 intern void pth_free_mem(void *memptr, size_t sz)
 {
-    errno_shield { munmap(memptr, sz); }
+    errno_shield ( munmap(memptr, sz); )
 }
 
 
diff -r -u ngpt-1.2.2/pth_tcb.c ngpt-1.2.2-6/pth_tcb.c
--- ngpt-1.2.2/pth_tcb.c	Wed Jun  5 13:17:06 2002
+++ ngpt-1.2.2-6/pth_tcb.c	Wed Jun  5 13:14:41 2002
@@ -165,12 +165,12 @@
      * that doesn't require it, we waste 8 bytes.
      */
     
-    errno_shield {
+    errno_shield (
 	t = mmap(NULL, sizeof(struct pth_st)+8,
 	     PROT_READ | PROT_WRITE | PROT_EXEC,
 	     MAP_PRIVATE | MAP_ANONYMOUS,
 	     -1, 0);
-    }
+    )
     if (t == MAP_FAILED)
 	return(NULL);
 
@@ -205,14 +205,14 @@
 			 ? npages * pagesize				/*ibm*/
 			 : (++npages) * pagesize;			/*ibm*/
 #endif
-	    errno_shield {
+	    errno_shield (
 		stack = mmap(NULL, (t->stacksize+8),
 			    PROT_READ | PROT_WRITE | PROT_EXEC,
 			    MAP_PRIVATE | MAP_ANONYMOUS,
 			    -1, 0);
-	    }
+	    )
 	    if (stack == MAP_FAILED) {
-		errno_shield { munmap(t, sizeof(struct pth_st)+8); }
+		errno_shield ( munmap(t, sizeof(struct pth_st)+8); )
 		return(NULL);
 	    }
 
@@ -270,7 +270,7 @@
 
     /* Cleanup the stack. (can't unmap the stack for current running thread) */
     if (t->true_stack != NULL && !t->stackloan && t != descr->current)
-        errno_shield { munmap(t->true_stack, t->stacksize+8); }
+        errno_shield ( munmap(t->true_stack, t->stacksize+8); )
 
     /* Run the specific data destructors */
     if (t->data_value != NULL)
@@ -323,7 +323,7 @@
 	t = (pth_t)((char *)((char *)t - 8));
     /*ibm end*/
 
-    errno_shield { munmap(t, sizeof(struct pth_st)+8); }
+    errno_shield ( munmap(t, sizeof(struct pth_st)+8); )
     return;
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.