diff options
| author | Tim Foley <tfoley@nvidia.com> | 2020-01-09 11:26:06 -0800 |
|---|---|---|
| committer | Tim Foley <tfoley@nvidia.com> | 2020-01-09 11:26:06 -0800 |
| commit | 63bed4c37199f2436c81089a08834d7b58b8e576 (patch) | |
| tree | b9095e1206c20c9918716f247f5d15e95f62aa21 | |
| parent | 0a856f458ff9f17d76bc646d008602713c6c66d1 (diff) | |
Catch exceptions inside FindTypeByName()
If `spReflection_FindTypeByName` is called with a string that refers to the name of a variable instead of a type, then it ends up causing a fatal error to be diagnosed, leading to an `AbortCompilationException` being thrown. This exception then propagates up to the application that called `spReflection_FindTypeByName()`, which actually violates the contract for our `extern "C"` API.
This change adds a wrapper `try`/`catch` around the meat of the operation and turns any exception into a null result (this function has no other way to report errors to the caller).
It would be nice for a separate change to make the error message that caused the problem non-fatal, but that is orthogonal to this fix.
| -rw-r--r-- | source/slang/slang-reflection.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/source/slang/slang-reflection.cpp b/source/slang/slang-reflection.cpp index c0c5bd72f..037bc2d97 100644 --- a/source/slang/slang-reflection.cpp +++ b/source/slang/slang-reflection.cpp @@ -598,8 +598,15 @@ SLANG_API SlangReflectionType * spReflection_FindTypeByName(SlangReflection * re Slang::DiagnosticSink sink( programLayout->getTargetReq()->getLinkage()->getSourceManager()); - RefPtr<Type> result = program->getTypeFromString(name, &sink); - return (SlangReflectionType*)result.Ptr(); + try + { + RefPtr<Type> result = program->getTypeFromString(name, &sink); + return (SlangReflectionType*)result.Ptr(); + } + catch( ... ) + { + return nullptr; + } } SLANG_API SlangReflectionTypeLayout* spReflection_GetTypeLayout( |
