summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2020-09-08 14:48:05 -0400
committerGitHub <noreply@github.com>2020-09-08 14:48:05 -0400
commit3a34db6e8864df51b9ae93fe46c6d98c4cfc77bb (patch)
tree1e6c98f470e1300cb17f55e2cc1e9ff26fb87e9b
parent8740252f04c4fe96c5d19a8f07cac43037087e15 (diff)
Test if blob is returned. (#1535)
-rwxr-xr-xsource/slang/slang-compiler.cpp17
-rw-r--r--source/slang/slang-emit-cpp.cpp7
-rw-r--r--source/slang/slang.cpp20
3 files changed, 29 insertions, 15 deletions
diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp
index 859da5d11..71582f60d 100755
--- a/source/slang/slang-compiler.cpp
+++ b/source/slang/slang-compiler.cpp
@@ -122,13 +122,17 @@ namespace Slang
{
switch(format)
{
- case ResultFormat::None:
default:
- break;
-
+ case ResultFormat::None:
+ {
+ // If no blob is returned, it's an error
+ return SLANG_FAIL;
+ }
case ResultFormat::Text:
+ {
blob = StringUtil::createStringBlob(outputString);
break;
+ }
case ResultFormat::Binary:
{
if (downstreamResult)
@@ -1968,7 +1972,11 @@ SlangResult dissassembleDXILUsingDXC(
case ResultFormat::Binary:
{
ComPtr<ISlangBlob> blob;
- result.getBlob(blob);
+ if (SLANG_FAILED(result.getBlob(blob)))
+ {
+ SLANG_UNEXPECTED("No blob to emit");
+ return;
+ }
writeOutputFile(compileRequest,
outputPath,
blob->getBufferPointer(),
@@ -2020,6 +2028,7 @@ SlangResult dissassembleDXILUsingDXC(
ComPtr<ISlangBlob> blob;
if (SLANG_FAILED(result.getBlob(blob)))
{
+ SLANG_UNEXPECTED("No blob to emit");
return;
}
diff --git a/source/slang/slang-emit-cpp.cpp b/source/slang/slang-emit-cpp.cpp
index d22b202f5..650b8aa8f 100644
--- a/source/slang/slang-emit-cpp.cpp
+++ b/source/slang/slang-emit-cpp.cpp
@@ -2598,7 +2598,12 @@ void CPPSourceEmitter::emitModuleImpl(IRModule* module)
targetProgram->getOrCreateEntryPointResult(index, &sink);
Slang::ComPtr<ISlangBlob> blob;
- result.getBlob(blob);
+ if (SLANG_FAILED(result.getBlob(blob)))
+ {
+ SLANG_UNEXPECTED("No blob to emit");
+ return;
+ }
+
auto ptr = (const unsigned char*)blob->getBufferPointer();
m_writer->emit("size_t __");
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index b9381eec3..c97da7125 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -3390,6 +3390,13 @@ SLANG_API void const* spGetEntryPointCode(
size_t* outSize)
{
using namespace Slang;
+
+ // Zero the size initially, in case need to return nullptr for error.
+ if (outSize)
+ {
+ *outSize = 0;
+ }
+
auto req = Slang::asInternal(request);
auto linkage = req->getLinkage();
auto program = req->getSpecializedGlobalAndEntryPointsComponentType();
@@ -3411,22 +3418,15 @@ SLANG_API void const* spGetEntryPointCode(
return nullptr;
CompileResult& result = targetProgram->getExistingEntryPointResult(entryPointIndex);
- void const* data = nullptr;
- size_t size = 0;
-
ComPtr<ISlangBlob> blob;
- if (SLANG_SUCCEEDED(result.getBlob(blob)))
- {
- data = blob->getBufferPointer();
- size = blob->getBufferSize();
- }
+ SLANG_RETURN_NULL_ON_FAIL(result.getBlob(blob));
if (outSize)
{
- *outSize = size;
+ *outSize = blob->getBufferSize();
}
- return data;
+ return (void*)blob->getBufferPointer();
}
static SlangResult _getEntryPointResult(