From c6a48460e878611ab28f093e9c9eb4fc9375f9fa Mon Sep 17 00:00:00 2001 From: asuessenbach Date: Tue, 16 Jun 2020 10:05:22 +0200 Subject: [PATCH] Use memcmp instead of operator==() to compare unknown types from external headers, as they might not support that operator. --- VulkanHppGenerator.cpp | 27 ++++++++++++++++++++++----- vulkan/vulkan.hpp | 11 ++++++----- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index 63e8e66..6be28e1 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -2748,9 +2748,9 @@ void VulkanHppGenerator::appendFunctionHeaderArgumentEnhancedVector( std::string // it's optional, if it's marked as optional and there's no size specified bool optional = param.optional && !hasSizeParam; - bool useString = ( param.type.type.find( "char" ) != std::string::npos ); + bool useString = ( param.type.type.find( "char" ) != std::string::npos ); std::string optionalBegin = optional ? "Optional<" : ""; - std::string optionalEnd = optional ? "> " : (useString ? " & " : ""); + std::string optionalEnd = optional ? "> " : ( useString ? " & " : "" ); if ( useString ) { @@ -2774,8 +2774,8 @@ void VulkanHppGenerator::appendFunctionHeaderArgumentEnhancedVector( std::string // otherwise, use our ArrayProxy bool isConst = ( param.type.prefix.find( "const" ) != std::string::npos ); str += optionalBegin + "ArrayProxy<" + - ( isTemplateParam ? ( isConst ? "const T" : "T" ) : stripPostfix( param.type.compose(), "*" ) ) + "> " + optionalEnd + - strippedParameterName; + ( isTemplateParam ? ( isConst ? "const T" : "T" ) : stripPostfix( param.type.compose(), "*" ) ) + "> " + + optionalEnd + strippedParameterName; } } @@ -3490,13 +3490,30 @@ ${prefix}} void VulkanHppGenerator::appendStructCompareOperators( std::string & str, std::pair const & structData ) const { + static const std::set simpleTypes = { "char", "double", "DWORD", "float", "HANDLE", + "HINSTANCE", "HMONITOR", "HWND", "int", "int8_t", + "int16_t", "int32_t", "int64_t", "LPCWSTR", "size_t", + "uint8_t", "uint16_t", "uint32_t", "uint64_t" }; // two structs are compared by comparing each of the elements std::string compareMembers; std::string intro = ""; for ( size_t i = 0; i < structData.second.members.size(); i++ ) { MemberData const & member = structData.second.members[i]; - compareMembers += intro + "( " + member.name + " == rhs." + member.name + " )"; + auto typeIt = m_types.find( member.type.type ); + assert( typeIt != m_types.end() ); + if ( ( typeIt->second.category == TypeCategory::Requires ) && member.type.postfix.empty() && + ( simpleTypes.find( member.type.type ) == simpleTypes.end() ) ) + { + // this type might support operator==()... that is, use memcmp + compareMembers += + intro + "( memcmp( &" + member.name + ", &rhs." + member.name + ", sizeof( " + member.type.type + " ) ) == 0 )"; + } + else + { + // for all others, we use the operator== of that type + compareMembers += intro + "( " + member.name + " == rhs." + member.name + " )"; + } intro = "\n && "; } diff --git a/vulkan/vulkan.hpp b/vulkan/vulkan.hpp index 1261352..41c04e0 100644 --- a/vulkan/vulkan.hpp +++ b/vulkan/vulkan.hpp @@ -49197,7 +49197,7 @@ namespace VULKAN_HPP_NAMESPACE bool operator==( ImagePipeSurfaceCreateInfoFUCHSIA const & rhs ) const VULKAN_HPP_NOEXCEPT { return ( sType == rhs.sType ) && ( pNext == rhs.pNext ) && ( flags == rhs.flags ) && - ( imagePipeHandle == rhs.imagePipeHandle ); + ( memcmp( &imagePipeHandle, &rhs.imagePipeHandle, sizeof( zx_handle_t ) ) == 0 ); } bool operator!=( ImagePipeSurfaceCreateInfoFUCHSIA const & rhs ) const VULKAN_HPP_NOEXCEPT @@ -70507,7 +70507,8 @@ namespace VULKAN_HPP_NAMESPACE # else bool operator==( PresentFrameTokenGGP const & rhs ) const VULKAN_HPP_NOEXCEPT { - return ( sType == rhs.sType ) && ( pNext == rhs.pNext ) && ( frameToken == rhs.frameToken ); + return ( sType == rhs.sType ) && ( pNext == rhs.pNext ) && + ( memcmp( &frameToken, &rhs.frameToken, sizeof( GgpFrameToken ) ) == 0 ); } bool operator!=( PresentFrameTokenGGP const & rhs ) const VULKAN_HPP_NOEXCEPT @@ -76134,7 +76135,7 @@ namespace VULKAN_HPP_NAMESPACE bool operator==( StreamDescriptorSurfaceCreateInfoGGP const & rhs ) const VULKAN_HPP_NOEXCEPT { return ( sType == rhs.sType ) && ( pNext == rhs.pNext ) && ( flags == rhs.flags ) && - ( streamDescriptor == rhs.streamDescriptor ); + ( memcmp( &streamDescriptor, &rhs.streamDescriptor, sizeof( GgpStreamDescriptor ) ) == 0 ); } bool operator!=( StreamDescriptorSurfaceCreateInfoGGP const & rhs ) const VULKAN_HPP_NOEXCEPT @@ -79316,7 +79317,7 @@ namespace VULKAN_HPP_NAMESPACE bool operator==( XcbSurfaceCreateInfoKHR const & rhs ) const VULKAN_HPP_NOEXCEPT { return ( sType == rhs.sType ) && ( pNext == rhs.pNext ) && ( flags == rhs.flags ) && - ( connection == rhs.connection ) && ( window == rhs.window ); + ( connection == rhs.connection ) && ( memcmp( &window, &rhs.window, sizeof( xcb_window_t ) ) == 0 ); } bool operator!=( XcbSurfaceCreateInfoKHR const & rhs ) const VULKAN_HPP_NOEXCEPT @@ -79414,7 +79415,7 @@ namespace VULKAN_HPP_NAMESPACE bool operator==( XlibSurfaceCreateInfoKHR const & rhs ) const VULKAN_HPP_NOEXCEPT { return ( sType == rhs.sType ) && ( pNext == rhs.pNext ) && ( flags == rhs.flags ) && ( dpy == rhs.dpy ) && - ( window == rhs.window ); + ( memcmp( &window, &rhs.window, sizeof( Window ) ) == 0 ); } bool operator!=( XlibSurfaceCreateInfoKHR const & rhs ) const VULKAN_HPP_NOEXCEPT