Hi Christian,

Christian Weisgerber wrote on Mon, Apr 16, 2018 at 12:05:20AM +0200:

> FreeBSD fixed Proxy.cc this way.  I'm uncertain if this is correct.

It is.
The intention of the test is to find out whether the file was opened
successfully.  My old Stroustrup book says that can be tested with
"basic_ifstream<...> ifs(...); if (ifs)", without explaining why.
I found the reason in the base-base class basic_ios in the file
bits/basic_ios.h: it defines a conversion function (KNF'ed):

public:
        operator
        void*() const
        {
                return this->fail() ? 0 :
                    const_cast<basic_ios*>(this);
        }

Because there is a standard conversion from any pointer type
to bool, casting basic_ifstream to bool actually goes via void *
and ultimately calls basic_ios::fail.  The wonders of C++ type
conversion.

The Value.cc patch is also correct.  Weird as it may seem,
the Value class really represents NULL pointers by
setting the double[2] array val.dval to { 0.0, whatever }.
You can see that in other places in the file...

The game also builds and works for me with the patch.

OK schwarze@
  Ingo


> Index: Makefile
> ===================================================================
> RCS file: /cvs/ports/games/enigma/Makefile,v
> retrieving revision 1.33
> diff -u -p -r1.33 Makefile
> --- Makefile  13 Mar 2018 21:13:48 -0000      1.33
> +++ Makefile  15 Apr 2018 22:03:43 -0000
> @@ -4,6 +4,7 @@ COMMENT=      Oxyd/Rock'n'Roll clone
>  
>  V=           1.21
>  DISTNAME=    enigma-${V}
> +REVISION=    0
>  
>  CATEGORIES=  games x11
>  
> Index: patches/patch-src_Value_cc
> ===================================================================
> RCS file: patches/patch-src_Value_cc
> diff -N patches/patch-src_Value_cc
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ patches/patch-src_Value_cc        15 Apr 2018 22:03:43 -0000
> @@ -0,0 +1,14 @@
> +$OpenBSD$
> +
> +Index: src/Value.cc
> +--- src/Value.cc.orig
> ++++ src/Value.cc
> +@@ -149,7 +149,7 @@ namespace enigma {
> +                 val.dval[0] = false;
> +                 break;
> +             case OBJECT :
> +-                val.dval[0] = (double) NULL;
> ++                val.dval[0] = 0;
> +                 break;
> +             case NAMEDOBJECT:
> +                 ASSERT(false, XLevelRuntime, "Value: illegal type usage");
> Index: patches/patch-src_lev_Proxy_cc
> ===================================================================
> RCS file: patches/patch-src_lev_Proxy_cc
> diff -N patches/patch-src_lev_Proxy_cc
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ patches/patch-src_lev_Proxy_cc    15 Apr 2018 22:03:43 -0000
> @@ -0,0 +1,14 @@
> +$OpenBSD$
> +
> +Index: src/lev/Proxy.cc
> +--- src/lev/Proxy.cc.orig
> ++++ src/lev/Proxy.cc
> +@@ -933,7 +933,7 @@ namespace enigma { namespace lev {
> +                     } else if (haveLocalCopy) {
> +                         // plain file
> +                         basic_ifstream<char> ifs(absExtPath.c_str(), 
> ios::binary | ios::in);
> +-                        if (ifs != NULL)
> ++                        if (ifs)
> +                             Readfile(ifs, extCode);
> +                         else
> +                             haveLocalCopy = false;

Reply via email to