Merge pull request #5852 from ethereum/solc-api-cleanup

Introduce solidity_free in libsolc
This commit is contained in:
Alex Beregszaszi
2019-01-31 16:26:17 +00:00
committed by GitHub
5 changed files with 17 additions and 0 deletions
+1
View File
@@ -10,6 +10,7 @@ Language Features:
Compiler Features:
* C API (``libsolc`` / raw ``soljson.js``): Introduce ``solidity_free`` method which releases all internal buffers to save memory.
Bugfixes:
+4
View File
@@ -98,4 +98,8 @@ extern char const* solidity_compile(char const* _input, CStyleReadFileCallback _
s_outputBuffer = compile(_input, _readCallback);
return s_outputBuffer.c_str();
}
extern void solidity_free() noexcept
{
s_outputBuffer.clear();
}
}
+5
View File
@@ -55,6 +55,11 @@ char const* solidity_version() SOLC_NOEXCEPT;
/// The pointer returned must not be freed by the caller.
char const* solidity_compile(char const* _input, CStyleReadFileCallback _readCallback) SOLC_NOEXCEPT;
/// Frees up any allocated memory.
///
/// NOTE: the pointer returned by solidity_compile is invalid after calling this!
void solidity_free() SOLC_NOEXCEPT;
#ifdef __cplusplus
}
#endif
+3
View File
@@ -45,6 +45,7 @@ Json::Value compile(string const& _input)
string output(solidity_compile(_input.c_str(), nullptr));
Json::Value ret;
BOOST_REQUIRE(jsonParseStrict(output, ret));
solidity_free();
return ret;
}
@@ -56,12 +57,14 @@ BOOST_AUTO_TEST_CASE(read_version)
{
string output(solidity_version());
BOOST_CHECK(output.find(VersionString) == 0);
solidity_free();
}
BOOST_AUTO_TEST_CASE(read_license)
{
string output(solidity_license());
BOOST_CHECK(output.find("GNU GENERAL PUBLIC LICENSE") != string::npos);
solidity_free();
}
BOOST_AUTO_TEST_CASE(standard_compilation)
+4
View File
@@ -35,6 +35,10 @@ void FuzzerUtil::runCompiler(string const& _input, bool _quiet)
string outputString(solidity_compile(_input.c_str(), nullptr));
if (!_quiet)
cout << "Output JSON: " << outputString << endl;
// This should be safe given the above copies the output.
solidity_free();
Json::Value output;
if (!jsonParseStrict(outputString, output))
{