// Check if reference ivalue has been saved before
const void* ivalue_ptr = getPointer(ivalue);
if (ivalue_ptr) {
- auto memo_entry = memo_.find(ivalue_ptr);
- if (memo_entry != memo_.end()) {
+ auto memo_entry = memo_map_.find(ivalue_ptr);
+ if (memo_entry != memo_map_.end()) {
// This value has already been pushed, just do a BINGET
pushBinGet(memo_entry->second);
return;
void Pickler::pushClass(PicklerClass cls) {
const auto& name = getClassName(cls);
// Write it to the tensor table
- auto memo_entry = memo_.find(&name);
- if (memo_entry == memo_.end()) {
+ auto memo_entry = memo_map_.find(&name);
+ if (memo_entry == memo_map_.end()) {
push<OpCode>(OpCode::GLOBAL);
// Module name + "\n"
pushString(getModuleName());
push<OpCode>(OpCode::LONG_BINPUT);
push<uint32_t>(memo_id);
}
- memo_[item] = memo_id;
+ memo_map_[item] = memo_id;
AT_ASSERT(memo_id <= std::numeric_limits<uint32_t>::max());
++memo_id;
}
} break;
case OpCode::BINPUT: {
size_t memo_id = read<uint8_t>();
- if (memo_.size() <= memo_id) {
- memo_.reserve(1 + 2 * memo_id);
+ if (memo_table_.size() <= memo_id) {
+ memo_table_.reserve(1 + 2 * memo_id);
}
- memo_.push_back(stack_.back());
+ memo_table_.push_back(stack_.back());
} break;
case OpCode::MARK: {
// Mark location of the container ivalue in the stack
stack_.resize(start);
} break;
case OpCode::BINGET: {
- stack_.push_back(memo_.at(read<uint8_t>()));
+ stack_.push_back(memo_table_.at(read<uint8_t>()));
} break;
case OpCode::STOP:
break;
// Read a newline terminated string
std::string Unpickler::readString() {
const char* chars = reinterpret_cast<const char*>(bytes_);
+ const char* char_end_ptr = reinterpret_cast<const char*>(end_ptr_);
size_t n = 0;
while (true) {
char c = chars[n];
// Increment after to exclude newline from string
++n;
+ AT_CHECK(
+ chars + n < char_end_ptr,
+ "Unpickler overran buffer while reading a string (expected a newline)");
}
// Increment by string length + newline char
// Memoization of IValues that have been written (index in table is used for
// BINPUT opcodes) to enable shared references
- std::unordered_map<const void*, uint32_t> memo_;
+ std::unordered_map<const void*, uint32_t> memo_map_;
// External table of tensors to serialize
std::vector<at::Tensor>* tensor_table_;
void readList();
std::vector<IValue> stack_;
- std::vector<IValue> memo_;
+ std::vector<IValue> memo_table_;
std::vector<size_t> marks_;
const uint8_t* bytes_;
const uint8_t* end_ptr_;