eos icon indicating copy to clipboard operation
eos copied to clipboard

DAWN-73 ⁃ Cannot include memory.hpp twice

Open blockone-syncclient opened this issue 9 years ago • 11 comments

(replaces github issue #578)

Pravin:

memory.hpp defines a variable memory_heap which causes linker issues due to multiple definitions if this file in included in more than one cpp file. This prevents us from using string.hpp (which internally uses memory.hpp). Problem does not occur in smart contracts if we have only one source file but test_api does not link anymore because it has multiple sources.

ATC (Acceptance Trest Criteria):

  • Include memory.hpp in more than one contract .cpp file.
  • Run contract and verify no error messages about memory allocation.
  • Note test_api does this now, so running tests/test_api is a verification of this issue
  • Ensure documentation is accurate and up-to-date

blockone-syncclient avatar Nov 06 '17 23:11 blockone-syncclient

➤ Kevin Heifner commented:

Brian submitted a PR for this on 10/19.

blockone-syncclient avatar Nov 06 '17 23:11 blockone-syncclient

➤ Kevin Heifner commented:

Just need to merge PR.

blockone-syncclient avatar Nov 06 '17 23:11 blockone-syncclient

➤ Kevin Heifner commented:

I took some time to look into this and I could not find a way to create a true global in wasm via c++. Extern doesn't work, static local in a function doesn't work, etc. However, if we go with Dan's recommendation above:

bq. My understanding is that we would not build multiple .o files from multiple cpp files. Instead, all CPP files for a contract should be built as a single compilation unit.

Then the need for a true global is not needed as there is only one compilation unit. Therefore, [~brian.johnson] is going to rework the cmake instructions so that only one compilation unit is in play. This will then allow the existing memory.hpp to work.

blockone-syncclient avatar Nov 06 '17 23:11 blockone-syncclient

➤ Kevin Heifner commented:

Changed to only compile the ${target}.cpp and require any subsequent cpp files be included in ${target}.cpp. [~thomas.cox] this affects documentation for contract creation.

blockone-syncclient avatar Nov 06 '17 23:11 blockone-syncclient

➤ Kevin Heifner commented:

Merged to master: https://github.com/EOSIO/eos/commit/6927220086c1e019d480ea9aa0f001e45274e86a

blockone-syncclient avatar Nov 06 '17 23:11 blockone-syncclient

➤ Thomas B. Cox commented:

[~kevin.heifner] when you say "this affects documentation for contract creation" can I get some more detail on HOW it "affects" the doc?

blockone-syncclient avatar Nov 06 '17 23:11 blockone-syncclient

➤ Brian Johnson commented:

[~thomas.cox] It depends on the level of documentation, if https://eosio.github.io/eos/md_contracts_eoslib_tutorial.html is all we have, then we just need to add a that eos contracts are "only designed to be compiled and linked from one cpp file. Any subsequent cpp files must be included in the one linked file." I don't think we go further than that, so I think that will be enough.

blockone-syncclient avatar Nov 06 '17 23:11 blockone-syncclient

➤ Kevin Heifner commented:

[~thomas.cox] What Brian said. From the original issue by Dan:

My understanding is that we would not build multiple .o files from multiple cpp files. Instead, all CPP files for a contract should be built as a single compilation unit. If developers want to divide up their cpp files into "libraries" then it would look like this:

/** @file library.cpp */ #include <memory.cpp> #include <contract.cpp>Then you would simply compile library.cpp and be done with it.

Smart contracts shouldn't be all that big where multiple compilation units are required.

blockone-syncclient avatar Nov 06 '17 23:11 blockone-syncclient

➤ Thomas B. Cox commented:

Added "and ensure docs are accurate" to the test criteria.

blockone-syncclient avatar Nov 06 '17 23:11 blockone-syncclient

➤ Bezwada Satyapravin commented:

Verified and tested successfully.

blockone-syncclient avatar Nov 06 '17 23:11 blockone-syncclient

Sync'd the issue back to JIRA and closing.

coreylederer avatar Nov 06 '17 23:11 coreylederer