diff options
| -rw-r--r-- | slang.h | 24 | ||||
| -rw-r--r-- | source/compiler-core/slang-artifact-handler-impl.cpp | 2 | ||||
| -rw-r--r-- | source/compiler-core/slang-artifact-impl.cpp | 2 | ||||
| -rw-r--r-- | source/compiler-core/slang-slice-allocator.cpp | 2 | ||||
| -rw-r--r-- | source/core/slang-blob.h | 2 | ||||
| -rw-r--r-- | source/core/slang-castable-list-impl.cpp | 2 | ||||
| -rw-r--r-- | source/core/slang-castable-util.cpp | 2 | ||||
| -rw-r--r-- | source/core/slang-file-system.cpp | 4 | ||||
| -rw-r--r-- | source/core/slang-lazy-castable-list.cpp | 2 | ||||
| -rwxr-xr-x | source/slang/slang-compiler.h | 2 | ||||
| -rw-r--r-- | source/slang/slang.cpp | 4 |
11 files changed, 30 insertions, 18 deletions
@@ -932,21 +932,33 @@ extern "C" // It is not necessary to use the multiple parameters (we can wrap in parens), but this is simple. #define SLANG_COM_INTERFACE(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \ public: \ - SLANG_FORCE_INLINE static const SlangUUID& getTypeGuid() \ + SLANG_FORCE_INLINE constexpr static SlangUUID getTypeGuid() \ { \ - static const SlangUUID guid = { a, b, c, d0, d1, d2, d3, d4, d5, d6, d7 }; \ - return guid; \ + return { a, b, c, d0, d1, d2, d3, d4, d5, d6, d7 }; \ } // Sometimes it's useful to associate a guid with a class to identify it. This macro can used for this, // and the guid extracted via the getTypeGuid() function defined in the type #define SLANG_CLASS_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \ - SLANG_FORCE_INLINE static const SlangUUID& getTypeGuid() \ + SLANG_FORCE_INLINE constexpr static SlangUUID getTypeGuid() \ { \ - static const SlangUUID guid = { a, b, c, d0, d1, d2, d3, d4, d5, d6, d7 }; \ - return guid; \ + return { a, b, c, d0, d1, d2, d3, d4, d5, d6, d7 }; \ } +// Helper to fill in pairs of GUIDs and return pointers. This ensures that the +// type of the GUID passed matches the pointer type, and that it is derived +// from ISlangUnknown, +// TODO(c++20): would is_derived_from be more appropriate here for private inheritance of ISlangUnknown? +// +// with : void createFoo(SlangUUID, void**); +// Slang::ComPtr<Bar> myBar; +// call with: createFoo(SLANG_IID_PPV_ARGS(myBar.writeRef())) +// to call : createFoo(Bar::getTypeGuid(), (void**)(myBar.writeRef())) +#define SLANG_IID_PPV_ARGS(ppType) \ + std::decay_t<decltype(**(ppType))>::getTypeGuid(), \ + ((void)[]{static_assert(std::is_base_of_v<ISlangUnknown, std::decay_t<decltype(**(ppType))>>);}, reinterpret_cast<void**>(ppType)) + + /** Base interface for components exchanged through the API. This interface definition is compatible with the COM `IUnknown`, diff --git a/source/compiler-core/slang-artifact-handler-impl.cpp b/source/compiler-core/slang-artifact-handler-impl.cpp index 9bf4313a9..84b786784 100644 --- a/source/compiler-core/slang-artifact-handler-impl.cpp +++ b/source/compiler-core/slang-artifact-handler-impl.cpp @@ -68,7 +68,7 @@ SlangResult DefaultArtifactHandler::_addRepresentation(IArtifact* artifact, Arti // See if it implements ICastable { ComPtr<ICastable> castable; - if (SLANG_SUCCEEDED(rep->queryInterface(ICastable::getTypeGuid(), (void**)castable.writeRef())) && castable) + if (SLANG_SUCCEEDED(rep->queryInterface(SLANG_IID_PPV_ARGS(castable.writeRef()))) && castable) { return _addRepresentation(artifact, keep, castable, outCastable); } diff --git a/source/compiler-core/slang-artifact-impl.cpp b/source/compiler-core/slang-artifact-impl.cpp index bec28f3eb..237ea7436 100644 --- a/source/compiler-core/slang-artifact-impl.cpp +++ b/source/compiler-core/slang-artifact-impl.cpp @@ -178,7 +178,7 @@ void Artifact::addRepresentationUnknown(ISlangUnknown* unk) } ComPtr<ICastable> castable; - if (SLANG_SUCCEEDED(unk->queryInterface(ICastable::getTypeGuid(), (void**)castable.writeRef())) && castable) + if (SLANG_SUCCEEDED(unk->queryInterface(SLANG_IID_PPV_ARGS(castable.writeRef()))) && castable) { if (m_representations.indexOf(castable) >= 0) { diff --git a/source/compiler-core/slang-slice-allocator.cpp b/source/compiler-core/slang-slice-allocator.cpp index 9a0620ced..738bdf303 100644 --- a/source/compiler-core/slang-slice-allocator.cpp +++ b/source/compiler-core/slang-slice-allocator.cpp @@ -39,7 +39,7 @@ namespace Slang { // See if it has a castable interface ComPtr<ICastable> castable; - if (SLANG_SUCCEEDED(blob->queryInterface(ICastable::getTypeGuid(), (void**)castable.writeRef()))) + if (SLANG_SUCCEEDED(blob->queryInterface(SLANG_IID_PPV_ARGS(castable.writeRef())))) { if (castable->castAs(SlangTerminatedChars::getTypeGuid())) { diff --git a/source/core/slang-blob.h b/source/core/slang-blob.h index e528f55a8..aa503a6e5 100644 --- a/source/core/slang-blob.h +++ b/source/core/slang-blob.h @@ -346,7 +346,7 @@ protected: m_scope(scope) { // Cache the ICastable interface if there is one. - blob->queryInterface(ICastable::getTypeGuid(), (void**)m_castable.writeRef()); + blob->queryInterface(SLANG_IID_PPV_ARGS(m_castable.writeRef())); } ComPtr<ISlangUnknown> m_scope; diff --git a/source/core/slang-castable-list-impl.cpp b/source/core/slang-castable-list-impl.cpp index 1cc5dc2d4..4f4b07790 100644 --- a/source/core/slang-castable-list-impl.cpp +++ b/source/core/slang-castable-list-impl.cpp @@ -113,7 +113,7 @@ Index CastableList::indexOfUnknown(ISlangUnknown* unk) // If it has a castable interface we can just look for that { ComPtr<ICastable> castable; - if (SLANG_SUCCEEDED(unk->queryInterface(ICastable::getTypeGuid(), (void**)castable.writeRef())) && castable) + if (SLANG_SUCCEEDED(unk->queryInterface(SLANG_IID_PPV_ARGS(castable.writeRef()))) && castable) { return indexOf(castable); } diff --git a/source/core/slang-castable-util.cpp b/source/core/slang-castable-util.cpp index 408e36cb3..38652d47b 100644 --- a/source/core/slang-castable-util.cpp +++ b/source/core/slang-castable-util.cpp @@ -9,7 +9,7 @@ namespace Slang { { SLANG_ASSERT(unk); ComPtr<ICastable> castable; - if (SLANG_SUCCEEDED(unk->queryInterface(ICastable::getTypeGuid(), (void**)castable.writeRef()))) + if (SLANG_SUCCEEDED(unk->queryInterface(SLANG_IID_PPV_ARGS(castable.writeRef())))) { SLANG_ASSERT(castable); } diff --git a/source/core/slang-file-system.cpp b/source/core/slang-file-system.cpp index 0369d0a02..db75e5365 100644 --- a/source/core/slang-file-system.cpp +++ b/source/core/slang-file-system.cpp @@ -338,7 +338,7 @@ void CacheFileSystem::setInnerFileSystem(ISlangFileSystem* fileSystem, UniqueIde if (fileSystem) { // Try to get the more sophisticated interface - fileSystem->queryInterface(ISlangFileSystemExt::getTypeGuid(), (void**)m_fileSystemExt.writeRef()); + fileSystem->queryInterface(SLANG_IID_PPV_ARGS(m_fileSystemExt.writeRef())); } // Determine how paths map @@ -826,7 +826,7 @@ RelativeFileSystem::RelativeFileSystem(ISlangFileSystem* fileSystem, const Strin m_osPathKind = OSPathKind::None; ComPtr<ISlangFileSystemExt> ext; - if (SLANG_SUCCEEDED(fileSystem->queryInterface(ISlangFileSystemExt::getTypeGuid(), (void**)ext.writeRef()))) + if (SLANG_SUCCEEDED(fileSystem->queryInterface(SLANG_IID_PPV_ARGS(ext.writeRef())))) { m_osPathKind = ext->getOSPathKind(); diff --git a/source/core/slang-lazy-castable-list.cpp b/source/core/slang-lazy-castable-list.cpp index 1832a67f4..112172108 100644 --- a/source/core/slang-lazy-castable-list.cpp +++ b/source/core/slang-lazy-castable-list.cpp @@ -150,7 +150,7 @@ Index LazyCastableList::indexOfUnknown(ISlangUnknown* unk) const // Try as a ICastable first { ComPtr<ICastable> castable; - if (SLANG_SUCCEEDED(unk->queryInterface(ICastable::getTypeGuid(), (void**)castable.writeRef())) && castable) + if (SLANG_SUCCEEDED(unk->queryInterface(SLANG_IID_PPV_ARGS(castable.writeRef()))) && castable) { return indexOf(castable); } diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index 895834312..52d154e5c 100755 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -3114,7 +3114,7 @@ SLANG_FORCE_INLINE EndToEndCompileRequest* asInternal(SlangCompileRequest* reque SLANG_ASSERT(request); EndToEndCompileRequest* endToEndRequest = nullptr; // NOTE! We aren't using to access an interface, so *doesn't* return with a refcount - request->queryInterface(EndToEndCompileRequest::getTypeGuid(), (void**)&endToEndRequest); + request->queryInterface(SLANG_IID_PPV_ARGS(&endToEndRequest)); SLANG_ASSERT(endToEndRequest); return endToEndRequest; } diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 283e7c16e..2f02dcfb7 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -3393,7 +3393,7 @@ ComponentType* asInternal(slang::IComponentType* inComponentType) // (without even `addRef`-ing it). // ComPtr<slang::IComponentType> componentType; - inComponentType->queryInterface(slang::IComponentType::getTypeGuid(), (void**) componentType.writeRef()); + inComponentType->queryInterface(SLANG_IID_PPV_ARGS(componentType.writeRef())); return static_cast<ComponentType*>(componentType.get()); } @@ -4454,7 +4454,7 @@ void Linkage::setFileSystem(ISlangFileSystem* inFileSystem) else { // See if we have the full ISlangFileSystemExt interface, if we do just use it - inFileSystem->queryInterface(ISlangFileSystemExt::getTypeGuid(), (void**)m_fileSystemExt.writeRef()); + inFileSystem->queryInterface(SLANG_IID_PPV_ARGS(m_fileSystemExt.writeRef())); // If not wrap with CacheFileSystem that emulates ISlangFileSystemExt from the ISlangFileSystem interface if (!m_fileSystemExt) |
