Skip to content

Commit d8c6fdf

Browse files
committed
Address comments
1 parent e8e10f1 commit d8c6fdf

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

bytecode.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -604,14 +604,14 @@ void bc_disasm(std::ostream& pyc_output, PycRef<PycCode> code, PycModule* mod,
604604
void bc_exceptiontable(std::ostream& pyc_output, PycRef<PycCode> code,
605605
int indent)
606606
{
607-
for (auto tuple: code->exceptTableEntries()) {
607+
for (const auto& entry : code->exceptionTableEntries()) {
608608

609609
for (int i=0; i<indent; i++)
610610
pyc_output << " ";
611611

612-
pyc_output << std::get<0>(tuple) << " to " << std::get<1>(tuple);
613-
pyc_output << " -> " << std::get<2>(tuple) << " ";
614-
pyc_output << "[" << std::get<3>(tuple) << "] " << (std::get<4>(tuple) ? "lasti": "");
615-
pyc_output << "\n";
612+
pyc_output << entry.start_offset << " to " << entry.end_offset
613+
<< " -> " << entry.target << " [" << entry.stack_depth
614+
<< "] " << (entry.push_lasti ? "lasti": "")
615+
<< "\n";
616616
}
617-
}
617+
}

pyc_code.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,23 +133,23 @@ int _parse_varint(PycBuffer& data, int& pos) {
133133
int b = data.getByte();
134134
pos += 1;
135135

136-
int val = b & 63;
137-
while (b & 64) {
136+
int val = b & 0x3F;
137+
while (b & 0x40) {
138138
val <<= 6;
139139

140140
b = data.getByte();
141141
pos += 1;
142142

143-
val |= (b & 63);
143+
val |= (b & 0x3F);
144144
}
145145
return val;
146146
}
147147

148-
std::vector<PycCode::exception_table_entry_t> PycCode::exceptTableEntries() const
148+
std::vector<PycExceptionTableEntry> PycCode::exceptionTableEntries() const
149149
{
150150
PycBuffer data(m_exceptTable->value(), m_exceptTable->length());
151151

152-
std::vector<exception_table_entry_t> entries;
152+
std::vector<PycExceptionTableEntry> entries;
153153

154154
int pos = 0;
155155
while (!data.atEof()) {
@@ -164,8 +164,8 @@ std::vector<PycCode::exception_table_entry_t> PycCode::exceptTableEntries() cons
164164
int depth = dl >> 1;
165165
bool lasti = bool(dl & 1);
166166

167-
entries.emplace_back(start, end, target, depth, lasti);
167+
entries.push_back(PycExceptionTableEntry(start, end, target, depth, lasti));
168168
}
169169

170170
return entries;
171-
}
171+
}

pyc_code.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@
88
class PycData;
99
class PycModule;
1010

11+
class PycExceptionTableEntry {
12+
public:
13+
int start_offset; // inclusive
14+
int end_offset; // exclusive
15+
int target;
16+
int stack_depth;
17+
bool push_lasti;
18+
19+
PycExceptionTableEntry(int m_start_offset, int m_end_offset, int m_target, int m_stack_depth, bool m_push_lasti) :
20+
start_offset(m_start_offset), end_offset(m_end_offset), target(m_target), stack_depth(m_stack_depth), push_lasti(m_push_lasti) {};
21+
};
22+
1123
class PycCode : public PycObject {
1224
public:
1325
typedef std::vector<PycRef<PycString>> globals_t;
@@ -87,9 +99,7 @@ class PycCode : public PycObject {
8799
m_globalsUsed.emplace_back(std::move(varname));
88100
}
89101

90-
typedef std::tuple<int, int, int, int, bool> exception_table_entry_t;
91-
92-
std::vector<exception_table_entry_t> exceptTableEntries() const;
102+
std::vector<PycExceptionTableEntry> exceptionTableEntries() const;
93103

94104
private:
95105
int m_argCount, m_posOnlyArgCount, m_kwOnlyArgCount, m_numLocals;

0 commit comments

Comments
 (0)