delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2003/05/07/22:10:01

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
X-Authentication-Warning: slinky.cs.nyu.edu: pechtcha owned process doing -bs
Date: Wed, 7 May 2003 22:09:51 -0400 (EDT)
From: Igor Pechtchanski <pechtcha AT cs DOT nyu DOT edu>
Reply-To: cygwin AT cygwin DOT com
To: cygwin AT cygwin DOT com
cc: Charles Wilson <cwilson AT ece DOT gatech DOT edu>, Jason Tishler <jason AT tishler DOT net>
Subject: Re: cygipc (and PostgreSQL) XP problem resolved!
In-Reply-To: <Pine.GSO.4.44.0305072136040.3212-100000@slinky.cs.nyu.edu>
Message-ID: <Pine.GSO.4.44.0305072148060.3212-100000@slinky.cs.nyu.edu>
Importance: Normal
MIME-Version: 1.0

On Wed, 7 May 2003, Igor Pechtchanski wrote:

> On Wed, 7 May 2003, Charles Wilson wrote:
>
> > Jason Tishler wrote:
> >
> > > +#define NAMESPACE_PREFIX "Global\\"
> > > +#define FULL_NAMESPACE_PATH(name) \
> > > +     ((LOBYTE(LOWORD(GetVersion())) >= 5 && \
> > > +     HIBYTE(LOWORD(GetVersion())) >= 1) ? NAMESPACE_PREFIX name : name) \
> > > +
> > > +#define CYGWIN_IPCNT_SEMCTL  FULL_NAMESPACE_PATH(CYGWIN_IPCNT_SEMCTL_BASE)
> > > +#define CYGWIN_IPCNT_SEMSEM  FULL_NAMESPACE_PATH(CYGWIN_IPCNT_SEMSEM_BASE)
> > > +#define CYGWIN_IPCNT_SEMSHM  FULL_NAMESPACE_PATH(CYGWIN_IPCNT_SEMSHM_BASE)
> > > +#define CYGWIN_IPCNT_SEMMSG  FULL_NAMESPACE_PATH(CYGWIN_IPCNT_SEMMSG_BASE)
> >
> > Wait, aren't #define macros resolved at compile time?  This would then
> > define these names as "foo" or "Global\\foo" depending on which machine
> > the package was BUILT on.
> >
> > Worse, if the cygipc library itself were built on WinXP, but you build a
> > client app on W98 -- then your code thinks "foo" but the daemon things
> > "Global\\foo".  Or vice versa.
> >
> > I think this needs to be a runtime function, not a compiletime macro.
> > --Chuck
>
> Umm, Chuck, GetVersion() is a run-time function...
>
> For example, the CYGWIN_IPCNT_SEMCTL macro will resolve to :
>
>   ((LOBYTE(LOWORD(GetVersion())) >= 5 && HIBYTE(LOWORD(GetVersion())) >= 1) ?
>     "Global\\" "MultiSemCtl2_" : "MultiSemCtl2_")
>
> which will be evaluated at run-time (the two strings between '?' and ':'
> will be concatenated at compile-time, though).
>         Igor

I should mention, however, that this *will* *break* if Microsoft ever
decides to release an OS with GetVersion() returning something like 0x0006
in the low byte (I wouldn't put it past them [OS v6, build 0]).

Also, the FULL_NAMESPACE_PATH() macro doesn't examine the high-order bit,
but that should be ok, as no Win9x variant currently returns more than
0x04 in the low-order byte (source: MSDN
<http://msdn.microsoft.com/library/en-us/sysinfo/base/getversion.asp>).

It also calls GetVersion() twice every time it resolves a semaphore name.
It might be better to use something like

#define FULL_NAMESPACE_PATH(name) \
     ({WORD ver=LOWORD(GetVersion()); \
      (MAKEWORD(HIBYTE(ver),LOBYTE(ver)) >= MAKEWORD(1,5)) ? \
       NAMESPACE_PREFIX name : name})

The second MAKEWORD() may be replaced by 0x0501, but as it will be
completely evaluated at compile-time, that's not necessary.  Also, this
macro uses GNU extensions, but, unless you ever plan to compile cygipc
with something other than GCC, it shouldn't matter, either.
	Igor
P.S. Nitpicking: the final '\' in Jason's definition of this macro is
redundant (and will hurt if you ever choose to delete the blank line).
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha AT cs DOT nyu DOT edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor AT watson DOT ibm DOT com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

Knowledge is an unending adventure at the edge of uncertainty.
  -- Leto II


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019