diff options
author | Jose <jose@zeroc.com> | 2019-02-05 14:08:24 +0100 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2019-02-05 14:10:12 +0100 |
commit | f4f1c45b1fe339a72b10454d5d8d4de05a4ca7d4 (patch) | |
tree | 11ea8c3e6bc920cf5bb4d1a8db2793b260a8e05f | |
parent | Allow components to set properties for testing (diff) | |
download | ice-f4f1c45b1fe339a72b10454d5d8d4de05a4ca7d4.tar.bz2 ice-f4f1c45b1fe339a72b10454d5d8d4de05a4ca7d4.tar.xz ice-f4f1c45b1fe339a72b10454d5d8d4de05a4ca7d4.zip |
Fix compiler crash if forward declared class has no definition
This affects slice2py and slice2php Slice compilers
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | cpp/src/Slice/PythonUtil.cpp | 5 | ||||
-rw-r--r-- | cpp/src/slice2php/Main.cpp | 7 | ||||
-rw-r--r-- | cpp/test/Slice/errorDetection/forward/Forward.ice | 4 | ||||
-rw-r--r-- | cpp/test/Slice/errorDetection/test.py | 14 | ||||
-rw-r--r-- | cpp/test/Slice/errorDetection/tmp/.gitignore | 1 |
6 files changed, 24 insertions, 8 deletions
diff --git a/.gitignore b/.gitignore index 90deb7e210d..d54503fd64f 100644 --- a/.gitignore +++ b/.gitignore @@ -110,3 +110,4 @@ csharp/AppX *.runtimeconfig.dev.json *.runtimeconfig.json cpp/AppX +cpp/test/Slice/errorDetection/tmp diff --git a/cpp/src/Slice/PythonUtil.cpp b/cpp/src/Slice/PythonUtil.cpp index 2637ca26321..8e95f47b753 100644 --- a/cpp/src/Slice/PythonUtil.cpp +++ b/cpp/src/Slice/PythonUtil.cpp @@ -427,7 +427,8 @@ Slice::Python::CodeVisitor::visitClassDecl(const ClassDeclPtr& p) _out << nl << "_M_" << getAbsolute(p, "_t_") << " = IcePy.declareValue('" << scoped << "')"; } - if(!p->isLocal() && (p->isInterface() || p->definition()->allOperations().size())) + ClassDefPtr def = p->definition(); + if(!p->isLocal() && (p->isInterface() || (def && def->allOperations().size()))) { _out << nl << "_M_" << getAbsolute(p, "_t_", "Disp") << " = IcePy.declareClass('" << scoped << "')"; _out << nl << "_M_" << getAbsolute(p, "_t_", "Prx") << " = IcePy.declareProxy('" << scoped << "')"; @@ -1826,7 +1827,7 @@ Slice::Python::CodeVisitor::writeType(const TypePtr& p) if(prx) { ClassDefPtr def = prx->_class()->definition(); - if(def->isInterface() || def->allOperations().size() > 0) + if(def && (def->isInterface() || def->allOperations().size() > 0)) { _out << "_M_" << getAbsolute(prx->_class(), "_t_", "Prx"); } diff --git a/cpp/src/slice2php/Main.cpp b/cpp/src/slice2php/Main.cpp index b5d354af1fb..f9b8d768aad 100644 --- a/cpp/src/slice2php/Main.cpp +++ b/cpp/src/slice2php/Main.cpp @@ -168,14 +168,15 @@ CodeVisitor::visitClassDecl(const ClassDeclPtr& p) _out << sp << nl << "global " << type << ';'; bool isInterface = p->isInterface(); - if(!p->isLocal() && (isInterface || p->definition()->allOperations().size() > 0)) + ClassDefPtr def = p->definition(); + if(!p->isLocal() && (isInterface || (def && def->allOperations().size() > 0))) { _out << nl << "global " << type << "Prx;"; } _out << nl << "if(!isset(" << type << "))"; _out << sb; _out << nl << type << " = IcePHP_declareClass('" << scoped << "');"; - if(!p->isLocal() && (isInterface || p->definition()->allOperations().size() > 0)) + if(!p->isLocal() && (isInterface || (def && def->allOperations().size() > 0))) { _out << nl << type << "Prx = IcePHP_declareProxy('" << scoped << "');"; } @@ -1233,7 +1234,7 @@ CodeVisitor::getType(const TypePtr& p) if(prx) { ClassDefPtr def = prx->_class()->definition(); - if(def->isInterface() || def->allOperations().size() > 0) + if(def && (def->isInterface() || def->allOperations().size() > 0)) { return getTypeVar(prx->_class(), "Prx"); } diff --git a/cpp/test/Slice/errorDetection/forward/Forward.ice b/cpp/test/Slice/errorDetection/forward/Forward.ice new file mode 100644 index 00000000000..86bd34a8c54 --- /dev/null +++ b/cpp/test/Slice/errorDetection/forward/Forward.ice @@ -0,0 +1,4 @@ +module test +{ +class F; +} diff --git a/cpp/test/Slice/errorDetection/test.py b/cpp/test/Slice/errorDetection/test.py index a0ed798edea..d9a7664b086 100644 --- a/cpp/test/Slice/errorDetection/test.py +++ b/cpp/test/Slice/errorDetection/test.py @@ -4,6 +4,9 @@ # import glob +import os +import shutil + class SliceErrorDetectionTestCase(ClientTestCase): @@ -39,8 +42,15 @@ class SliceErrorDetectionTestCase(ClientTestCase): i = i + 1 else: current.writeln("ok") + + for language in ["cpp", "cs", "html", "java", "js", "matlab", "objc", "php", "py", "rb"]: + compiler = SliceTranslator('slice2%s' % language) + if not os.path.isfile(compiler.getCommandLine(current)): + continue + compiler.run(current, args=["forward/Forward.ice", "--output-dir", "tmp"]) + current.writeln("ok") finally: - for file in glob.glob("{0}/tmp/*".format(testdir)): - current.files.append(file) + if os.path.exists("{0}/tmp".format(testdir)): + shutil.rmtree("{0}/tmp".format(testdir)) TestSuite(__name__, [ SliceErrorDetectionTestCase() ]) diff --git a/cpp/test/Slice/errorDetection/tmp/.gitignore b/cpp/test/Slice/errorDetection/tmp/.gitignore deleted file mode 100644 index 72e8ffc0db8..00000000000 --- a/cpp/test/Slice/errorDetection/tmp/.gitignore +++ /dev/null @@ -1 +0,0 @@ -* |