C to C++ migration and refactoring #17

Merged
harraiken merged 67 commits from cxxtest into master 2025-09-24 20:18:35 +02:00
7 changed files with 13 additions and 13 deletions
Showing only changes of commit 6e10089280 - Show all commits

View File

@@ -398,5 +398,5 @@ XTCDECL
BOOLEAN
Debug::SerialPortReady()
{
return (BOOLEAN)(SerialPort.Flags & COMPORT_FLAG_INIT);
return (SerialPort.Flags & COMPORT_FLAG_INIT);
belliash marked this conversation as resolved Outdated

Do we need to typecast each bool operation? In C this returned integer value and compiler knew how to cast it into our BOOLEAN enum. In C++, result value is of bool type that cannot be automatically typecasted into enum.

Do we need to typecast each bool operation? In C this returned integer value and compiler knew how to cast it into our BOOLEAN enum. In C++, result value is of bool type that cannot be automatically typecasted into enum.

No, we do not have to. Alternatively, I can suggest moving the BOOLEAN type definition from xttypes.h to xtcompat.h:

#ifdef __cplusplus
    /* C++ definitions */
    #define XTCLINK         extern "C"
    #define NULLPTR         nullptr

    /* C++ boolean type */
    typedef bool BOOLEAN, *PBOOLEAN;
    #define TRUE true
    #define FALSE false

    /* C++ widechar type */
    typedef wchar_t wchar;
#else
    /* C definitions */
    #define XTCLINK
    #define NULLPTR         ((void *)0)

    /* C boolean type */
    typedef enum _BOOLEAN
    {
        FALSE = 0,
        TRUE = 1
    } BOOLEAN, *PBOOLEAN;

    /* C widechar type */
    typedef unsigned short wchar;
#endif

This will allow us to maintain backward compatibility with C and get rid of explicit typecasts at the same time.
This should also work in the case of the quoted fragment, even though the result of the operation is not of type bool but int. The result of the expression will be 0 if the flag is not set, or the value of COMPORT_FLAG_INIT if it is. It is only the comparison of this result, for example (SerialPort.Flags & COMPORT_FLAG_INIT) != 0, that actually yields a bool type.

Please let me know if you accept this, then I will commit the proposed change.

No, we do not have to. Alternatively, I can suggest moving the BOOLEAN type definition from xttypes.h to xtcompat.h: ``` #ifdef __cplusplus /* C++ definitions */ #define XTCLINK extern "C" #define NULLPTR nullptr /* C++ boolean type */ typedef bool BOOLEAN, *PBOOLEAN; #define TRUE true #define FALSE false /* C++ widechar type */ typedef wchar_t wchar; #else /* C definitions */ #define XTCLINK #define NULLPTR ((void *)0) /* C boolean type */ typedef enum _BOOLEAN { FALSE = 0, TRUE = 1 } BOOLEAN, *PBOOLEAN; /* C widechar type */ typedef unsigned short wchar; #endif ``` This will allow us to maintain backward compatibility with C and get rid of explicit typecasts at the same time. This should also work in the case of the quoted fragment, even though the result of the operation is not of type bool but int. The result of the expression will be 0 if the flag is not set, or the value of COMPORT_FLAG_INIT if it is. It is only the comparison of this result, for example (SerialPort.Flags & COMPORT_FLAG_INIT) != 0, that actually yields a bool type. Please let me know if you accept this, then I will commit the proposed change.

You are right, this results in int, not bool. There are more such changes like this in the diff, and I added a comment to the first one, as its the only one that fits on first page. unfortunately. Never mind, I think the proposed solution will be OK.

You are right, this results in int, not bool. There are more such changes like this in the diff, and I added a comment to the first one, as its the only one that fits on first page. unfortunately. Never mind, I think the proposed solution will be OK.
}

View File

@@ -24,7 +24,7 @@ BOOLEAN
KE::KUbsan::CheckReport(PKUBSAN_SOURCE_LOCATION Location)
{
/* Make sure, this error should be reported */
return (BOOLEAN)!ActiveFrame;
return !ActiveFrame;
}
/**

View File

@@ -126,8 +126,8 @@ XTAPI
BOOLEAN
MM::Init::VerifyMemoryTypeFree(LOADER_MEMORY_TYPE MemoryType)
{
return (BOOLEAN)((MemoryType == LoaderFree) || (MemoryType == LoaderFirmwareTemporary) ||
(MemoryType == LoaderLoadedProgram) || (MemoryType == LoaderOsloaderStack));
return ((MemoryType == LoaderFree) || (MemoryType == LoaderFirmwareTemporary) ||
(MemoryType == LoaderLoadedProgram) || (MemoryType == LoaderOsloaderStack));
}
/**
@@ -144,7 +144,7 @@ XTAPI
BOOLEAN
MM::Init::VerifyMemoryTypeInvisible(LOADER_MEMORY_TYPE MemoryType)
{
return (BOOLEAN)((MemoryType == LoaderFirmwarePermanent) ||
(MemoryType == LoaderSpecialMemory) ||
(MemoryType == LoaderBBTMemory));
return ((MemoryType == LoaderFirmwarePermanent) ||
(MemoryType == LoaderSpecialMemory) ||
(MemoryType == LoaderBBTMemory));
}

View File

@@ -313,7 +313,7 @@ RTL::BitMap::FindBits(IN PRTL_BITMAP BitMap,
while(BitOffset + Length < BitMapEnd)
{
/* Increment offset */
BitOffset += CountBits(BitMap, BitMap->Size - BitOffset, BitOffset, (BOOLEAN)!SetBits);
BitOffset += CountBits(BitMap, BitMap->Size - BitOffset, BitOffset, !SetBits);
if(BitOffset + Length > BitMapEnd)
{
/* No match found, break loop execution */

View File

@@ -34,6 +34,6 @@ RTL::Guid::CompareGuids(IN PGUID Guid1,
Guid2Ptr = (PUINT)Guid2;
/* Compare GUIDs */
return (BOOLEAN)(Guid1Ptr[0] == Guid2Ptr[0] && Guid1Ptr[1] == Guid2Ptr[1] &&
Guid1Ptr[2] == Guid2Ptr[2] && Guid1Ptr[3] == Guid2Ptr[3]);
return (Guid1Ptr[0] == Guid2Ptr[0] && Guid1Ptr[1] == Guid2Ptr[1] &&
Guid1Ptr[2] == Guid2Ptr[2] && Guid1Ptr[3] == Guid2Ptr[3]);
}

View File

@@ -107,7 +107,7 @@ XTCDECL
BOOLEAN
RTL::LinkedList::ListEmpty(IN PLIST_ENTRY ListHead)
{
return (BOOLEAN)(((ListHead->Flink == NULLPTR) && (ListHead->Blink == NULLPTR)) || (ListHead->Flink == ListHead));
return (((ListHead->Flink == NULLPTR) && (ListHead->Blink == NULLPTR)) || (ListHead->Flink == ListHead));
}
/**

View File

@@ -631,7 +631,7 @@ RTL::Math::InfiniteDouble(IN DOUBLE Value)
Var.Double = &Value;
/* Return TRUE if it is infinite, or FALSE otherwise */
return (BOOLEAN)((Var.DoubleS->Exponent & 0x7FF) == 0x7FF);
return ((Var.DoubleS->Exponent & 0x7FF) == 0x7FF);
}
/**
@@ -690,5 +690,5 @@ RTL::Math::NanDouble(IN DOUBLE Value)
Var.Double = &Value;
/* Return TRUE if it is NaN, or FALSE otherwise */
return (BOOLEAN)(Var.DoubleS->Exponent == 0x7FF && (Var.DoubleS->MantissaHigh != 0 || Var.DoubleS->MantissaLow != 0));
return (Var.DoubleS->Exponent == 0x7FF && (Var.DoubleS->MantissaHigh != 0 || Var.DoubleS->MantissaLow != 0));
}