Merge pull request #7976 from ethereum/solc-api

Test solidity_free in tests too
This commit is contained in:
chriseth 2019-12-12 12:48:28 +01:00 committed by GitHub
commit 276c777af3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 4 deletions

View File

@ -125,7 +125,7 @@ extern char const* solidity_version() noexcept
return VersionString.c_str(); return VersionString.c_str();
} }
extern char const* solidity_compile(char const* _input, CStyleReadFileCallback _readCallback, void* _readContext) noexcept extern char* solidity_compile(char const* _input, CStyleReadFileCallback _readCallback, void* _readContext) noexcept
{ {
return solidityAllocations.emplace_back(compile(_input, _readCallback, _readContext)).data(); return solidityAllocations.emplace_back(compile(_input, _readCallback, _readContext)).data();
} }

View File

@ -87,7 +87,7 @@ void solidity_free(char* _data) SOLC_NOEXCEPT;
/// @param _readContext An optional context pointer passed to _readCallback. Can be NULL. /// @param _readContext An optional context pointer passed to _readCallback. Can be NULL.
/// ///
/// @returns A pointer to the result. The pointer returned must be freed by the caller using solidity_free() or solidity_reset(). /// @returns A pointer to the result. The pointer returned must be freed by the caller using solidity_free() or solidity_reset().
char const* solidity_compile(char const* _input, CStyleReadFileCallback _readCallback, void* _readContext) SOLC_NOEXCEPT; char* solidity_compile(char const* _input, CStyleReadFileCallback _readCallback, void* _readContext) SOLC_NOEXCEPT;
/// Frees up any allocated memory. /// Frees up any allocated memory.
/// ///

View File

@ -59,8 +59,9 @@ bool containsError(Json::Value const& _compilerResult, string const& _type, stri
Json::Value compile(string const& _input, CStyleReadFileCallback _callback = nullptr) Json::Value compile(string const& _input, CStyleReadFileCallback _callback = nullptr)
{ {
string output(solidity_compile(_input.c_str(), _callback, nullptr)); char* output_ptr = solidity_compile(_input.c_str(), _callback, nullptr);
// This should be safe given the above copies the output. string output(output_ptr);
solidity_free(output_ptr);
solidity_reset(); solidity_reset();
Json::Value ret; Json::Value ret;
BOOST_REQUIRE(jsonParseStrict(output, ret)); BOOST_REQUIRE(jsonParseStrict(output, ret));