diff --git a/src/common/variant.h b/src/common/variant.h index 8ec9ccb7a92acb06417a74d9ebe95189ac9e547f..ca2fcc090769bc49603176dc361d5f8c8e22890c 100644 --- a/src/common/variant.h +++ b/src/common/variant.h @@ -79,13 +79,13 @@ struct Variant { template void Set(Args &&... args) { - helper::Destroy(type_id, &data.data); - new (&data.data) T(std::forward(args)...); + helper::Destroy(type_id, data.data); + new (data.data) T(std::forward(args)...); type_id = typeid(T).hash_code(); } void SetString(std::string &string) { - // helper::Destroy(type_id, &data); + helper::Destroy(type_id, data.data); type_id = typeid(std::string).hash_code(); strcpy(data.data, string.c_str()); } @@ -109,7 +109,7 @@ struct Variant { "stl lib with string copy)"); exit(0); } else if (type_id == typeid(T).hash_code()) { - return *const_cast(reinterpret_cast(&data)); + return *const_cast(reinterpret_cast(data.data)); } else { PADDLE_MOBILE_THROW_EXCEPTION(" bad cast in variant"); exit(0); @@ -122,7 +122,8 @@ struct Variant { static inline size_t invalid_type() { return typeid(void).hash_code(); } typedef VariantHelper helper; size_t type_id; - RawData data; + // todo use an anto size to suite this. + RawData<64> data; }; template diff --git a/test/executor_for_test.h b/test/executor_for_test.h index 93847af20a6d48a6df33dc50f6c6a1db76facf51..60f1856bb9294c6f9b4bd5cfb7d44f984c6f0794 100644 --- a/test/executor_for_test.h +++ b/test/executor_for_test.h @@ -43,7 +43,7 @@ template class Executor4Test : public Executor { public: Executor4Test(Program p, string op_type, - bool use_optimize = false, int predict_op_count = 1) + bool use_optimize = false) : Executor() { this->use_optimize_ = use_optimize; this->program_ = p; @@ -64,7 +64,7 @@ class Executor4Test : public Executor { std::vector> ops = block_desc->Ops(); for (int i = 0; i < ops.size(); ++i) { auto op = ops[i]; - if (op->Type() == op_type && i < predict_op_count) { + if (op->Type() == op_type) { DLOG << "匹配到: " << op->Type(); /// test first meeting op in program @@ -74,6 +74,7 @@ class Executor4Test : public Executor { op->Type(), op->GetInputs(), op->GetOutputs(), op->GetAttrMap(), this->program_.scope); this->ops_of_block_[*block_desc.get()].push_back(op_ptr); + break; } } }