[PATCH] Re: help fixing up SetConsoleCtrlHandler()

Peter Riocreux par+wine_devel at silistix.com
Thu Apr 15 07:22:37 CDT 2004


"Dimitrie O. Paun" <dpaun at rogers.com> writes:

> On April 15, 2004 7:58 am, Peter Riocreux wrote:
>> Here is my first cut.
>>
>> Remember that this is my first patch, so go easy on me with he
>> flamethrowers. I know the indenting isn't quite right.
>
> The formatting doesn't seem too bad, but the format is wrong.
> Please use uniffied diff (-u):
>     http://www.winehq.org/site/sending_patches

D'oh! I did the first time I generated the patch, but forgot this
time. I *had* read that page, but ..... old age don' you know. :-^

I will include at the end the new patch.

>> I think that, despite what Juan Lang advised, I need to detect version
>> numbers as the FIXME can be triggered by perfecly legal use in
>> XP/NT/?? but illegal code in ME/98/95.
>
> Then allow it. Are there apps that depend on the 9x behaviour
> of not allowing it?

I don't know, I just had thought that Wine was attempting to be
bug-for-bug compatible, and assumed that part of that was honouring
all the restrictions on usage of functions and how these varied
between versions.

I am not seeing this FIXME coming out, so I am not concerned with
leaving it in, but have no strong opinion.

Peter


Index: dlls/kernel/console.c
===================================================================
RCS file: /home/wine/wine/dlls/kernel/console.c,v
retrieving revision 1.30
diff -u -r1.30 console.c
--- dlls/kernel/console.c	13 Apr 2004 21:16:26 -0000	1.30
+++ dlls/kernel/console.c	15 Apr 2004 12:08:08 -0000
@@ -1448,17 +1448,20 @@
 {
     BOOL        ret = TRUE;
 
-    FIXME("(%p,%i) - no error checking or testing yet\n", func, add);
-
     if (!func)
     {
+        FIXME("(%p,%i) - this is not allowed in WinME, Win98 or Win95\n", func, add);
 	CONSOLE_IgnoreCtrlC = add;
     }
     else if (add)
     {
         struct ConsoleHandler*  ch = HeapAlloc(GetProcessHeap(), 0, sizeof(struct ConsoleHandler));
 
-        if (!ch) return FALSE;
+        if (!ch)
+	{
+	    SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+	    return FALSE;
+	}
         ch->handler = func;
         RtlEnterCriticalSection(&CONSOLE_CritSect);
         ch->next = CONSOLE_Handlers;
@@ -1467,34 +1470,37 @@
     }
     else
     {
-        struct ConsoleHandler**  ch;
         RtlEnterCriticalSection(&CONSOLE_CritSect);
-        for (ch = &CONSOLE_Handlers; *ch; *ch = (*ch)->next)
-        {
-            if ((*ch)->handler == func) break;
-        }
-        if (*ch)
-        {
-            struct ConsoleHandler*   rch = *ch;
+	if (func == CONSOLE_DefaultHandler)
+	{
+	    ERR("Attempt to remove default CtrlHandler %p\n", func);
+	    SetLastError(ERROR_FUNCTION_FAILED);
+	    ret = FALSE;
+	}
+	else
+	{
+	    struct ConsoleHandler* ch, * prev ;
+	    prev = NULL;
+	    for (ch = CONSOLE_Handlers; ch; prev = ch, ch = ch->next)
+	    {
+	        if (ch->handler == func)
+		{
+		    if (ch == CONSOLE_Handlers)
+		        CONSOLE_Handlers = ch->next;
+		    else
+		        prev->next = ch->next;
+		    HeapFree(GetProcessHeap(), 0, ch);
+		    break;
+		}
+	    }
 
-            /* sanity check */
-            if (rch == &CONSOLE_DefaultConsoleHandler)
-            {
-                ERR("Who's trying to remove default handler???\n");
-                ret = FALSE;
-            }
-            else
-            {
-                rch = *ch;
-                *ch = (*ch)->next;
-                HeapFree(GetProcessHeap(), 0, rch);
-            }
-        }
-        else
-        {
-            WARN("Attempt to remove non-installed CtrlHandler %p\n", func);
-            ret = FALSE;
-        }
+	    if (! ch)
+	    {
+	        WARN("Attempt to remove non-installed CtrlHandler %p\n", func);
+		SetLastError(ERROR_INVALID_ADDRESS);
+		ret = FALSE;
+	    }
+	}
         RtlLeaveCriticalSection(&CONSOLE_CritSect);
     }
     return ret;



More information about the wine-devel mailing list