mirror of
https://github.com/narzoul/DDrawCompat
synced 2024-12-30 08:55:36 +01:00
Fixed logging of uninitialized output parameters
This commit is contained in:
parent
5b5863b028
commit
e6bb6b1e35
@ -26,6 +26,11 @@ std::ostream& operator<<(std::ostream& os, const char* str)
|
||||
return os << "null";
|
||||
}
|
||||
|
||||
if (!Compat::Log::isPointerDereferencingAllowed())
|
||||
{
|
||||
return os << static_cast<const void*>(str);
|
||||
}
|
||||
|
||||
return os.write(str, strlen(str));
|
||||
}
|
||||
|
||||
@ -41,6 +46,11 @@ std::ostream& operator<<(std::ostream& os, const WCHAR* wstr)
|
||||
return os << "null";
|
||||
}
|
||||
|
||||
if (!Compat::Log::isPointerDereferencingAllowed())
|
||||
{
|
||||
return os << static_cast<const void*>(wstr);
|
||||
}
|
||||
|
||||
CStringA str(wstr);
|
||||
return os << '"' << static_cast<const char*>(str) << '"';
|
||||
}
|
||||
@ -167,4 +177,6 @@ namespace Compat
|
||||
}
|
||||
|
||||
std::ofstream Log::s_logFile("ddraw.log");
|
||||
DWORD Log::s_outParamDepth = 0;
|
||||
bool Log::s_isLeaveLog = false;
|
||||
}
|
||||
|
@ -31,28 +31,10 @@ std::ostream& operator<<(std::ostream& os, const DDSURFACEDESC2& sd);
|
||||
std::ostream& operator<<(std::ostream& os, const CWPSTRUCT& cwrp);
|
||||
std::ostream& operator<<(std::ostream& os, const CWPRETSTRUCT& cwrp);
|
||||
|
||||
template <typename T>
|
||||
typename std::enable_if<std::is_class<T>::value && !std::is_same<T, std::string>::value, std::ostream&>::type
|
||||
operator<<(std::ostream& os, const T& t)
|
||||
{
|
||||
return os << static_cast<const void*>(&t);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename std::enable_if<std::is_class<T>::value, std::ostream&>::type
|
||||
operator<<(std::ostream& os, T* t)
|
||||
{
|
||||
return t ? (os << *t) : (os << "null");
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::ostream& operator<<(std::ostream& os, T** t)
|
||||
{
|
||||
return t ? (os << reinterpret_cast<void*>(t) << '=' << *t) : (os << "null");
|
||||
}
|
||||
|
||||
namespace Compat
|
||||
{
|
||||
using ::operator<<;
|
||||
|
||||
template <typename Num>
|
||||
struct Hex
|
||||
{
|
||||
@ -76,6 +58,15 @@ namespace Compat
|
||||
return Array<Elem>(elem, size);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct Out
|
||||
{
|
||||
explicit Out(const T& val) : val(val) {}
|
||||
const T& val;
|
||||
};
|
||||
|
||||
template <typename T> Out<T> out(const T& val) { return Out<T>(val); }
|
||||
|
||||
class Log
|
||||
{
|
||||
public:
|
||||
@ -89,6 +80,8 @@ namespace Compat
|
||||
return *this;
|
||||
}
|
||||
|
||||
static bool isPointerDereferencingAllowed() { return s_isLeaveLog || 0 == s_outParamDepth; }
|
||||
|
||||
protected:
|
||||
template <typename... Params>
|
||||
Log(const char* prefix, const char* funcName, Params... params) : Log()
|
||||
@ -99,6 +92,9 @@ namespace Compat
|
||||
}
|
||||
|
||||
private:
|
||||
friend class LogLeaveGuard;
|
||||
template <typename T> friend std::ostream& operator<<(std::ostream& os, Out<T> out);
|
||||
|
||||
void toList()
|
||||
{
|
||||
}
|
||||
@ -117,6 +113,8 @@ namespace Compat
|
||||
}
|
||||
|
||||
static std::ofstream s_logFile;
|
||||
static DWORD s_outParamDepth;
|
||||
static bool s_isLeaveLog;
|
||||
};
|
||||
|
||||
class LogParams;
|
||||
@ -162,7 +160,14 @@ namespace Compat
|
||||
}
|
||||
};
|
||||
|
||||
class LogLeave : private Log
|
||||
class LogLeaveGuard
|
||||
{
|
||||
public:
|
||||
LogLeaveGuard() { Log::s_isLeaveLog = true; }
|
||||
~LogLeaveGuard() { Log::s_isLeaveLog = false; }
|
||||
};
|
||||
|
||||
class LogLeave : private LogLeaveGuard, private Log
|
||||
{
|
||||
public:
|
||||
template <typename... Params>
|
||||
@ -193,26 +198,80 @@ namespace Compat
|
||||
|
||||
typedef LogEnter LogLeave;
|
||||
#endif
|
||||
|
||||
template <typename Num>
|
||||
std::ostream& operator<<(std::ostream& os, Hex<Num> hex)
|
||||
{
|
||||
os << "0x" << std::hex << hex.val << std::dec;
|
||||
return os;
|
||||
}
|
||||
|
||||
template <typename Elem>
|
||||
std::ostream& operator<<(std::ostream& os, Array<Elem> array)
|
||||
{
|
||||
os << '[';
|
||||
if (Log::isPointerDereferencingAllowed())
|
||||
{
|
||||
if (0 != array.size)
|
||||
{
|
||||
os << array.elem[0];
|
||||
}
|
||||
for (unsigned long i = 1; i < array.size; ++i)
|
||||
{
|
||||
os << ',' << array.elem[i];
|
||||
}
|
||||
}
|
||||
return os << ']';
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::ostream& operator<<(std::ostream& os, Out<T> out)
|
||||
{
|
||||
++Log::s_outParamDepth;
|
||||
os << out.val;
|
||||
--Log::s_outParamDepth;
|
||||
return os;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Num>
|
||||
std::ostream& operator<<(std::ostream& os, Compat::Hex<Num> hex)
|
||||
template <typename T>
|
||||
typename std::enable_if<std::is_class<T>::value && !std::is_same<T, std::string>::value, std::ostream&>::type
|
||||
operator<<(std::ostream& os, const T& t)
|
||||
{
|
||||
os << "0x" << std::hex << hex.val << std::dec;
|
||||
return os << static_cast<const void*>(&t);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename std::enable_if<std::is_class<T>::value, std::ostream&>::type
|
||||
operator<<(std::ostream& os, T* t)
|
||||
{
|
||||
if (!t)
|
||||
{
|
||||
return os << "null";
|
||||
}
|
||||
|
||||
if (!Compat::Log::isPointerDereferencingAllowed())
|
||||
{
|
||||
return os << static_cast<const void*>(t);
|
||||
}
|
||||
|
||||
return os << *t;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::ostream& operator<<(std::ostream& os, T** t)
|
||||
{
|
||||
if (!t)
|
||||
{
|
||||
return os << "null";
|
||||
}
|
||||
|
||||
os << static_cast<const void*>(t);
|
||||
|
||||
if (Compat::Log::isPointerDereferencingAllowed())
|
||||
{
|
||||
os << '=' << *t;
|
||||
}
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
template <typename Elem>
|
||||
std::ostream& operator<<(std::ostream& os, Compat::Array<Elem> array)
|
||||
{
|
||||
os << '[';
|
||||
if (0 != array.size)
|
||||
{
|
||||
os << array.elem[0];
|
||||
}
|
||||
for (unsigned long i = 1; i < array.size; ++i)
|
||||
{
|
||||
os << ',' << array.elem[i];
|
||||
}
|
||||
return os << ']';
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ std::ostream& operator<<(std::ostream& os, const D3DDDIARG_OPENADAPTER& data)
|
||||
<< data.Interface
|
||||
<< data.Version
|
||||
<< data.pAdapterCallbacks
|
||||
<< data.pAdapterFuncs
|
||||
<< Compat::out(data.pAdapterFuncs)
|
||||
<< data.DriverVersion;
|
||||
}
|
||||
|
||||
|
@ -28,11 +28,11 @@ std::ostream& operator<<(std::ostream& os, const D3DDDIARG_CREATEDEVICE& data)
|
||||
<< data.pCallbacks
|
||||
<< data.pCommandBuffer
|
||||
<< data.CommandBufferSize
|
||||
<< data.pAllocationList
|
||||
<< Compat::out(Compat::array(data.pAllocationList, data.AllocationListSize))
|
||||
<< data.AllocationListSize
|
||||
<< data.pPatchLocationList
|
||||
<< Compat::out(Compat::array(data.pPatchLocationList, data.PatchLocationListSize))
|
||||
<< data.PatchLocationListSize
|
||||
<< data.pDeviceFuncs
|
||||
<< Compat::out(data.pDeviceFuncs)
|
||||
<< Compat::hex(data.Flags.Value)
|
||||
<< Compat::hex(data.CommandBuffer);
|
||||
}
|
||||
|
@ -14,9 +14,9 @@ std::ostream& operator<<(std::ostream& os, const D3DKMT_CREATECONTEXT& data)
|
||||
<< Compat::hex(data.hContext)
|
||||
<< data.pCommandBuffer
|
||||
<< data.CommandBufferSize
|
||||
<< Compat::array(data.pAllocationList, data.AllocationListSize)
|
||||
<< Compat::out(Compat::array(data.pAllocationList, data.AllocationListSize))
|
||||
<< data.AllocationListSize
|
||||
<< Compat::array(data.pPatchLocationList, data.PatchLocationListSize)
|
||||
<< Compat::out(Compat::array(data.pPatchLocationList, data.PatchLocationListSize))
|
||||
<< data.PatchLocationListSize
|
||||
<< Compat::hex(data.CommandBuffer);
|
||||
}
|
||||
@ -42,9 +42,9 @@ std::ostream& operator<<(std::ostream& os, const D3DKMT_CREATEDEVICE& data)
|
||||
<< Compat::hex(data.hDevice)
|
||||
<< data.pCommandBuffer
|
||||
<< data.CommandBufferSize
|
||||
<< Compat::array(data.pAllocationList, data.AllocationListSize)
|
||||
<< Compat::out(Compat::array(data.pAllocationList, data.AllocationListSize))
|
||||
<< data.AllocationListSize
|
||||
<< Compat::array(data.pPatchLocationList, data.PatchLocationListSize)
|
||||
<< Compat::out(Compat::array(data.pPatchLocationList, data.PatchLocationListSize))
|
||||
<< data.PatchLocationListSize;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user