From ec6f1758c15763bfc0d7a0c9222deb6cf68348bd Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Mon, 14 Mar 2022 16:18:57 +0100 Subject: [PATCH] libsolc: guard LSP initialization in try/catch block. --- libsolc/libsolc.cpp | 15 ++++++++++++--- libsolc/libsolc.h | 6 +++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/libsolc/libsolc.cpp b/libsolc/libsolc.cpp index 95468eb79..f0566471f 100644 --- a/libsolc/libsolc.cpp +++ b/libsolc/libsolc.cpp @@ -137,13 +137,22 @@ extern char* solidity_compile(char const* _input, CStyleReadFileCallback _readCa return solidityAllocations.emplace_back(compile(_input, _readCallback, _readContext)).data(); } -extern int solidity_lsp_start(CStyleReadFileCallback /*TODO(pr) _readCallback*/, void* /*_readContext*/) noexcept +extern int solidity_lsp_start(CStyleReadFileCallback _readCallback) noexcept { if (languageServer || languageServerTransport) return -1; - languageServerTransport = make_unique(); - languageServer = make_unique(*languageServerTransport); + try + { + languageServerTransport = make_unique(); + languageServer = make_unique(*languageServerTransport); + (void) _readCallback; // TODO(pr) pass to LanguageServer() + } + catch (...) + { + return -2; + } + return 0; } diff --git a/libsolc/libsolc.h b/libsolc/libsolc.h index 691157d88..6106456c8 100644 --- a/libsolc/libsolc.h +++ b/libsolc/libsolc.h @@ -98,7 +98,7 @@ char* solidity_compile(char const* _input, CStyleReadFileCallback _readCallback, /// /// @returns 0 on success and -1 on failure. A failure can only happen due to mis-use of the API, /// such as, the LSP mode has been already initiated. -int solidity_lsp_start(CStyleReadFileCallback _readCallback, void* _readContext) SOLC_NOEXCEPT; +int solidity_lsp_start(CStyleReadFileCallback _readCallback) SOLC_NOEXCEPT; /// Sends a single JSON-RPC message to the LSP server. /// This message must not include any HTTP headers but only hold the payload. @@ -120,8 +120,8 @@ char const* solidity_try_receive() SOLC_NOEXCEPT; /// @returns JSON-RPC message (inculding HTTP headers), can be empty (or nullptr). /// If the result is not null, it has to be freed by the caller using solidity_free. /// -/// This can cause the callback provided in solidity_lsp to be invoked. -/// Should only be called after having called solidity_lsp. +/// This can cause the callback provided in solidity_lsp_start to be invoked. +/// Should only be called after having called solidity_lsp_start. char const *solidity_lsp_send_receive(char const* _input) SOLC_NOEXCEPT; /// Frees up any allocated memory.