Changeset: 81f823279c8f for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=81f823279c8f
Modified Files:
        NT/monetdb_config.h.in
        common/stream/stream_socket.h
        gdk/gdk_atoms.c
        gdk/gdk_bat.c
        gdk/gdk_posix.c
        gdk/gdk_posix.h
        gdk/gdk_storage.c
        gdk/gdk_system.h
        gdk/gdk_utils.c
        monetdb5/modules/kernel/batmmath.c
        monetdb5/modules/kernel/mmath.c
        monetdb5/modules/mal/mal_mapi.c
        sql/server/sql_parser.y
Branch: Oct2014
Log Message:

Some fixes to how errno is used on Windows.
We now don't use our own version of errno but reuse the one that the
Windows runtime provides.  We also don't blithely write an error there
when we check for errno.  By doing this, we can actually use errno to
test for errors in the math library on Windows.


diffs (truncated from 336 to 300 lines):

diff --git a/NT/monetdb_config.h.in b/NT/monetdb_config.h.in
--- a/NT/monetdb_config.h.in
+++ b/NT/monetdb_config.h.in
@@ -151,6 +151,9 @@
 /* If the system has a working fdatasync */
 /* #undef HAVE_FDATASYNC */
 
+/* Define to 1 if you have the <fenv.h> header file. */
+/* #undef HAVE_FENV_H */
+
 /* Define to 1 if you have the `fpclass' function. */
 #define HAVE_FPCLASS 1
 
diff --git a/common/stream/stream_socket.h b/common/stream/stream_socket.h
--- a/common/stream/stream_socket.h
+++ b/common/stream/stream_socket.h
@@ -30,6 +30,9 @@
 #ifndef INVALID_SOCKET
 #define INVALID_SOCKET (-1)
 #endif
+#ifndef SOCKET_ERROR
+#define SOCKET_ERROR (-1)
+#endif
 
 stream_export stream *socket_rstream(SOCKET socket, const char *name);
 stream_export stream *socket_wstream(SOCKET socket, const char *name);
diff --git a/gdk/gdk_atoms.c b/gdk/gdk_atoms.c
--- a/gdk/gdk_atoms.c
+++ b/gdk/gdk_atoms.c
@@ -764,7 +764,7 @@ dblFromStr(const char *src, int *len, db
                 * normalized double, and may or may not set errno to
                 * ERANGE.  We accept underflow, but not overflow. */
                char *pe;
-               errno = 0;
+               set_errno(0);
                d = strtod(src, &pe);
                p = pe;
                if (p == src || (errno == ERANGE && (d < -1 || d > 1))) {
@@ -806,7 +806,7 @@ fltFromStr(const char *src, int *len, fl
                 * normalized float, and may or may not set errno to
                 * ERANGE.  We accept underflow, but not overflow. */
                char *pe;
-               errno = 0;
+               set_errno(0);
                f = strtof(src, &pe);
                p = pe;
                while (GDKisspace(*p))
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -352,8 +352,8 @@ BATattach(int tt, const char *heapfile, 
        path = GDKfilepath(bn->T->heap.farmid, BATDIR, bn->T->heap.filename, 
"new");
        GDKcreatedir(path);
        if (rename(heapfile, path) < 0) {
+               GDKsyserror("BATattach: cannot rename heapfile\n");
                GDKfree(path);
-               GDKsyserror("BATattach: cannot rename heapfile\n");
                HEAPfree(&bn->T->heap);
                GDKfree(bs);
                return NULL;
diff --git a/gdk/gdk_posix.c b/gdk/gdk_posix.c
--- a/gdk/gdk_posix.c
+++ b/gdk/gdk_posix.c
@@ -1156,20 +1156,15 @@ win_errmap_t win_errmap[] = {
 
 #define GDK_WIN_ERRNO_TLS 13
 
+#undef _errno
 int *
 win_errno(void)
 {
        /* get address of thread-local Posix errno; refresh its value
         * from WIN32 error code */
        int i, err = GetLastError() & 0xff;
-       int *result = TlsGetValue(GDK_WIN_ERRNO_TLS);
+       int *result = _errno();
 
-       if (result == NULL) {
-               result = (int *) malloc(sizeof(int));
-               *result = 0;
-               TlsSetValue(GDK_WIN_ERRNO_TLS, result);
-       }
-       *result = ENOSYS;       /* fallback error */
        for (i = 0; win_errmap[i].w != 0; ++i) {
                if (err == win_errmap[i].w) {
                        *result = win_errmap[i].e;
@@ -1179,6 +1174,20 @@ win_errno(void)
        SetLastError(err);
        return result;
 }
+
+void
+set_errno(int e)
+{
+       int i;
+
+       for (i = 0; win_errmap[i].w != 0; i++) {
+               if (win_errmap[i].e == e) {
+                       SetLastError(win_errmap[i].w);
+                       break;
+               }
+       }
+       _set_errno(e);
+}
 #endif
 
 #ifndef WIN32
diff --git a/gdk/gdk_posix.h b/gdk/gdk_posix.h
--- a/gdk/gdk_posix.h
+++ b/gdk/gdk_posix.h
@@ -247,10 +247,15 @@ gdk_export int win_mkdir(const char *, c
 #define link           win_link
 #endif
 
-#endif
-
 #define _errno         win_errno
 
 gdk_export int *win_errno(void);
+gdk_export void set_errno(int);
+
+#else
+
+#define set_errno(e)   (errno = (e))
+
+#endif /* NATIVE_WIN32 */
 
 #endif /* GDK_POSIX_H */
diff --git a/gdk/gdk_storage.c b/gdk/gdk_storage.c
--- a/gdk/gdk_storage.c
+++ b/gdk/gdk_storage.c
@@ -253,6 +253,7 @@ GDKmove(int farmid, const char *dir1, co
        IODEBUG t0 = GDKms();
 
        if ((nme1 == NULL) || (*nme1 == 0)) {
+               set_errno(EFAULT);
                return -1;
        }
        path1 = GDKfilepath(farmid, dir1, nme1, ext1);
diff --git a/gdk/gdk_system.h b/gdk/gdk_system.h
--- a/gdk/gdk_system.h
+++ b/gdk/gdk_system.h
@@ -74,9 +74,6 @@ gdk_export int gprof_pthread_create(pthr
 /* debug and errno integers */
 gdk_export int GDKdebug;
 
-#define MT_geterrno()  errno
-#define MT_seterrno(x) errno=x
-
 /* lock performance tracing */
 /* #define MT_LOCK_TRACE 1 */
 #ifdef MT_LOCK_TRACE
diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -1053,7 +1053,7 @@ GDKinit(opt *set, int setlen)
                MT_lock_init(&GDKbbpLock[i].trim, "GDKtrimLock");
                GDKbbpLock[i].free = 0;
        }
-       errno = 0;
+       set_errno(0);
        if (!GDKenvironment(dbpath))
                return 0;
 
@@ -1561,7 +1561,7 @@ GDKsyserror(const char *format, ...)
        }
        GDKaddbuf(message);
 
-       errno = 0;
+       set_errno(0);
        return err;
 }
 
diff --git a/monetdb5/modules/kernel/batmmath.c 
b/monetdb5/modules/kernel/batmmath.c
--- a/monetdb5/modules/kernel/batmmath.c
+++ b/monetdb5/modules/kernel/batmmath.c
@@ -66,7 +66,7 @@ str CMDscience_bat_##TYPE##_##FUNC(bat *
        p = (TYPE *) Tloc(b, BUNfirst(b));                                      
                        \
        q = (TYPE *) Tloc(b, BUNlast(b));                                       
                        \
                                                                                
                                                        \
-       errno = 0;                                                              
                                                \
+       set_errno(0);                                                           
                                                \
        feclearexcept(FE_ALL_EXCEPT);                                           
                        \
        if (b->T->nonil) {                                                      
                                        \
                for (; p < q; o++, p++)                                         
                                \
@@ -115,7 +115,7 @@ str CMDscience_bat_cst_##FUNC##_##TYPE(b
        p = (TYPE *) Tloc(b, BUNfirst(b));                                      
                                \
        q = (TYPE *) Tloc(b, BUNlast(b));                                       
                                \
                                                                                
                                                                \
-       errno = 0;                                                              
                                                        \
+       set_errno(0);                                                           
                                                        \
        feclearexcept(FE_ALL_EXCEPT);                                           
                                \
        if (b->T->nonil) {                                                      
                                                \
                for (; p < q; o++, p++)                                         
                                        \
diff --git a/monetdb5/modules/kernel/mmath.c b/monetdb5/modules/kernel/mmath.c
--- a/monetdb5/modules/kernel/mmath.c
+++ b/monetdb5/modules/kernel/mmath.c
@@ -141,7 +141,7 @@ MATHunary##NAME##dbl(dbl *res , const db
                *res =dbl_nil;                                                  
                        \
        } else {                                                                
                                \
                tmp1= *a;                                                       
                                \
-               errno = 0;                                                      
                                \
+               set_errno(0);                                                   
                                \
                feclearexcept(FE_ALL_EXCEPT);                                   
        \
                tmp2 = FUNC(tmp1);                                              
                        \
                if (errno != 0 ||                                               
                        \
@@ -161,7 +161,7 @@ MATHunary##NAME##flt(flt *res , const fl
                *res =flt_nil;                                                  
                        \
        } else {                                                                
                                \
                tmp1= *a;                                                       
                                \
-               errno = 0;                                                      
                                \
+               set_errno(0);                                                   
                                \
                feclearexcept(FE_ALL_EXCEPT);                                   
        \
                tmp2 = FUNC(tmp1);                                              
                        \
                if (errno != 0 ||                                               
                        \
diff --git a/monetdb5/modules/mal/mal_mapi.c b/monetdb5/modules/mal/mal_mapi.c
--- a/monetdb5/modules/mal/mal_mapi.c
+++ b/monetdb5/modules/mal/mal_mapi.c
@@ -238,8 +238,14 @@ SERVERlistenThread(SOCKET *Sock)
                        /* nothing interesting has happened */
                        continue;
                }
-               if (retval < 0) {
-                       if (MT_geterrno() != EINTR) {
+               if (retval == SOCKET_ERROR) {
+                       if (
+#ifdef _MSC_VER
+                               WSAGetLastError() != WSAEINTR
+#else
+                               errno != EINTR
+#endif
+                               ) {
                                msg = "select failed";
                                goto error;
                        }
@@ -247,7 +253,13 @@ SERVERlistenThread(SOCKET *Sock)
                }
                if (sock != INVALID_SOCKET && FD_ISSET(sock, &fds)) {
                        if ((msgsock = accept(sock, (SOCKPTR)0, (socklen_t 
*)0)) == INVALID_SOCKET) {
-                               if (MT_geterrno() != EINTR || 
!ATOMIC_GET(serveractive, atomicLock, "SERVERlistenThread")) {
+                               if (
+#ifdef _MSC_VER
+                                       WSAGetLastError() != WSAEINTR
+#else
+                                       errno != EINTR
+#endif
+                                       || !ATOMIC_GET(serveractive, 
atomicLock, "SERVERlistenThread")) {
                                        msg = "accept failed";
                                        goto error;
                                }
@@ -263,7 +275,13 @@ SERVERlistenThread(SOCKET *Sock)
                        struct cmsghdr *cmsg;
 
                        if ((msgsock = accept(usock, (SOCKPTR)0, (socklen_t 
*)0)) == INVALID_SOCKET) {
-                               if (MT_geterrno() != EINTR) {
+                               if (
+#ifdef _MSC_VER
+                                       WSAGetLastError() != WSAEINTR
+#else
+                                       errno != EINTR
+#endif
+                                       ) {
                                        msg = "accept failed";
                                        goto error;
                                }
@@ -463,7 +481,7 @@ SERVERlisten(int *Port, str *Usockfile, 
                                        strerror(errno));
                }
 
-               if( setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, 
sizeof on) ) {
+               if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, 
sizeof on) == SOCKET_ERROR) {
                        char *err = strerror(errno);
                        GDKfree(psock);
                        if (usockfile)
@@ -483,16 +501,17 @@ SERVERlisten(int *Port, str *Usockfile, 
 
                do {
                        server.sin_port = htons((unsigned short) ((port) & 
0xFFFF));
-                       if (bind(sock, (SOCKPTR) &server, length) < 0) {
+                       if (bind(sock, (SOCKPTR) &server, length) == 
SOCKET_ERROR) {
                                if (
+#ifdef _MSC_VER
+                                       WSAGetLastError() == WSAEADDRINUSE &&
+#else
 #ifdef EADDRINUSE
-                                               errno == EADDRINUSE &&
+                                       errno == EADDRINUSE &&
 #else
-#ifdef WSAEADDRINUSE
-                                               errno == WSAEADDRINUSE &&
 #endif
 #endif
-                                               autosense && port <= 65535)
+                                       autosense && port <= 65535)
                                {
                                        port++;
                                        continue;
@@ -509,7 +528,7 @@ SERVERlisten(int *Port, str *Usockfile, 
                        }
                } while (1);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to