Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Initial Wasm memory allocation #400

Merged
merged 10 commits into from
Sep 12, 2017

Conversation

brianjohnson5972
Copy link
Contributor

#129
Added malloc, realloc, and free to eoslib. Currently does not free memory, just allocates/reallocates what is available. Changed user stack to 8K.

Copy link
Contributor

@wanderingbort wanderingbort left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the looks of things, this set of test cases probably belongs in the api_tests suite that @elmato put together (and its coordinating test_api contract). Is there a compelling reason to have this memory API tested outside of that rig?

I realize it would be a non-trivial change from what is presented so, I have not bothered to comment in the contract code until we resolve this top-level issue.

@@ -0,0 +1,2 @@
file(GLOB SOURCE_FILES "*.cpp")
add_wast_target(memory_test "${SOURCE_FILES}" "${CMAKE_SOURCE_DIR}/contracts" ${CMAKE_CURRENT_SOURCE_DIR})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This directive will build the memory test contract code intp contracts/ however you later attempt to include the .wast.hpp file relative to the slow tests source.

we have precedence for storing "test" contracts in the contracts tree that are used in slow tests. the memory_test contract should be placed there (along side api_test). Then you can include the .wast.hpp using brackets and it should work just fine.

@@ -11,6 +11,7 @@ add_executable( chain_test ${UNIT_TESTS} ${COMMON_SOURCES} )
target_link_libraries( chain_test eos_native_contract eos_chain chainbase eos_utilities eos_egenesis_none wallet_plugin fc ${PLATFORM_SPECIFIC_LIBS} )

if(WASM_TOOLCHAIN)
add_subdirectory(slow_tests/memory_test)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be necessary once the memory test contract is moved to the contracts tree.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my previous response.

@@ -47,6 +47,7 @@
#include <currency/currency.wast.hpp>
#include <exchange/exchange.wast.hpp>
#include <infinite/infinite.wast.hpp>
#include "memory_test/memory_test.wast.hpp"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

once memory_test is moved to the contracts/ tree, this should become #include <memory_test/memory_test.wast.hpp>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my previous response.

@@ -121,7 +121,7 @@ macro(add_wast_target target SOURCE_FILES INCLUDE_FOLDERS DESTINATION_FOLDER)

add_custom_command(OUTPUT ${DESTINATION_FOLDER}/${target}.wast
DEPENDS ${target}.s
COMMAND ${BINARYEN_BIN}/s2wasm -o ${DESTINATION_FOLDER}/${target}.wast -s 1024 ${target}.s
COMMAND ${BINARYEN_BIN}/s2wasm -o ${DESTINATION_FOLDER}/${target}.wast -s 8192 ${target}.s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should consider making this something each contract can override. Setting 1 true stack size for all contracts seems overly limiting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree, but I'd like @bytemaster 's input, since I am not sure how we want to handle this. Any wasm *.cpp file that included memory.hpp would need to have it set, or else we need to set the memory space allocated based on the user stack. So I'll keep this as an open issue for now (while I fix everything else), unless you have more input on this.

@brianjohnson5972
Copy link
Contributor Author

@wanderingbort I'm fine with moving memory_test in with contracts, if you still want it there, just wanted to indicate why I did it initially and that I think eventually it would be good to have a place for usable or emulatable contracts and a place for test contracts that would cause confusion or would would be examples of what not to do (since they are test) . But with the short time I will defer to you and move it, just let me know.

@wanderingbort
Copy link
Contributor

I don't mean to block this, I agree @bytemaster should weigh in. given that this falls into the category of "unit tests for contract API", I think it should be with the other unit tests. If those tests should be under the test/ tree rather than contracts, then I am fine with it. We can do that move in another issue.

I'm going to change my review to an approval for now and start a new issue to unify the memory tests and existing API tests and determine the correct directory for them.

@bytemaster bytemaster merged commit aaa9773 into EOSIO:master Sep 12, 2017
@brianjohnson5972 brianjohnson5972 deleted the wasm_memory_129 branch September 14, 2017 12:33
taokayan pushed a commit to taokayan/eos that referenced this pull request May 15, 2019
taokayan pushed a commit to taokayan/eos that referenced this pull request May 15, 2019
fix issue EOSIO#400 extract signed_int from datastream
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants