[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: Conceptual Patch - Handle wrapper class

From: Stefan Küng <tortoisesvn_at_gmail.com>
Date: Sat, 12 Mar 2011 09:30:04 +0100

On 11.03.2011 13:40, Oto BREZINA wrote:
> Hello Stefan,
>
> After you commit patch I sent you (r20974), I checked if there are other
> places with similar issues. I found out that wrapping class may help
> here. It adds some overhead but not much. Some optimization can be still
> done by trade it for readability and maintainability.
>
> This is conceptual patch and is not intended as patch to be commit as is
> (especialy for may English (better to say English like language :) )). I
> don't have VC so I did not try to even compile it.
> If you are not interesting about this in TSVN no problem, just let me know.
>
> If you interest in it. There may be answers which may help to improve it.
> Is there any situation when 0 is valid handler ?

No, NULL can not be a valid handle.

> If no: would be better to use NULL (0) as Invalid handler.

not really. Some APIs return INVALID_HANDLE_VALUE in case of an error,
so with those we have to check for that value and not 0.

> It may simplify test for invalid handle a bit, also bValid attribute may
> be removed from class.
> As I understand INVALID_HANDLER_VALUE is for compatibily with win16 API.

I don't know about that. AFAIK even current APIs still return
INVALID_HANDLE_VALUE instead of 0 for errors. I think this isn't an
issue with compatibility but depends on the API, i.e. which dev team is
responsible for the API and to which part of the OS it belongs.

> Is there any situation when INVALID_HANDLER_VALUE is valid handler?

No, that's always invalid.

> if both are no: we don't need to pass invalid value into object
> Is there any real bed efect when we call CloseHanlde with 0 or
> INVALID_HANDLER_VALUE? As I understand INVALID_HANDLER_VALUE is also
> pseudo handler to windows itself, or something like that.

If you use CloseHandle() with an invalid handle, an exception is thrown.
If you run the app under a debugger, it will catch that exception. With
no debugger, nothing will happen because the exception is caught
automatically.
So we really have to make sure to not call CloseHandle() with invalid
handles because the exceptions make debugging a real nightmare.

While I usually like helper classes, I don't think this would help with
readability. I kind of like to use 'plain' checks for handle values
because it's easier to read and also easier to debug.

Stefan

-- 
        ___
   oo  // \\      "De Chelonian Mobile"
  (_,\/ \_/ \     TortoiseSVN
    \ \_/_\_/>    The coolest Interface to (Sub)Version Control
    /_/   \_\     http://tortoisesvn.net
------------------------------------------------------
http://tortoisesvn.tigris.org/ds/viewMessage.do?dsForumId=757&dsMessageId=2711090
To unsubscribe from this discussion, e-mail: [dev-unsubscribe_at_tortoisesvn.tigris.org].
Received on 2011-03-12 09:30:17 CET

This is an archived mail posted to the TortoiseSVN Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.