-
Notifications
You must be signed in to change notification settings - Fork 486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add xrt::elf raw elf data constructor #7963
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
#include <stdexcept> | ||
#include <string> | ||
#include <vector> | ||
#include <sstream> | ||
|
||
namespace xrt { | ||
|
||
|
@@ -28,6 +29,14 @@ class elf_impl | |
throw std::runtime_error(fnm + " is not found or is not a valid ELF file"); | ||
} | ||
|
||
elf_impl(const std::vector<char>& data) | ||
{ | ||
std::istringstream elf_stream; | ||
elf_stream.rdbuf()->pubsetbuf(const_cast<char*>(data.data()), data.size()); | ||
if (!m_elf.load(elf_stream)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are copying the vector here. Can we write a simple adapter for std::vector to make it look like std::istream? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
throw std::runtime_error("not a valid ELF data"); | ||
} | ||
|
||
const ELFIO::elfio& | ||
get_elfio() const | ||
{ | ||
|
@@ -85,6 +94,11 @@ elf(const std::string& fnm) | |
: detail::pimpl<elf_impl>{std::make_shared<elf_impl>(fnm)} | ||
{} | ||
|
||
elf:: | ||
elf(const std::vector<char>& data) | ||
: detail::pimpl<elf_impl>{std::make_shared<elf_impl>(data)} | ||
{} | ||
|
||
xrt::uuid | ||
elf:: | ||
get_cfg_uuid() const | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
|
||
#ifdef __cplusplus | ||
# include <string> | ||
# include <vector> | ||
#endif | ||
|
||
#ifdef __cplusplus | ||
|
@@ -32,7 +33,17 @@ class elf : public detail::pimpl<elf_impl> | |
public: | ||
XRT_API_EXPORT | ||
elf(const std::string& fnm); | ||
|
||
|
||
/** | ||
* elf() - Constructor from raw ELF data | ||
* | ||
* @param data | ||
* Raw data of elf | ||
* | ||
*/ | ||
XRT_API_EXPORT | ||
elf(const std::vector<char>& data); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A constructor from std::vector isn't great IMO. What if data is not held in a vector? A std::span would be better, but that's c++20. I would opt for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @stsoe |
||
|
||
XRT_API_EXPORT | ||
xrt::uuid | ||
get_cfg_uuid() const; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The const_cast looks evil here. Can you add a comment why we are doing it and the fact that elf_stream is input stream (read only) so it cannot accidentally change data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since data is const type so data.data() return const char*
https://cplusplus.com/reference/vector/vector/data/
If the vector object is const-qualified, the function returns a pointer to const value_type. Otherwise, it returns a pointer to value_type.
while
streambuf* pubsetbuf (char* s, streamsize n);
https://cplusplus.com/reference/streambuf/streambuf/pubsetbuf/