To give everyone (especially the ones knowing the code better than I - a
new user of it - do) an incentive to check this out, I've come up with
the following patches to add the UT_Bool as a class instead of as a
typedef for 'unsigned char' that sheds light over the problems about
uninitilalized UT_Bools being used. This "patch" is against the released
0.7.9 code.

Again I apologize for not supplying it in diff format, but since I'm not
on a Unix platform (i.e. Win32), I hope you consider these changes for
your development copies anyway. If not, stop reading here.

---

First the definition (typedef) of UT_Bool in af/util/xp/ut_types.h has to
change. I've done it like

#if 0

typedef  unsigned char  UT_Bool;
#define  UT_TRUE    ((UT_Bool) 1)
#define  UT_FALSE   ((UT_Bool) 0)

#else

#define  UT_TRUE    ((UT_Bool) 1)
#define  UT_FALSE   ((UT_Bool) 0)

#define chSTR(x)           #x
#define chSTR2(x)        chSTR(x)
#define chMSG(desc) message(__FILE__ "(" chSTR2(__LINE__) "):" desc)
#pragma chMSG("UT_Bool patched. Remove later")

#include "ut_assert.h"

class UT_Bool
{
public:
    UT_Bool(unsigned char a = 3) : v(a) { }
    operator unsigned char() const { check(); return v; }
    unsigned char operator!() const { check(); return v ? UT_FALSE :
UT_TRUE; }
    UT_Bool& operator=(const UT_Bool& rhs)
    { rhs.check(); v = rhs.v; return *this; }
    UT_Bool& operator|=(const UT_Bool& rhs)
    { check(); rhs.check(); v = rhs.v; return *this; }

    void check() const { UT_ASSERT(v != 3); }
private:
    unsigned char v;
};

#endif

---

Then there's some other changes needed to get it to compile.


1. The unnamed struct 'm_parserState' used as member in
af/xap/xp/xap_Strings.h must have a name. "_dummyname" works.
2. The same goes for the member 'm_parserState' in
af/xap/xp/xap_Prefs.h'.

Now, there are a few places where the (real) definition of 'UT_Bool' has
to be removed, since these datatypes are use in array (aggregate)
initializations. Use the following construct: for the 'UT_Bool' members
mentioned.

Before the member
  #define UT_Bool unsigned char
after the mentioned member
  #undef UT_Bool

3. wp/ap/xp/ap_LoadBinding.cpp (around line 62)
4. text/ptbl/xp/pp_Property.h (around line 39)
5. wp/ap/xp/ap_Menu_LabelSet.cpp (around line 67)
6. wp/ap/xp/ap_Toolbar_LabelSet.cpp (around line 70)
And finally if on Win32, do the following
7. af/xap/win/xap_Win32Slurp.cpp (around line 111)
    return (HDDEDATA)!!bAccept;
Notice the _two_ '!'.

Now compile, disregard warnings about extern "C" using UT_Bool, and
finally at runtime: sorrow.
There's a _lot_ of places that need to be fixed. As I'm new to the code I
_think_ it's a major design problem regarding if mapXY should set both
bBOL and bEOL or if it's supposed to be defaulted to UT_FALSE.

/Mike





Reply via email to