diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2022-09-01 16:39:08 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-01 16:39:08 -0400 |
| commit | cc0b81350f6b681c794b4ac7c0f3b5fe73cb19eb (patch) | |
| tree | 7fd935748f4da5daa381f6cf4ef5d06c6adfc0a6 /source/slang/slang.cpp | |
| parent | f64d8748d4396a90d27adbdc17db3bac4a58d666 (diff) | |
Make ISlangFileSystem derive from ICastable (#2386)
* #include an absolute path didn't work - because paths were taken to always be relative.
* Make ISlangFileSystem derive from ICastable.
* Make ArchiveFileSystem into an interface
Make file systems atomically reference counted.
* Small fix.
* Some small fixes to work around issues of ICastable on ISlangFileSystem
* Use ISlangFileSystem derived type instead of IArchiveFileSystem. Can always get other interface with castAs.
* Some small fixes around change of interface returned from archive type functions.
* Remove CacheFileSystem member from linkage. Can access easily from m_fileSystemExt if necessary with as cast.
* Fix RiffFileSystem casting issue.
* Add a check around CacheFileSystem.
Diffstat (limited to 'source/slang/slang.cpp')
| -rw-r--r-- | source/slang/slang.cpp | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 18b9b3c99..a0355c266 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -352,7 +352,7 @@ SlangResult Session::loadStdLib(const void* stdLib, size_t stdLibSizeInBytes) } // Make a file system to read it from - RefPtr<ArchiveFileSystem> fileSystem; + ComPtr<ISlangFileSystemExt> fileSystem; SLANG_RETURN_ON_FAIL(loadArchiveFileSystem(stdLib, stdLibSizeInBytes, fileSystem)); // Let's try loading serialized modules and adding them @@ -371,9 +371,16 @@ SlangResult Session::saveStdLib(SlangArchiveType archiveType, ISlangBlob** outBl } // Make a file system to read it from - RefPtr<ArchiveFileSystem> fileSystem; + ComPtr<ISlangMutableFileSystem> fileSystem; SLANG_RETURN_ON_FAIL(createArchiveFileSystem(archiveType, fileSystem)); + // Must have archiveFileSystem interface + auto archiveFileSystem = as<IArchiveFileSystem>(fileSystem); + if (!archiveFileSystem) + { + return SLANG_FAIL; + } + for (auto& pair : m_builtinLinkage->mapNameToLoadedModules) { const Name* moduleName = pair.Key; @@ -402,7 +409,7 @@ SlangResult Session::saveStdLib(SlangArchiveType archiveType, ISlangBlob** outBl } // Now need to convert into a blob - SLANG_RETURN_ON_FAIL(fileSystem->storeArchive(true, outBlob)); + SLANG_RETURN_ON_FAIL(archiveFileSystem->storeArchive(true, outBlob)); return SLANG_OK; } @@ -4287,29 +4294,23 @@ void Linkage::setFileSystem(ISlangFileSystem* inFileSystem) // Release what's there m_fileSystemExt.setNull(); - m_cacheFileSystem.setNull(); - + // If nullptr passed in set up default if (inFileSystem == nullptr) { - m_cacheFileSystem = new Slang::CacheFileSystem(Slang::OSFileSystem::getExtSingleton()); - m_fileSystemExt = m_cacheFileSystem; + m_fileSystemExt = new Slang::CacheFileSystem(Slang::OSFileSystem::getExtSingleton()); } else { - CacheFileSystem* cacheFileSystemPtr = nullptr; - inFileSystem->queryInterface(CacheFileSystem::getTypeGuid(), (void**)&cacheFileSystemPtr); - if (cacheFileSystemPtr) + if (auto cacheFileSystem = as<CacheFileSystem>(inFileSystem)) { - m_cacheFileSystem = cacheFileSystemPtr; - m_fileSystemExt = cacheFileSystemPtr; + m_fileSystemExt = cacheFileSystem; } else { if (m_requireCacheFileSystem) { - m_cacheFileSystem = new Slang::CacheFileSystem(inFileSystem); - m_fileSystemExt = m_cacheFileSystem; + m_fileSystemExt = new Slang::CacheFileSystem(inFileSystem); } else { @@ -4320,13 +4321,15 @@ void Linkage::setFileSystem(ISlangFileSystem* inFileSystem) if (!m_fileSystemExt) { // Construct a wrapper to emulate the extended interface behavior - m_cacheFileSystem = new Slang::CacheFileSystem(m_fileSystem); - m_fileSystemExt = m_cacheFileSystem; + m_fileSystemExt = new Slang::CacheFileSystem(m_fileSystem); } } } } + // If requires a cache file system, check that it does have one + SLANG_ASSERT(m_requireCacheFileSystem == false || as<CacheFileSystem>(m_fileSystemExt)); + // Set the file system used on the source manager getSourceManager()->setFileSystemExt(m_fileSystemExt); } |
