Skip to content

Commit

Permalink
Fix PycCode incompatibility with Python 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zrax committed Apr 26, 2018
1 parent 0c39558 commit 7f63529
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pyc_code.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
Expand Down
14 changes: 14 additions & 0 deletions pyc_sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions pyc_sequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class PycTuple : public PycSequence {
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;
};
Expand Down

0 comments on commit 7f63529

Please sign in to comment.