Rework io-layer logging to use a single DEBUG macro instead of #ifdef DEBUG.
authorZoltan Varga <vargaz@gmail.com>
Thu, 17 Nov 2011 09:53:17 +0000 (04:53 -0500)
committerZoltan Varga <vargaz@gmail.com>
Thu, 17 Nov 2011 09:53:17 +0000 (04:53 -0500)
17 files changed:
mono/io-layer/collection.c
mono/io-layer/critical-sections.c
mono/io-layer/daemon-messages.c
mono/io-layer/daemon.c
mono/io-layer/events.c
mono/io-layer/handles.c
mono/io-layer/io.c
mono/io-layer/locking.c
mono/io-layer/mutexes.c
mono/io-layer/posix.c
mono/io-layer/processes.c
mono/io-layer/semaphores.c
mono/io-layer/sockets.c
mono/io-layer/versioninfo.c
mono/io-layer/wait.c
mono/io-layer/wapi_glob.c
mono/io-layer/wthreads.c

index fff2187d2edda240429cb1ab377f3d7469af99f7..9e118a35814f4cba69c91001c5868547a8b10914 100644 (file)
 #include <mono/io-layer/collection.h>
 #include <mono/io-layer/handles-private.h>
 
-#define LOGDEBUG(...)
-// #define LOGDEBUG(...) g_message(__VA_ARGS__)
+#if 0
+// #define DEBUG(...) g_message(__VA_ARGS__)
+#else
+#define DEBUG(...)
+#endif
 
 static pthread_t collection_thread_id;
 
@@ -82,13 +85,13 @@ void _wapi_handle_collect (void)
        if (!_wapi_shm_enabled ())
                return;
        
-       LOGDEBUG ("%s: (%d) Starting a collection", __func__, _wapi_getpid ());
+       DEBUG ("%s: (%d) Starting a collection", __func__, _wapi_getpid ());
 
        /* Become the collection master */
        thr_ret = _wapi_handle_lock_shared_handles ();
        g_assert (thr_ret == 0);
        
-       LOGDEBUG ("%s: (%d) Master set", __func__, _wapi_getpid ());
+       DEBUG ("%s: (%d) Master set", __func__, _wapi_getpid ());
        
        /* If count has changed, someone else jumped in as master */
        if (count == _wapi_shared_layout->collection_count) {
@@ -99,7 +102,7 @@ void _wapi_handle_collect (void)
                        
                        data = &_wapi_shared_layout->handles[i];
                        if (data->timestamp < too_old) {
-                               LOGDEBUG ("%s: (%d) Deleting handle 0x%x", __func__, _wapi_getpid (), i);
+                               DEBUG ("%s: (%d) Deleting handle 0x%x", __func__, _wapi_getpid (), i);
                                memset (&_wapi_shared_layout->handles[i], '\0', sizeof(struct _WapiHandleShared));
                        }
                }
@@ -118,5 +121,5 @@ void _wapi_handle_collect (void)
        
        _wapi_handle_unlock_shared_handles ();
 
-       LOGDEBUG ("%s: (%d) Collection done", __func__, _wapi_getpid ());
+       DEBUG ("%s: (%d) Collection done", __func__, _wapi_getpid ());
 }
index 3d2700da962f6a84d8ee34c964fcfe2a92c8ac64..479b419b79d58f87397de4be33dcb7f6eb6bad08 100644 (file)
@@ -16,8 +16,6 @@
 
 #include "mono-mutex.h"
 
-#undef DEBUG
-
 /* A critical section is really just like a lightweight mutex. It
  * can't be waited for, and doesn't have a handle.
  */
index 812d435de5b7735dfc799e8b5d42c1017ef9a2d1..afc7fde9e8f1a5515194b7c3fb65950272d02c76 100644 (file)
 #define CMSG_SPACE(size)  (sizeof (struct cmsghdr) + (size))
 #endif
 
-#define LOGDEBUG(...)
-// #define LOGDEBUG(...) g_message(__VA_ARGS__)
+#if 0
+// #define DEBUG(...) g_message(__VA_ARGS__)
+#else
+#define DEBUG(...)
+#endif
 
 static mono_mutex_t req_mutex;
 static mono_once_t attr_key_once = MONO_ONCE_INIT;
@@ -230,7 +233,7 @@ int _wapi_daemon_request (int fd, WapiHandleRequest *req, int *fds,
                /* The next loop around poll() should tidy up */
        }
 
-#ifdef DEBUG
+#ifdef DEBUG_ENABLED
        if(msg.msg_flags & MSG_OOB) {
                g_message ("%s: OOB data received", __func__);
        }
@@ -243,15 +246,15 @@ int _wapi_daemon_request (int fd, WapiHandleRequest *req, int *fds,
        cmsg=CMSG_FIRSTHDR (&msg);
        if(cmsg!=NULL && cmsg->cmsg_level==SOL_SOCKET &&
           cmsg->cmsg_type==SCM_RIGHTS) {
-               LOGDEBUG ("%s: cmsg->cmsg_len=%d", __func__, cmsg->cmsg_len);
-               LOGDEBUG ("%s: cmsg->level=%d cmsg->type=%d", __func__, cmsg->cmsg_level, cmsg->cmsg_type);
+               DEBUG ("%s: cmsg->cmsg_len=%d", __func__, cmsg->cmsg_len);
+               DEBUG ("%s: cmsg->level=%d cmsg->type=%d", __func__, cmsg->cmsg_level, cmsg->cmsg_type);
 
                memcpy (fds, (int *)CMSG_DATA (cmsg), sizeof(int)*3);
                *has_fds=TRUE;
 
-               LOGDEBUG ("%s: fd[0]=%d, fd[1]=%d, fd[2]=%d", __func__, fds[0], fds[1], fds[2]);
+               DEBUG ("%s: fd[0]=%d, fd[1]=%d, fd[2]=%d", __func__, fds[0], fds[1], fds[2]);
        } else {
-               LOGDEBUG ("%s: no ancillary data", __func__);
+               DEBUG ("%s: no ancillary data", __func__);
                *has_fds=FALSE;
        }
 
@@ -272,7 +275,7 @@ int _wapi_daemon_response (int fd, WapiHandleResponse *resp)
        }
        while (ret==-1 && errno==EINTR);
 
-#ifdef DEBUG
+#ifdef DEBUG_ENABLED
        if(ret==-1 || ret != sizeof(WapiHandleResponse)) {
                g_warning ("%s: Send error: %s", __func__, strerror (errno));
                /* The next loop around poll() should tidy up */
index b5ff32afc11bb45751949388226d6298ad6478f8..f5c56d958054f1a7d448355a310c5984ca86c739 100644 (file)
 #include <mono/io-layer/daemon-private.h>
 #include <mono/io-layer/socket-wrappers.h>
 
-#define LOGDEBUG(...)
-#undef DEBUG
-// #define LOGDEBUG(...) g_message(__VA_ARGS__)
+#if 0
+// #define DEBUG(...) g_message(__VA_ARGS__)
+#else
+#define DEBUG(...)
+#endif
 
 /* The shared thread codepath doesn't seem to work yet... */
 #undef _POSIX_THREAD_PROCESS_SHARED
@@ -110,10 +112,10 @@ static void maybe_exit (void)
 {
        guint32 i;
 
-       LOGDEBUG ("%s: Seeing if we should exit", __func__);
+       DEBUG ("%s: Seeing if we should exit", __func__);
 
        if(nfds>1) {
-               LOGDEBUG ("%s: Still got clients", __func__);
+               DEBUG ("%s: Still got clients", __func__);
                return;
        }
 
@@ -124,7 +126,7 @@ static void maybe_exit (void)
            i<_wapi_shared_data[0]->num_segments * _WAPI_HANDLES_PER_SEGMENT;
            i++) {
                if(daemon_channel_data->open_handles[i]>0) {
-                       LOGDEBUG ("%s: Still got handle references", __func__);
+                       DEBUG ("%s: Still got handle references", __func__);
                        _wapi_shared_data[0]->daemon_running=DAEMON_RUNNING;
                        return;
                }
@@ -150,11 +152,11 @@ static void maybe_exit (void)
                fds[0].events=POLLIN;
                fds[0].revents=0;
                
-               LOGDEBUG ("%s: Last connect check", __func__);
+               DEBUG ("%s: Last connect check", __func__);
 
                if(poll (fds, 1, 0)>0) {
                        /* Someone did connect, so carry on running */
-                       LOGDEBUG ("%s: Someone connected", __func__);
+                       DEBUG ("%s: Someone connected", __func__);
 
                        _wapi_shared_data[0]->daemon_running=DAEMON_RUNNING;
                        return;
@@ -162,7 +164,7 @@ static void maybe_exit (void)
        }
 #endif
        
-       LOGDEBUG ("%s: Byebye", __func__);
+       DEBUG ("%s: Byebye", __func__);
        
        cleanup ();
        exit (0);
@@ -176,7 +178,7 @@ static void maybe_exit (void)
  */
 static void signal_handler (int signo)
 {
-       LOGDEBUG ("%s: daemon received signal %d", __func__, signo);
+       DEBUG ("%s: daemon received signal %d", __func__, signo);
 
        cleanup ();
        exit (-1);
@@ -286,7 +288,7 @@ static void ref_handle (ChannelData *channel_data, guint32 handle)
        _wapi_shared_data[segment]->handles[idx].ref++;
        channel_data->open_handles[handle]++;
        
-       LOGDEBUG ("%s: handle 0x%x ref now %d (%d this process)", __func__, handle,
+       DEBUG ("%s: handle 0x%x ref now %d (%d this process)", __func__, handle,
                  _wapi_shared_data[segment]->handles[idx].ref,
                  channel_data->open_handles[handle]);
 }
@@ -319,7 +321,7 @@ static gboolean unref_handle (ChannelData *channel_data, guint32 handle)
        _wapi_shared_data[segment]->handles[idx].ref--;
        channel_data->open_handles[handle]--;
        
-       LOGDEBUG ("%s: handle 0x%x ref now %d (%d this process)", __func__, handle,
+       DEBUG ("%s: handle 0x%x ref now %d (%d this process)", __func__, handle,
                   _wapi_shared_data[segment]->handles[idx].ref,
                   channel_data->open_handles[handle]);
 
@@ -335,7 +337,7 @@ static gboolean unref_handle (ChannelData *channel_data, guint32 handle)
                        g_warning ("%s: per-process open_handles mismatch, set to %d, should be 0",__func__, channel_data->open_handles[handle]);
                }
                
-               LOGDEBUG ("%s: Destroying handle 0x%x", __func__, handle);
+               DEBUG ("%s: Destroying handle 0x%x", __func__, handle);
 
                /* if this was a file handle, save the device and
                 * inode numbers so we can scan the share info data
@@ -464,10 +466,10 @@ static void rem_fd(GIOChannel *channel, ChannelData *channel_data)
                exit (-1);
        }
        
-       LOGDEBUG ("%s: Removing client fd %d", __func__, fd);
+       DEBUG ("%s: Removing client fd %d", __func__, fd);
 
        if (channel_data->io_source == 0) {
-               LOGDEBUG ("%s: channel already closed for fd %d", __func__, fd);
+               DEBUG ("%s: channel already closed for fd %d", __func__, fd);
                return;
        }
 
@@ -482,7 +484,7 @@ static void rem_fd(GIOChannel *channel, ChannelData *channel_data)
                handle_count=channel_data->open_handles[i];
                
                for(j=0; j<handle_count; j++) {
-                       LOGDEBUG ("%s: closing handle 0x%x for client at index %d", __func__, i, g_io_channel_unix_get_fd (channel));
+                       DEBUG ("%s: closing handle 0x%x for client at index %d", __func__, i, g_io_channel_unix_get_fd (channel));
                        /* Ignore the hint to the client to destroy
                         * the handle private data
                         */
@@ -563,7 +565,7 @@ static gboolean share_compare (gpointer handle, gpointer user_data)
        
        if (file_handle->device == sharekey->device &&
            file_handle->inode == sharekey->inode) {
-               LOGDEBUG ("%s: found one, handle %p", __func__, handle);
+               DEBUG ("%s: found one, handle %p", __func__, handle);
                return(TRUE);
        } else {
                return(FALSE);
@@ -575,7 +577,7 @@ static void check_sharing (dev_t device, ino_t inode)
        ShareKey sharekey;
        gpointer file_handle;
        
-       LOGDEBUG ("%s: Checking if anything has (dev 0x%llx, inode %lld) still open", __func__, device, inode);
+       DEBUG ("%s: Checking if anything has (dev 0x%llx, inode %lld) still open", __func__, device, inode);
 
        sharekey.device = device;
        sharekey.inode = inode;
@@ -587,7 +589,7 @@ static void check_sharing (dev_t device, ino_t inode)
                /* Delete this share info, as the last handle to it
                 * has been closed
                 */
-               LOGDEBUG ("%s: Deleting share data for (dev 0x%llx inode %lld)", __func__, device, inode);
+               DEBUG ("%s: Deleting share data for (dev 0x%llx inode %lld)", __func__, device, inode);
                
                g_hash_table_remove (file_share_hash, &sharekey);
        }
@@ -638,7 +640,7 @@ static gboolean process_thread_compare (gpointer handle, gpointer user_data)
                 * _wapi_handle_set_signal_state() unless we have
                 * process-shared pthread support.
                 */
-               LOGDEBUG ("%s: Set thread handle %p signalled, because its process died", __func__, handle);
+               DEBUG ("%s: Set thread handle %p signalled, because its process died", __func__, handle);
 
                thread_handle->exitstatus=0;
 
@@ -685,7 +687,7 @@ static void process_post_mortem (pid_t pid, int status)
                 * This may happen if we use Process.EnableRaisingEvents +
                 * process.Exited event and the parent has finished.
                 */
-               LOGDEBUG ("%s: Couldn't find handle for process %d!", __func__, pid);
+               DEBUG ("%s: Couldn't find handle for process %d!", __func__, pid);
        } else {
                /* Signal the handle.  Don't use
                 * _wapi_handle_set_signal_state() unless we have
@@ -693,7 +695,7 @@ static void process_post_mortem (pid_t pid, int status)
                 */
                struct timeval tv;
                
-               LOGDEBUG ("%s: Set process %d exitstatus to %d", __func__, pid,
+               DEBUG ("%s: Set process %d exitstatus to %d", __func__, pid,
                           WEXITSTATUS (status));
                
                /* If the child terminated due to the receipt of a signal,
@@ -746,7 +748,7 @@ static void process_died (void)
        
        check_processes=FALSE;
 
-       LOGDEBUG ("%s: Reaping processes", __func__);
+       DEBUG ("%s: Reaping processes", __func__);
 
        while(TRUE) {
                pid=waitpid (-1, &status, WNOHANG);
@@ -759,7 +761,7 @@ static void process_died (void)
                        return;
                } else {
                        /* pid contains the ID of a dead process */
-                       LOGDEBUG ( "%s: process %d reaped", __func__, pid);
+                       DEBUG ( "%s: process %d reaped", __func__, pid);
                        process_post_mortem (pid, status);
                }
        }
@@ -842,7 +844,7 @@ static void process_new (GIOChannel *channel, ChannelData *channel_data,
 
        ref_handle (channel_data, handle);
 
-       LOGDEBUG ("%s: returning new handle 0x%x", __func__, handle);
+       DEBUG ("%s: returning new handle 0x%x", __func__, handle);
 
        resp.type=WapiHandleResponseType_New;
        resp.u.new.type=type;
@@ -873,7 +875,7 @@ static void process_open (GIOChannel *channel, ChannelData *channel_data,
        if(shared->type!=WAPI_HANDLE_UNUSED && handle!=0) {
                ref_handle (channel_data, handle);
 
-               LOGDEBUG ("%s: returning new handle 0x%x", __func__, handle);
+               DEBUG ("%s: returning new handle 0x%x", __func__, handle);
 
                resp.type=WapiHandleResponseType_Open;
                resp.u.new.type=shared->type;
@@ -907,7 +909,7 @@ static void process_close (GIOChannel *channel, ChannelData *channel_data,
        resp.type=WapiHandleResponseType_Close;
        resp.u.close.destroy=unref_handle (channel_data, handle);
 
-       LOGDEBUG ("%s: unreffing handle 0x%x", __func__, handle);
+       DEBUG ("%s: unreffing handle 0x%x", __func__, handle);
 
        send_reply (channel, &resp);
 }
@@ -926,7 +928,7 @@ static void process_scratch (GIOChannel *channel, guint32 length)
        resp.type=WapiHandleResponseType_Scratch;
        resp.u.scratch.idx=_wapi_handle_scratch_store_internal (length, &resp.u.scratch.remap);
 
-       LOGDEBUG ("%s: allocating scratch index 0x%x", __func__, resp.u.scratch.idx);
+       DEBUG ("%s: allocating scratch index 0x%x", __func__, resp.u.scratch.idx);
                        
        send_reply (channel, &resp);
 }
@@ -945,7 +947,7 @@ static void process_scratch_free (GIOChannel *channel, guint32 scratch_idx)
        resp.type=WapiHandleResponseType_ScratchFree;
        _wapi_handle_scratch_delete_internal (scratch_idx);
 
-       LOGDEBUG ("%s: deleting scratch index 0x%x", __func__, scratch_idx);
+       DEBUG ("%s: deleting scratch index 0x%x", __func__, scratch_idx);
                        
        send_reply (channel, &resp);
 }
@@ -965,11 +967,11 @@ process_process_kill (GIOChannel *channel,
 
        resp.type = WapiHandleResponseType_ProcessKill;
 
-       LOGDEBUG ("%s: kill (%d, %d)", __func__, process_kill.pid, process_kill.signo);
+       DEBUG ("%s: kill (%d, %d)", __func__, process_kill.pid, process_kill.signo);
 
        if (kill (process_kill.pid, process_kill.signo) == -1) {
                resp.u.process_kill.err = errno;
-               LOGDEBUG ("%s: kill (%d, %d) failed: %d", __func__, process_kill.pid, process_kill.signo, resp.u.process_kill.err);
+               DEBUG ("%s: kill (%d, %d) failed: %d", __func__, process_kill.pid, process_kill.signo, resp.u.process_kill.err);
        }
 
        send_reply (channel, &resp);
@@ -1053,7 +1055,7 @@ static void process_process_fork (GIOChannel *channel, ChannelData *channel_data
                         */
                        process_handle_data->exec_errno=gerr->code;
                } else {
-                       LOGDEBUG ("%s: forking", __func__);
+                       DEBUG ("%s: forking", __func__);
 
                        /* Fork, exec cmd with args and optional env,
                         * and return the handles with pid and blank
@@ -1104,18 +1106,18 @@ static void process_process_fork (GIOChannel *channel, ChannelData *channel_data
                                        env[env_count+2]=NULL;
                                }
 
-#ifdef DEBUG
-                               LOGDEBUG ("%s: exec()ing [%s] in dir [%s]", __func__, cmd, dir);
+#ifdef DEBUG_ENABLED
+                               DEBUG ("%s: exec()ing [%s] in dir [%s]", __func__, cmd, dir);
                                {
                                        i=0;
                                        while(argv[i]!=NULL) {
-                                               LOGDEBUG ("arg %d: [%s]", i, argv[i]);
+                                               DEBUG ("arg %d: [%s]", i, argv[i]);
                                                i++;
                                        }
 
                                        i=0;
                                        while(env[i]!=NULL) {
-                                               LOGDEBUG ("env %d: [%s]", i, env[i]);
+                                               DEBUG ("env %d: [%s]", i, env[i]);
                                                i++;
                                        }
                                }
@@ -1208,7 +1210,7 @@ static void process_set_share (GIOChannel *channel, ChannelData *channel_data,
 
        resp.type = WapiHandleResponseType_SetShare;
        
-       LOGDEBUG ("%s: Setting share for file (dev:0x%llx, ino:%lld) mode 0x%x access 0x%x", __func__, set_share.device, set_share.inode, set_share.sharemode, set_share.access);
+       DEBUG ("%s: Setting share for file (dev:0x%llx, ino:%lld) mode 0x%x access 0x%x", __func__, set_share.device, set_share.inode, set_share.sharemode, set_share.access);
        
        sharemode_set (set_share.device, set_share.inode, set_share.sharemode,
                       set_share.access);
@@ -1233,14 +1235,14 @@ static void process_get_or_set_share (GIOChannel *channel,
        
        resp.type = WapiHandleResponseType_GetOrSetShare;
        
-       LOGDEBUG ("%s: Getting share status for file (dev:0x%llx, ino:%lld)", __func__, get_share.device, get_share.inode);
+       DEBUG ("%s: Getting share status for file (dev:0x%llx, ino:%lld)", __func__, get_share.device, get_share.inode);
 
        resp.u.get_or_set_share.exists = sharemode_get (get_share.device, get_share.inode, &resp.u.get_or_set_share.sharemode, &resp.u.get_or_set_share.access);
        
        if (resp.u.get_or_set_share.exists) {
-               LOGDEBUG ("%s: Share mode: 0x%x", __func__, resp.u.get_or_set_share.sharemode);
+               DEBUG ("%s: Share mode: 0x%x", __func__, resp.u.get_or_set_share.sharemode);
        } else {
-               LOGDEBUG ("%s: file share info not already known, setting", __func__);
+               DEBUG ("%s: file share info not already known, setting", __func__);
                sharemode_set (get_share.device, get_share.inode,
                               get_share.new_sharemode, get_share.new_access);
        }
@@ -1269,25 +1271,25 @@ static gboolean read_message (GIOChannel *channel, ChannelData *channel_data)
                                  fds, &has_fds);
        if(ret==0) {
                /* Other end went away */
-               LOGDEBUG ("Read 0 bytes on fd %d, closing it",
+               DEBUG ("Read 0 bytes on fd %d, closing it",
                           g_io_channel_unix_get_fd (channel));
                rem_fd (channel, channel_data);
                return(FALSE);
        }
        
-       LOGDEBUG ("Process request %d", req.type);
+       DEBUG ("Process request %d", req.type);
        switch(req.type) {
        case WapiHandleRequestType_New:
                process_new (channel, channel_data, req.u.new.type);
                break;
        case WapiHandleRequestType_Open:
-#ifdef DEBUG
+#ifdef DEBUG_ENABLED
                g_assert(req.u.open.handle < _wapi_shared_data[0]->num_segments * _WAPI_HANDLES_PER_SEGMENT);
 #endif
                process_open (channel, channel_data, req.u.open.handle);
                break;
        case WapiHandleRequestType_Close:
-#ifdef DEBUG
+#ifdef DEBUG_ENABLED
                g_assert(req.u.close.handle < _wapi_shared_data[0]->num_segments * _WAPI_HANDLES_PER_SEGMENT);
 #endif
                process_close (channel, channel_data, req.u.close.handle);
@@ -1321,9 +1323,9 @@ static gboolean read_message (GIOChannel *channel, ChannelData *channel_data)
        }
 
        if(has_fds==TRUE) {
-               LOGDEBUG ("%s: closing %d", __func__, fds[0]);
-               LOGDEBUG ("%s: closing %d", __func__, fds[1]);
-               LOGDEBUG ("%s: closing %d", __func__, fds[2]);
+               DEBUG ("%s: closing %d", __func__, fds[0]);
+               DEBUG ("%s: closing %d", __func__, fds[1]);
+               DEBUG ("%s: closing %d", __func__, fds[2]);
                
                close (fds[0]);
                close (fds[1]);
@@ -1350,7 +1352,7 @@ static gboolean fd_activity (GIOChannel *channel, GIOCondition condition,
        GMainContext *context=data;
        
        if(condition & (G_IO_HUP | G_IO_ERR | G_IO_NVAL)) {
-               LOGDEBUG ("fd %d error", fd);
+               DEBUG ("fd %d error", fd);
                rem_fd (channel, channel_data);
                return(FALSE);
        }
@@ -1368,10 +1370,10 @@ static gboolean fd_activity (GIOChannel *channel, GIOCondition condition,
                                exit (-1);
                        }
 
-                       LOGDEBUG ("accept returning %d", newsock);
+                       DEBUG ("accept returning %d", newsock);
                        add_fd (newsock, context);
                } else {
-                       LOGDEBUG ("reading data on fd %d", fd);
+                       DEBUG ("reading data on fd %d", fd);
 
                        return(read_message (channel, channel_data));
                }
@@ -1393,7 +1395,7 @@ void _wapi_daemon_main(gpointer data, gpointer scratch)
        int ret;
        GMainContext *context;
 
-       LOGDEBUG ("Starting up...");
+       DEBUG ("Starting up...");
 
        _wapi_shared_data[0]=data;
        _wapi_shared_scratch=scratch;
@@ -1422,7 +1424,7 @@ void _wapi_daemon_main(gpointer data, gpointer scratch)
                exit(-1);
        }
 
-       LOGDEBUG("bound");
+       DEBUG("bound");
 
        ret=listen(main_sock, 5);
        if(ret==-1) {
@@ -1430,7 +1432,7 @@ void _wapi_daemon_main(gpointer data, gpointer scratch)
                _wapi_shared_data[0]->daemon_running=DAEMON_DIED_AT_STARTUP;
                exit(-1);
        }
-       LOGDEBUG("listening");
+       DEBUG("listening");
 
        context = g_main_context_new ();
 
@@ -1447,7 +1449,7 @@ void _wapi_daemon_main(gpointer data, gpointer scratch)
                        process_died ();
                }
                
-               LOGDEBUG ("polling");
+               DEBUG ("polling");
 
                /* Block until something happens. We don't use
                 * g_main_loop_run() because we rely on the SIGCHLD
index b55e8e75fbcd8ac88038640532b80587cdf4bc9e..5c072aafd9ef1603b820fe03904df144d29a3363 100644 (file)
 
 #include <mono/io-layer/event-private.h>
 
-#undef DEBUG
+#if 0
+#define DEBUG(...) g_message(__VA_ARGS__)
+#else
+#define DEBUG(...)
+#endif
 
 static void event_signal(gpointer handle);
 static gboolean event_own (gpointer handle);
@@ -112,9 +116,7 @@ static gboolean event_own (gpointer handle)
                return (FALSE);
        }
        
-#ifdef DEBUG
-       g_message("%s: owning event handle %p", __func__, handle);
-#endif
+       DEBUG("%s: owning event handle %p", __func__, handle);
 
        if(event_handle->manual==FALSE) {
                g_assert (event_handle->set_count > 0);
@@ -138,9 +140,7 @@ static gboolean namedevent_own (gpointer handle)
        struct _WapiHandle_namedevent *namedevent_handle;
        gboolean ok;
        
-#ifdef DEBUG
-       g_message ("%s: owning named event handle %p", __func__, handle);
-#endif
+       DEBUG ("%s: owning named event handle %p", __func__, handle);
 
        ok = _wapi_lookup_handle (handle, WAPI_HANDLE_NAMEDEVENT,
                                  (gpointer *)&namedevent_handle);
@@ -173,9 +173,7 @@ static gpointer event_create (WapiSecurityAttributes *security G_GNUC_UNUSED,
         */
        SetLastError (ERROR_SUCCESS);
 
-#ifdef DEBUG
-       g_message ("%s: Creating unnamed event", __func__);
-#endif
+       DEBUG ("%s: Creating unnamed event", __func__);
        
        event_handle.manual = manual;
        event_handle.set_count = 0;
@@ -202,9 +200,7 @@ static gpointer event_create (WapiSecurityAttributes *security G_GNUC_UNUSED,
                _wapi_handle_set_signal_state (handle, TRUE, FALSE);
        }
        
-#ifdef DEBUG
-       g_message("%s: created new event handle %p", __func__, handle);
-#endif
+       DEBUG("%s: created new event handle %p", __func__, handle);
 
        thr_ret = _wapi_handle_unlock_handle (handle);
        g_assert (thr_ret == 0);
@@ -239,9 +235,7 @@ static gpointer namedevent_create (WapiSecurityAttributes *security G_GNUC_UNUSE
        
        utf8_name = g_utf16_to_utf8 (name, -1, NULL, NULL, NULL);
        
-#ifdef DEBUG
-       g_message ("%s: Creating named event [%s]", __func__, utf8_name);
-#endif
+       DEBUG ("%s: Creating named event [%s]", __func__, utf8_name);
        
        offset = _wapi_search_handle_namespace (WAPI_HANDLE_NAMEDEVENT,
                                                utf8_name);
@@ -312,9 +306,7 @@ static gpointer namedevent_create (WapiSecurityAttributes *security G_GNUC_UNUSE
                _wapi_handle_unlock_shared_handles ();
        }
        
-#ifdef DEBUG
-       g_message ("%s: returning event handle %p", __func__, handle);
-#endif
+       DEBUG ("%s: returning event handle %p", __func__, handle);
 
 cleanup:
        g_free (utf8_name);
@@ -378,9 +370,7 @@ static gboolean event_pulse (gpointer handle)
        thr_ret = _wapi_handle_lock_handle (handle);
        g_assert (thr_ret == 0);
 
-#ifdef DEBUG
-       g_message ("%s: Pulsing event handle %p", __func__, handle);
-#endif
+       DEBUG ("%s: Pulsing event handle %p", __func__, handle);
 
        if (event_handle->manual == TRUE) {
                _wapi_handle_set_signal_state (handle, TRUE, TRUE);
@@ -407,10 +397,8 @@ static gboolean event_pulse (gpointer handle)
                 * have proceeded.  Currently we rely on broadcasting
                 * a condition.
                 */
-#ifdef DEBUG
-               g_message ("%s: Obtained write lock on event handle %p",
+               DEBUG ("%s: Obtained write lock on event handle %p",
                           __func__, handle);
-#endif
 
                pthread_cleanup_push ((void(*)(void *))_wapi_handle_unlock_handle, handle);
                thr_ret = _wapi_handle_lock_handle (handle);
@@ -443,9 +431,7 @@ static gboolean namedevent_pulse (gpointer handle)
        thr_ret = _wapi_handle_lock_shared_handles ();
        g_assert (thr_ret == 0);
 
-#ifdef DEBUG
-       g_message ("%s: Pulsing named event handle %p", __func__, handle);
-#endif
+       DEBUG ("%s: Pulsing named event handle %p", __func__, handle);
 
        if (namedevent_handle->manual == TRUE) {
                _wapi_shared_handle_set_signal_state (handle, TRUE);
@@ -469,10 +455,8 @@ static gboolean namedevent_pulse (gpointer handle)
                 * have proceeded.  Currently we rely on waiting for
                 * twice the shared handle poll interval.
                 */
-#ifdef DEBUG
-               g_message ("%s: Obtained write lock on event handle %p",
+               DEBUG ("%s: Obtained write lock on event handle %p",
                           __func__, handle);
-#endif
 
                thr_ret = _wapi_handle_lock_shared_handles ();
                g_assert (thr_ret == 0);
@@ -533,9 +517,7 @@ static gboolean event_reset (gpointer handle)
                return(FALSE);
        }
 
-#ifdef DEBUG
-       g_message ("%s: Resetting event handle %p", __func__, handle);
-#endif
+       DEBUG ("%s: Resetting event handle %p", __func__, handle);
 
        pthread_cleanup_push ((void(*)(void *))_wapi_handle_unlock_handle,
                              handle);
@@ -543,15 +525,11 @@ static gboolean event_reset (gpointer handle)
        g_assert (thr_ret == 0);
        
        if (_wapi_handle_issignalled (handle) == FALSE) {
-#ifdef DEBUG
-               g_message ("%s: No need to reset event handle %p", __func__,
+               DEBUG ("%s: No need to reset event handle %p", __func__,
                           handle);
-#endif
        } else {
-#ifdef DEBUG
-               g_message ("%s: Obtained write lock on event handle %p",
+               DEBUG ("%s: Obtained write lock on event handle %p",
                           __func__, handle);
-#endif
 
                _wapi_handle_set_signal_state (handle, FALSE, FALSE);
        }
@@ -580,23 +558,17 @@ static gboolean namedevent_reset (gpointer handle)
                return(FALSE);
        }
 
-#ifdef DEBUG
-       g_message ("%s: Resetting named event handle %p", __func__, handle);
-#endif
+       DEBUG ("%s: Resetting named event handle %p", __func__, handle);
 
        thr_ret = _wapi_handle_lock_shared_handles ();
        g_assert (thr_ret == 0);
        
        if (_wapi_handle_issignalled (handle) == FALSE) {
-#ifdef DEBUG
-               g_message ("%s: No need to reset named event handle %p",
+               DEBUG ("%s: No need to reset named event handle %p",
                           __func__, handle);
-#endif
        } else {
-#ifdef DEBUG
-               g_message ("%s: Obtained write lock on named event handle %p",
+               DEBUG ("%s: Obtained write lock on named event handle %p",
                           __func__, handle);
-#endif
 
                _wapi_shared_handle_set_signal_state (handle, FALSE);
        }
@@ -655,9 +627,7 @@ static gboolean event_set (gpointer handle)
        thr_ret = _wapi_handle_lock_handle (handle);
        g_assert (thr_ret == 0);
 
-#ifdef DEBUG
-       g_message ("%s: Setting event handle %p", __func__, handle);
-#endif
+       DEBUG ("%s: Setting event handle %p", __func__, handle);
 
        if (event_handle->manual == TRUE) {
                _wapi_handle_set_signal_state (handle, TRUE, TRUE);
@@ -691,9 +661,7 @@ static gboolean namedevent_set (gpointer handle)
        thr_ret = _wapi_handle_lock_shared_handles ();
        g_assert (thr_ret == 0);
 
-#ifdef DEBUG
-       g_message ("%s: Setting named event handle %p", __func__, handle);
-#endif
+       DEBUG ("%s: Setting named event handle %p", __func__, handle);
 
        if (namedevent_handle->manual == TRUE) {
                _wapi_shared_handle_set_signal_state (handle, TRUE);
@@ -758,9 +726,7 @@ gpointer OpenEvent (guint32 access G_GNUC_UNUSED, gboolean inherit G_GNUC_UNUSED
 
        utf8_name = g_utf16_to_utf8 (name, -1, NULL, NULL, NULL);
        
-#ifdef DEBUG
-       g_message ("%s: Opening named event [%s]", __func__, utf8_name);
-#endif
+       DEBUG ("%s: Opening named event [%s]", __func__, utf8_name);
        
        offset = _wapi_search_handle_namespace (WAPI_HANDLE_NAMEDEVENT,
                                                utf8_name);
@@ -789,9 +755,7 @@ gpointer OpenEvent (guint32 access G_GNUC_UNUSED, gboolean inherit G_GNUC_UNUSED
        }
        ret = handle;
 
-#ifdef DEBUG
-       g_message ("%s: returning named event handle %p", __func__, handle);
-#endif
+       DEBUG ("%s: returning named event handle %p", __func__, handle);
 
 cleanup:
        g_free (utf8_name);
index 7eaf93ae082286d096082f1dd67426ed1158d5b3..baadb3b62a9a7a149b022f08ccad81bf753108d4 100644 (file)
 #include <mono/io-layer/process-private.h>
 #include <mono/io-layer/critical-section-private.h>
 
-#undef DEBUG
 #undef DEBUG_REFS
 
+#if 0
+#define DEBUG(...) g_message(__VA_ARGS__)
+#else
+#define DEBUG(...)
+#endif
+
 static void (*_wapi_handle_ops_get_close_func (WapiHandleType type))(gpointer, gpointer);
 
 static WapiHandleCapability handle_caps[WAPI_HANDLE_COUNT]={0};
@@ -208,9 +213,7 @@ static void handle_cleanup (void)
                        }
                                
                        for(k = handle_data->ref; k > 0; k--) {
-#ifdef DEBUG
-                               g_message ("%s: unreffing %s handle %p", __func__, _wapi_handle_typename[type], handle);
-#endif
+                               DEBUG ("%s: unreffing %s handle %p", __func__, _wapi_handle_typename[type], handle);
                                        
                                _wapi_handle_unref_full (handle, TRUE);
                        }
@@ -451,10 +454,8 @@ static gpointer _wapi_handle_real_new (WapiHandleType type, gpointer handle_spec
        gpointer handle;
        int thr_ret;
        
-#ifdef DEBUG
-       g_message ("%s: Creating new handle of type %s", __func__,
+       DEBUG ("%s: Creating new handle of type %s", __func__,
                   _wapi_handle_typename[type]);
-#endif
 
        g_assert(!_WAPI_FD_HANDLE(type));
        
@@ -492,9 +493,7 @@ static gpointer _wapi_handle_real_new (WapiHandleType type, gpointer handle_spec
        
        handle = GUINT_TO_POINTER (handle_idx);
 
-#ifdef DEBUG
-       g_message ("%s: Allocated new handle %p", __func__, handle);
-#endif
+       DEBUG ("%s: Allocated new handle %p", __func__, handle);
        
        if (_WAPI_SHARED_HANDLE(type)) {
                /* Add the shared section too */
@@ -512,10 +511,8 @@ static gpointer _wapi_handle_real_new (WapiHandleType type, gpointer handle_spec
                }
                
                _WAPI_PRIVATE_HANDLES(handle_idx).u.shared.offset = ref;
-#ifdef DEBUG
-               g_message ("%s: New shared handle at offset 0x%x", __func__,
+               DEBUG ("%s: New shared handle at offset 0x%x", __func__,
                           ref);
-#endif
        }
                
 done:
@@ -543,10 +540,8 @@ gpointer _wapi_handle_new_from_offset (WapiHandleType type, guint32 offset,
        
        mono_once (&shared_init_once, shared_init);
 
-#ifdef DEBUG
-       g_message ("%s: Creating new handle of type %s to offset %d", __func__,
+       DEBUG ("%s: Creating new handle of type %s to offset %d", __func__,
                   _wapi_handle_typename[type], offset);
-#endif
 
        g_assert(!_WAPI_FD_HANDLE(type));
        g_assert(_WAPI_SHARED_HANDLE(type));
@@ -586,10 +581,8 @@ first_pass_done:
        if (handle != INVALID_HANDLE_VALUE) {
                _wapi_handle_ref (handle);
 
-#ifdef DEBUG
-               g_message ("%s: Returning old handle %p referencing 0x%x",
+               DEBUG ("%s: Returning old handle %p referencing 0x%x",
                           __func__, handle, offset);
-#endif
                return (handle);
        }
 
@@ -599,19 +592,15 @@ first_pass_done:
        
        if (shared->type == WAPI_HANDLE_UNUSED) {
                /* Someone deleted this handle while we were working */
-#ifdef DEBUG
-               g_message ("%s: Handle at 0x%x unused", __func__, offset);
-#endif
+               DEBUG ("%s: Handle at 0x%x unused", __func__, offset);
                goto done;
        }
 
        if (shared->type != type) {
-#ifdef DEBUG
-               g_message ("%s: Wrong type at %d 0x%x! Found %s wanted %s",
+               DEBUG ("%s: Wrong type at %d 0x%x! Found %s wanted %s",
                           __func__, offset, offset,
                           _wapi_handle_typename[shared->type],
                           _wapi_handle_typename[type]);
-#endif
                goto done;
        }
        
@@ -642,9 +631,7 @@ first_pass_done:
        _WAPI_PRIVATE_HANDLES(handle_idx).u.shared.offset = offset;
        InterlockedIncrement ((gint32 *)&shared->handle_refs);
        
-#ifdef DEBUG
-       g_message ("%s: Allocated new handle %p referencing 0x%x (shared refs %d)", __func__, handle, offset, shared->handle_refs);
-#endif
+       DEBUG ("%s: Allocated new handle %p referencing 0x%x (shared refs %d)", __func__, handle, offset, shared->handle_refs);
        
 done:
        _wapi_handle_unlock_shared_handles ();
@@ -683,18 +670,14 @@ gpointer _wapi_handle_new_fd (WapiHandleType type, int fd,
        
        mono_once (&shared_init_once, shared_init);
        
-#ifdef DEBUG
-       g_message ("%s: Creating new handle of type %s", __func__,
+       DEBUG ("%s: Creating new handle of type %s", __func__,
                   _wapi_handle_typename[type]);
-#endif
        
        g_assert(_WAPI_FD_HANDLE(type));
        g_assert(!_WAPI_SHARED_HANDLE(type));
        
        if (fd >= _wapi_fd_reserve) {
-#ifdef DEBUG
-               g_message ("%s: fd %d is too big", __func__, fd);
-#endif
+               DEBUG ("%s: fd %d is too big", __func__, fd);
 
                return(GUINT_TO_POINTER (_WAPI_HANDLE_INVALID));
        }
@@ -706,17 +689,13 @@ gpointer _wapi_handle_new_fd (WapiHandleType type, int fd,
        handle = &_WAPI_PRIVATE_HANDLES(fd);
        
        if (handle->type != WAPI_HANDLE_UNUSED) {
-#ifdef DEBUG
-               g_message ("%s: fd %d is already in use!", __func__, fd);
-#endif
+               DEBUG ("%s: fd %d is already in use!", __func__, fd);
                /* FIXME: clean up this handle?  We can't do anything
                 * with the fd, cos thats the new one
                 */
        }
 
-#ifdef DEBUG
-       g_message ("%s: Assigning new fd handle %d", __func__, fd);
-#endif
+       DEBUG ("%s: Assigning new fd handle %d", __func__, fd);
 
        /* Prevent file share entries racing with us, when the file
         * handle is only half initialised
@@ -864,9 +843,7 @@ gpointer _wapi_search_handle (WapiHandleType type,
 
        if (!found && search_shared && _WAPI_SHARED_HANDLE (type)) {
                /* Not found yet, so search the shared memory too */
-#ifdef DEBUG
-               g_message ("%s: Looking at other shared handles...", __func__);
-#endif
+               DEBUG ("%s: Looking at other shared handles...", __func__);
 
                for (i = 0; i < _WAPI_HANDLE_INITIAL_COUNT; i++) {
                        shared = &_wapi_shared_layout->handles[i];
@@ -887,9 +864,7 @@ gpointer _wapi_search_handle (WapiHandleType type,
                                        continue;
                                }
                                
-#ifdef DEBUG
-                               g_message ("%s: Opened tmp handle %p (type %s) from offset %d", __func__, ret, _wapi_handle_typename[type], i);
-#endif
+                               DEBUG ("%s: Opened tmp handle %p (type %s) from offset %d", __func__, ret, _wapi_handle_typename[type], i);
 
                                /* It's possible that the shared part
                                 * of this handle has now been blown
@@ -966,10 +941,8 @@ gint32 _wapi_search_handle_namespace (WapiHandleType type,
        
        g_assert(_WAPI_SHARED_HANDLE(type));
        
-#ifdef DEBUG
-       g_message ("%s: Lookup for handle named [%s] type %s", __func__,
+       DEBUG ("%s: Lookup for handle named [%s] type %s", __func__,
                   utf8_name, _wapi_handle_typename[type]);
-#endif
 
        /* Do a handle collection before starting to look, so that any
         * stale cruft gets removed
@@ -992,28 +965,20 @@ gint32 _wapi_search_handle_namespace (WapiHandleType type,
                        continue;
                }
 
-#ifdef DEBUG
-               g_message ("%s: found a shared namespace handle at 0x%x (type %s)", __func__, i, _wapi_handle_typename[shared_handle_data->type]);
-#endif
+               DEBUG ("%s: found a shared namespace handle at 0x%x (type %s)", __func__, i, _wapi_handle_typename[shared_handle_data->type]);
 
                sharedns=(WapiSharedNamespace *)&shared_handle_data->u;
                        
-#ifdef DEBUG
-               g_message ("%s: name is [%s]", __func__, sharedns->name);
-#endif
+               DEBUG ("%s: name is [%s]", __func__, sharedns->name);
 
                if (strcmp (sharedns->name, utf8_name) == 0) {
                        if (shared_handle_data->type != type) {
                                /* Its the wrong type, so fail now */
-#ifdef DEBUG
-                               g_message ("%s: handle 0x%x matches name but is wrong type: %s", __func__, i, _wapi_handle_typename[shared_handle_data->type]);
-#endif
+                               DEBUG ("%s: handle 0x%x matches name but is wrong type: %s", __func__, i, _wapi_handle_typename[shared_handle_data->type]);
                                ret = -1;
                                goto done;
                        } else {
-#ifdef DEBUG
-                               g_message ("%s: handle 0x%x matches name and type", __func__, i);
-#endif
+                               DEBUG ("%s: handle 0x%x matches name and type", __func__, i);
                                ret = i;
                                goto done;
                        }
@@ -1120,9 +1085,7 @@ static void _wapi_handle_unref_full (gpointer handle, gboolean ignore_private_bu
                pthread_cleanup_push ((void(*)(void *))mono_mutex_unlock_in_cleanup, (void *)&scan_mutex);
                thr_ret = mono_mutex_lock (&scan_mutex);
 
-#ifdef DEBUG
-               g_message ("%s: Destroying handle %p", __func__, handle);
-#endif
+               DEBUG ("%s: Destroying handle %p", __func__, handle);
                
                memcpy (&handle_data, &_WAPI_PRIVATE_HANDLES(idx),
                        sizeof (struct _WapiHandleUnshared));
@@ -1216,10 +1179,8 @@ gboolean _wapi_handle_test_capabilities (gpointer handle,
        
        type = _WAPI_PRIVATE_HANDLES(idx).type;
 
-#ifdef DEBUG
-       g_message ("%s: testing 0x%x against 0x%x (%d)", __func__,
+       DEBUG ("%s: testing 0x%x against 0x%x (%d)", __func__,
                   handle_caps[type], caps, handle_caps[type] & caps);
-#endif
        
        return((handle_caps[type] & caps) != 0);
 }
@@ -1419,9 +1380,7 @@ again:
                gpointer handle = handles[i];
                guint32 idx = GPOINTER_TO_UINT(handle);
 
-#ifdef DEBUG
-               g_message ("%s: attempting to lock %p", __func__, handle);
-#endif
+               DEBUG ("%s: attempting to lock %p", __func__, handle);
 
                type = _WAPI_PRIVATE_HANDLES(idx).type;
 
@@ -1430,10 +1389,8 @@ again:
                if (thr_ret != 0) {
                        /* Bummer */
                        
-#ifdef DEBUG
-                       g_message ("%s: attempt failed for %p: %s", __func__,
+                       DEBUG ("%s: attempt failed for %p: %s", __func__,
                                   handle, strerror (thr_ret));
-#endif
 
                        thr_ret = _wapi_handle_unlock_shared_handles ();
                        g_assert (thr_ret == 0);
@@ -1457,19 +1414,15 @@ again:
                                iter=1;
                        }
                        
-#ifdef DEBUG
-                       g_message ("%s: Backing off for %d ms", __func__,
+                       DEBUG ("%s: Backing off for %d ms", __func__,
                                   iter*10);
-#endif
                        _wapi_handle_spin (10 * iter);
                        
                        goto again;
                }
        }
        
-#ifdef DEBUG
-       g_message ("%s: Locked all handles", __func__);
-#endif
+       DEBUG ("%s: Locked all handles", __func__);
 
        count=0;
        *lowest=numhandles;
@@ -1480,9 +1433,7 @@ again:
                
                type = _WAPI_PRIVATE_HANDLES(idx).type;
 
-#ifdef DEBUG
-               g_message ("%s: Checking handle %p", __func__, handle);
-#endif
+               DEBUG ("%s: Checking handle %p", __func__, handle);
 
                if(((_wapi_handle_test_capabilities (handle, WAPI_HANDLE_CAP_OWN)==TRUE) &&
                    (_wapi_handle_ops_isowned (handle) == TRUE)) ||
@@ -1492,19 +1443,15 @@ again:
                    _WAPI_PRIVATE_HANDLES(idx).signalled == TRUE)) {
                        count++;
                        
-#ifdef DEBUG
-                       g_message ("%s: Handle %p signalled", __func__,
+                       DEBUG ("%s: Handle %p signalled", __func__,
                                   handle);
-#endif
                        if(*lowest>i) {
                                *lowest=i;
                        }
                }
        }
        
-#ifdef DEBUG
-       g_message ("%s: %d event handles signalled", __func__, count);
-#endif
+       DEBUG ("%s: %d event handles signalled", __func__, count);
 
        if ((waitall == TRUE && count == numhandles) ||
            (waitall == FALSE && count > 0)) {
@@ -1513,9 +1460,7 @@ again:
                ret=FALSE;
        }
        
-#ifdef DEBUG
-       g_message ("%s: Returning %d", __func__, ret);
-#endif
+       DEBUG ("%s: Returning %d", __func__, ret);
 
        *retcount=count;
        
@@ -1533,9 +1478,7 @@ void _wapi_handle_unlock_handles (guint32 numhandles, gpointer *handles)
        for(i=0; i<numhandles; i++) {
                gpointer handle = handles[i];
                
-#ifdef DEBUG
-               g_message ("%s: unlocking handle %p", __func__, handle);
-#endif
+               DEBUG ("%s: unlocking handle %p", __func__, handle);
 
                thr_ret = _wapi_handle_unlock_handle (handle);
                g_assert (thr_ret == 0);
@@ -1587,9 +1530,7 @@ int _wapi_handle_timedwait_signal (struct timespec *timeout, gboolean poll)
 
 int _wapi_handle_wait_signal_handle (gpointer handle, gboolean alertable)
 {
-#ifdef DEBUG
-       g_message ("%s: waiting for %p", __func__, handle);
-#endif
+       DEBUG ("%s: waiting for %p", __func__, handle);
        
        return _wapi_handle_timedwait_signal_handle (handle, NULL, alertable, FALSE);
 }
@@ -1597,10 +1538,8 @@ int _wapi_handle_wait_signal_handle (gpointer handle, gboolean alertable)
 int _wapi_handle_timedwait_signal_handle (gpointer handle,
                                                                                  struct timespec *timeout, gboolean alertable, gboolean poll)
 {
-#ifdef DEBUG
-       g_message ("%s: waiting for %p (type %s)", __func__, handle,
+       DEBUG ("%s: waiting for %p (type %s)", __func__, handle,
                   _wapi_handle_typename[_wapi_handle_type (handle)]);
-#endif
        
        if (_WAPI_SHARED_HANDLE (_wapi_handle_type (handle))) {
                if (WAPI_SHARED_HANDLE_DATA(handle).signalled == TRUE) {
@@ -1833,9 +1772,7 @@ static void _wapi_handle_check_share_by_pid (struct _WapiFileShare *share_info)
                 * owned by someone else) so mark this share info as
                 * dead
                 */
-#ifdef DEBUG
-               g_message ("%s: Didn't find it, destroying entry", __func__);
-#endif
+               DEBUG ("%s: Didn't find it, destroying entry", __func__);
 
                memset (share_info, '\0', sizeof(struct _WapiFileShare));
        }
@@ -1885,10 +1822,8 @@ void _wapi_handle_check_share (struct _WapiFileShare *share_info, int fd)
                                struct _WapiHandle_file *file_handle = &handle->u.file;
 
                                if (file_handle->share_info == share_info) {
-#ifdef DEBUG
-                                       g_message ("%s: handle 0x%x has this file open!",
+                                       DEBUG ("%s: handle 0x%x has this file open!",
                                                           __func__, i);
-#endif
 
                                        goto done;
                                }
@@ -1922,9 +1857,7 @@ void _wapi_handle_check_share (struct _WapiFileShare *share_info, int fd)
                                continue;
                        }
 
-#ifdef DEBUG
-                       g_message ("%s: Looking in %s", __func__, subdir);
-#endif
+                       DEBUG ("%s: Looking in %s", __func__, subdir);
                        
                        proc_fds = TRUE;
                        
@@ -1946,10 +1879,8 @@ void _wapi_handle_check_share (struct _WapiFileShare *share_info, int fd)
                                stat (path, &link_stat);
                                if (link_stat.st_dev == share_info->device &&
                                    link_stat.st_ino == share_info->inode) {
-#ifdef DEBUG
-                                       g_message ("%s:  Found it at %s",
+                                       DEBUG ("%s:  Found it at %s",
                                                   __func__, path);
-#endif
 
                                        found = TRUE;
                                }
@@ -1963,9 +1894,7 @@ void _wapi_handle_check_share (struct _WapiFileShare *share_info, int fd)
                _wapi_handle_check_share_by_pid (share_info);
        } else if (found == FALSE) {
                /* Blank out this entry, as it is stale */
-#ifdef DEBUG
-               g_message ("%s: Didn't find it, destroying entry", __func__);
-#endif
+               DEBUG ("%s: Didn't find it, destroying entry", __func__);
 
                memset (share_info, '\0', sizeof(struct _WapiFileShare));
        }
@@ -2067,29 +1996,21 @@ void _wapi_handle_update_refs (void)
                                if (_WAPI_SHARED_HANDLE(handle->type)) {
                                        struct _WapiHandleShared *shared_data;
                                
-#ifdef DEBUG
-                                       g_message ("%s: (%d) handle 0x%x is SHARED (%s)", __func__, _wapi_getpid (), i * _WAPI_HANDLE_INITIAL_COUNT + k, _wapi_handle_typename[handle->type]);
-#endif
+                                       DEBUG ("%s: (%d) handle 0x%x is SHARED (%s)", __func__, _wapi_getpid (), i * _WAPI_HANDLE_INITIAL_COUNT + k, _wapi_handle_typename[handle->type]);
 
                                        shared_data = &_wapi_shared_layout->handles[handle->u.shared.offset];
 
-#ifdef DEBUG
-                                       g_message ("%s: (%d) Updating timestamp of handle 0x%x", __func__, _wapi_getpid (), handle->u.shared.offset);
-#endif
+                                       DEBUG ("%s: (%d) Updating timestamp of handle 0x%x", __func__, _wapi_getpid (), handle->u.shared.offset);
 
                                        InterlockedExchange ((gint32 *)&shared_data->timestamp, now);
                                } else if (handle->type == WAPI_HANDLE_FILE) {
                                        struct _WapiHandle_file *file_handle = &handle->u.file;
                                
-#ifdef DEBUG
-                                       g_message ("%s: (%d) handle 0x%x is FILE", __func__, _wapi_getpid (), i * _WAPI_HANDLE_INITIAL_COUNT + k);
-#endif
+                                       DEBUG ("%s: (%d) handle 0x%x is FILE", __func__, _wapi_getpid (), i * _WAPI_HANDLE_INITIAL_COUNT + k);
                                
                                        g_assert (file_handle->share_info != NULL);
 
-#ifdef DEBUG
-                                       g_message ("%s: (%d) Inc refs on fileshare 0x%x", __func__, _wapi_getpid (), (file_handle->share_info - &_wapi_fileshare_layout->share_info[0]) / sizeof(struct _WapiFileShare));
-#endif
+                                       DEBUG ("%s: (%d) Inc refs on fileshare 0x%x", __func__, _wapi_getpid (), (file_handle->share_info - &_wapi_fileshare_layout->share_info[0]) / sizeof(struct _WapiFileShare));
 
                                        InterlockedExchange ((gint32 *)&file_handle->share_info->timestamp, now);
                                }
index f081bb688951dd8356f6bfb865c4cb6b518626f6..1a300e41a7324559ed045a7516b3d271fea9b7af 100644 (file)
 #include <mono/io-layer/io-portability.h>
 #include <mono/utils/strenc.h>
 
-#undef DEBUG
+#if 0
+#define DEBUG(...) g_message(__VA_ARGS__)
+#define DEBUG_ENABLED 1
+#else
+#define DEBUG(...)
+#endif
 
 static void file_close (gpointer handle, gpointer data);
 static WapiFileType file_getfiletype(void);
@@ -325,10 +330,8 @@ static void file_close (gpointer handle, gpointer data)
 {
        struct _WapiHandle_file *file_handle = (struct _WapiHandle_file *)data;
        
-#ifdef DEBUG
-       g_message("%s: closing file handle %p [%s]", __func__, handle,
+       DEBUG("%s: closing file handle %p [%s]", __func__, handle,
                  file_handle->filename);
-#endif
 
        if (file_handle->attrs & FILE_FLAG_DELETE_ON_CLOSE)
                _wapi_unlink (file_handle->filename);
@@ -370,10 +373,8 @@ static gboolean file_read(gpointer handle, gpointer buffer,
        
        if(!(file_handle->fileaccess & GENERIC_READ) &&
           !(file_handle->fileaccess & GENERIC_ALL)) {
-#ifdef DEBUG
-               g_message("%s: handle %p doesn't have GENERIC_READ access: %u",
+               DEBUG("%s: handle %p doesn't have GENERIC_READ access: %u",
                          __func__, handle, file_handle->fileaccess);
-#endif
 
                SetLastError (ERROR_ACCESS_DENIED);
                return(FALSE);
@@ -387,10 +388,8 @@ static gboolean file_read(gpointer handle, gpointer buffer,
        if(ret==-1) {
                gint err = errno;
 
-#ifdef DEBUG
-               g_message("%s: read of handle %p error: %s", __func__,
+               DEBUG("%s: read of handle %p error: %s", __func__,
                          handle, strerror(err));
-#endif
                SetLastError (_wapi_get_win32_file_error (err));
                return(FALSE);
        }
@@ -427,9 +426,7 @@ static gboolean file_write(gpointer handle, gconstpointer buffer,
        
        if(!(file_handle->fileaccess & GENERIC_WRITE) &&
           !(file_handle->fileaccess & GENERIC_ALL)) {
-#ifdef DEBUG
-               g_message("%s: handle %p doesn't have GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess);
-#endif
+               DEBUG("%s: handle %p doesn't have GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess);
 
                SetLastError (ERROR_ACCESS_DENIED);
                return(FALSE);
@@ -442,10 +439,8 @@ static gboolean file_write(gpointer handle, gconstpointer buffer,
                 */
                current_pos = lseek (fd, (off_t)0, SEEK_CUR);
                if (current_pos == -1) {
-#ifdef DEBUG
-                       g_message ("%s: handle %p lseek failed: %s", __func__,
+                       DEBUG ("%s: handle %p lseek failed: %s", __func__,
                                   handle, strerror (errno));
-#endif
                        _wapi_set_last_error_from_errno ();
                        return(FALSE);
                }
@@ -472,10 +467,8 @@ static gboolean file_write(gpointer handle, gconstpointer buffer,
                } else {
                        _wapi_set_last_error_from_errno ();
                                
-#ifdef DEBUG
-                       g_message("%s: write of handle %p error: %s",
+                       DEBUG("%s: write of handle %p error: %s",
                                  __func__, handle, strerror(errno));
-#endif
 
                        return(FALSE);
                }
@@ -504,9 +497,7 @@ static gboolean file_flush(gpointer handle)
 
        if(!(file_handle->fileaccess & GENERIC_WRITE) &&
           !(file_handle->fileaccess & GENERIC_ALL)) {
-#ifdef DEBUG
-               g_message("%s: handle %p doesn't have GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess);
-#endif
+               DEBUG("%s: handle %p doesn't have GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess);
 
                SetLastError (ERROR_ACCESS_DENIED);
                return(FALSE);
@@ -514,10 +505,8 @@ static gboolean file_flush(gpointer handle)
 
        ret=fsync(fd);
        if (ret==-1) {
-#ifdef DEBUG
-               g_message("%s: fsync of handle %p error: %s", __func__, handle,
+               DEBUG("%s: fsync of handle %p error: %s", __func__, handle,
                          strerror(errno));
-#endif
 
                _wapi_set_last_error_from_errno ();
                return(FALSE);
@@ -548,9 +537,7 @@ static guint32 file_seek(gpointer handle, gint32 movedistance,
        if(!(file_handle->fileaccess & GENERIC_READ) &&
           !(file_handle->fileaccess & GENERIC_WRITE) &&
           !(file_handle->fileaccess & GENERIC_ALL)) {
-#ifdef DEBUG
-               g_message ("%s: handle %p doesn't have GENERIC_READ or GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess);
-#endif
+               DEBUG ("%s: handle %p doesn't have GENERIC_READ or GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess);
 
                SetLastError (ERROR_ACCESS_DENIED);
                return(INVALID_SET_FILE_POINTER);
@@ -567,9 +554,7 @@ static guint32 file_seek(gpointer handle, gint32 movedistance,
                whence=SEEK_END;
                break;
        default:
-#ifdef DEBUG
-               g_message("%s: invalid seek type %d", __func__, method);
-#endif
+               DEBUG("%s: invalid seek type %d", __func__, method);
 
                SetLastError (ERROR_INVALID_PARAMETER);
                return(INVALID_SET_FILE_POINTER);
@@ -578,48 +563,38 @@ static guint32 file_seek(gpointer handle, gint32 movedistance,
 #ifdef HAVE_LARGE_FILE_SUPPORT
        if(highmovedistance==NULL) {
                offset=movedistance;
-#ifdef DEBUG
-               g_message("%s: setting offset to %lld (low %d)", __func__,
+               DEBUG("%s: setting offset to %lld (low %d)", __func__,
                          offset, movedistance);
-#endif
        } else {
                offset=((gint64) *highmovedistance << 32) | (guint32)movedistance;
                
-#ifdef DEBUG
-               g_message("%s: setting offset to %lld 0x%llx (high %d 0x%x, low %d 0x%x)", __func__, offset, offset, *highmovedistance, *highmovedistance, movedistance, movedistance);
-#endif
+               DEBUG("%s: setting offset to %lld 0x%llx (high %d 0x%x, low %d 0x%x)", __func__, offset, offset, *highmovedistance, *highmovedistance, movedistance, movedistance);
        }
 #else
        offset=movedistance;
 #endif
 
-#ifdef DEBUG
 #ifdef HAVE_LARGE_FILE_SUPPORT
-       g_message("%s: moving handle %p by %lld bytes from %d", __func__,
+       DEBUG ("%s: moving handle %p by %lld bytes from %d", __func__,
                  handle, offset, whence);
 #else
-       g_message("%s: moving handle %p fd %d by %ld bytes from %d", __func__,
+       DEBUG ("%s: moving handle %p fd %d by %ld bytes from %d", __func__,
                  handle, offset, whence);
-#endif
 #endif
 
        newpos=lseek(fd, offset, whence);
        if(newpos==-1) {
-#ifdef DEBUG
-               g_message("%s: lseek on handle %p returned error %s",
+               DEBUG("%s: lseek on handle %p returned error %s",
                          __func__, handle, strerror(errno));
-#endif
 
                _wapi_set_last_error_from_errno ();
                return(INVALID_SET_FILE_POINTER);
        }
 
-#ifdef DEBUG
 #ifdef HAVE_LARGE_FILE_SUPPORT
-       g_message("%s: lseek returns %lld", __func__, newpos);
+       DEBUG ("%s: lseek returns %lld", __func__, newpos);
 #else
-       g_message ("%s: lseek returns %ld", __func__, newpos);
-#endif
+       DEBUG ("%s: lseek returns %ld", __func__, newpos);
 #endif
 
 #ifdef HAVE_LARGE_FILE_SUPPORT
@@ -635,10 +610,8 @@ static guint32 file_seek(gpointer handle, gint32 movedistance,
        }
 #endif
 
-#ifdef DEBUG
-       g_message ("%s: move of handle %p returning %d/%d", __func__,
+       DEBUG ("%s: move of handle %p returning %d/%d", __func__,
                   handle, ret, highmovedistance==NULL?0:*highmovedistance);
-#endif
 
        return(ret);
 }
@@ -663,9 +636,7 @@ static gboolean file_setendoffile(gpointer handle)
        
        if(!(file_handle->fileaccess & GENERIC_WRITE) &&
           !(file_handle->fileaccess & GENERIC_ALL)) {
-#ifdef DEBUG
-               g_message("%s: handle %p doesn't have GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess);
-#endif
+               DEBUG("%s: handle %p doesn't have GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess);
 
                SetLastError (ERROR_ACCESS_DENIED);
                return(FALSE);
@@ -679,10 +650,8 @@ static gboolean file_setendoffile(gpointer handle)
        
        ret=fstat(fd, &statbuf);
        if(ret==-1) {
-#ifdef DEBUG
-               g_message ("%s: handle %p fstat failed: %s", __func__,
+               DEBUG ("%s: handle %p fstat failed: %s", __func__,
                           handle, strerror(errno));
-#endif
 
                _wapi_set_last_error_from_errno ();
                return(FALSE);
@@ -691,10 +660,8 @@ static gboolean file_setendoffile(gpointer handle)
 
        pos=lseek(fd, (off_t)0, SEEK_CUR);
        if(pos==-1) {
-#ifdef DEBUG
-               g_message("%s: handle %p lseek failed: %s", __func__,
+               DEBUG("%s: handle %p lseek failed: %s", __func__,
                          handle, strerror(errno));
-#endif
 
                _wapi_set_last_error_from_errno ();
                return(FALSE);
@@ -719,9 +686,7 @@ static gboolean file_setendoffile(gpointer handle)
                         !_wapi_thread_cur_apc_pending());
 
                if(ret==-1) {
-#ifdef DEBUG
-                       g_message("%s: handle %p extend write failed: %s", __func__, handle, strerror(errno));
-#endif
+                       DEBUG("%s: handle %p extend write failed: %s", __func__, handle, strerror(errno));
 
                        _wapi_set_last_error_from_errno ();
                        return(FALSE);
@@ -730,10 +695,8 @@ static gboolean file_setendoffile(gpointer handle)
                /* And put the file position back after the write */
                ret = lseek (fd, pos, SEEK_SET);
                if (ret == -1) {
-#ifdef DEBUG
-                       g_message ("%s: handle %p second lseek failed: %s",
+                       DEBUG ("%s: handle %p second lseek failed: %s",
                                   __func__, handle, strerror(errno));
-#endif
 
                        _wapi_set_last_error_from_errno ();
                        return(FALSE);
@@ -749,10 +712,8 @@ static gboolean file_setendoffile(gpointer handle)
        }
        while (ret==-1 && errno==EINTR && !_wapi_thread_cur_apc_pending()); 
        if(ret==-1) {
-#ifdef DEBUG
-               g_message("%s: handle %p ftruncate failed: %s", __func__,
+               DEBUG("%s: handle %p ftruncate failed: %s", __func__,
                          handle, strerror(errno));
-#endif
                
                _wapi_set_last_error_from_errno ();
                return(FALSE);
@@ -782,9 +743,7 @@ static guint32 file_getfilesize(gpointer handle, guint32 *highsize)
        if(!(file_handle->fileaccess & GENERIC_READ) &&
           !(file_handle->fileaccess & GENERIC_WRITE) &&
           !(file_handle->fileaccess & GENERIC_ALL)) {
-#ifdef DEBUG
-               g_message("%s: handle %p doesn't have GENERIC_READ or GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess);
-#endif
+               DEBUG("%s: handle %p doesn't have GENERIC_READ or GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess);
 
                SetLastError (ERROR_ACCESS_DENIED);
                return(INVALID_FILE_SIZE);
@@ -798,10 +757,8 @@ static guint32 file_getfilesize(gpointer handle, guint32 *highsize)
        
        ret = fstat(fd, &statbuf);
        if (ret == -1) {
-#ifdef DEBUG
-               g_message ("%s: handle %p fstat failed: %s", __func__,
+               DEBUG ("%s: handle %p fstat failed: %s", __func__,
                           handle, strerror(errno));
-#endif
 
                _wapi_set_last_error_from_errno ();
                return(INVALID_FILE_SIZE);
@@ -812,10 +769,8 @@ static guint32 file_getfilesize(gpointer handle, guint32 *highsize)
        if (S_ISBLK(statbuf.st_mode)) {
                guint64 bigsize;
                if (ioctl(fd, BLKGETSIZE64, &bigsize) < 0) {
-#ifdef DEBUG
-                       g_message ("%s: handle %p ioctl BLKGETSIZE64 failed: %s",
+                       DEBUG ("%s: handle %p ioctl BLKGETSIZE64 failed: %s",
                                   __func__, handle, strerror(errno));
-#endif
 
                        _wapi_set_last_error_from_errno ();
                        return(INVALID_FILE_SIZE);
@@ -826,10 +781,8 @@ static guint32 file_getfilesize(gpointer handle, guint32 *highsize)
                        *highsize = bigsize>>32;
                }
 
-#ifdef DEBUG
-               g_message ("%s: Returning block device size %d/%d",
+               DEBUG ("%s: Returning block device size %d/%d",
                           __func__, size, *highsize);
-#endif
        
                return(size);
        }
@@ -848,9 +801,7 @@ static guint32 file_getfilesize(gpointer handle, guint32 *highsize)
        size = statbuf.st_size;
 #endif
 
-#ifdef DEBUG
-       g_message ("%s: Returning size %d/%d", __func__, size, *highsize);
-#endif
+       DEBUG ("%s: Returning size %d/%d", __func__, size, *highsize);
        
        return(size);
 }
@@ -877,10 +828,8 @@ static gboolean file_getfiletime(gpointer handle, WapiFileTime *create_time,
 
        if(!(file_handle->fileaccess & GENERIC_READ) &&
           !(file_handle->fileaccess & GENERIC_ALL)) {
-#ifdef DEBUG
-               g_message("%s: handle %p doesn't have GENERIC_READ access: %u",
+               DEBUG("%s: handle %p doesn't have GENERIC_READ access: %u",
                          __func__, handle, file_handle->fileaccess);
-#endif
 
                SetLastError (ERROR_ACCESS_DENIED);
                return(FALSE);
@@ -888,20 +837,16 @@ static gboolean file_getfiletime(gpointer handle, WapiFileTime *create_time,
        
        ret=fstat(fd, &statbuf);
        if(ret==-1) {
-#ifdef DEBUG
-               g_message("%s: handle %p fstat failed: %s", __func__, handle,
+               DEBUG("%s: handle %p fstat failed: %s", __func__, handle,
                          strerror(errno));
-#endif
 
                _wapi_set_last_error_from_errno ();
                return(FALSE);
        }
 
-#ifdef DEBUG
-       g_message("%s: atime: %ld ctime: %ld mtime: %ld", __func__,
+       DEBUG("%s: atime: %ld ctime: %ld mtime: %ld", __func__,
                  statbuf.st_atime, statbuf.st_ctime,
                  statbuf.st_mtime);
-#endif
 
        /* Try and guess a meaningful create time by using the older
         * of atime or ctime
@@ -920,10 +865,8 @@ static gboolean file_getfiletime(gpointer handle, WapiFileTime *create_time,
        access_ticks=((guint64)statbuf.st_atime*10000000)+116444736000000000ULL;
        write_ticks=((guint64)statbuf.st_mtime*10000000)+116444736000000000ULL;
        
-#ifdef DEBUG
-       g_message("%s: aticks: %llu cticks: %llu wticks: %llu", __func__,
+       DEBUG("%s: aticks: %llu cticks: %llu wticks: %llu", __func__,
                  access_ticks, create_ticks, write_ticks);
-#endif
 
        if(create_time!=NULL) {
                create_time->dwLowDateTime = create_ticks & 0xFFFFFFFF;
@@ -967,18 +910,14 @@ static gboolean file_setfiletime(gpointer handle,
        
        if(!(file_handle->fileaccess & GENERIC_WRITE) &&
           !(file_handle->fileaccess & GENERIC_ALL)) {
-#ifdef DEBUG
-               g_message("%s: handle %p doesn't have GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess);
-#endif
+               DEBUG("%s: handle %p doesn't have GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess);
 
                SetLastError (ERROR_ACCESS_DENIED);
                return(FALSE);
        }
 
        if(file_handle->filename == NULL) {
-#ifdef DEBUG
-               g_message("%s: handle %p unknown filename", __func__, handle);
-#endif
+               DEBUG("%s: handle %p unknown filename", __func__, handle);
 
                SetLastError (ERROR_INVALID_HANDLE);
                return(FALSE);
@@ -989,10 +928,8 @@ static gboolean file_setfiletime(gpointer handle,
         */
        ret=fstat (fd, &statbuf);
        if(ret==-1) {
-#ifdef DEBUG
-               g_message("%s: handle %p fstat failed: %s", __func__, handle,
+               DEBUG("%s: handle %p fstat failed: %s", __func__, handle,
                          strerror(errno));
-#endif
 
                SetLastError (ERROR_INVALID_PARAMETER);
                return(FALSE);
@@ -1005,10 +942,8 @@ static gboolean file_setfiletime(gpointer handle,
                 * but this will do for now.
                 */
                if (access_ticks < 116444736000000000ULL) {
-#ifdef DEBUG
-                       g_message ("%s: attempt to set access time too early",
+                       DEBUG ("%s: attempt to set access time too early",
                                   __func__);
-#endif
                        SetLastError (ERROR_INVALID_PARAMETER);
                        return(FALSE);
                }
@@ -1025,10 +960,8 @@ static gboolean file_setfiletime(gpointer handle,
                 * but this will do for now.
                 */
                if (write_ticks < 116444736000000000ULL) {
-#ifdef DEBUG
-                       g_message ("%s: attempt to set write time too early",
+                       DEBUG ("%s: attempt to set write time too early",
                                   __func__);
-#endif
                        SetLastError (ERROR_INVALID_PARAMETER);
                        return(FALSE);
                }
@@ -1038,18 +971,14 @@ static gboolean file_setfiletime(gpointer handle,
                utbuf.modtime=statbuf.st_mtime;
        }
 
-#ifdef DEBUG
-       g_message ("%s: setting handle %p access %ld write %ld", __func__,
+       DEBUG ("%s: setting handle %p access %ld write %ld", __func__,
                   handle, utbuf.actime, utbuf.modtime);
-#endif
 
        ret = _wapi_utime (file_handle->filename, &utbuf);
        if (ret == -1) {
-#ifdef DEBUG
-               g_message ("%s: handle %p [%s] utime failed: %s", __func__,
+               DEBUG ("%s: handle %p [%s] utime failed: %s", __func__,
                           handle, file_handle->filename, strerror(errno));
 
-#endif
                SetLastError (ERROR_INVALID_PARAMETER);
                return(FALSE);
        }
@@ -1061,9 +990,7 @@ static void console_close (gpointer handle, gpointer data)
 {
        struct _WapiHandle_file *console_handle = (struct _WapiHandle_file *)data;
        
-#ifdef DEBUG
-       g_message("%s: closing console handle %p", __func__, handle);
-#endif
+       DEBUG("%s: closing console handle %p", __func__, handle);
 
        g_free (console_handle->filename);
        
@@ -1099,10 +1026,8 @@ static gboolean console_read(gpointer handle, gpointer buffer,
        
        if(!(console_handle->fileaccess & GENERIC_READ) &&
           !(console_handle->fileaccess & GENERIC_ALL)) {
-#ifdef DEBUG
-               g_message ("%s: handle %p doesn't have GENERIC_READ access: %u",
+               DEBUG ("%s: handle %p doesn't have GENERIC_READ access: %u",
                           __func__, handle, console_handle->fileaccess);
-#endif
 
                SetLastError (ERROR_ACCESS_DENIED);
                return(FALSE);
@@ -1113,10 +1038,8 @@ static gboolean console_read(gpointer handle, gpointer buffer,
        } while (ret==-1 && errno==EINTR && !_wapi_thread_cur_apc_pending());
 
        if(ret==-1) {
-#ifdef DEBUG
-               g_message("%s: read of handle %p error: %s", __func__, handle,
+               DEBUG("%s: read of handle %p error: %s", __func__, handle,
                          strerror(errno));
-#endif
 
                _wapi_set_last_error_from_errno ();
                return(FALSE);
@@ -1153,9 +1076,7 @@ static gboolean console_write(gpointer handle, gconstpointer buffer,
        
        if(!(console_handle->fileaccess & GENERIC_WRITE) &&
           !(console_handle->fileaccess & GENERIC_ALL)) {
-#ifdef DEBUG
-               g_message("%s: handle %p doesn't have GENERIC_WRITE access: %u", __func__, handle, console_handle->fileaccess);
-#endif
+               DEBUG("%s: handle %p doesn't have GENERIC_WRITE access: %u", __func__, handle, console_handle->fileaccess);
 
                SetLastError (ERROR_ACCESS_DENIED);
                return(FALSE);
@@ -1172,10 +1093,8 @@ static gboolean console_write(gpointer handle, gconstpointer buffer,
                } else {
                        _wapi_set_last_error_from_errno ();
                        
-#ifdef DEBUG
-                       g_message ("%s: write of handle %p error: %s",
+                       DEBUG ("%s: write of handle %p error: %s",
                                   __func__, handle, strerror(errno));
-#endif
 
                        return(FALSE);
                }
@@ -1189,9 +1108,7 @@ static gboolean console_write(gpointer handle, gconstpointer buffer,
 
 static void pipe_close (gpointer handle, gpointer data G_GNUC_UNUSED)
 {
-#ifdef DEBUG
-       g_message("%s: closing pipe handle %p", __func__, handle);
-#endif
+       DEBUG("%s: closing pipe handle %p", __func__, handle);
 
        /* No filename with pipe handles */
 
@@ -1227,19 +1144,15 @@ static gboolean pipe_read (gpointer handle, gpointer buffer,
        
        if(!(pipe_handle->fileaccess & GENERIC_READ) &&
           !(pipe_handle->fileaccess & GENERIC_ALL)) {
-#ifdef DEBUG
-               g_message("%s: handle %p doesn't have GENERIC_READ access: %u",
+               DEBUG("%s: handle %p doesn't have GENERIC_READ access: %u",
                          __func__, handle, pipe_handle->fileaccess);
-#endif
 
                SetLastError (ERROR_ACCESS_DENIED);
                return(FALSE);
        }
        
-#ifdef DEBUG
-       g_message ("%s: reading up to %d bytes from pipe %p", __func__,
+       DEBUG ("%s: reading up to %d bytes from pipe %p", __func__,
                   numbytes, handle);
-#endif
 
        do {
                ret=read(fd, buffer, numbytes);
@@ -1251,18 +1164,14 @@ static gboolean pipe_read (gpointer handle, gpointer buffer,
                } else {
                        _wapi_set_last_error_from_errno ();
                        
-#ifdef DEBUG
-                       g_message("%s: read of handle %p error: %s", __func__,
+                       DEBUG("%s: read of handle %p error: %s", __func__,
                                  handle, strerror(errno));
-#endif
 
                        return(FALSE);
                }
        }
        
-#ifdef DEBUG
-       g_message ("%s: read %d bytes from pipe", __func__, ret);
-#endif
+       DEBUG ("%s: read %d bytes from pipe", __func__, ret);
 
        if(bytesread!=NULL) {
                *bytesread=ret;
@@ -1295,18 +1204,14 @@ static gboolean pipe_write(gpointer handle, gconstpointer buffer,
        
        if(!(pipe_handle->fileaccess & GENERIC_WRITE) &&
           !(pipe_handle->fileaccess & GENERIC_ALL)) {
-#ifdef DEBUG
-               g_message("%s: handle %p doesn't have GENERIC_WRITE access: %u", __func__, handle, pipe_handle->fileaccess);
-#endif
+               DEBUG("%s: handle %p doesn't have GENERIC_WRITE access: %u", __func__, handle, pipe_handle->fileaccess);
 
                SetLastError (ERROR_ACCESS_DENIED);
                return(FALSE);
        }
        
-#ifdef DEBUG
-       g_message ("%s: writing up to %d bytes to pipe %p", __func__, numbytes,
+       DEBUG ("%s: writing up to %d bytes to pipe %p", __func__, numbytes,
                   handle);
-#endif
 
        do {
                ret = write (fd, buffer, numbytes);
@@ -1319,10 +1224,8 @@ static gboolean pipe_write(gpointer handle, gconstpointer buffer,
                } else {
                        _wapi_set_last_error_from_errno ();
                        
-#ifdef DEBUG
-                       g_message("%s: write of handle %p error: %s", __func__,
+                       DEBUG("%s: write of handle %p error: %s", __func__,
                                  handle, strerror(errno));
-#endif
 
                        return(FALSE);
                }
@@ -1349,10 +1252,8 @@ static int convert_flags(guint32 fileaccess, guint32 createmode)
                flags=O_RDWR;
                break;
        default:
-#ifdef DEBUG
-               g_message("%s: Unknown access type 0x%x", __func__,
+               DEBUG("%s: Unknown access type 0x%x", __func__,
                          fileaccess);
-#endif
                break;
        }
 
@@ -1372,10 +1273,8 @@ static int convert_flags(guint32 fileaccess, guint32 createmode)
                flags|=O_TRUNC;
                break;
        default:
-#ifdef DEBUG
-               g_message("%s: Unknown create mode 0x%x", __func__,
+               DEBUG("%s: Unknown create mode 0x%x", __func__,
                          createmode);
-#endif
                break;
        }
        
@@ -1414,9 +1313,7 @@ static gboolean share_allows_open (struct stat *statbuf, guint32 sharemode,
                 */
                if (file_existing_share == 0) {
                        /* Quick and easy, no possibility to share */
-#ifdef DEBUG
-                       g_message ("%s: Share mode prevents open: requested access: 0x%x, file has sharing = NONE", __func__, fileaccess);
-#endif
+                       DEBUG ("%s: Share mode prevents open: requested access: 0x%x, file has sharing = NONE", __func__, fileaccess);
 
                        _wapi_handle_share_release (*share_info);
                        
@@ -1428,9 +1325,7 @@ static gboolean share_allows_open (struct stat *statbuf, guint32 sharemode,
                    ((file_existing_share == FILE_SHARE_WRITE) &&
                     (fileaccess != GENERIC_WRITE))) {
                        /* New access mode doesn't match up */
-#ifdef DEBUG
-                       g_message ("%s: Share mode prevents open: requested access: 0x%x, file has sharing: 0x%x", __func__, fileaccess, file_existing_share);
-#endif
+                       DEBUG ("%s: Share mode prevents open: requested access: 0x%x, file has sharing: 0x%x", __func__, fileaccess, file_existing_share);
 
                        _wapi_handle_share_release (*share_info);
                
@@ -1442,18 +1337,14 @@ static gboolean share_allows_open (struct stat *statbuf, guint32 sharemode,
                    ((file_existing_access & GENERIC_WRITE) &&
                     !(sharemode & FILE_SHARE_WRITE))) {
                        /* New share mode doesn't match up */
-#ifdef DEBUG
-                       g_message ("%s: Access mode prevents open: requested share: 0x%x, file has access: 0x%x", __func__, sharemode, file_existing_access);
-#endif
+                       DEBUG ("%s: Access mode prevents open: requested share: 0x%x, file has access: 0x%x", __func__, sharemode, file_existing_access);
 
                        _wapi_handle_share_release (*share_info);
                
                        return(FALSE);
                }
        } else {
-#ifdef DEBUG
-               g_message ("%s: New file!", __func__);
-#endif
+               DEBUG ("%s: New file!", __func__);
        }
 
        return(TRUE);
@@ -1549,9 +1440,7 @@ gpointer CreateFile(const gunichar2 *name, guint32 fileaccess,
        }
        
        if (name == NULL) {
-#ifdef DEBUG
-               g_message ("%s: name is NULL", __func__);
-#endif
+               DEBUG ("%s: name is NULL", __func__);
 
                SetLastError (ERROR_INVALID_NAME);
                return(INVALID_HANDLE_VALUE);
@@ -1559,18 +1448,14 @@ gpointer CreateFile(const gunichar2 *name, guint32 fileaccess,
 
        filename = mono_unicode_to_external (name);
        if (filename == NULL) {
-#ifdef DEBUG
-               g_message("%s: unicode conversion returned NULL", __func__);
-#endif
+               DEBUG("%s: unicode conversion returned NULL", __func__);
 
                SetLastError (ERROR_INVALID_NAME);
                return(INVALID_HANDLE_VALUE);
        }
        
-#ifdef DEBUG
-       g_message ("%s: Opening %s with share 0x%x and access 0x%x", __func__,
+       DEBUG ("%s: Opening %s with share 0x%x and access 0x%x", __func__,
                   filename, sharemode, fileaccess);
-#endif
        
        fd = _wapi_open (filename, flags, perms);
     
@@ -1589,10 +1474,8 @@ gpointer CreateFile(const gunichar2 *name, guint32 fileaccess,
        }
        
        if (fd == -1) {
-#ifdef DEBUG
-               g_message("%s: Error opening file %s: %s", __func__, filename,
+               DEBUG("%s: Error opening file %s: %s", __func__, filename,
                          strerror(errno));
-#endif
                _wapi_set_last_path_error_from_errno (NULL, filename);
                g_free (filename);
 
@@ -1600,9 +1483,7 @@ gpointer CreateFile(const gunichar2 *name, guint32 fileaccess,
        }
 
        if (fd >= _wapi_fd_reserve) {
-#ifdef DEBUG
-               g_message ("%s: File descriptor is too big", __func__);
-#endif
+               DEBUG ("%s: File descriptor is too big", __func__);
 
                SetLastError (ERROR_TOO_MANY_OPEN_FILES);
                
@@ -1614,10 +1495,8 @@ gpointer CreateFile(const gunichar2 *name, guint32 fileaccess,
 
        ret = fstat (fd, &statbuf);
        if (ret == -1) {
-#ifdef DEBUG
-               g_message ("%s: fstat error of file %s: %s", __func__,
+               DEBUG ("%s: fstat error of file %s: %s", __func__,
                           filename, strerror (errno));
-#endif
                _wapi_set_last_error_from_errno ();
                g_free (filename);
                close (fd);
@@ -1635,9 +1514,7 @@ gpointer CreateFile(const gunichar2 *name, guint32 fileaccess,
        }
        if (file_handle.share_info == NULL) {
                /* No space, so no more files can be opened */
-#ifdef DEBUG
-               g_message ("%s: No space in the share table", __func__);
-#endif
+               DEBUG ("%s: No space in the share table", __func__);
 
                SetLastError (ERROR_TOO_MANY_OPEN_FILES);
                close (fd);
@@ -1685,9 +1562,7 @@ gpointer CreateFile(const gunichar2 *name, guint32 fileaccess,
                return(INVALID_HANDLE_VALUE);
        }
        
-#ifdef DEBUG
-       g_message("%s: returning handle %p", __func__, handle);
-#endif
+       DEBUG("%s: returning handle %p", __func__, handle);
        
        return(handle);
 }
@@ -1713,9 +1588,7 @@ gboolean DeleteFile(const gunichar2 *name)
 #endif
        
        if(name==NULL) {
-#ifdef DEBUG
-               g_message("%s: name is NULL", __func__);
-#endif
+               DEBUG("%s: name is NULL", __func__);
 
                SetLastError (ERROR_INVALID_NAME);
                return(FALSE);
@@ -1723,9 +1596,7 @@ gboolean DeleteFile(const gunichar2 *name)
 
        filename=mono_unicode_to_external(name);
        if(filename==NULL) {
-#ifdef DEBUG
-               g_message("%s: unicode conversion returned NULL", __func__);
-#endif
+               DEBUG("%s: unicode conversion returned NULL", __func__);
 
                SetLastError (ERROR_INVALID_NAME);
                return(FALSE);
@@ -1733,9 +1604,7 @@ gboolean DeleteFile(const gunichar2 *name)
 
        attrs = GetFileAttributes (name);
        if (attrs == INVALID_FILE_ATTRIBUTES) {
-#ifdef DEBUG
-               g_message ("%s: file attributes error", __func__);
-#endif
+               DEBUG ("%s: file attributes error", __func__);
                /* Error set by GetFileAttributes() */
                g_free (filename);
                return(FALSE);
@@ -1800,9 +1669,7 @@ gboolean MoveFile (const gunichar2 *name, const gunichar2 *dest_name)
        struct _WapiFileShare *shareinfo;
        
        if(name==NULL) {
-#ifdef DEBUG
-               g_message("%s: name is NULL", __func__);
-#endif
+               DEBUG("%s: name is NULL", __func__);
 
                SetLastError (ERROR_INVALID_NAME);
                return(FALSE);
@@ -1810,18 +1677,14 @@ gboolean MoveFile (const gunichar2 *name, const gunichar2 *dest_name)
 
        utf8_name = mono_unicode_to_external (name);
        if (utf8_name == NULL) {
-#ifdef DEBUG
-               g_message ("%s: unicode conversion returned NULL", __func__);
-#endif
+               DEBUG ("%s: unicode conversion returned NULL", __func__);
                
                SetLastError (ERROR_INVALID_NAME);
                return FALSE;
        }
        
        if(dest_name==NULL) {
-#ifdef DEBUG
-               g_message("%s: name is NULL", __func__);
-#endif
+               DEBUG("%s: name is NULL", __func__);
 
                g_free (utf8_name);
                SetLastError (ERROR_INVALID_NAME);
@@ -1830,9 +1693,7 @@ gboolean MoveFile (const gunichar2 *name, const gunichar2 *dest_name)
 
        utf8_dest_name = mono_unicode_to_external (dest_name);
        if (utf8_dest_name == NULL) {
-#ifdef DEBUG
-               g_message ("%s: unicode conversion returned NULL", __func__);
-#endif
+               DEBUG ("%s: unicode conversion returned NULL", __func__);
 
                g_free (utf8_name);
                SetLastError (ERROR_INVALID_NAME);
@@ -1954,9 +1815,7 @@ write_file (int src_fd, int dest_fd, struct stat *st_src, gboolean report_errors
 
                                if (report_errors)
                                        _wapi_set_last_error_from_errno ();
-#ifdef DEBUG
-                               g_message ("%s: write failed.", __func__);
-#endif
+                               DEBUG ("%s: write failed.", __func__);
                                free (buf);
                                return FALSE;
                        }
@@ -1991,9 +1850,7 @@ gboolean CopyFile (const gunichar2 *name, const gunichar2 *dest_name,
        gboolean ret = TRUE;
        
        if(name==NULL) {
-#ifdef DEBUG
-               g_message("%s: name is NULL", __func__);
-#endif
+               DEBUG("%s: name is NULL", __func__);
 
                SetLastError (ERROR_INVALID_NAME);
                return(FALSE);
@@ -2001,19 +1858,15 @@ gboolean CopyFile (const gunichar2 *name, const gunichar2 *dest_name,
        
        utf8_src = mono_unicode_to_external (name);
        if (utf8_src == NULL) {
-#ifdef DEBUG
-               g_message ("%s: unicode conversion of source returned NULL",
+               DEBUG ("%s: unicode conversion of source returned NULL",
                           __func__);
-#endif
 
                SetLastError (ERROR_INVALID_PARAMETER);
                return(FALSE);
        }
        
        if(dest_name==NULL) {
-#ifdef DEBUG
-               g_message("%s: dest is NULL", __func__);
-#endif
+               DEBUG("%s: dest is NULL", __func__);
 
                g_free (utf8_src);
                SetLastError (ERROR_INVALID_NAME);
@@ -2022,10 +1875,8 @@ gboolean CopyFile (const gunichar2 *name, const gunichar2 *dest_name,
        
        utf8_dest = mono_unicode_to_external (dest_name);
        if (utf8_dest == NULL) {
-#ifdef DEBUG
-               g_message ("%s: unicode conversion of dest returned NULL",
+               DEBUG ("%s: unicode conversion of dest returned NULL",
                           __func__);
-#endif
 
                SetLastError (ERROR_INVALID_PARAMETER);
 
@@ -2112,19 +1963,15 @@ convert_arg_to_utf8 (const gunichar2 *arg, const gchar *arg_name)
        gchar *utf8_ret;
 
        if (arg == NULL) {
-#ifdef DEBUG
-               g_message ("%s: %s is NULL", __func__, arg_name);
-#endif
+               DEBUG ("%s: %s is NULL", __func__, arg_name);
                SetLastError (ERROR_INVALID_NAME);
                return NULL;
        }
 
        utf8_ret = mono_unicode_to_external (arg);
        if (utf8_ret == NULL) {
-#ifdef DEBUG
-               g_message ("%s: unicode conversion of %s returned NULL",
+               DEBUG ("%s: unicode conversion of %s returned NULL",
                           __func__, arg_name);
-#endif
                SetLastError (ERROR_INVALID_PARAMETER);
                return NULL;
        }
@@ -2228,9 +2075,7 @@ gpointer GetStdHandle(WapiStdHandle stdhandle)
                break;
 
        default:
-#ifdef DEBUG
-               g_message("%s: unknown standard handle type", __func__);
-#endif
+               DEBUG("%s: unknown standard handle type", __func__);
 
                SetLastError (ERROR_INVALID_PARAMETER);
                return(INVALID_HANDLE_VALUE);
@@ -2619,9 +2464,7 @@ gboolean FileTimeToSystemTime(const WapiFileTime *file_time,
        const guint16 *ip;
        
        if(system_time==NULL) {
-#ifdef DEBUG
-               g_message("%s: system_time NULL", __func__);
-#endif
+               DEBUG("%s: system_time NULL", __func__);
 
                SetLastError (ERROR_INVALID_PARAMETER);
                return(FALSE);
@@ -2635,9 +2478,7 @@ gboolean FileTimeToSystemTime(const WapiFileTime *file_time,
         * year and day calculation to work later
         */
        if(file_ticks<0) {
-#ifdef DEBUG
-               g_message("%s: file_time too big", __func__);
-#endif
+               DEBUG("%s: file_time too big", __func__);
 
                SetLastError (ERROR_INVALID_PARAMETER);
                return(FALSE);
@@ -2645,41 +2486,29 @@ gboolean FileTimeToSystemTime(const WapiFileTime *file_time,
 
        totaldays=(file_ticks / TICKS_PER_DAY);
        rem = file_ticks % TICKS_PER_DAY;
-#ifdef DEBUG
-       g_message("%s: totaldays: %lld rem: %lld", __func__, totaldays, rem);
-#endif
+       DEBUG("%s: totaldays: %lld rem: %lld", __func__, totaldays, rem);
 
        system_time->wHour=rem/TICKS_PER_HOUR;
        rem %= TICKS_PER_HOUR;
-#ifdef DEBUG
-       g_message("%s: Hour: %d rem: %lld", __func__, system_time->wHour, rem);
-#endif
+       DEBUG("%s: Hour: %d rem: %lld", __func__, system_time->wHour, rem);
        
        system_time->wMinute = rem / TICKS_PER_MINUTE;
        rem %= TICKS_PER_MINUTE;
-#ifdef DEBUG
-       g_message("%s: Minute: %d rem: %lld", __func__, system_time->wMinute,
+       DEBUG("%s: Minute: %d rem: %lld", __func__, system_time->wMinute,
                  rem);
-#endif
        
        system_time->wSecond = rem / TICKS_PER_SECOND;
        rem %= TICKS_PER_SECOND;
-#ifdef DEBUG
-       g_message("%s: Second: %d rem: %lld", __func__, system_time->wSecond,
+       DEBUG("%s: Second: %d rem: %lld", __func__, system_time->wSecond,
                  rem);
-#endif
        
        system_time->wMilliseconds = rem / TICKS_PER_MILLISECOND;
-#ifdef DEBUG
-       g_message("%s: Milliseconds: %d", __func__,
+       DEBUG("%s: Milliseconds: %d", __func__,
                  system_time->wMilliseconds);
-#endif
 
        /* January 1, 1601 was a Monday, according to Emacs calendar */
        system_time->wDayOfWeek = ((1 + totaldays) % 7) + 1;
-#ifdef DEBUG
-       g_message("%s: Day of week: %d", __func__, system_time->wDayOfWeek);
-#endif
+       DEBUG("%s: Day of week: %d", __func__, system_time->wDayOfWeek);
        
        /* This algorithm to find year and month given days from epoch
         * from glibc
@@ -2692,31 +2521,23 @@ gboolean FileTimeToSystemTime(const WapiFileTime *file_time,
        while(totaldays < 0 || totaldays >= (isleap(y)?366:365)) {
                /* Guess a corrected year, assuming 365 days per year */
                gint64 yg = y + totaldays / 365 - (totaldays % 365 < 0);
-#ifdef DEBUG
-               g_message("%s: totaldays: %lld yg: %lld y: %lld", __func__,
+               DEBUG("%s: totaldays: %lld yg: %lld y: %lld", __func__,
                          totaldays, yg,
                          y);
                g_message("%s: LEAPS(yg): %lld LEAPS(y): %lld", __func__,
                          LEAPS_THRU_END_OF(yg-1), LEAPS_THRU_END_OF(y-1));
-#endif
                
                /* Adjust days and y to match the guessed year. */
                totaldays -= ((yg - y) * 365
                              + LEAPS_THRU_END_OF (yg - 1)
                              - LEAPS_THRU_END_OF (y - 1));
-#ifdef DEBUG
-               g_message("%s: totaldays: %lld", __func__, totaldays);
-#endif
+               DEBUG("%s: totaldays: %lld", __func__, totaldays);
                y = yg;
-#ifdef DEBUG
-               g_message("%s: y: %lld", __func__, y);
-#endif
+               DEBUG("%s: y: %lld", __func__, y);
        }
        
        system_time->wYear = y;
-#ifdef DEBUG
-       g_message("%s: Year: %d", __func__, system_time->wYear);
-#endif
+       DEBUG("%s: Year: %d", __func__, system_time->wYear);
 
        ip = mon_yday[isleap(y)];
        
@@ -2724,19 +2545,13 @@ gboolean FileTimeToSystemTime(const WapiFileTime *file_time,
                continue;
        }
        totaldays-=ip[y];
-#ifdef DEBUG
-       g_message("%s: totaldays: %lld", __func__, totaldays);
-#endif
+       DEBUG("%s: totaldays: %lld", __func__, totaldays);
        
        system_time->wMonth = y + 1;
-#ifdef DEBUG
-       g_message("%s: Month: %d", __func__, system_time->wMonth);
-#endif
+       DEBUG("%s: Month: %d", __func__, system_time->wMonth);
 
        system_time->wDay = totaldays + 1;
-#ifdef DEBUG
-       g_message("%s: Day: %d", __func__, system_time->wDay);
-#endif
+       DEBUG("%s: Day: %d", __func__, system_time->wDay);
        
        return(TRUE);
 }
@@ -2749,9 +2564,7 @@ gpointer FindFirstFile (const gunichar2 *pattern, WapiFindData *find_data)
        int result;
        
        if (pattern == NULL) {
-#ifdef DEBUG
-               g_message ("%s: pattern is NULL", __func__);
-#endif
+               DEBUG ("%s: pattern is NULL", __func__);
 
                SetLastError (ERROR_PATH_NOT_FOUND);
                return(INVALID_HANDLE_VALUE);
@@ -2759,17 +2572,13 @@ gpointer FindFirstFile (const gunichar2 *pattern, WapiFindData *find_data)
 
        utf8_pattern = mono_unicode_to_external (pattern);
        if (utf8_pattern == NULL) {
-#ifdef DEBUG
-               g_message ("%s: unicode conversion returned NULL", __func__);
-#endif
+               DEBUG ("%s: unicode conversion returned NULL", __func__);
                
                SetLastError (ERROR_INVALID_NAME);
                return(INVALID_HANDLE_VALUE);
        }
 
-#ifdef DEBUG
-       g_message ("%s: looking for [%s]", __func__, utf8_pattern);
-#endif
+       DEBUG ("%s: looking for [%s]", __func__, utf8_pattern);
        
        /* Figure out which bit of the pattern is the directory */
        dir_part = _wapi_dirname (utf8_pattern);
@@ -2825,14 +2634,12 @@ gpointer FindFirstFile (const gunichar2 *pattern, WapiFindData *find_data)
        }
        
        if (result < 0) {
-#ifdef DEBUG
+#ifdef DEBUG_ENABLED
                gint errnum = errno;
 #endif
                _wapi_set_last_path_error_from_errno (dir_part, NULL);
-#ifdef DEBUG
-               g_message ("%s: scandir error: %s", __func__,
+               DEBUG ("%s: scandir error: %s", __func__,
                           g_strerror (errnum));
-#endif
                g_free (utf8_pattern);
                g_free (entry_part);
                g_free (dir_part);
@@ -2842,9 +2649,7 @@ gpointer FindFirstFile (const gunichar2 *pattern, WapiFindData *find_data)
        g_free (utf8_pattern);
        g_free (entry_part);
        
-#ifdef DEBUG
-       g_message ("%s: Got %d matches", __func__, result);
-#endif
+       DEBUG ("%s: Got %d matches", __func__, result);
 
        find_handle.dir_part = dir_part;
        find_handle.num = result;
@@ -2916,9 +2721,7 @@ retry:
        }
        
        if (result != 0) {
-#ifdef DEBUG
-               g_message ("%s: stat failed: %s", __func__, filename);
-#endif
+               DEBUG ("%s: stat failed: %s", __func__, filename);
 
                g_free (filename);
                goto retry;
@@ -2926,9 +2729,7 @@ retry:
 
        result = _wapi_lstat (filename, &linkbuf);
        if (result != 0) {
-#ifdef DEBUG
-               g_message ("%s: lstat failed: %s", __func__, filename);
-#endif
+               DEBUG ("%s: lstat failed: %s", __func__, filename);
 
                g_free (filename);
                goto retry;
@@ -2947,9 +2748,7 @@ retry:
        }
        g_free (filename);
        
-#ifdef DEBUG
-       g_message ("%s: Found [%s]", __func__, utf8_filename);
-#endif
+       DEBUG ("%s: Found [%s]", __func__, utf8_filename);
        
        /* fill data block */
 
@@ -3072,9 +2871,7 @@ gboolean CreateDirectory (const gunichar2 *name,
        int result;
        
        if (name == NULL) {
-#ifdef DEBUG
-               g_message("%s: name is NULL", __func__);
-#endif
+               DEBUG("%s: name is NULL", __func__);
 
                SetLastError (ERROR_INVALID_NAME);
                return(FALSE);
@@ -3082,9 +2879,7 @@ gboolean CreateDirectory (const gunichar2 *name,
        
        utf8_name = mono_unicode_to_external (name);
        if (utf8_name == NULL) {
-#ifdef DEBUG
-               g_message ("%s: unicode conversion returned NULL", __func__);
-#endif
+               DEBUG ("%s: unicode conversion returned NULL", __func__);
        
                SetLastError (ERROR_INVALID_NAME);
                return FALSE;
@@ -3117,9 +2912,7 @@ gboolean RemoveDirectory (const gunichar2 *name)
        int result;
        
        if (name == NULL) {
-#ifdef DEBUG
-               g_message("%s: name is NULL", __func__);
-#endif
+               DEBUG("%s: name is NULL", __func__);
 
                SetLastError (ERROR_INVALID_NAME);
                return(FALSE);
@@ -3127,9 +2920,7 @@ gboolean RemoveDirectory (const gunichar2 *name)
 
        utf8_name = mono_unicode_to_external (name);
        if (utf8_name == NULL) {
-#ifdef DEBUG
-               g_message ("%s: unicode conversion returned NULL", __func__);
-#endif
+               DEBUG ("%s: unicode conversion returned NULL", __func__);
                
                SetLastError (ERROR_INVALID_NAME);
                return FALSE;
@@ -3163,9 +2954,7 @@ guint32 GetFileAttributes (const gunichar2 *name)
        guint32 ret;
        
        if (name == NULL) {
-#ifdef DEBUG
-               g_message("%s: name is NULL", __func__);
-#endif
+               DEBUG("%s: name is NULL", __func__);
 
                SetLastError (ERROR_INVALID_NAME);
                return(FALSE);
@@ -3173,9 +2962,7 @@ guint32 GetFileAttributes (const gunichar2 *name)
        
        utf8_name = mono_unicode_to_external (name);
        if (utf8_name == NULL) {
-#ifdef DEBUG
-               g_message ("%s: unicode conversion returned NULL", __func__);
-#endif
+               DEBUG ("%s: unicode conversion returned NULL", __func__);
 
                SetLastError (ERROR_INVALID_PARAMETER);
                return (INVALID_FILE_ATTRIBUTES);
@@ -3227,19 +3014,15 @@ gboolean GetFileAttributesEx (const gunichar2 *name, WapiGetFileExInfoLevels lev
        int result;
        
        if (level != GetFileExInfoStandard) {
-#ifdef DEBUG
-               g_message ("%s: info level %d not supported.", __func__,
+               DEBUG ("%s: info level %d not supported.", __func__,
                           level);
-#endif
 
                SetLastError (ERROR_INVALID_PARAMETER);
                return FALSE;
        }
        
        if (name == NULL) {
-#ifdef DEBUG
-               g_message("%s: name is NULL", __func__);
-#endif
+               DEBUG("%s: name is NULL", __func__);
 
                SetLastError (ERROR_INVALID_NAME);
                return(FALSE);
@@ -3247,9 +3030,7 @@ gboolean GetFileAttributesEx (const gunichar2 *name, WapiGetFileExInfoLevels lev
 
        utf8_name = mono_unicode_to_external (name);
        if (utf8_name == NULL) {
-#ifdef DEBUG
-               g_message ("%s: unicode conversion returned NULL", __func__);
-#endif
+               DEBUG ("%s: unicode conversion returned NULL", __func__);
 
                SetLastError (ERROR_INVALID_PARAMETER);
                return FALSE;
@@ -3327,9 +3108,7 @@ extern gboolean SetFileAttributes (const gunichar2 *name, guint32 attrs)
         */
        
        if (name == NULL) {
-#ifdef DEBUG
-               g_message("%s: name is NULL", __func__);
-#endif
+               DEBUG("%s: name is NULL", __func__);
 
                SetLastError (ERROR_INVALID_NAME);
                return(FALSE);
@@ -3337,9 +3116,7 @@ extern gboolean SetFileAttributes (const gunichar2 *name, guint32 attrs)
 
        utf8_name = mono_unicode_to_external (name);
        if (utf8_name == NULL) {
-#ifdef DEBUG
-               g_message ("%s: unicode conversion returned NULL", __func__);
-#endif
+               DEBUG ("%s: unicode conversion returned NULL", __func__);
 
                SetLastError (ERROR_INVALID_NAME);
                return FALSE;
@@ -3476,16 +3253,12 @@ gboolean CreatePipe (gpointer *readpipe, gpointer *writepipe,
        
        mono_once (&io_ops_once, io_ops_init);
        
-#ifdef DEBUG
-       g_message ("%s: Creating pipe", __func__);
-#endif
+       DEBUG ("%s: Creating pipe", __func__);
 
        ret=pipe (filedes);
        if(ret==-1) {
-#ifdef DEBUG
-               g_message ("%s: Error creating pipe: %s", __func__,
+               DEBUG ("%s: Error creating pipe: %s", __func__,
                           strerror (errno));
-#endif
                
                _wapi_set_last_error_from_errno ();
                return(FALSE);
@@ -3493,9 +3266,7 @@ gboolean CreatePipe (gpointer *readpipe, gpointer *writepipe,
 
        if (filedes[0] >= _wapi_fd_reserve ||
            filedes[1] >= _wapi_fd_reserve) {
-#ifdef DEBUG
-               g_message ("%s: File descriptor is too big", __func__);
-#endif
+               DEBUG ("%s: File descriptor is too big", __func__);
 
                SetLastError (ERROR_TOO_MANY_OPEN_FILES);
                
@@ -3536,10 +3307,8 @@ gboolean CreatePipe (gpointer *readpipe, gpointer *writepipe,
        *readpipe = read_handle;
        *writepipe = write_handle;
 
-#ifdef DEBUG
-       g_message ("%s: Returning pipe: read handle %p, write handle %p",
+       DEBUG ("%s: Returning pipe: read handle %p, write handle %p",
                   __func__, read_handle, write_handle);
-#endif
 
        return(TRUE);
 }
@@ -3565,10 +3334,8 @@ guint32 GetTempPath (guint32 len, gunichar2 *buf)
                dirlen=(bytes/2);
                
                if(dirlen+1>len) {
-#ifdef DEBUG
-                       g_message ("%s: Size %d smaller than needed (%ld)",
+                       DEBUG ("%s: Size %d smaller than needed (%ld)",
                                   __func__, len, dirlen+1);
-#endif
                
                        ret=dirlen+1;
                } else {
@@ -4052,9 +3819,7 @@ gboolean GetDiskFreeSpaceEx(const gunichar2 *path_name, WapiULargeInteger *free_
        else {
                utf8_path_name = mono_unicode_to_external (path_name);
                if (utf8_path_name == NULL) {
-#ifdef DEBUG
-                       g_message("%s: unicode conversion returned NULL", __func__);
-#endif
+                       DEBUG("%s: unicode conversion returned NULL", __func__);
 
                        SetLastError (ERROR_INVALID_NAME);
                        return(FALSE);
@@ -4077,9 +3842,7 @@ gboolean GetDiskFreeSpaceEx(const gunichar2 *path_name, WapiULargeInteger *free_
 
        if (ret == -1) {
                _wapi_set_last_error_from_errno ();
-#ifdef DEBUG
-               g_message ("%s: statvfs failed: %s", __func__, strerror (errno));
-#endif
+               DEBUG ("%s: statvfs failed: %s", __func__, strerror (errno));
                return(FALSE);
        }
 
@@ -4368,9 +4131,7 @@ guint32 GetDriveType(const gunichar2 *root_path_name)
        else {
                utf8_root_path_name = mono_unicode_to_external (root_path_name);
                if (utf8_root_path_name == NULL) {
-#ifdef DEBUG
-                       g_message("%s: unicode conversion returned NULL", __func__);
-#endif
+                       DEBUG("%s: unicode conversion returned NULL", __func__);
                        return(DRIVE_NO_ROOT_DIR);
                }
                
index a3439d019ce745ea2c20a8112f9a802ceb0366fc..57b18ca662e936243e78c14908fb6cf87d26cc4a 100644 (file)
 #include <mono/io-layer/handles-private.h>
 #include <mono/io-layer/io-private.h>
 
-#define LOGDEBUG(...)
-//#define LOGDEBUG(...) g_message (__VA_ARGS__)
+#if 0
+// #define DEBUG(...) g_message(__VA_ARGS__)
+#else
+#define DEBUG(...)
+#endif
 
 gboolean
 _wapi_lock_file_region (int fd, off_t offset, off_t length)
@@ -40,7 +43,7 @@ _wapi_lock_file_region (int fd, off_t offset, off_t length)
                ret = fcntl (fd, F_SETLK, &lock_data);
        } while(ret == -1 && errno == EINTR);
        
-       LOGDEBUG ("%s: fcntl returns %d", __func__, ret);
+       DEBUG ("%s: fcntl returns %d", __func__, ret);
 
        if (ret == -1) {
                /*
@@ -85,7 +88,7 @@ _wapi_unlock_file_region (int fd, off_t offset, off_t length)
                ret = fcntl (fd, F_SETLK, &lock_data);
        } while(ret == -1 && errno == EINTR);
        
-       LOGDEBUG ("%s: fcntl returns %d", __func__, ret);
+       DEBUG ("%s: fcntl returns %d", __func__, ret);
        
        if (ret == -1) {
                /*
@@ -132,7 +135,7 @@ LockFile (gpointer handle, guint32 offset_low, guint32 offset_high,
        if (!(file_handle->fileaccess & GENERIC_READ) &&
            !(file_handle->fileaccess & GENERIC_WRITE) &&
            !(file_handle->fileaccess & GENERIC_ALL)) {
-               LOGDEBUG ("%s: handle %p doesn't have GENERIC_READ or GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess);
+               DEBUG ("%s: handle %p doesn't have GENERIC_READ or GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess);
                SetLastError (ERROR_ACCESS_DENIED);
                return(FALSE);
        }
@@ -141,15 +144,13 @@ LockFile (gpointer handle, guint32 offset_low, guint32 offset_high,
        offset = ((gint64)offset_high << 32) | offset_low;
        length = ((gint64)length_high << 32) | length_low;
 
-       LOGDEBUG ("%s: Locking handle %p, offset %lld, length %lld", __func__, handle, offset, length);
+       DEBUG ("%s: Locking handle %p, offset %lld, length %lld", __func__, handle, offset, length);
 #else
        offset = offset_low;
        length = length_low;
 
-#ifdef DEBUG
-       g_message ("%s: Locking handle %p, offset %ld, length %ld", __func__,
+       DEBUG ("%s: Locking handle %p, offset %ld, length %ld", __func__,
                   handle, offset, length);
-#endif
 #endif
 
        return(_wapi_lock_file_region (fd, offset, length));
@@ -177,7 +178,7 @@ UnlockFile (gpointer handle, guint32 offset_low,
        if (!(file_handle->fileaccess & GENERIC_READ) &&
            !(file_handle->fileaccess & GENERIC_WRITE) &&
            !(file_handle->fileaccess & GENERIC_ALL)) {
-               LOGDEBUG ("%s: handle %p doesn't have GENERIC_READ or GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess);
+               DEBUG ("%s: handle %p doesn't have GENERIC_READ or GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess);
                SetLastError (ERROR_ACCESS_DENIED);
                return(FALSE);
        }
@@ -186,12 +187,12 @@ UnlockFile (gpointer handle, guint32 offset_low,
        offset = ((gint64)offset_high << 32) | offset_low;
        length = ((gint64)length_high << 32) | length_low;
 
-       LOGDEBUG ("%s: Unlocking handle %p, offset %lld, length %lld", __func__, handle, offset, length);
+       DEBUG ("%s: Unlocking handle %p, offset %lld, length %lld", __func__, handle, offset, length);
 #else
        offset = offset_low;
        length = length_low;
 
-       LOGDEBUG ("%s: Unlocking handle %p, offset %ld, length %ld", __func__, handle, offset, length);
+       DEBUG ("%s: Unlocking handle %p, offset %ld, length %ld", __func__, handle, offset, length);
 #endif
 
        return(_wapi_unlock_file_region (fd, offset, length));
index 63fad05bb8890e59d692d5b1b836fceb674bfe91..074a5f79672d717b5eabc53007cbad594f6aecea 100644 (file)
 #include <mono/io-layer/mono-mutex.h>
 #include <mono/io-layer/mutex-private.h>
 
-#undef DEBUG
+#if 0
+#define DEBUG(...) g_message(__VA_ARGS__)
+#else
+#define DEBUG(...)
+#endif
 
 static void mutex_signal(gpointer handle);
 static gboolean mutex_own (gpointer handle);
@@ -117,9 +121,7 @@ static gboolean mutex_own (gpointer handle)
 
        _wapi_thread_own_mutex (handle);
        
-#ifdef DEBUG
-       g_message("%s: owning mutex handle %p", __func__, handle);
-#endif
+       DEBUG("%s: owning mutex handle %p", __func__, handle);
 
        _wapi_handle_set_signal_state (handle, FALSE, FALSE);
        
@@ -127,11 +129,9 @@ static gboolean mutex_own (gpointer handle)
        mutex_handle->tid = pthread_self ();
        mutex_handle->recursion++;
 
-#ifdef DEBUG
-       g_message ("%s: mutex handle %p locked %d times by %d:%ld", __func__,
+       DEBUG ("%s: mutex handle %p locked %d times by %d:%ld", __func__,
                   handle, mutex_handle->recursion, mutex_handle->pid,
                   mutex_handle->tid);
-#endif
 
        return(TRUE);
 }
@@ -149,23 +149,17 @@ static gboolean mutex_is_owned (gpointer handle)
                return(FALSE);
        }
        
-#ifdef DEBUG
-       g_message("%s: testing ownership mutex handle %p", __func__, handle);
-#endif
+       DEBUG("%s: testing ownership mutex handle %p", __func__, handle);
 
        if (mutex_handle->recursion > 0 &&
            mutex_handle->pid == _wapi_getpid () &&
            pthread_equal (mutex_handle->tid, pthread_self ())) {
-#ifdef DEBUG
-               g_message ("%s: mutex handle %p owned by %d:%ld", __func__,
+               DEBUG ("%s: mutex handle %p owned by %d:%ld", __func__,
                           handle, _wapi_getpid (), pthread_self ());
-#endif
 
                return(TRUE);
        } else {
-#ifdef DEBUG
-               g_message ("%s: mutex handle %p not owned by %d:%ld, but locked %d times by %d:%ld", __func__, handle, _wapi_getpid (), pthread_self (), mutex_handle->recursion, mutex_handle->pid, mutex_handle->tid);
-#endif
+               DEBUG ("%s: mutex handle %p not owned by %d:%ld, but locked %d times by %d:%ld", __func__, handle, _wapi_getpid (), pthread_self (), mutex_handle->recursion, mutex_handle->pid, mutex_handle->tid);
 
                return(FALSE);
        }
@@ -182,9 +176,7 @@ static gboolean namedmutex_own (gpointer handle)
        struct _WapiHandle_namedmutex *namedmutex_handle;
        gboolean ok;
        
-#ifdef DEBUG
-       g_message ("%s: owning named mutex handle %p", __func__, handle);
-#endif
+       DEBUG ("%s: owning named mutex handle %p", __func__, handle);
        
        ok = _wapi_lookup_handle (handle, WAPI_HANDLE_NAMEDMUTEX,
                                  (gpointer *)&namedmutex_handle);
@@ -202,11 +194,9 @@ static gboolean namedmutex_own (gpointer handle)
 
        _wapi_shared_handle_set_signal_state (handle, FALSE);
 
-#ifdef DEBUG
-       g_message ("%s: mutex handle %p locked %d times by %d:%ld", __func__,
+       DEBUG ("%s: mutex handle %p locked %d times by %d:%ld", __func__,
                   handle, namedmutex_handle->recursion,
                   namedmutex_handle->pid, namedmutex_handle->tid);
-#endif
        
        return(TRUE);
 }
@@ -224,23 +214,17 @@ static gboolean namedmutex_is_owned (gpointer handle)
                return(FALSE);
        }
        
-#ifdef DEBUG
-       g_message ("%s: testing ownership mutex handle %p", __func__, handle);
-#endif
+       DEBUG ("%s: testing ownership mutex handle %p", __func__, handle);
 
        if (namedmutex_handle->recursion > 0 &&
            namedmutex_handle->pid == _wapi_getpid () &&
            pthread_equal (namedmutex_handle->tid, pthread_self ())) {
-#ifdef DEBUG
-               g_message ("%s: mutex handle %p owned by %d:%ld", __func__,
+               DEBUG ("%s: mutex handle %p owned by %d:%ld", __func__,
                           handle, _wapi_getpid (), pthread_self ());
-#endif
 
                return(TRUE);
        } else {
-#ifdef DEBUG
-               g_message ("%s: mutex handle %p not owned by %d:%ld, but locked %d times by %d:%ld", __func__, handle, _wapi_getpid (), pthread_self (), namedmutex_handle->recursion, namedmutex_handle->pid, namedmutex_handle->tid);
-#endif
+               DEBUG ("%s: mutex handle %p not owned by %d:%ld, but locked %d times by %d:%ld", __func__, handle, _wapi_getpid (), pthread_self (), namedmutex_handle->recursion, namedmutex_handle->pid, namedmutex_handle->tid);
 
                return(FALSE);
        }
@@ -266,36 +250,26 @@ static void namedmutex_prewait (gpointer handle)
                return;
        }
        
-#ifdef DEBUG
-       g_message ("%s: Checking ownership of named mutex handle %p", __func__,
+       DEBUG ("%s: Checking ownership of named mutex handle %p", __func__,
                   handle);
-#endif
 
        if (namedmutex_handle->recursion == 0) {
-#ifdef DEBUG
-               g_message ("%s: Named mutex handle %p not owned", __func__,
+               DEBUG ("%s: Named mutex handle %p not owned", __func__,
                           handle);
-#endif
        } else if (namedmutex_handle->pid == _wapi_getpid ()) {
-#ifdef DEBUG
-               g_message ("%s: Named mutex handle %p owned by this process",
+               DEBUG ("%s: Named mutex handle %p owned by this process",
                           __func__, handle);
-#endif
        } else {
                int thr_ret;
                gpointer proc_handle;
                
-#ifdef DEBUG
-               g_message ("%s: Named mutex handle %p owned by another process", __func__, handle);
-#endif
+               DEBUG ("%s: Named mutex handle %p owned by another process", __func__, handle);
                proc_handle = OpenProcess (0, 0, namedmutex_handle->pid);
                if (proc_handle == NULL) {
                        /* Didn't find the process that this handle
                         * was owned by, overriding it
                         */
-#ifdef DEBUG
-                       g_message ("%s: overriding old owner of named mutex handle %p", __func__, handle);
-#endif
+                       DEBUG ("%s: overriding old owner of named mutex handle %p", __func__, handle);
                        thr_ret = _wapi_handle_lock_shared_handles ();
                        g_assert (thr_ret == 0);
 
@@ -306,9 +280,7 @@ static void namedmutex_prewait (gpointer handle)
                        _wapi_shared_handle_set_signal_state (handle, TRUE);
                        _wapi_handle_unlock_shared_handles ();
                } else {
-#ifdef DEBUG
-                       g_message ("%s: Found active pid %d for named mutex handle %p", __func__, namedmutex_handle->pid, handle);
-#endif
+                       DEBUG ("%s: Found active pid %d for named mutex handle %p", __func__, namedmutex_handle->pid, handle);
                }
                if (proc_handle != NULL)
                        CloseProcess (proc_handle);
@@ -336,9 +308,7 @@ static void mutex_abandon (gpointer handle, pid_t pid, pthread_t tid)
        
        if (mutex_handle->pid == pid &&
            pthread_equal (mutex_handle->tid, tid)) {
-#ifdef DEBUG
-               g_message ("%s: Mutex handle %p abandoned!", __func__, handle);
-#endif
+               DEBUG ("%s: Mutex handle %p abandoned!", __func__, handle);
 
                mutex_handle->recursion = 0;
                mutex_handle->pid = 0;
@@ -371,9 +341,7 @@ static void namedmutex_abandon (gpointer handle, pid_t pid, pthread_t tid)
        
        if (mutex_handle->pid == pid &&
            pthread_equal (mutex_handle->tid, tid)) {
-#ifdef DEBUG
-               g_message ("%s: Mutex handle %p abandoned!", __func__, handle);
-#endif
+               DEBUG ("%s: Mutex handle %p abandoned!", __func__, handle);
 
                mutex_handle->recursion = 0;
                mutex_handle->pid = 0;
@@ -415,9 +383,7 @@ static gpointer mutex_create (WapiSecurityAttributes *security G_GNUC_UNUSED,
         */
        SetLastError (ERROR_SUCCESS);
        
-#ifdef DEBUG
-       g_message ("%s: Creating unnamed mutex", __func__);
-#endif
+       DEBUG ("%s: Creating unnamed mutex", __func__);
        
        handle = _wapi_handle_new (WAPI_HANDLE_MUTEX, &mutex_handle);
        if (handle == _WAPI_HANDLE_INVALID) {
@@ -437,9 +403,7 @@ static gpointer mutex_create (WapiSecurityAttributes *security G_GNUC_UNUSED,
                _wapi_handle_set_signal_state (handle, TRUE, FALSE);
        }
        
-#ifdef DEBUG
-       g_message ("%s: returning mutex handle %p", __func__, handle);
-#endif
+       DEBUG ("%s: returning mutex handle %p", __func__, handle);
 
        thr_ret = _wapi_handle_unlock_handle (handle);
        g_assert (thr_ret == 0);
@@ -473,9 +437,7 @@ static gpointer namedmutex_create (WapiSecurityAttributes *security G_GNUC_UNUSE
        
        utf8_name = g_utf16_to_utf8 (name, -1, NULL, NULL, NULL);
        
-#ifdef DEBUG
-       g_message ("%s: Creating named mutex [%s]", __func__, utf8_name);
-#endif
+       DEBUG ("%s: Creating named mutex [%s]", __func__, utf8_name);
        
        offset = _wapi_search_handle_namespace (WAPI_HANDLE_NAMEDMUTEX,
                                                utf8_name);
@@ -539,9 +501,7 @@ static gpointer namedmutex_create (WapiSecurityAttributes *security G_GNUC_UNUSE
                _wapi_handle_unlock_shared_handles ();
        }
        
-#ifdef DEBUG
-       g_message ("%s: returning mutex handle %p", __func__, handle);
-#endif
+       DEBUG ("%s: returning mutex handle %p", __func__, handle);
 
 cleanup:
        g_free (utf8_name);
@@ -604,15 +564,11 @@ static gboolean mutex_release (gpointer handle)
        thr_ret = _wapi_handle_lock_handle (handle);
        g_assert (thr_ret == 0);
        
-#ifdef DEBUG
-       g_message("%s: Releasing mutex handle %p", __func__, handle);
-#endif
+       DEBUG("%s: Releasing mutex handle %p", __func__, handle);
 
        if (!pthread_equal (mutex_handle->tid, tid) ||
            mutex_handle->pid != pid) {
-#ifdef DEBUG
-               g_message("%s: We don't own mutex handle %p (owned by %d:%ld, me %d:%ld)", __func__, handle, mutex_handle->pid, mutex_handle->tid, _wapi_getpid (), tid);
-#endif
+               DEBUG("%s: We don't own mutex handle %p (owned by %d:%ld, me %d:%ld)", __func__, handle, mutex_handle->pid, mutex_handle->tid, _wapi_getpid (), tid);
 
                goto cleanup;
        }
@@ -624,9 +580,7 @@ static gboolean mutex_release (gpointer handle)
        if(mutex_handle->recursion==0) {
                _wapi_thread_disown_mutex (handle);
 
-#ifdef DEBUG
-               g_message("%s: Unlocking mutex handle %p", __func__, handle);
-#endif
+               DEBUG("%s: Unlocking mutex handle %p", __func__, handle);
 
                mutex_handle->pid=0;
                mutex_handle->tid=0;
@@ -661,15 +615,11 @@ static gboolean namedmutex_release (gpointer handle)
        thr_ret = _wapi_handle_lock_shared_handles ();
        g_assert (thr_ret == 0);
        
-#ifdef DEBUG
-       g_message("%s: Releasing mutex handle %p", __func__, handle);
-#endif
+       DEBUG("%s: Releasing mutex handle %p", __func__, handle);
 
        if (!pthread_equal (mutex_handle->tid, tid) ||
            mutex_handle->pid != pid) {
-#ifdef DEBUG
-               g_message("%s: We don't own mutex handle %p (owned by %d:%ld, me %d:%ld)", __func__, handle, mutex_handle->pid, mutex_handle->tid, _wapi_getpid (), tid);
-#endif
+               DEBUG("%s: We don't own mutex handle %p (owned by %d:%ld, me %d:%ld)", __func__, handle, mutex_handle->pid, mutex_handle->tid, _wapi_getpid (), tid);
 
                goto cleanup;
        }
@@ -681,9 +631,7 @@ static gboolean namedmutex_release (gpointer handle)
        if(mutex_handle->recursion==0) {
                _wapi_thread_disown_mutex (handle);
 
-#ifdef DEBUG
-               g_message("%s: Unlocking mutex handle %p", __func__, handle);
-#endif
+               DEBUG("%s: Unlocking mutex handle %p", __func__, handle);
 
                mutex_handle->pid=0;
                mutex_handle->tid=0;
@@ -742,9 +690,7 @@ gpointer OpenMutex (guint32 access G_GNUC_UNUSED, gboolean inherit G_GNUC_UNUSED
 
        utf8_name = g_utf16_to_utf8 (name, -1, NULL, NULL, NULL);
        
-#ifdef DEBUG
-       g_message ("%s: Opening named mutex [%s]", __func__, utf8_name);
-#endif
+       DEBUG ("%s: Opening named mutex [%s]", __func__, utf8_name);
        
        offset = _wapi_search_handle_namespace (WAPI_HANDLE_NAMEDMUTEX,
                                                utf8_name);
@@ -773,9 +719,7 @@ gpointer OpenMutex (guint32 access G_GNUC_UNUSED, gboolean inherit G_GNUC_UNUSED
        }
        ret = handle;
 
-#ifdef DEBUG
-       g_message ("%s: returning named mutex handle %p", __func__, handle);
-#endif
+       DEBUG ("%s: returning named mutex handle %p", __func__, handle);
 
 cleanup:
        g_free (utf8_name);
index a7781bdd7bd544a80d58dad401d0f57a37eb5d11..b79025c2905d9078cae5ed9482a4ba5db55b78ab 100644 (file)
 #include <mono/io-layer/handles-private.h>
 #include <mono/io-layer/io-private.h>
 
+#if 0
+#define DEBUG(...) g_message(__VA_ARGS__)
+#else
+#define DEBUG(...)
+#endif
+
 static guint32
 convert_from_flags(int flags)
 {
@@ -39,9 +45,7 @@ convert_from_flags(int flags)
        } else if ((flags & O_ACCMODE) == O_RDWR) {
                fileaccess=GENERIC_READ|GENERIC_WRITE;
        } else {
-#ifdef DEBUG
-               g_message("%s: Can't figure out flags 0x%x", __func__, flags);
-#endif
+               DEBUG("%s: Can't figure out flags 0x%x", __func__, flags);
        }
 
        /* Maybe sort out create mode too */
@@ -56,10 +60,8 @@ gpointer _wapi_stdhandle_create (int fd, const gchar *name)
        gpointer handle;
        int flags;
        
-#ifdef DEBUG
-       g_message("%s: creating standard handle type %s, fd %d", __func__,
+       DEBUG("%s: creating standard handle type %s, fd %d", __func__,
                  name, fd);
-#endif
 
 #if !defined(__native_client__)        
        /* Check if fd is valid */
@@ -71,10 +73,8 @@ gpointer _wapi_stdhandle_create (int fd, const gchar *name)
                /* Invalid fd.  Not really much point checking for EBADF
                 * specifically
                 */
-#ifdef DEBUG
-               g_message("%s: fcntl error on fd %d: %s", __func__, fd,
+               DEBUG("%s: fcntl error on fd %d: %s", __func__, fd,
                          strerror(errno));
-#endif
 
                SetLastError (_wapi_get_win32_file_error (errno));
                return(INVALID_HANDLE_VALUE);
@@ -109,9 +109,7 @@ gpointer _wapi_stdhandle_create (int fd, const gchar *name)
                return(INVALID_HANDLE_VALUE);
        }
        
-#ifdef DEBUG
-       g_message("%s: returning handle %p", __func__, handle);
-#endif
+       DEBUG("%s: returning handle %p", __func__, handle);
 
        return(handle);
 }
index 2404b3cfd2e9ff2386e5904269809e2794db8144..936528a0df505137d201fe681ff97ba8c23aa191 100644 (file)
@@ -83,7 +83,12 @@ gchar ***_NSGetEnviron(void);
 extern char **environ;
 #endif
 
-#undef DEBUG
+#if 0
+#define DEBUG(...) g_message(__VA_ARGS__)
+#define DEBUG_ENABLED 1
+#else
+#define DEBUG(...)
+#endif
 
 static guint32 process_wait (gpointer handle, guint32 timeout, gboolean alertable);
 static void process_close (gpointer handle, gpointer data);
@@ -259,7 +264,7 @@ static const gunichar2 *utf16_space = utf16_space_bytes;
 static const gunichar2 utf16_quote_bytes [2] = { 0x22, 0 };
 static const gunichar2 *utf16_quote = utf16_quote_bytes;
 
-#ifdef DEBUG
+#ifdef DEBUG_ENABLED
 /* Useful in gdb */
 void
 print_utf16 (gunichar2 *str)
@@ -586,10 +591,8 @@ gboolean CreateProcess (const gunichar2 *appname, const gunichar2 *cmdline,
        if (appname != NULL) {
                cmd = mono_unicode_to_external (appname);
                if (cmd == NULL) {
-#ifdef DEBUG
-                       g_message ("%s: unicode conversion returned NULL",
+                       DEBUG ("%s: unicode conversion returned NULL",
                                   __func__);
-#endif
 
                        SetLastError (ERROR_PATH_NOT_FOUND);
                        goto free_strings;
@@ -601,9 +604,7 @@ gboolean CreateProcess (const gunichar2 *appname, const gunichar2 *cmdline,
        if (cmdline != NULL) {
                args = mono_unicode_to_external (cmdline);
                if (args == NULL) {
-#ifdef DEBUG
-                       g_message ("%s: unicode conversion returned NULL", __func__);
-#endif
+                       DEBUG ("%s: unicode conversion returned NULL", __func__);
 
                        SetLastError (ERROR_PATH_NOT_FOUND);
                        goto free_strings;
@@ -613,9 +614,7 @@ gboolean CreateProcess (const gunichar2 *appname, const gunichar2 *cmdline,
        if (cwd != NULL) {
                dir = mono_unicode_to_external (cwd);
                if (dir == NULL) {
-#ifdef DEBUG
-                       g_message ("%s: unicode conversion returned NULL", __func__);
-#endif
+                       DEBUG ("%s: unicode conversion returned NULL", __func__);
 
                        SetLastError (ERROR_PATH_NOT_FOUND);
                        goto free_strings;
@@ -645,10 +644,8 @@ gboolean CreateProcess (const gunichar2 *appname, const gunichar2 *cmdline,
 
                        /* Executable existing ? */
                        if (!is_executable (prog)) {
-#ifdef DEBUG
-                               g_message ("%s: Couldn't find executable %s",
+                               DEBUG ("%s: Couldn't find executable %s",
                                           __func__, prog);
-#endif
                                g_free (unquoted);
                                SetLastError (ERROR_FILE_NOT_FOUND);
                                goto free_strings;
@@ -664,10 +661,8 @@ gboolean CreateProcess (const gunichar2 *appname, const gunichar2 *cmdline,
 
                        /* And make sure it's executable */
                        if (!is_executable (prog)) {
-#ifdef DEBUG
-                               g_message ("%s: Couldn't find executable %s",
+                               DEBUG ("%s: Couldn't find executable %s",
                                           __func__, prog);
-#endif
                                g_free (unquoted);
                                SetLastError (ERROR_FILE_NOT_FOUND);
                                goto free_strings;
@@ -731,9 +726,7 @@ gboolean CreateProcess (const gunichar2 *appname, const gunichar2 *cmdline,
                
                if (token == NULL) {
                        /* Give up */
-#ifdef DEBUG
-                       g_message ("%s: Couldn't find what to exec", __func__);
-#endif
+                       DEBUG ("%s: Couldn't find what to exec", __func__);
 
                        SetLastError (ERROR_PATH_NOT_FOUND);
                        goto free_strings;
@@ -759,10 +752,8 @@ gboolean CreateProcess (const gunichar2 *appname, const gunichar2 *cmdline,
                        
                        /* Executable existing ? */
                        if (!is_executable (prog)) {
-#ifdef DEBUG
-                               g_message ("%s: Couldn't find executable %s",
+                               DEBUG ("%s: Couldn't find executable %s",
                                           __func__, token);
-#endif
                                g_free (token);
                                SetLastError (ERROR_FILE_NOT_FOUND);
                                goto free_strings;
@@ -787,9 +778,7 @@ gboolean CreateProcess (const gunichar2 *appname, const gunichar2 *cmdline,
                                g_free (prog);
                                prog = g_find_program_in_path (token);
                                if (prog == NULL) {
-#ifdef DEBUG
-                                       g_message ("%s: Couldn't find executable %s", __func__, token);
-#endif
+                                       DEBUG ("%s: Couldn't find executable %s", __func__, token);
 
                                        g_free (token);
                                        SetLastError (ERROR_FILE_NOT_FOUND);
@@ -801,10 +790,8 @@ gboolean CreateProcess (const gunichar2 *appname, const gunichar2 *cmdline,
                g_free (token);
        }
 
-#ifdef DEBUG
-       g_message ("%s: Exec prog [%s] args [%s]", __func__, prog,
+       DEBUG ("%s: Exec prog [%s] args [%s]", __func__, prog,
                   args_after_prog);
-#endif
        
        /* Check for CLR binaries; if found, we will try to invoke
         * them using the same mono binary that started us.
@@ -962,9 +949,7 @@ gboolean CreateProcess (const gunichar2 *appname, const gunichar2 *cmdline,
                /* Could not create the pipe to synchroniz process startup. We'll just not synchronize.
                 * This is just for a very hard to hit race condition in the first place */
                startup_pipe [0] = startup_pipe [1] = -1;
-#if DEBUG
-               g_warning ("%s: new process startup not synchronized. We may not notice if the newly created process exits immediately.", __func__);
-#endif
+               DEBUG ("%s: new process startup not synchronized. We may not notice if the newly created process exits immediately.", __func__);
        }
 
        thr_ret = _wapi_handle_lock_shared_handles ();
@@ -982,9 +967,7 @@ gboolean CreateProcess (const gunichar2 *appname, const gunichar2 *cmdline,
                if (startup_pipe [0] != -1) {
                        /* Wait until the parent has updated it's internal data */
                        read (startup_pipe [0], &dummy, 1);
-#if DEBUG
-                       g_warning ("%s: child: parent has completed its setup", __func__);
-#endif
+                       DEBUG ("%s: child: parent has completed its setup", __func__);
                        close (startup_pipe [0]);
                        close (startup_pipe [1]);
                }
@@ -1005,8 +988,7 @@ gboolean CreateProcess (const gunichar2 *appname, const gunichar2 *cmdline,
                        close (i);
                }
 
-#ifdef DEBUG
-               g_message ("%s: exec()ing [%s] in dir [%s]", __func__, cmd,
+               DEBUG ("%s: exec()ing [%s] in dir [%s]", __func__, cmd,
                           dir==NULL?".":dir);
                for (i = 0; argv[i] != NULL; i++) {
                        g_message ("arg %d: [%s]", i, argv[i]);
@@ -1015,7 +997,6 @@ gboolean CreateProcess (const gunichar2 *appname, const gunichar2 *cmdline,
                for (i = 0; env_strings[i] != NULL; i++) {
                        g_message ("env %d: [%s]", i, env_strings[i]);
                }
-#endif
 
                /* set cwd */
                if (dir != NULL && chdir (dir) == -1) {
@@ -1111,10 +1092,8 @@ free_strings:
                g_strfreev (argv);
        }
        
-#ifdef DEBUG
-       g_message ("%s: returning handle %p for pid %d", __func__, handle,
+       DEBUG ("%s: returning handle %p for pid %d", __func__, handle,
                   pid);
-#endif
 
        /* Check if something needs to be cleaned up. */
        mono_processes_cleanup ();
@@ -1129,9 +1108,7 @@ static void process_set_name (struct _WapiHandle_process *process_handle)
        progname=g_get_prgname ();
        utf8_progname=mono_utf8_from_external (progname);
 
-#ifdef DEBUG
-       g_message ("%s: using [%s] as prog name", __func__, progname);
-#endif
+       DEBUG ("%s: using [%s] as prog name", __func__, progname);
 
        if(utf8_progname!=NULL) {
                slash=strrchr (utf8_progname, '/');
@@ -1172,11 +1149,9 @@ static void process_set_current (void)
                
                current_process = _wapi_handle_new_from_offset (WAPI_HANDLE_PROCESS, atoi (handle_env), TRUE);
                
-#ifdef DEBUG
-               g_message ("%s: Found my process handle: %p (offset %d 0x%x)",
+               DEBUG ("%s: Found my process handle: %p (offset %d 0x%x)",
                           __func__, current_process, atoi (handle_env),
                           atoi (handle_env));
-#endif
 
                ok = _wapi_lookup_handle (current_process, WAPI_HANDLE_PROCESS,
                                          (gpointer *)&process_handlep);
@@ -1189,15 +1164,11 @@ static void process_set_current (void)
                                procname = process_handlep->proc_name;
                                if (!strcmp (procname, "mono")) {
                                        /* Set a better process name */
-#ifdef DEBUG
-                                       g_message ("%s: Setting better process name", __func__);
-#endif
+                                       DEBUG ("%s: Setting better process name", __func__);
                                        
                                        process_set_name (process_handlep);
                                } else {
-#ifdef DEBUG
-                                       g_message ("%s: Leaving process name: %s", __func__, procname);
-#endif
+                                       DEBUG ("%s: Leaving process name: %s", __func__, procname);
                                }
 
                                return;
@@ -1217,9 +1188,7 @@ static void process_set_current (void)
         * child got a chance to attach it.)
         */
 
-#ifdef DEBUG
-       g_message ("%s: Need to create my own process handle", __func__);
-#endif
+       DEBUG ("%s: Need to create my own process handle", __func__);
 
        process_handle.id = pid;
 
@@ -1302,9 +1271,7 @@ static pid_t signal_process_if_gone (gpointer handle)
                return (0);
        }
        
-#ifdef DEBUG
-       g_message ("%s: looking at process %d", __func__, process_handle->id);
-#endif
+       DEBUG ("%s: looking at process %d", __func__, process_handle->id);
 
        if (kill (process_handle->id, 0) == -1 &&
            (errno == ESRCH ||
@@ -1332,9 +1299,7 @@ static gboolean process_enum (gpointer handle, gpointer user_data)
        
        /* Ignore processes that have already exited (ie they are signalled) */
        if (_wapi_handle_issignalled (handle) == FALSE) {
-#ifdef DEBUG
-               g_message ("%s: process %d added to array", __func__, pid);
-#endif
+               DEBUG ("%s: process %d added to array", __func__, pid);
 
                /* This ensures that duplicates aren't returned (see
                 * the comment above _wapi_search_handle () for why
@@ -1539,9 +1504,7 @@ gpointer OpenProcess (guint32 req_access G_GNUC_UNUSED, gboolean inherit G_GNUC_
        
        mono_once (&process_current_once, process_set_current);
 
-#ifdef DEBUG
-       g_message ("%s: looking for process %d", __func__, pid);
-#endif
+       DEBUG ("%s: looking for process %d", __func__, pid);
 
        handle = _wapi_search_handle (WAPI_HANDLE_PROCESS,
                                      process_open_compare,
@@ -1553,9 +1516,7 @@ gpointer OpenProcess (guint32 req_access G_GNUC_UNUSED, gboolean inherit G_GNUC_
                         */
                        return GINT_TO_POINTER (_WAPI_PROCESS_UNHANDLED + pid);
                } else {
-#ifdef DEBUG
-                       g_message ("%s: Can't find pid %d", __func__, pid);
-#endif
+                       DEBUG ("%s: Can't find pid %d", __func__, pid);
 
                        SetLastError (ERROR_PROC_NOT_FOUND);
        
@@ -1595,9 +1556,7 @@ gboolean GetExitCodeProcess (gpointer process, guint32 *code)
        ok=_wapi_lookup_handle (process, WAPI_HANDLE_PROCESS,
                                (gpointer *)&process_handle);
        if(ok==FALSE) {
-#ifdef DEBUG
-               g_message ("%s: Can't find process %p", __func__, process);
-#endif
+               DEBUG ("%s: Can't find process %p", __func__, process);
                
                return(FALSE);
        }
@@ -1644,9 +1603,7 @@ gboolean GetProcessTimes (gpointer process, WapiFileTime *create_time,
        ok=_wapi_lookup_handle (process, WAPI_HANDLE_PROCESS,
                                (gpointer *)&process_handle);
        if(ok==FALSE) {
-#ifdef DEBUG
-               g_message ("%s: Can't find process %p", __func__, process);
-#endif
+               DEBUG ("%s: Can't find process %p", __func__, process);
                
                return(FALSE);
        }
@@ -1816,10 +1773,8 @@ static GSList *load_modules (void)
                mod->inode = (ino_t) i;
                mod->filename = g_strdup (info->dlpi_name); 
 
-#ifdef DEBUG
-               g_message ("%s: inode=%d, filename=%s, address_start=%p, address_end=%p", __func__,
+               DEBUG ("%s: inode=%d, filename=%s, address_start=%p, address_end=%p", __func__,
                                   mod->inode, mod->filename, mod->address_start, mod->address_end);
-#endif
 
                free(info);
 
@@ -2075,9 +2030,7 @@ gboolean EnumProcessModules (gpointer process, gpointer *modules,
                ok = _wapi_lookup_handle (process, WAPI_HANDLE_PROCESS,
                                          (gpointer *)&process_handle);
                if (ok == FALSE) {
-#ifdef DEBUG
-                       g_message ("%s: Can't find process %p", __func__, process);
-#endif
+                       DEBUG ("%s: Can't find process %p", __func__, process);
                
                        return(FALSE);
                }
@@ -2179,9 +2132,7 @@ static gchar *get_process_name_from_proc (pid_t pid)
        if (sysctl (mib, 4, pi, &size, NULL, 0) < 0) {
                if (errno == ENOMEM) {
                        free(pi);
-#ifdef DEBUG
-                       g_message ("%s: Didn't allocate enough memory for kproc info", __func__);
-#endif
+                       DEBUG ("%s: Didn't allocate enough memory for kproc info", __func__);
                }
                return(ret);
        }
@@ -2300,10 +2251,8 @@ static guint32 get_module_name (gpointer process, gpointer module,
        
        mono_once (&process_current_once, process_set_current);
 
-#ifdef DEBUG
-       g_message ("%s: Getting module base name, process handle %p module %p",
+       DEBUG ("%s: Getting module base name, process handle %p module %p",
                   __func__, process, module);
-#endif
 
        size = size*sizeof(gunichar2); /* adjust for unicode characters */
 
@@ -2319,10 +2268,8 @@ static guint32 get_module_name (gpointer process, gpointer module,
                ok = _wapi_lookup_handle (process, WAPI_HANDLE_PROCESS,
                                          (gpointer *)&process_handle);
                if (ok == FALSE) {
-#ifdef DEBUG
-                       g_message ("%s: Can't find process %p", __func__,
+                       DEBUG ("%s: Can't find process %p", __func__,
                                   process);
-#endif
                        
                        return(0);
                }
@@ -2384,10 +2331,8 @@ static guint32 get_module_name (gpointer process, gpointer module,
        }
 
        if (procname_ext != NULL) {
-#ifdef DEBUG
-               g_message ("%s: Process name is [%s]", __func__,
+               DEBUG ("%s: Process name is [%s]", __func__,
                           procname_ext);
-#endif
 
                procname = mono_unicode_from_external (procname_ext, &bytes);
                if (procname == NULL) {
@@ -2402,16 +2347,12 @@ static guint32 get_module_name (gpointer process, gpointer module,
                bytes += 2;
                
                if (size < bytes) {
-#ifdef DEBUG
-                       g_message ("%s: Size %d smaller than needed (%ld); truncating", __func__, size, bytes);
-#endif
+                       DEBUG ("%s: Size %d smaller than needed (%ld); truncating", __func__, size, bytes);
 
                        memcpy (basename, procname, size);
                } else {
-#ifdef DEBUG
-                       g_message ("%s: Size %d larger than needed (%ld)",
+                       DEBUG ("%s: Size %d larger than needed (%ld)",
                                   __func__, size, bytes);
-#endif
 
                        memcpy (basename, procname, bytes);
                }
@@ -2455,10 +2396,8 @@ gboolean GetModuleInformation (gpointer process, gpointer module,
        
        mono_once (&process_current_once, process_set_current);
        
-#ifdef DEBUG
-       g_message ("%s: Getting module info, process handle %p module %p",
+       DEBUG ("%s: Getting module info, process handle %p module %p",
                   __func__, process, module);
-#endif
 
        if (modinfo == NULL || size < sizeof(WapiModuleInfo)) {
                return(FALSE);
@@ -2472,10 +2411,8 @@ gboolean GetModuleInformation (gpointer process, gpointer module,
                ok = _wapi_lookup_handle (process, WAPI_HANDLE_PROCESS,
                                          (gpointer *)&process_handle);
                if (ok == FALSE) {
-#ifdef DEBUG
-                       g_message ("%s: Can't find process %p", __func__,
+                       DEBUG ("%s: Can't find process %p", __func__,
                                   process);
-#endif
                        
                        return(FALSE);
                }
@@ -2546,9 +2483,7 @@ gboolean GetProcessWorkingSetSize (gpointer process, size_t *min, size_t *max)
        ok=_wapi_lookup_handle (process, WAPI_HANDLE_PROCESS,
                                (gpointer *)&process_handle);
        if(ok==FALSE) {
-#ifdef DEBUG
-               g_message ("%s: Can't find process %p", __func__, process);
-#endif
+               DEBUG ("%s: Can't find process %p", __func__, process);
                
                return(FALSE);
        }
@@ -2575,9 +2510,7 @@ gboolean SetProcessWorkingSetSize (gpointer process, size_t min, size_t max)
        ok=_wapi_lookup_handle (process, WAPI_HANDLE_PROCESS,
                                (gpointer *)&process_handle);
        if(ok==FALSE) {
-#ifdef DEBUG
-               g_message ("%s: Can't find process %p", __func__, process);
-#endif
+               DEBUG ("%s: Can't find process %p", __func__, process);
                
                return(FALSE);
        }
@@ -2606,10 +2539,8 @@ TerminateProcess (gpointer process, gint32 exitCode)
                                          (gpointer *) &process_handle);
 
                if (ok == FALSE) {
-#ifdef DEBUG
-                       g_message ("%s: Can't find process %p", __func__,
+                       DEBUG ("%s: Can't find process %p", __func__,
                                   process);
-#endif
                        SetLastError (ERROR_INVALID_HANDLE);
                        return FALSE;
                }
@@ -2776,9 +2707,7 @@ mono_processes_cleanup (void)
        gpointer unref_handle;
        int spin;
 
-#if DEBUG
-       g_warning ("%s", __func__);
-#endif
+       DEBUG ("%s", __func__);
 
        /* Ensure we're not in here in multiple threads at once, nor recursive. */
        if (InterlockedCompareExchange (&mono_processes_cleaning_up, 1, 0) != 0)
@@ -2837,9 +2766,7 @@ mono_processes_cleanup (void)
                                /* We've modified the list of processes, and we know the sigchld handler
                                 * isn't executing, so even if it executes at any moment, it'll see the
                                 * new version of the list. So now we can free the candidate. */
-#if DEBUG
-                               g_warning ("%s: freeing candidate %p", __func__, candidate);
-#endif
+                               DEBUG ("%s: freeing candidate %p", __func__, candidate);
                                mp = candidate->next;
                                MONO_SEM_DESTROY (&candidate->exit_sem);
                                g_free (candidate);
@@ -2855,9 +2782,7 @@ mono_processes_cleanup (void)
                mp = mp->next;
        }
 
-#if DEBUG
-       g_warning ("%s done", __func__);
-#endif
+       DEBUG ("%s done", __func__);
 
        InterlockedDecrement (&mono_processes_cleaning_up);
 }
@@ -2867,9 +2792,7 @@ process_close (gpointer handle, gpointer data)
 {
        struct _WapiHandle_process *process_handle;
 
-#if DEBUG
-       g_warning ("%s", __func__);
-#endif
+       DEBUG ("%s", __func__);
 
        process_handle = (struct _WapiHandle_process *) data;
        if (process_handle->mono_process && process_handle->self == _wapi_getpid ())
@@ -2931,9 +2854,7 @@ static void process_add_sigchld_handler (void)
        sigemptyset (&sa.sa_mask);
        sa.sa_flags = SA_NOCLDSTOP | SA_SIGINFO;
        g_assert (sigaction (SIGCHLD, &sa, &previous_chld_sa) != -1);
-#if DEBUG
-       g_warning ("Added SIGCHLD handler");
-#endif
+       DEBUG ("Added SIGCHLD handler");
 #endif
 }
 
@@ -2959,9 +2880,7 @@ static guint32 process_wait (gpointer handle, guint32 timeout, gboolean alertabl
         * but WaitFor*Object won't call us for pseudo handles. */
        g_assert ((GPOINTER_TO_UINT (handle) & _WAPI_PROCESS_UNHANDLED) != _WAPI_PROCESS_UNHANDLED);
 
-#if DEBUG
-       g_warning ("%s (%p, %u)", __func__, handle, timeout);
-#endif
+       DEBUG ("%s (%p, %u)", __func__, handle, timeout);
 
        ok = _wapi_lookup_handle (handle, WAPI_HANDLE_PROCESS, (gpointer *)&process_handle);
        if (ok == FALSE) {
@@ -2971,17 +2890,13 @@ static guint32 process_wait (gpointer handle, guint32 timeout, gboolean alertabl
 
        if (process_handle->exited) {
                /* We've already done this one */
-#if DEBUG
-               g_warning ("%s (%p, %u): Process already exited", __func__, handle, timeout);
-#endif
+               DEBUG ("%s (%p, %u): Process already exited", __func__, handle, timeout);
                return WAIT_OBJECT_0;
        }
 
        pid = process_handle->id;
 
-#if DEBUG
-       g_warning ("%s (%p, %u): PID: %d", __func__, handle, timeout, pid);
-#endif
+       DEBUG ("%s (%p, %u): PID: %d", __func__, handle, timeout, pid);
 
        /* We don't need to lock mono_processes here, the entry
         * has a handle_count > 0 which means it will not be freed. */
@@ -2999,25 +2914,19 @@ static guint32 process_wait (gpointer handle, guint32 timeout, gboolean alertabl
                if (mp != NULL) {
                        /* We have a semaphore we can wait on */
                        if (timeout != INFINITE) {
-#if DEBUG
-                               g_warning ("%s (%p, %u): waiting on semaphore for %li ms...", 
+                               DEBUG ("%s (%p, %u): waiting on semaphore for %li ms...", 
                                        __func__, handle, timeout, (timeout - (now - start)));
-#endif
 
                                ret = MONO_SEM_TIMEDWAIT_ALERTABLE (&mp->exit_sem, (timeout - (now - start)), alertable);
                        } else {
-#if DEBUG
-                               g_warning ("%s (%p, %u): waiting on semaphore forever...", 
+                               DEBUG ("%s (%p, %u): waiting on semaphore forever...", 
                                        __func__, handle, timeout);
-#endif
                                ret = MONO_SEM_WAIT_ALERTABLE (&mp->exit_sem, alertable);
                        }
 
                        if (ret == -1 && errno != EINTR && errno != ETIMEDOUT) {
-#if DEBUG
-                               g_warning ("%s (%p, %u): sem_timedwait failure: %s", 
+                               DEBUG ("%s (%p, %u): sem_timedwait failure: %s", 
                                        __func__, handle, timeout, g_strerror (errno));
-#endif
                                /* Should we return a failure here? */
                        }
 
@@ -3029,9 +2938,7 @@ static guint32 process_wait (gpointer handle, guint32 timeout, gboolean alertabl
                } else {
                        /* We did not create this process, so we can't waidpid / sem_wait it.
                         * We need to poll for the pid existence */
-#if DEBUG
-                       g_warning ("%s (%p, %u): polling on pid...", __func__, handle, timeout);
-#endif
+                       DEBUG ("%s (%p, %u): polling on pid...", __func__, handle, timeout);
                        if (!is_pid_valid (pid)) {
                                /* Success, process has exited */
                                break;
@@ -3039,17 +2946,13 @@ static guint32 process_wait (gpointer handle, guint32 timeout, gboolean alertabl
                }
 
                if (timeout == 0) {
-#if DEBUG
-                       g_warning ("%s (%p, %u): WAIT_TIMEOUT (timeout = 0)", __func__, handle, timeout);
-#endif
+                       DEBUG ("%s (%p, %u): WAIT_TIMEOUT (timeout = 0)", __func__, handle, timeout);
                        return WAIT_TIMEOUT;
                }
 
                now = mono_msec_ticks ();
                if (now - start >= timeout) {
-#if DEBUG
-                       g_warning ("%s (%p, %u): WAIT_TIMEOUT", __func__, handle, timeout);
-#endif
+                       DEBUG ("%s (%p, %u): WAIT_TIMEOUT", __func__, handle, timeout);
                        return WAIT_TIMEOUT;
                }
 
@@ -3060,17 +2963,13 @@ static guint32 process_wait (gpointer handle, guint32 timeout, gboolean alertabl
                }
                
                if (alertable && _wapi_thread_apc_pending (current_thread)) {
-#if DEBUG
-                       g_warning ("%s (%p, %u): WAIT_IO_COMPLETION", __func__, handle, timeout);
-#endif
+                       DEBUG ("%s (%p, %u): WAIT_IO_COMPLETION", __func__, handle, timeout);
                        return WAIT_IO_COMPLETION;
                }
        }
 
        /* Process must have exited */
-#if DEBUG
-       g_warning ("%s (%p, %u): Waited successfully", __func__, handle, timeout);
-#endif
+       DEBUG ("%s (%p, %u): Waited successfully", __func__, handle, timeout);
 
        ret = _wapi_handle_lock_shared_handles ();
        g_assert (ret == 0);
@@ -3085,10 +2984,8 @@ static guint32 process_wait (gpointer handle, guint32 timeout, gboolean alertabl
 
        process_handle->exited = TRUE;
 
-#if DEBUG
-       g_warning ("%s (%p, %u): Setting pid %d signalled, exit status %d",
+       DEBUG ("%s (%p, %u): Setting pid %d signalled, exit status %d",
                   __func__, handle, timeout, process_handle->id, process_handle->exitstatus);
-#endif
 
        _wapi_shared_handle_set_signal_state (handle, TRUE);
 
index 73fda73552db2218fbe39388cf08279f08fe85d1..8b4bb0ebcca6599b727ef5feb5d3b1f6791dd09f 100644 (file)
 #include <mono/io-layer/mono-mutex.h>
 #include <mono/io-layer/semaphore-private.h>
 
-#undef DEBUG
+#if 0
+#define DEBUG(...) g_message(__VA_ARGS__)
+#else
+#define DEBUG(...)
+#endif
 
 static void sema_signal(gpointer handle);
 static gboolean sema_own (gpointer handle);
@@ -109,15 +113,11 @@ static gboolean sema_own (gpointer handle)
                return(FALSE);
        }
        
-#ifdef DEBUG
-       g_message("%s: owning sem handle %p", __func__, handle);
-#endif
+       DEBUG("%s: owning sem handle %p", __func__, handle);
 
        sem_handle->val--;
        
-#ifdef DEBUG
-       g_message ("%s: sem %p val now %d", __func__, handle, sem_handle->val);
-#endif
+       DEBUG ("%s: sem %p val now %d", __func__, handle, sem_handle->val);
 
        if(sem_handle->val==0) {
                _wapi_handle_set_signal_state (handle, FALSE, FALSE);
@@ -137,9 +137,7 @@ static gboolean namedsema_own (gpointer handle)
        struct _WapiHandle_namedsem *namedsem_handle;
        gboolean ok;
        
-#ifdef DEBUG
-       g_message ("%s: owning named sem handle %p", __func__, handle);
-#endif
+       DEBUG ("%s: owning named sem handle %p", __func__, handle);
 
        ok = _wapi_lookup_handle (handle, WAPI_HANDLE_NAMEDSEM,
                                  (gpointer *)&namedsem_handle);
@@ -151,10 +149,8 @@ static gboolean namedsema_own (gpointer handle)
        
        namedsem_handle->val--;
        
-#ifdef DEBUG
-       g_message ("%s: named sem %p val now %d", __func__, handle,
+       DEBUG ("%s: named sem %p val now %d", __func__, handle,
                   namedsem_handle->val);
-#endif
 
        if (namedsem_handle->val == 0) {
                _wapi_shared_handle_set_signal_state (handle, FALSE);
@@ -194,10 +190,8 @@ static gpointer sem_create (WapiSecurityAttributes *security G_GNUC_UNUSED,
                _wapi_handle_set_signal_state (handle, TRUE, FALSE);
        }
 
-#ifdef DEBUG
-       g_message ("%s: Created semaphore handle %p initial %d max %d",
+       DEBUG ("%s: Created semaphore handle %p initial %d max %d",
                   __func__, handle, initial, max);
-#endif
 
        thr_ret = _wapi_handle_unlock_handle (handle);
        g_assert (thr_ret == 0);
@@ -230,9 +224,7 @@ static gpointer namedsem_create (WapiSecurityAttributes *security G_GNUC_UNUSED,
 
        utf8_name = g_utf16_to_utf8 (name, -1, NULL, NULL, NULL);
        
-#ifdef DEBUG
-       g_message ("%s: Creating named sem [%s]", __func__, utf8_name);
-#endif
+       DEBUG ("%s: Creating named sem [%s]", __func__, utf8_name);
 
        offset = _wapi_search_handle_namespace (WAPI_HANDLE_NAMEDSEM,
                                                utf8_name);
@@ -296,9 +288,7 @@ static gpointer namedsem_create (WapiSecurityAttributes *security G_GNUC_UNUSED,
                _wapi_handle_unlock_shared_handles ();
        }
        
-#ifdef DEBUG
-       g_message ("%s: returning named sem handle %p", __func__, handle);
-#endif
+       DEBUG ("%s: returning named sem handle %p", __func__, handle);
 
 cleanup:
        g_free (utf8_name);
@@ -332,18 +322,14 @@ gpointer CreateSemaphore(WapiSecurityAttributes *security G_GNUC_UNUSED, gint32
        mono_once (&sem_ops_once, sem_ops_init);
        
        if (max <= 0) {
-#ifdef DEBUG
-               g_message ("%s: max <= 0", __func__);
-#endif
+               DEBUG ("%s: max <= 0", __func__);
 
                SetLastError (ERROR_INVALID_PARAMETER);
                return(NULL);
        }
        
        if (initial > max || initial < 0) {
-#ifdef DEBUG
-               g_message ("%s: initial>max or < 0", __func__);
-#endif
+               DEBUG ("%s: initial>max or < 0", __func__);
 
                SetLastError (ERROR_INVALID_PARAMETER);
                return(NULL);
@@ -376,10 +362,8 @@ static gboolean sem_release (gpointer handle, gint32 count, gint32 *prevcount)
        thr_ret = _wapi_handle_lock_handle (handle);
        g_assert (thr_ret == 0);
 
-#ifdef DEBUG
-       g_message ("%s: sem %p val %d count %d", __func__, handle,
+       DEBUG ("%s: sem %p val %d count %d", __func__, handle,
                   sem_handle->val, count);
-#endif
        
        /* Do this before checking for count overflow, because overflowing max
         * is a listed technique for finding the current value
@@ -390,9 +374,7 @@ static gboolean sem_release (gpointer handle, gint32 count, gint32 *prevcount)
        
        /* No idea why max is signed, but thats the spec :-( */
        if (sem_handle->val + count > (guint32)sem_handle->max) {
-#ifdef DEBUG
-               g_message ("%s: sem %p max value would be exceeded: max %d current %d count %d", __func__, handle, sem_handle->max, sem_handle->val, count);
-#endif
+               DEBUG ("%s: sem %p max value would be exceeded: max %d current %d count %d", __func__, handle, sem_handle->max, sem_handle->val, count);
 
                goto end;
        }
@@ -402,9 +384,7 @@ static gboolean sem_release (gpointer handle, gint32 count, gint32 *prevcount)
        
        ret = TRUE;
 
-#ifdef DEBUG
-       g_message ("%s: sem %p val now %d", __func__, handle, sem_handle->val);
-#endif
+       DEBUG ("%s: sem %p val now %d", __func__, handle, sem_handle->val);
        
 end:
        thr_ret = _wapi_handle_unlock_handle (handle);
@@ -433,10 +413,8 @@ static gboolean namedsem_release (gpointer handle, gint32 count,
        thr_ret = _wapi_handle_lock_shared_handles ();
        g_assert (thr_ret == 0);
 
-#ifdef DEBUG
-       g_message("%s: named sem %p val %d count %d", __func__, handle,
+       DEBUG("%s: named sem %p val %d count %d", __func__, handle,
                  sem_handle->val, count);
-#endif
        
        /* Do this before checking for count overflow, because overflowing max
         * is a listed technique for finding the current value
@@ -447,9 +425,7 @@ static gboolean namedsem_release (gpointer handle, gint32 count,
        
        /* No idea why max is signed, but thats the spec :-( */
        if (sem_handle->val + count > (guint32)sem_handle->max) {
-#ifdef DEBUG
-               g_message ("%s: named sem %p max value would be exceeded: max %d current %d count %d", __func__, handle, sem_handle->max, sem_handle->val, count);
-#endif
+               DEBUG ("%s: named sem %p max value would be exceeded: max %d current %d count %d", __func__, handle, sem_handle->max, sem_handle->val, count);
 
                goto end;
        }
@@ -459,10 +435,8 @@ static gboolean namedsem_release (gpointer handle, gint32 count,
        
        ret = TRUE;
 
-#ifdef DEBUG
-       g_message("%s: named sem %p val now %d", __func__, handle,
+       DEBUG("%s: named sem %p val now %d", __func__, handle,
                  sem_handle->val);
-#endif
        
 end:
        _wapi_handle_unlock_shared_handles ();
@@ -520,9 +494,7 @@ gpointer OpenSemaphore (guint32 access G_GNUC_UNUSED, gboolean inherit G_GNUC_UN
        
        utf8_name = g_utf16_to_utf8 (name, -1, NULL, NULL, NULL);
        
-#ifdef DEBUG
-       g_message ("%s: Opening named sem [%s]", __func__, utf8_name);
-#endif
+       DEBUG ("%s: Opening named sem [%s]", __func__, utf8_name);
 
        offset = _wapi_search_handle_namespace (WAPI_HANDLE_NAMEDSEM,
                                                utf8_name);
@@ -551,9 +523,7 @@ gpointer OpenSemaphore (guint32 access G_GNUC_UNUSED, gboolean inherit G_GNUC_UN
        }
        ret = handle;
        
-#ifdef DEBUG
-       g_message ("%s: returning named sem handle %p", __func__, handle);
-#endif
+       DEBUG ("%s: returning named sem handle %p", __func__, handle);
 
 cleanup:
        g_free (utf8_name);
index 079e01d6528d34836db0626f355d13c6de895f2b..817b8478105edd703c9c2663eec19c47c58b1c53 100644 (file)
 #include <sys/sendfile.h>
 #endif
 
-#undef DEBUG
+#if 0
+#define DEBUG(...) g_message(__VA_ARGS__)
+#else
+#define DEBUG(...)
+#endif
 
 static guint32 startup_count=0;
 static guint32 in_cleanup = 0;
@@ -79,9 +83,7 @@ static void socket_close (gpointer handle, gpointer data)
        int ret;
        struct _WapiHandle_socket *socket_handle = (struct _WapiHandle_socket *)data;
 
-#ifdef DEBUG
-       g_message ("%s: closing socket handle %p", __func__, handle);
-#endif
+       DEBUG ("%s: closing socket handle %p", __func__, handle);
 
        if (startup_count == 0 && !in_cleanup) {
                WSASetLastError (WSANOTINITIALISED);
@@ -100,9 +102,7 @@ static void socket_close (gpointer handle, gpointer data)
        
        if (ret == -1) {
                gint errnum = errno;
-#ifdef DEBUG
-               g_message ("%s: close error: %s", __func__, strerror (errno));
-#endif
+               DEBUG ("%s: close error: %s", __func__, strerror (errno));
                errnum = errno_to_WSA (errnum, __func__);
                if (!in_cleanup)
                        WSASetLastError (errnum);
@@ -131,9 +131,7 @@ int WSAStartup(guint32 requested, WapiWSAData *data)
        data->wVersion = requested < data->wHighVersion? requested:
                data->wHighVersion;
 
-#ifdef DEBUG
-       g_message ("%s: high version 0x%x", __func__, data->wHighVersion);
-#endif
+       DEBUG ("%s: high version 0x%x", __func__, data->wHighVersion);
        
        strncpy (data->szDescription, "WAPI", WSADESCRIPTION_LEN);
        strncpy (data->szSystemStatus, "groovy", WSASYS_STATUS_LEN);
@@ -150,9 +148,7 @@ cleanup_close (gpointer handle, gpointer data)
 
 int WSACleanup(void)
 {
-#ifdef DEBUG
-       g_message ("%s: cleaning up", __func__);
-#endif
+       DEBUG ("%s: cleaning up", __func__);
 
        if (--startup_count) {
                /* Do nothing */
@@ -228,9 +224,7 @@ guint32 _wapi_accept(guint32 fd, struct sockaddr *addr, socklen_t *addrlen)
 
        if (new_fd == -1) {
                gint errnum = errno;
-#ifdef DEBUG
-               g_message ("%s: accept error: %s", __func__, strerror(errno));
-#endif
+               DEBUG ("%s: accept error: %s", __func__, strerror(errno));
 
                errnum = errno_to_WSA (errnum, __func__);
                WSASetLastError (errnum);
@@ -239,9 +233,7 @@ guint32 _wapi_accept(guint32 fd, struct sockaddr *addr, socklen_t *addrlen)
        }
 
        if (new_fd >= _wapi_fd_reserve) {
-#ifdef DEBUG
-               g_message ("%s: File descriptor is too big", __func__);
-#endif
+               DEBUG ("%s: File descriptor is too big", __func__);
 
                WSASetLastError (WSASYSCALLFAILURE);
                
@@ -263,10 +255,8 @@ guint32 _wapi_accept(guint32 fd, struct sockaddr *addr, socklen_t *addrlen)
                return(INVALID_SOCKET);
        }
 
-#ifdef DEBUG
-       g_message ("%s: returning newly accepted socket handle %p with",
+       DEBUG ("%s: returning newly accepted socket handle %p with",
                   __func__, new_handle);
-#endif
        
        return(new_fd);
 }
@@ -289,9 +279,7 @@ int _wapi_bind(guint32 fd, struct sockaddr *my_addr, socklen_t addrlen)
        ret = bind (fd, my_addr, addrlen);
        if (ret == -1) {
                gint errnum = errno;
-#ifdef DEBUG
-               g_message ("%s: bind error: %s", __func__, strerror(errno));
-#endif
+               DEBUG ("%s: bind error: %s", __func__, strerror(errno));
                errnum = errno_to_WSA (errnum, __func__);
                WSASetLastError (errnum);
                
@@ -326,10 +314,8 @@ int _wapi_connect(guint32 fd, const struct sockaddr *serv_addr,
                errnum = errno;
                
                if (errno != EINTR) {
-#ifdef DEBUG
-                       g_message ("%s: connect error: %s", __func__,
+                       DEBUG ("%s: connect error: %s", __func__,
                                   strerror (errnum));
-#endif
 
                        errnum = errno_to_WSA (errnum, __func__);
                        if (errnum == WSAEINPROGRESS)
@@ -365,10 +351,8 @@ int _wapi_connect(guint32 fd, const struct sockaddr *serv_addr,
                        if (errno != EINTR) {
                                errnum = errno_to_WSA (errno, __func__);
 
-#ifdef DEBUG
-                               g_message ("%s: connect poll error: %s",
+                               DEBUG ("%s: connect poll error: %s",
                                           __func__, strerror (errno));
-#endif
 
                                WSASetLastError (errnum);
                                return(SOCKET_ERROR);
@@ -380,10 +364,8 @@ int _wapi_connect(guint32 fd, const struct sockaddr *serv_addr,
                                &len) == -1) {
                        errnum = errno_to_WSA (errno, __func__);
 
-#ifdef DEBUG
-                       g_message ("%s: connect getsockopt error: %s",
+                       DEBUG ("%s: connect getsockopt error: %s",
                                   __func__, strerror (errno));
-#endif
 
                        WSASetLastError (errnum);
                        return(SOCKET_ERROR);
@@ -401,10 +383,8 @@ int _wapi_connect(guint32 fd, const struct sockaddr *serv_addr,
                                socket_handle->saved_error = errnum;
                        }
                        
-#ifdef DEBUG
-                       g_message ("%s: connect getsockopt returned error: %s",
+                       DEBUG ("%s: connect getsockopt returned error: %s",
                                   __func__, strerror (so_error));
-#endif
 
                        WSASetLastError (errnum);
                        return(SOCKET_ERROR);
@@ -432,10 +412,8 @@ int _wapi_getpeername(guint32 fd, struct sockaddr *name, socklen_t *namelen)
        ret = getpeername (fd, name, namelen);
        if (ret == -1) {
                gint errnum = errno;
-#ifdef DEBUG
-               g_message ("%s: getpeername error: %s", __func__,
+               DEBUG ("%s: getpeername error: %s", __func__,
                           strerror (errno));
-#endif
 
                errnum = errno_to_WSA (errnum, __func__);
                WSASetLastError (errnum);
@@ -464,10 +442,8 @@ int _wapi_getsockname(guint32 fd, struct sockaddr *name, socklen_t *namelen)
        ret = getsockname (fd, name, namelen);
        if (ret == -1) {
                gint errnum = errno;
-#ifdef DEBUG
-               g_message ("%s: getsockname error: %s", __func__,
+               DEBUG ("%s: getsockname error: %s", __func__,
                           strerror (errno));
-#endif
 
                errnum = errno_to_WSA (errnum, __func__);
                WSASetLastError (errnum);
@@ -508,10 +484,8 @@ int _wapi_getsockopt(guint32 fd, int level, int optname, void *optval,
        ret = getsockopt (fd, level, optname, tmp_val, optlen);
        if (ret == -1) {
                gint errnum = errno;
-#ifdef DEBUG
-               g_message ("%s: getsockopt error: %s", __func__,
+               DEBUG ("%s: getsockopt error: %s", __func__,
                           strerror (errno));
-#endif
 
                errnum = errno_to_WSA (errnum, __func__);
                WSASetLastError (errnum);
@@ -567,9 +541,7 @@ int _wapi_listen(guint32 fd, int backlog)
        ret = listen (fd, backlog);
        if (ret == -1) {
                gint errnum = errno;
-#ifdef DEBUG
-               g_message ("%s: listen error: %s", __func__, strerror (errno));
-#endif
+               DEBUG ("%s: listen error: %s", __func__, strerror (errno));
 
                errnum = errno_to_WSA (errnum, __func__);
                WSASetLastError (errnum);
@@ -637,9 +609,7 @@ int _wapi_recvfrom(guint32 fd, void *buf, size_t len, int recv_flags,
        
        if (ret == -1) {
                gint errnum = errno;
-#ifdef DEBUG
-               g_message ("%s: recv error: %s", __func__, strerror(errno));
-#endif
+               DEBUG ("%s: recv error: %s", __func__, strerror(errno));
 
                errnum = errno_to_WSA (errnum, __func__);
                WSASetLastError (errnum);
@@ -684,9 +654,7 @@ _wapi_recvmsg(guint32 fd, struct msghdr *msg, int recv_flags)
        
        if (ret == -1) {
                gint errnum = errno;
-#ifdef DEBUG
-               g_message ("%s: recvmsg error: %s", __func__, strerror(errno));
-#endif
+               DEBUG ("%s: recvmsg error: %s", __func__, strerror(errno));
 
                errnum = errno_to_WSA (errnum, __func__);
                WSASetLastError (errnum);
@@ -718,9 +686,7 @@ int _wapi_send(guint32 fd, const void *msg, size_t len, int send_flags)
 
        if (ret == -1) {
                gint errnum = errno;
-#ifdef DEBUG
-               g_message ("%s: send error: %s", __func__, strerror (errno));
-#endif
+               DEBUG ("%s: send error: %s", __func__, strerror (errno));
 
 #ifdef O_NONBLOCK
                /* At least linux returns EAGAIN/EWOULDBLOCK when the timeout has been set on
@@ -762,9 +728,7 @@ int _wapi_sendto(guint32 fd, const void *msg, size_t len, int send_flags,
 
        if (ret == -1) {
                gint errnum = errno;
-#ifdef DEBUG
-               g_message ("%s: send error: %s", __func__, strerror (errno));
-#endif
+               DEBUG ("%s: send error: %s", __func__, strerror (errno));
 
                errnum = errno_to_WSA (errnum, __func__);
                WSASetLastError (errnum);
@@ -797,9 +761,7 @@ _wapi_sendmsg(guint32 fd,  const struct msghdr *msg, int send_flags)
 
        if (ret == -1) {
                gint errnum = errno;
-#ifdef DEBUG
-               g_message ("%s: sendmsg error: %s", __func__, strerror (errno));
-#endif
+               DEBUG ("%s: sendmsg error: %s", __func__, strerror (errno));
 
                errnum = errno_to_WSA (errnum, __func__);
                WSASetLastError (errnum);
@@ -852,10 +814,8 @@ int _wapi_setsockopt(guint32 fd, int level, int optname,
        ret = setsockopt (fd, level, optname, tmp_val, optlen);
        if (ret == -1) {
                gint errnum = errno;
-#ifdef DEBUG
-               g_message ("%s: setsockopt error: %s", __func__,
+               DEBUG ("%s: setsockopt error: %s", __func__,
                           strerror (errno));
-#endif
 
                errnum = errno_to_WSA (errnum, __func__);
                WSASetLastError (errnum);
@@ -913,10 +873,8 @@ int _wapi_shutdown(guint32 fd, int how)
        ret = shutdown (fd, how);
        if (ret == -1) {
                gint errnum = errno;
-#ifdef DEBUG
-               g_message ("%s: shutdown error: %s", __func__,
+               DEBUG ("%s: shutdown error: %s", __func__,
                           strerror (errno));
-#endif
 
                errnum = errno_to_WSA (errnum, __func__);
                WSASetLastError (errnum);
@@ -949,9 +907,7 @@ guint32 _wapi_socket(int domain, int type, int protocol, void *unused,
        
        if (fd == -1) {
                gint errnum = errno;
-#ifdef DEBUG
-               g_message ("%s: socket error: %s", __func__, strerror (errno));
-#endif
+               DEBUG ("%s: socket error: %s", __func__, strerror (errno));
                errnum = errno_to_WSA (errnum, __func__);
                WSASetLastError (errnum);
 
@@ -959,10 +915,8 @@ guint32 _wapi_socket(int domain, int type, int protocol, void *unused,
        }
 
        if (fd >= _wapi_fd_reserve) {
-#ifdef DEBUG
-               g_message ("%s: File descriptor is too big (%d >= %d)",
+               DEBUG ("%s: File descriptor is too big (%d >= %d)",
                           __func__, fd, _wapi_fd_reserve);
-#endif
 
                WSASetLastError (WSASYSCALLFAILURE);
                close (fd);
@@ -991,9 +945,7 @@ guint32 _wapi_socket(int domain, int type, int protocol, void *unused,
                if (ret == -1) {
                        int errnum = errno;
 
-#ifdef DEBUG
-                       g_message ("%s: Error setting SO_REUSEADDR", __func__);
-#endif
+                       DEBUG ("%s: Error setting SO_REUSEADDR", __func__);
                        
                        errnum = errno_to_WSA (errnum, __func__);
                        WSASetLastError (errnum);
@@ -1015,9 +967,7 @@ guint32 _wapi_socket(int domain, int type, int protocol, void *unused,
                return(INVALID_SOCKET);
        }
 
-#ifdef DEBUG
-       g_message ("%s: returning socket handle %p", __func__, handle);
-#endif
+       DEBUG ("%s: returning socket handle %p", __func__, handle);
 
        return(fd);
 }
@@ -1033,10 +983,8 @@ struct hostent *_wapi_gethostbyname(const char *hostname)
 
        he = gethostbyname (hostname);
        if (he == NULL) {
-#ifdef DEBUG
-               g_message ("%s: gethostbyname error: %s", __func__,
+               DEBUG ("%s: gethostbyname error: %s", __func__,
                           strerror (h_errno));
-#endif
 
                switch(h_errno) {
                case HOST_NOT_FOUND:
@@ -1084,9 +1032,7 @@ static gboolean socket_disconnect (guint32 fd)
        if (newsock == -1) {
                gint errnum = errno;
 
-#ifdef DEBUG
-               g_message ("%s: socket error: %s", __func__, strerror (errno));
-#endif
+               DEBUG ("%s: socket error: %s", __func__, strerror (errno));
 
                errnum = errno_to_WSA (errnum, __func__);
                WSASetLastError (errnum);
@@ -1106,9 +1052,7 @@ static gboolean socket_disconnect (guint32 fd)
        if (ret == -1) {
                gint errnum = errno;
                
-#ifdef DEBUG
-               g_message ("%s: dup2 error: %s", __func__, strerror (errno));
-#endif
+               DEBUG ("%s: dup2 error: %s", __func__, strerror (errno));
 
                errnum = errno_to_WSA (errnum, __func__);
                WSASetLastError (errnum);
@@ -1124,9 +1068,7 @@ static gboolean socket_disconnect (guint32 fd)
 static gboolean wapi_disconnectex (guint32 fd, WapiOverlapped *overlapped,
                                   guint32 flags, guint32 reserved)
 {
-#ifdef DEBUG
-       g_message ("%s: called on socket %d!", __func__, fd);
-#endif
+       DEBUG ("%s: called on socket %d!", __func__, fd);
        
        if (reserved != 0) {
                WSASetLastError (WSAEINVAL);
@@ -1375,10 +1317,8 @@ WSAIoctl (guint32 fd, gint32 command,
        ret = ioctl (fd, command, buffer);
        if (ret == -1) {
                gint errnum = errno;
-#ifdef DEBUG
-               g_message("%s: WSAIoctl error: %s", __func__,
+               DEBUG("%s: WSAIoctl error: %s", __func__,
                          strerror (errno));
-#endif
 
                errnum = errno_to_WSA (errnum, __func__);
                WSASetLastError (errnum);
@@ -1475,9 +1415,7 @@ int ioctlsocket(guint32 fd, gint32 command, gpointer arg)
 
        if (ret == -1) {
                gint errnum = errno;
-#ifdef DEBUG
-               g_message ("%s: ioctl error: %s", __func__, strerror (errno));
-#endif
+               DEBUG ("%s: ioctl error: %s", __func__, strerror (errno));
 
                errnum = errno_to_WSA (errnum, __func__);
                WSASetLastError (errnum);
@@ -1519,9 +1457,7 @@ int _wapi_select(int nfds G_GNUC_UNUSED, fd_set *readfds, fd_set *writefds,
 
        if (ret == -1) {
                gint errnum = errno;
-#ifdef DEBUG
-               g_message ("%s: select error: %s", __func__, strerror (errno));
-#endif
+               DEBUG ("%s: select error: %s", __func__, strerror (errno));
                errnum = errno_to_WSA (errnum, __func__);
                WSASetLastError (errnum);
                
index 11590c73e0a9d7f504a9cca45ccd2dffc38fde10..2ba7fc96d5554ee1eaa5d1c7221aabaa020896ae 100644 (file)
 #include <mono/utils/strenc.h>
 #include <mono/utils/mono-mmap.h>
 
-#define LOGDEBUG(...)  
-//define LOGDEBUG(...) g_message(__VA_ARGS__)
+#if 0
+// #define DEBUG(...) g_message(__VA_ARGS__)
+#else
+#define DEBUG(...)
+#endif
 
 #define ALIGN32(ptr) ptr = (gpointer)((char *)ptr + 3); ptr = (gpointer)((char *)ptr - ((gsize)ptr & 3));
 
@@ -160,14 +163,14 @@ find_pe_file_resources32 (gpointer file_map, guint32 map_size,
 
        dos_header = (WapiImageDosHeader *)file_map;
        if (dos_header->e_magic != IMAGE_DOS_SIGNATURE) {
-               LOGDEBUG ("%s: Bad dos signature 0x%x", __func__, dos_header->e_magic);
+               DEBUG ("%s: Bad dos signature 0x%x", __func__, dos_header->e_magic);
 
                SetLastError (ERROR_INVALID_DATA);
                return(NULL);
        }
        
        if (map_size < sizeof(WapiImageNTHeaders32) + GUINT32_FROM_LE (dos_header->e_lfanew)) {
-               LOGDEBUG ("%s: File is too small: %d", __func__, map_size);
+               DEBUG ("%s: File is too small: %d", __func__, map_size);
 
                SetLastError (ERROR_BAD_LENGTH);
                return(NULL);
@@ -175,7 +178,7 @@ find_pe_file_resources32 (gpointer file_map, guint32 map_size,
        
        nt_headers = (WapiImageNTHeaders32 *)((guint8 *)file_map + GUINT32_FROM_LE (dos_header->e_lfanew));
        if (nt_headers->Signature != IMAGE_NT_SIGNATURE) {
-               LOGDEBUG ("%s: Bad NT signature 0x%x", __func__, nt_headers->Signature);
+               DEBUG ("%s: Bad NT signature 0x%x", __func__, nt_headers->Signature);
 
                SetLastError (ERROR_INVALID_DATA);
                return(NULL);
@@ -189,7 +192,7 @@ find_pe_file_resources32 (gpointer file_map, guint32 map_size,
        }
 
        if (resource_rva == 0) {
-               LOGDEBUG ("%s: No resources in file!", __func__);
+               DEBUG ("%s: No resources in file!", __func__);
 
                SetLastError (ERROR_INVALID_DATA);
                return(NULL);
@@ -197,7 +200,7 @@ find_pe_file_resources32 (gpointer file_map, guint32 map_size,
        
        resource_dir = (WapiImageResourceDirectory *)get_ptr_from_rva (resource_rva, (WapiImageNTHeaders32 *)nt_headers, file_map);
        if (resource_dir == NULL) {
-               LOGDEBUG ("%s: Can't find resource directory", __func__);
+               DEBUG ("%s: Can't find resource directory", __func__);
 
                SetLastError (ERROR_INVALID_DATA);
                return(NULL);
@@ -234,14 +237,14 @@ find_pe_file_resources64 (gpointer file_map, guint32 map_size,
 
        dos_header = (WapiImageDosHeader *)file_map;
        if (dos_header->e_magic != IMAGE_DOS_SIGNATURE) {
-               LOGDEBUG ("%s: Bad dos signature 0x%x", __func__, dos_header->e_magic);
+               DEBUG ("%s: Bad dos signature 0x%x", __func__, dos_header->e_magic);
 
                SetLastError (ERROR_INVALID_DATA);
                return(NULL);
        }
        
        if (map_size < sizeof(WapiImageNTHeaders64) + GUINT32_FROM_LE (dos_header->e_lfanew)) {
-               LOGDEBUG ("%s: File is too small: %d", __func__, map_size);
+               DEBUG ("%s: File is too small: %d", __func__, map_size);
 
                SetLastError (ERROR_BAD_LENGTH);
                return(NULL);
@@ -249,7 +252,7 @@ find_pe_file_resources64 (gpointer file_map, guint32 map_size,
        
        nt_headers = (WapiImageNTHeaders64 *)((guint8 *)file_map + GUINT32_FROM_LE (dos_header->e_lfanew));
        if (nt_headers->Signature != IMAGE_NT_SIGNATURE) {
-               LOGDEBUG ("%s: Bad NT signature 0x%x", __func__,
+               DEBUG ("%s: Bad NT signature 0x%x", __func__,
                           nt_headers->Signature);
 
                SetLastError (ERROR_INVALID_DATA);
@@ -264,7 +267,7 @@ find_pe_file_resources64 (gpointer file_map, guint32 map_size,
        }
 
        if (resource_rva == 0) {
-               LOGDEBUG ("%s: No resources in file!", __func__);
+               DEBUG ("%s: No resources in file!", __func__);
 
                SetLastError (ERROR_INVALID_DATA);
                return(NULL);
@@ -272,7 +275,7 @@ find_pe_file_resources64 (gpointer file_map, guint32 map_size,
        
        resource_dir = (WapiImageResourceDirectory *)get_ptr_from_rva (resource_rva, (WapiImageNTHeaders32 *)nt_headers, file_map);
        if (resource_dir == NULL) {
-               LOGDEBUG ("%s: Can't find resource directory", __func__);
+               DEBUG ("%s: Can't find resource directory", __func__);
 
                SetLastError (ERROR_INVALID_DATA);
                return(NULL);
@@ -325,7 +328,7 @@ map_pe_file (gunichar2 *filename, gint32 *map_size, void **handle)
 
        filename_ext = mono_unicode_to_external (filename);
        if (filename_ext == NULL) {
-               LOGDEBUG ("%s: unicode conversion returned NULL", __func__);
+               DEBUG ("%s: unicode conversion returned NULL", __func__);
 
                SetLastError (ERROR_INVALID_NAME);
                return(NULL);
@@ -333,7 +336,7 @@ map_pe_file (gunichar2 *filename, gint32 *map_size, void **handle)
        
        fd = _wapi_open (filename_ext, O_RDONLY, 0);
        if (fd == -1) {
-               LOGDEBUG ("%s: Error opening file %s: %s", __func__, filename_ext, strerror (errno));
+               DEBUG ("%s: Error opening file %s: %s", __func__, filename_ext, strerror (errno));
 
                SetLastError (_wapi_get_win32_file_error (errno));
                g_free (filename_ext);
@@ -342,7 +345,7 @@ map_pe_file (gunichar2 *filename, gint32 *map_size, void **handle)
        }
 
        if (fstat (fd, &statbuf) == -1) {
-               LOGDEBUG ("%s: Error stat()ing file %s: %s", __func__, filename_ext, strerror (errno));
+               DEBUG ("%s: Error stat()ing file %s: %s", __func__, filename_ext, strerror (errno));
 
                SetLastError (_wapi_get_win32_file_error (errno));
                g_free (filename_ext);
@@ -353,7 +356,7 @@ map_pe_file (gunichar2 *filename, gint32 *map_size, void **handle)
        
        /* Check basic file size */
        if (statbuf.st_size < sizeof(WapiImageDosHeader)) {
-               LOGDEBUG ("%s: File %s is too small: %lld", __func__, filename_ext, statbuf.st_size);
+               DEBUG ("%s: File %s is too small: %lld", __func__, filename_ext, statbuf.st_size);
 
                SetLastError (ERROR_BAD_LENGTH);
                g_free (filename_ext);
@@ -363,7 +366,7 @@ map_pe_file (gunichar2 *filename, gint32 *map_size, void **handle)
        
        file_map = mono_file_map (statbuf.st_size, MONO_MMAP_READ | MONO_MMAP_PRIVATE, fd, 0, handle);
        if (file_map == NULL) {
-               LOGDEBUG ("%s: Error mmap()int file %s: %s", __func__, filename_ext, strerror (errno));
+               DEBUG ("%s: Error mmap()int file %s: %s", __func__, filename_ext, strerror (errno));
 
                SetLastError (_wapi_get_win32_file_error (errno));
                g_free (filename_ext);
@@ -472,12 +475,12 @@ get_fixedfileinfo_block (gconstpointer data, version_data *block)
        data_len = block->data_len;
                
        if (block->value_len != sizeof(WapiFixedFileInfo)) {
-               LOGDEBUG ("%s: FIXEDFILEINFO size mismatch", __func__);
+               DEBUG ("%s: FIXEDFILEINFO size mismatch", __func__);
                return(NULL);
        }
 
        if (!unicode_string_equals (block->key, "VS_VERSION_INFO")) {
-               LOGDEBUG ("%s: VS_VERSION_INFO mismatch", __func__);
+               DEBUG ("%s: VS_VERSION_INFO mismatch", __func__);
 
                return(NULL);
        }
@@ -485,7 +488,7 @@ get_fixedfileinfo_block (gconstpointer data, version_data *block)
        ffi = ((WapiFixedFileInfo *)data_ptr);
        if ((ffi->dwSignature != VS_FFI_SIGNATURE) ||
            (ffi->dwStrucVersion != VS_FFI_STRUCVERSION)) {
-               LOGDEBUG ("%s: FIXEDFILEINFO bad signature", __func__);
+               DEBUG ("%s: FIXEDFILEINFO bad signature", __func__);
 
                return(NULL);
        }
@@ -527,7 +530,7 @@ get_string_block (gconstpointer data_ptr,
                        /* We must have hit padding, so give up
                         * processing now
                         */
-                       LOGDEBUG ("%s: Hit 0-length block, giving up", __func__);
+                       DEBUG ("%s: Hit 0-length block, giving up", __func__);
 
                        return(NULL);
                }
@@ -583,7 +586,7 @@ get_stringtable_block (gconstpointer data_ptr,
                        /* We must have hit padding, so give up
                         * processing now
                         */
-                       LOGDEBUG ("%s: Hit 0-length block, giving up", __func__);
+                       DEBUG ("%s: Hit 0-length block, giving up", __func__);
                        return(NULL);
                }
                
@@ -591,7 +594,7 @@ get_stringtable_block (gconstpointer data_ptr,
 
                found_lang = g_utf16_to_utf8 (block->key, 8, NULL, NULL, NULL);
                if (found_lang == NULL) {
-                       LOGDEBUG ("%s: Didn't find a valid language key, giving up", __func__);
+                       DEBUG ("%s: Didn't find a valid language key, giving up", __func__);
                        return(NULL);
                }
                
@@ -614,7 +617,7 @@ get_stringtable_block (gconstpointer data_ptr,
                
                if (data_ptr == NULL) {
                        /* Child block hit padding */
-                       LOGDEBUG ("%s: Child block hit 0-length block, giving up", __func__);
+                       DEBUG ("%s: Child block hit 0-length block, giving up", __func__);
                        return(NULL);
                }
        }
@@ -644,7 +647,7 @@ big_up_string_block (gconstpointer data_ptr, version_data *block)
                        /* We must have hit padding, so give up
                         * processing now
                         */
-                       LOGDEBUG ("%s: Hit 0-length block, giving up", __func__);
+                       DEBUG ("%s: Hit 0-length block, giving up", __func__);
                        return(NULL);
                }
                
@@ -655,7 +658,7 @@ big_up_string_block (gconstpointer data_ptr, version_data *block)
                                       "UTF-16BE", "UTF-16LE", NULL, NULL,
                                       NULL);
                if (big_value == NULL) {
-                       LOGDEBUG ("%s: Didn't find a valid string, giving up", __func__);
+                       DEBUG ("%s: Didn't find a valid string, giving up", __func__);
                        return(NULL);
                }
                
@@ -672,7 +675,7 @@ big_up_string_block (gconstpointer data_ptr, version_data *block)
                                       "UTF-16BE", "UTF-16LE", NULL, NULL,
                                       NULL);
                if (big_value == NULL) {
-                       LOGDEBUG ("%s: Didn't find a valid data string, giving up", __func__);
+                       DEBUG ("%s: Didn't find a valid data string, giving up", __func__);
                        return(NULL);
                }
                memcpy ((gpointer)data_ptr, big_value,
@@ -711,7 +714,7 @@ big_up_stringtable_block (gconstpointer data_ptr, version_data *block)
                        /* We must have hit padding, so give up
                         * processing now
                         */
-                       LOGDEBUG ("%s: Hit 0-length block, giving up", __func__);
+                       DEBUG ("%s: Hit 0-length block, giving up", __func__);
                        return(NULL);
                }
                
@@ -720,7 +723,7 @@ big_up_stringtable_block (gconstpointer data_ptr, version_data *block)
                big_value = g_convert ((gchar *)block->key, 16, "UTF-16BE",
                                       "UTF-16LE", NULL, NULL, NULL);
                if (big_value == NULL) {
-                       LOGDEBUG ("%s: Didn't find a valid string, giving up", __func__);
+                       DEBUG ("%s: Didn't find a valid string, giving up", __func__);
                        return(NULL);
                }
                
@@ -731,7 +734,7 @@ big_up_stringtable_block (gconstpointer data_ptr, version_data *block)
                
                if (data_ptr == NULL) {
                        /* Child block hit padding */
-                       LOGDEBUG ("%s: Child block hit 0-length block, giving up", __func__);
+                       DEBUG ("%s: Child block hit 0-length block, giving up", __func__);
                        return(NULL);
                }
        }
@@ -783,7 +786,7 @@ big_up (gconstpointer datablock, guint32 size)
                                /* We must have hit padding, so give
                                 * up processing now
                                 */
-                               LOGDEBUG ("%s: Hit 0-length block, giving up", __func__);
+                               DEBUG ("%s: Hit 0-length block, giving up", __func__);
                                return;
                        }
                        
@@ -799,13 +802,13 @@ big_up (gconstpointer datablock, guint32 size)
                                                                     &block);
                        } else {
                                /* Bogus data */
-                               LOGDEBUG ("%s: Not a valid VERSIONINFO child block", __func__);
+                               DEBUG ("%s: Not a valid VERSIONINFO child block", __func__);
                                return;
                        }
                        
                        if (data_ptr == NULL) {
                                /* Child block hit padding */
-                               LOGDEBUG ("%s: Child block hit 0-length block, giving up", __func__);
+                               DEBUG ("%s: Child block hit 0-length block, giving up", __func__);
                                return;
                        }
                }
@@ -877,7 +880,7 @@ VerQueryValue (gconstpointer datablock, const gunichar2 *subblock, gpointer *buf
                                        /* We must have hit padding,
                                         * so give up processing now
                                         */
-                                       LOGDEBUG ("%s: Hit 0-length block, giving up", __func__);
+                                       DEBUG ("%s: Hit 0-length block, giving up", __func__);
                                        goto done;
                                }
                                
@@ -906,13 +909,13 @@ VerQueryValue (gconstpointer datablock, const gunichar2 *subblock, gpointer *buf
                                        }
                                } else {
                                        /* Bogus data */
-                                       LOGDEBUG ("%s: Not a valid VERSIONINFO child block", __func__);
+                                       DEBUG ("%s: Not a valid VERSIONINFO child block", __func__);
                                        goto done;
                                }
                                
                                if (data_ptr == NULL) {
                                        /* Child block hit padding */
-                                       LOGDEBUG ("%s: Child block hit 0-length block, giving up", __func__);
+                                       DEBUG ("%s: Child block hit 0-length block, giving up", __func__);
                                        goto done;
                                }
                        }
index 3a86bd279319962a819024542602c87ef209993d..7981ef23466f4fd0d47701202822d1eee19d83f7 100644 (file)
 #include <mono/io-layer/mono-mutex.h>
 #include <mono/io-layer/misc-private.h>
 
-#undef DEBUG
+#if 0
+#define DEBUG(...) g_message(__VA_ARGS__)
+#else
+#define DEBUG(...)
+#endif
 
 static gboolean own_if_signalled(gpointer handle)
 {
@@ -112,10 +116,8 @@ guint32 WaitForSingleObjectEx(gpointer handle, guint32 timeout,
        
        if (_wapi_handle_test_capabilities (handle,
                                            WAPI_HANDLE_CAP_WAIT) == FALSE) {
-#ifdef DEBUG
-               g_message ("%s: handle %p can't be waited for", __func__,
+               DEBUG ("%s: handle %p can't be waited for", __func__,
                           handle);
-#endif
 
                return(WAIT_FAILED);
        }
@@ -123,9 +125,7 @@ guint32 WaitForSingleObjectEx(gpointer handle, guint32 timeout,
        _wapi_handle_ops_prewait (handle);
        
        if (_wapi_handle_test_capabilities (handle, WAPI_HANDLE_CAP_SPECIAL_WAIT) == TRUE) {
-#ifdef DEBUG
-               g_message ("%s: handle %p has special wait", __func__, handle);
-#endif
+               DEBUG ("%s: handle %p has special wait", __func__, handle);
 
                ret = _wapi_handle_ops_special_wait (handle, timeout, alertable);
        
@@ -138,9 +138,7 @@ guint32 WaitForSingleObjectEx(gpointer handle, guint32 timeout,
        }
        
        
-#ifdef DEBUG
-       g_message ("%s: locking handle %p", __func__, handle);
-#endif
+       DEBUG ("%s: locking handle %p", __func__, handle);
 
        pthread_cleanup_push ((void(*)(void *))_wapi_handle_unlock_handle,
                              handle);
@@ -150,10 +148,8 @@ guint32 WaitForSingleObjectEx(gpointer handle, guint32 timeout,
        if (_wapi_handle_test_capabilities (handle,
                                            WAPI_HANDLE_CAP_OWN) == TRUE) {
                if (own_if_owned (handle) == TRUE) {
-#ifdef DEBUG
-                       g_message ("%s: handle %p already owned", __func__,
+                       DEBUG ("%s: handle %p already owned", __func__,
                                   handle);
-#endif
                        ret = WAIT_OBJECT_0;
                        goto done;
                }
@@ -166,10 +162,8 @@ guint32 WaitForSingleObjectEx(gpointer handle, guint32 timeout,
        }
        
        if (own_if_signalled (handle) == TRUE) {
-#ifdef DEBUG
-               g_message ("%s: handle %p already signalled", __func__,
+               DEBUG ("%s: handle %p already signalled", __func__,
                           handle);
-#endif
 
                ret=WAIT_OBJECT_0;
                goto done;
@@ -190,10 +184,8 @@ guint32 WaitForSingleObjectEx(gpointer handle, guint32 timeout,
                _wapi_handle_ops_prewait (handle);
 
                if (own_if_signalled (handle)) {
-#ifdef DEBUG
-                       g_message ("%s: handle %p signalled", __func__,
+                       DEBUG ("%s: handle %p signalled", __func__,
                                   handle);
-#endif
 
                        ret = WAIT_OBJECT_0;
                        goto done;
@@ -214,10 +206,8 @@ guint32 WaitForSingleObjectEx(gpointer handle, guint32 timeout,
                         * if someone else got in before us.)
                         */
                        if (own_if_signalled (handle)) {
-#ifdef DEBUG
-                               g_message ("%s: handle %p signalled", __func__,
+                               DEBUG ("%s: handle %p signalled", __func__,
                                           handle);
-#endif
 
                                ret=WAIT_OBJECT_0;
                                goto done;
@@ -228,18 +218,14 @@ guint32 WaitForSingleObjectEx(gpointer handle, guint32 timeout,
        } while(waited == 0 && !apc_pending);
 
        /* Timeout or other error */
-#ifdef DEBUG
-       g_message ("%s: wait on handle %p error: %s", __func__, handle,
+       DEBUG ("%s: wait on handle %p error: %s", __func__, handle,
                   strerror (waited));
-#endif
 
        ret = WAIT_TIMEOUT;
        
 done:
 
-#ifdef DEBUG
-       g_message ("%s: unlocking handle %p", __func__, handle);
-#endif
+       DEBUG ("%s: unlocking handle %p", __func__, handle);
        
        thr_ret = _wapi_handle_unlock_handle (handle);
        g_assert (thr_ret == 0);
@@ -354,9 +340,7 @@ guint32 SignalObjectAndWait(gpointer signal_handle, gpointer wait,
                return (WAIT_FAILED);
        }
 
-#ifdef DEBUG
-       g_message ("%s: locking handle %p", __func__, wait);
-#endif
+       DEBUG ("%s: locking handle %p", __func__, wait);
 
        pthread_cleanup_push ((void(*)(void *))_wapi_handle_unlock_handle,
                              wait);
@@ -367,10 +351,8 @@ guint32 SignalObjectAndWait(gpointer signal_handle, gpointer wait,
 
        if (_wapi_handle_test_capabilities (wait, WAPI_HANDLE_CAP_OWN)==TRUE) {
                if (own_if_owned (wait)) {
-#ifdef DEBUG
-                       g_message ("%s: handle %p already owned", __func__,
+                       DEBUG ("%s: handle %p already owned", __func__,
                                   wait);
-#endif
                        ret = WAIT_OBJECT_0;
                        goto done;
                }
@@ -383,9 +365,7 @@ guint32 SignalObjectAndWait(gpointer signal_handle, gpointer wait,
        }
        
        if (own_if_signalled (wait)) {
-#ifdef DEBUG
-               g_message ("%s: handle %p already signalled", __func__, wait);
-#endif
+               DEBUG ("%s: handle %p already signalled", __func__, wait);
 
                ret = WAIT_OBJECT_0;
                goto done;
@@ -402,9 +382,7 @@ guint32 SignalObjectAndWait(gpointer signal_handle, gpointer wait,
                _wapi_handle_ops_prewait (wait);
        
                if (own_if_signalled (wait)) {
-#ifdef DEBUG
-                       g_message ("%s: handle %p signalled", __func__, wait);
-#endif
+                       DEBUG ("%s: handle %p signalled", __func__, wait);
 
                        ret = WAIT_OBJECT_0;
                        goto done;
@@ -426,10 +404,8 @@ guint32 SignalObjectAndWait(gpointer signal_handle, gpointer wait,
                         * if someone else got in before us.)
                         */
                        if (own_if_signalled (wait)) {
-#ifdef DEBUG
-                               g_message ("%s: handle %p signalled", __func__,
+                               DEBUG ("%s: handle %p signalled", __func__,
                                           wait);
-#endif
 
                                ret = WAIT_OBJECT_0;
                                goto done;
@@ -440,18 +416,14 @@ guint32 SignalObjectAndWait(gpointer signal_handle, gpointer wait,
        } while(waited == 0 && !apc_pending);
 
        /* Timeout or other error */
-#ifdef DEBUG
-       g_message ("%s: wait on handle %p error: %s", __func__, wait,
+       DEBUG ("%s: wait on handle %p error: %s", __func__, wait,
                   strerror (ret));
-#endif
 
        ret = WAIT_TIMEOUT;
        
 done:
 
-#ifdef DEBUG
-       g_message ("%s: unlocking handle %p", __func__, wait);
-#endif
+       DEBUG ("%s: unlocking handle %p", __func__, wait);
 
        thr_ret = _wapi_handle_unlock_handle (wait);
        g_assert (thr_ret == 0);
@@ -486,9 +458,7 @@ static gboolean test_and_own (guint32 numobjects, gpointer *handles,
        gboolean done;
        int i;
        
-#ifdef DEBUG
-       g_message ("%s: locking handles", __func__);
-#endif
+       DEBUG ("%s: locking handles", __func__);
        cleanup_data.numobjects = numobjects;
        cleanup_data.handles = handles;
        
@@ -505,9 +475,7 @@ static gboolean test_and_own (guint32 numobjects, gpointer *handles,
                }
        }
        
-#ifdef DEBUG
-       g_message ("%s: unlocking handles", __func__);
-#endif
+       DEBUG ("%s: unlocking handles", __func__);
 
        /* calls the unlock function */
        pthread_cleanup_pop (1);
@@ -566,9 +534,7 @@ guint32 WaitForMultipleObjectsEx(guint32 numobjects, gpointer *handles,
        }
        
        if (numobjects > MAXIMUM_WAIT_OBJECTS) {
-#ifdef DEBUG
-               g_message ("%s: Too many handles: %d", __func__, numobjects);
-#endif
+               DEBUG ("%s: Too many handles: %d", __func__, numobjects);
 
                return(WAIT_FAILED);
        }
@@ -583,9 +549,7 @@ guint32 WaitForMultipleObjectsEx(guint32 numobjects, gpointer *handles,
                        handles[i] = _wapi_thread_handle_from_id (pthread_self ());
                        
                        if (handles[i] == NULL) {
-#ifdef DEBUG
-                               g_message ("%s: Handle %d bogus", __func__, i);
-#endif
+                               DEBUG ("%s: Handle %d bogus", __func__, i);
 
                                bogustype = TRUE;
                                break;
@@ -593,20 +557,16 @@ guint32 WaitForMultipleObjectsEx(guint32 numobjects, gpointer *handles,
                }
 
                if ((GPOINTER_TO_UINT (handles[i]) & _WAPI_PROCESS_UNHANDLED) == _WAPI_PROCESS_UNHANDLED) {
-#ifdef DEBUG
-                       g_message ("%s: Handle %d pseudo process", __func__,
+                       DEBUG ("%s: Handle %d pseudo process", __func__,
                                   i);
-#endif
 
                        bogustype = TRUE;
                        break;
                }
 
                if (_wapi_handle_test_capabilities (handles[i], WAPI_HANDLE_CAP_WAIT) == FALSE) {
-#ifdef DEBUG
-                       g_message ("%s: Handle %p can't be waited for",
+                       DEBUG ("%s: Handle %p can't be waited for",
                                   __func__, handles[i]);
-#endif
 
                        bogustype = TRUE;
                        break;
@@ -625,17 +585,13 @@ guint32 WaitForMultipleObjectsEx(guint32 numobjects, gpointer *handles,
        }
 
        if (duplicate == TRUE) {
-#ifdef DEBUG
-               g_message ("%s: Returning due to duplicates", __func__);
-#endif
+               DEBUG ("%s: Returning due to duplicates", __func__);
 
                return(WAIT_FAILED);
        }
 
        if (bogustype == TRUE) {
-#ifdef DEBUG
-               g_message ("%s: Returning due to bogus type", __func__);
-#endif
+               DEBUG ("%s: Returning due to bogus type", __func__);
 
                return(WAIT_FAILED);
        }
@@ -686,9 +642,7 @@ guint32 WaitForMultipleObjectsEx(guint32 numobjects, gpointer *handles,
                        }
                }
                
-#ifdef DEBUG
-               g_message ("%s: locking signal mutex", __func__);
-#endif
+               DEBUG ("%s: locking signal mutex", __func__);
 
                pthread_cleanup_push ((void(*)(void *))_wapi_handle_unlock_signal_mutex, NULL);
                thr_ret = _wapi_handle_lock_signal_mutex ();
@@ -719,9 +673,7 @@ guint32 WaitForMultipleObjectsEx(guint32 numobjects, gpointer *handles,
                        ret = 0;
                }
 
-#ifdef DEBUG
-               g_message ("%s: unlocking signal mutex", __func__);
-#endif
+               DEBUG ("%s: unlocking signal mutex", __func__);
 
                thr_ret = _wapi_handle_unlock_signal_mutex (NULL);
                g_assert (thr_ret == 0);
@@ -746,10 +698,8 @@ guint32 WaitForMultipleObjectsEx(guint32 numobjects, gpointer *handles,
                        /* Didn't get all handles, and there was a
                         * timeout or other error
                         */
-#ifdef DEBUG
-                       g_message ("%s: wait returned error: %s", __func__,
+                       DEBUG ("%s: wait returned error: %s", __func__,
                                   strerror (ret));
-#endif
 
                        if(ret==ETIMEDOUT) {
                                retval = WAIT_TIMEOUT;
index 8831d03c420a384184c6c9f94fd6ccf42d762d37..bd5006db60729b4fb49d38c1947ea77b0a8290bf 100644 (file)
@@ -96,7 +96,7 @@ static int     glob3(GDir *dir, gchar *, gchar *, wapi_glob_t *, size_t *,
                       gboolean, gboolean);
 static int      globextend(const gchar *, wapi_glob_t *, size_t *);
 static int      match(const gchar *, gchar *, gchar *, gboolean);
-#ifdef DEBUG
+#ifdef DEBUG_ENABLED
 static void     qprintf(const char *, Char *);
 #endif
 
@@ -176,7 +176,7 @@ glob0(GDir *dir, const gchar *pattern, wapi_glob_t *pglob, gboolean ignorecase,
                }
        }
        *bufnext = EOS;
-#ifdef DEBUG
+#ifdef DEBUG_ENABLED
        qprintf("glob0:", patbuf);
 #endif
 
@@ -378,7 +378,7 @@ g_Ctoc(const gchar *str, char *buf, u_int len)
        return (1);
 }
 
-#ifdef DEBUG
+#ifdef DEBUG_ENABLED
 static void
 qprintf(const char *str, Char *s)
 {
index f7eb188e8b15fa0e93d1aa1e91ae43fec1607723..e0b2103e10f71db815f61804ce485621bd5f6967 100644 (file)
 #include <valgrind/memcheck.h>
 #endif
 
-#undef DEBUG
+#if 0
+#define DEBUG(...) g_message(__VA_ARGS__)
+#else
+#define DEBUG(...)
+#endif
 
 #if 0
 #define WAIT_DEBUG(code) do { code } while (0)
@@ -96,9 +100,7 @@ static void _wapi_thread_abandon_mutexes (gpointer handle)
        pid_t pid = _wapi_getpid ();
        pthread_t tid = pthread_self ();
        
-#ifdef DEBUG
-       g_message ("%s: Thread %p abandoning held mutexes", __func__, handle);
-#endif
+       DEBUG ("%s: Thread %p abandoning held mutexes", __func__, handle);
 
        if (handle == NULL) {
                handle = _wapi_thread_handle_from_id (pthread_self ());
@@ -143,9 +145,7 @@ void _wapi_thread_set_termination_details (gpointer handle,
                return;
        }
 
-#ifdef DEBUG
-       g_message ("%s: Thread %p terminating", __func__, handle);
-#endif
+       DEBUG ("%s: Thread %p terminating", __func__, handle);
 
        _wapi_thread_abandon_mutexes (handle);
        
@@ -174,10 +174,8 @@ void _wapi_thread_set_termination_details (gpointer handle,
        g_assert (thr_ret == 0);
        pthread_cleanup_pop (0);
        
-#ifdef DEBUG
-       g_message("%s: Recording thread handle %p id %ld status as %d",
+       DEBUG("%s: Recording thread handle %p id %ld status as %d",
                  __func__, handle, thread_handle->id, exitstatus);
-#endif
        
        /* The thread is no longer active, so unref it */
        _wapi_handle_unref (handle);
@@ -275,9 +273,7 @@ static void *thread_start_routine (gpointer args)
                mono_gc_pthread_exit (NULL);
        }
 
-#ifdef DEBUG
-       g_message ("%s: started thread id %ld", __func__, thread->id);
-#endif
+       DEBUG ("%s: started thread id %ld", __func__, thread->id);
 
        /* We set it again here since passing &thread->id to pthread_create is racy
           as the thread can start running before the value is set.*/
@@ -413,10 +409,8 @@ gpointer CreateThread(WapiSecurityAttributes *security G_GNUC_UNUSED, guint32 st
                                                                           thread_start_routine, (void *)thread_handle_p);
 
        if (ret != 0) {
-#ifdef DEBUG
-               g_message ("%s: Thread create error: %s", __func__,
+               DEBUG ("%s: Thread create error: %s", __func__,
                           strerror(ret));
-#endif
 
                /* Two, because of the reference we took above */
                unrefs = 2;
@@ -425,10 +419,8 @@ gpointer CreateThread(WapiSecurityAttributes *security G_GNUC_UNUSED, guint32 st
        }
        ct_ret = handle;
        
-#ifdef DEBUG
-       g_message("%s: Started thread handle %p ID %ld", __func__, handle,
+       DEBUG("%s: Started thread handle %p ID %ld", __func__, handle,
                  thread_handle_p->id);
-#endif
        
        if (tid != NULL) {
 #ifdef PTHREAD_POINTER_ID
@@ -470,18 +462,14 @@ gpointer _wapi_thread_handle_from_id (pthread_t tid)
            (ret = pthread_getspecific (thread_hash_key)) != NULL) {
                /* We know the handle */
 
-#ifdef DEBUG
-               g_message ("%s: Returning %p for self thread %ld from TLS",
+               DEBUG ("%s: Returning %p for self thread %ld from TLS",
                           __func__, ret, tid);
-#endif
                
                return(ret);
        }
        
-#ifdef DEBUG
-       g_message ("%s: Returning NULL for unknown or non-self thread %ld",
+       DEBUG ("%s: Returning NULL for unknown or non-self thread %ld",
                   __func__, tid);
-#endif
                
 
        return(NULL);
@@ -506,22 +494,16 @@ static gboolean find_thread_by_id (gpointer handle, gpointer user_data)
                        return(FALSE);
                }
                
-#ifdef DEBUG
-               g_message ("%s: looking at thread %ld from process %d", __func__, thread_handle->id, 0);
-#endif
+               DEBUG ("%s: looking at thread %ld from process %d", __func__, thread_handle->id, 0);
 
                if (pthread_equal (thread_handle->id, tid)) {
-#ifdef DEBUG
-                       g_message ("%s: found the thread we are looking for",
+                       DEBUG ("%s: found the thread we are looking for",
                                   __func__);
-#endif
                        return(TRUE);
                }
        }
        
-#ifdef DEBUG
-       g_message ("%s: not found %ld, returning FALSE", __func__, tid);
-#endif
+       DEBUG ("%s: not found %ld, returning FALSE", __func__, tid);
        
        return(FALSE);
 }
@@ -536,9 +518,7 @@ gpointer OpenThread (guint32 access G_GNUC_UNUSED, gboolean inherit G_GNUC_UNUSE
        mono_once (&thread_hash_once, thread_hash_init);
        mono_once (&thread_ops_once, thread_ops_init);
        
-#ifdef DEBUG
-       g_message ("%s: looking up thread %"G_GSIZE_FORMAT, __func__, tid);
-#endif
+       DEBUG ("%s: looking up thread %"G_GSIZE_FORMAT, __func__, tid);
 
        ret = _wapi_thread_handle_from_id ((pthread_t)tid);
        if (ret == NULL) {
@@ -551,9 +531,7 @@ gpointer OpenThread (guint32 access G_GNUC_UNUSED, gboolean inherit G_GNUC_UNUSE
                _wapi_handle_ref (ret);
        }
        
-#ifdef DEBUG
-       g_message ("%s: returning thread handle %p", __func__, ret);
-#endif
+       DEBUG ("%s: returning thread handle %p", __func__, ret);
        
        return(ret);
 }
@@ -602,24 +580,18 @@ gboolean GetExitCodeThread(gpointer handle, guint32 *exitcode)
                return (FALSE);
        }
        
-#ifdef DEBUG
-       g_message ("%s: Finding exit status for thread handle %p id %ld",
+       DEBUG ("%s: Finding exit status for thread handle %p id %ld",
                   __func__, handle, thread_handle->id);
-#endif
 
        if (exitcode == NULL) {
-#ifdef DEBUG
-               g_message ("%s: Nowhere to store exit code", __func__);
-#endif
+               DEBUG ("%s: Nowhere to store exit code", __func__);
                return(FALSE);
        }
        
        if (thread_handle->state != THREAD_STATE_EXITED) {
-#ifdef DEBUG
-               g_message ("%s: Thread still active (state %d, exited is %d)",
+               DEBUG ("%s: Thread still active (state %d, exited is %d)",
                           __func__, thread_handle->state,
                           THREAD_STATE_EXITED);
-#endif
                *exitcode = STILL_ACTIVE;
                return(TRUE);
        }
@@ -709,10 +681,8 @@ static gpointer thread_attach(gsize *tid)
        thr_ret = pthread_setspecific (thread_attached_key, (void *)handle);
        g_assert (thr_ret == 0);
        
-#ifdef DEBUG
-       g_message("%s: Attached thread handle %p ID %ld", __func__, handle,
+       DEBUG("%s: Attached thread handle %p ID %ld", __func__, handle,
                  thread_handle_p->id);
-#endif
 
        if (tid != NULL) {
 #ifdef PTHREAD_POINTER_ID
@@ -831,9 +801,7 @@ guint32 SleepEx(guint32 ms, gboolean alertable)
        int ret;
        gpointer current_thread = NULL;
        
-#ifdef DEBUG
-       g_message("%s: Sleeping for %d ms", __func__, ms);
-#endif
+       DEBUG("%s: Sleeping for %d ms", __func__, ms);
 
        if (alertable) {
                current_thread = _wapi_thread_handle_from_id (pthread_self ());
@@ -871,7 +839,7 @@ again:
        
        if(ret==-1) {
                /* Sleep interrupted with rem time remaining */
-#ifdef DEBUG
+#ifdef DEBUG_ENABLED
                guint32 rems=rem.tv_sec*1000 + rem.tv_nsec/1000000;
                
                g_message("%s: Still got %d ms to go", __func__, rems);
@@ -908,16 +876,14 @@ gboolean _wapi_thread_apc_pending (gpointer handle)
        ok = _wapi_lookup_handle (handle, WAPI_HANDLE_THREAD,
                                  (gpointer *)&thread);
        if (ok == FALSE) {
-#ifdef DEBUG
                /* This might happen at process shutdown, as all
                 * thread handles are forcibly closed.  If a thread
                 * still has an alertable wait the final
                 * _wapi_thread_apc_pending check will probably fail
                 * to find the handle
                 */
-               g_warning ("%s: error looking up thread handle %p", __func__,
+               DEBUG ("%s: error looking up thread handle %p", __func__,
                           handle);
-#endif
                return (FALSE);
        }