Fix PycCode incompatibility with Python 1.0
This commit is contained in:
10
pyc_code.cpp
10
pyc_code.cpp
@@ -36,8 +36,14 @@ void PycCode::load(PycData* stream, PycModule* mod)
|
||||
m_flags = 0;
|
||||
|
||||
m_code = LoadObject(stream, mod).require_cast<PycString>();
|
||||
m_consts = LoadObject(stream, mod).require_cast<PycTuple>();
|
||||
m_names = LoadObject(stream, mod).require_cast<PycTuple>();
|
||||
|
||||
if (mod->verCompare(1, 1) < 0) {
|
||||
m_consts = PycTuple::fromList(LoadObject(stream, mod).require_cast<PycList>());
|
||||
m_names = PycTuple::fromList(LoadObject(stream, mod).require_cast<PycList>());
|
||||
} else {
|
||||
m_consts = LoadObject(stream, mod).require_cast<PycTuple>();
|
||||
m_names = LoadObject(stream, mod).require_cast<PycTuple>();
|
||||
}
|
||||
|
||||
if (mod->verCompare(1, 3) >= 0)
|
||||
m_varNames = LoadObject(stream, mod).require_cast<PycTuple>();
|
||||
|
||||
@@ -34,6 +34,20 @@ bool PycTuple::isEqual(PycRef<PycObject> obj) const
|
||||
return true;
|
||||
}
|
||||
|
||||
PycRef<PycTuple> PycTuple::fromList(const PycRef<PycList>& obj)
|
||||
{
|
||||
PycRef<PycTuple> tuple = new PycTuple;
|
||||
if (!tuple)
|
||||
return tuple;
|
||||
|
||||
tuple->m_values.reserve(obj->values().size());
|
||||
for (PycList::value_t::const_iterator it = obj->values().begin();
|
||||
it != obj->values().end(); ++it) {
|
||||
tuple->m_values.push_back(*it);
|
||||
}
|
||||
return tuple;
|
||||
}
|
||||
|
||||
|
||||
/* PycList */
|
||||
void PycList::load(PycData* stream, PycModule* mod)
|
||||
|
||||
@@ -30,6 +30,8 @@ public:
|
||||
const value_t& values() const { return m_values; }
|
||||
PycRef<PycObject> get(int idx) const { return m_values.at(idx); }
|
||||
|
||||
static PycRef<PycTuple> fromList(const PycRef<class PycList>& obj);
|
||||
|
||||
private:
|
||||
value_t m_values;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user