From 1806dda3461e14e17a025c7d238240d89ca9e91d Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Fri, 24 Jul 2009 23:19:46 +0000 Subject: [PATCH] Fix for old python versions --- code.h | 30 +++++++++++++++--------------- pycdas.cpp | 25 ++++++++++--------------- sequence.h | 46 +++++++++++++++++++++++++++++++--------------- 3 files changed, 56 insertions(+), 45 deletions(-) diff --git a/code.h b/code.h index b57afae..1099dff 100644 --- a/code.h +++ b/code.h @@ -21,39 +21,39 @@ public: int stackSize() const { return m_stackSize; } int flags() const { return m_flags; } PycRef code() const { return m_code; } - PycRef consts() const { return m_consts; } - PycRef names() const { return m_names; } - PycRef varNames() const { return m_varNames; } - PycRef freeVars() const { return m_freeVars; } - PycRef cellVars() const { return m_cellVars; } + PycRef consts() const { return m_consts; } + PycRef names() const { return m_names; } + PycRef varNames() const { return m_varNames; } + PycRef freeVars() const { return m_freeVars; } + PycRef cellVars() const { return m_cellVars; } PycRef fileName() const { return m_fileName; } PycRef name() const { return m_name; } int firstLine() const { return m_firstLine; } PycRef lnTable() const { return m_lnTable; } PycRef getConst(int idx) const - { return m_consts->values()[idx]; } + { return m_consts->get(idx); } PycRef getName(int idx) const - { return m_names->values()[idx].cast(); } + { return m_names->get(idx).cast(); } PycRef getVarName(int idx) const - { return m_varNames->values()[idx].cast(); } + { return m_varNames->get(idx).cast(); } PycRef getCellVar(int idx) const { - return (idx > m_cellVars->size()) ? m_freeVars->values()[idx - m_cellVars->size()] - : m_cellVars->values()[idx]; + return (idx > m_cellVars->size()) ? m_freeVars->get(idx - m_cellVars->size()) + : m_cellVars->get(idx); } private: int m_argCount, m_kwOnlyArgCount, m_numLocals, m_stackSize, m_flags; PycRef m_code; - PycRef m_consts; - PycRef m_names; - PycRef m_varNames; - PycRef m_freeVars; - PycRef m_cellVars; + PycRef m_consts; + PycRef m_names; + PycRef m_varNames; + PycRef m_freeVars; + PycRef m_cellVars; PycRef m_fileName; PycRef m_name; int m_firstLine; diff --git a/pycdas.cpp b/pycdas.cpp index ebb4ca0..4585800 100644 --- a/pycdas.cpp +++ b/pycdas.cpp @@ -34,29 +34,24 @@ void output_object(PycRef obj, PycModule* mod, int indent) iprintf(indent + 1, "Flags: 0x%08X\n", codeObj->flags()); iprintf(indent + 1, "[Names]\n"); - PycTuple::value_t names = codeObj->names()->values(); - for (PycTuple::value_t::iterator i = names.begin(); i != names.end(); i++) - output_object(*i, mod, indent + 2); + for (int i=0; inames()->size(); i++) + output_object(codeObj->names()->get(i), mod, indent + 2); iprintf(indent + 1, "[Var Names]\n"); - names = codeObj->varNames()->values(); - for (PycTuple::value_t::iterator i = names.begin(); i != names.end(); i++) - output_object(*i, mod, indent + 2); + for (int i=0; ivarNames()->size(); i++) + output_object(codeObj->varNames()->get(i), mod, indent + 2); iprintf(indent + 1, "[Free Vars]\n"); - names = codeObj->freeVars()->values(); - for (PycTuple::value_t::iterator i = names.begin(); i != names.end(); i++) - output_object(*i, mod, indent + 2); + for (int i=0; ifreeVars()->size(); i++) + output_object(codeObj->freeVars()->get(i), mod, indent + 2); iprintf(indent + 1, "[Cell Vars]\n"); - names = codeObj->cellVars()->values(); - for (PycTuple::value_t::iterator i = names.begin(); i != names.end(); i++) - output_object(*i, mod, indent + 2); + for (int i=0; icellVars()->size(); i++) + output_object(codeObj->cellVars()->get(i), mod, indent + 2); iprintf(indent + 1, "[Constants]\n"); - PycTuple::value_t consts = codeObj->consts()->values(); - for (PycTuple::value_t::iterator i = consts.begin(); i != consts.end(); i++) - output_object(*i, mod, indent + 2); + for (int i=0; iconsts()->size(); i++) + output_object(codeObj->consts()->get(i), mod, indent + 2); iprintf(indent + 1, "[Disassembly]\n"); bc_disasm(codeObj, mod, indent + 2); diff --git a/sequence.h b/sequence.h index 5d1994d..8e7662c 100644 --- a/sequence.h +++ b/sequence.h @@ -5,12 +5,22 @@ #include #include -class PycTuple : public PycObject { +class PycSequence : public PycObject { +public: + PycSequence(int type) : PycObject(type), m_size(0) { } + + int size() const { return m_size; } + virtual PycRef get(int idx) const = 0; + +protected: + int m_size; +}; + +class PycTuple : public PycSequence { public: typedef std::vector > value_t; - PycTuple(int type = TYPE_TUPLE) - : PycObject(type), m_size(0) { } + PycTuple(int type = TYPE_TUPLE) : PycSequence(type) { } bool isType(int type) const { return (type == TYPE_TUPLE) || PycObject::isType(type); } @@ -19,20 +29,18 @@ public: void load(class PycData* stream, class PycModule* mod); - int size() const { return m_size; } value_t values() const { return m_values; } + PycRef get(int idx) const { return m_values[idx]; } private: - int m_size; value_t m_values; }; -class PycList : public PycObject { +class PycList : public PycSequence { public: typedef std::list > value_t; - PycList(int type = TYPE_LIST) - : PycObject(type), m_size(0) { } + PycList(int type = TYPE_LIST) : PycSequence(type) { } bool isType(int type) const { return (type == TYPE_LIST) || PycObject::isType(type); } @@ -41,21 +49,24 @@ public: void load(class PycData* stream, class PycModule* mod); - int size() const { return m_size; } value_t values() const { return m_values; } + PycRef get(int idx) const + { + value_t::const_iterator it = m_values.begin(); + for (int i=0; i > key_t; typedef std::list > value_t; - PycDict(int type = TYPE_DICT) - : PycObject(type), m_size(0) { } + PycDict(int type = TYPE_DICT) : PycSequence(type) { } bool isType(int type) const { return (type == TYPE_DICT) || PycObject::isType(type); } @@ -64,13 +75,18 @@ public: void load(class PycData* stream, class PycModule* mod); - int size() const { return m_size; } PycRef get(PycRef key) const; key_t keys() const { return m_keys; } value_t values() const { return m_values; } + PycRef get(int idx) const + { + value_t::const_iterator it = m_values.begin(); + for (int i=0; i