Fix access to unnamed bits in bitfields, and allow hook.apply(false)

develop
Alexander Gavrilov 2012-09-01 11:25:24 +04:00
parent c68afdaad2
commit e0097d8d43
4 changed files with 11 additions and 5 deletions

@ -374,7 +374,7 @@ void DFHack::bitfieldToString(std::vector<std::string> *pvec, const void *p,
unsigned size, const bitfield_item_info *items) unsigned size, const bitfield_item_info *items)
{ {
for (unsigned i = 0; i < size; i++) { for (unsigned i = 0; i < size; i++) {
int value = getBitfieldField(p, i, std::min(1,items[i].size)); int value = getBitfieldField(p, i, std::max(1,items[i].size));
if (value) { if (value) {
std::string name = format_key(items[i].name, i); std::string name = format_key(items[i].name, i);

@ -894,7 +894,7 @@ static int meta_bitfield_len(lua_State *state)
static void read_bitfield(lua_State *state, uint8_t *ptr, bitfield_identity *id, int idx) static void read_bitfield(lua_State *state, uint8_t *ptr, bitfield_identity *id, int idx)
{ {
int size = id->getBits()[idx].size; int size = std::max(1, id->getBits()[idx].size);
int value = getBitfieldField(ptr, idx, size); int value = getBitfieldField(ptr, idx, size);
if (size <= 1) if (size <= 1)
@ -951,7 +951,7 @@ static int meta_bitfield_newindex(lua_State *state)
} }
int idx = check_container_index(state, id->getNumBits(), 2, iidx, "write"); int idx = check_container_index(state, id->getNumBits(), 2, iidx, "write");
int size = id->getBits()[idx].size; int size = std::max(1, id->getBits()[idx].size);
if (lua_isboolean(state, 3) || lua_isnil(state, 3)) if (lua_isboolean(state, 3) || lua_isnil(state, 3))
setBitfieldField(ptr, idx, size, lua_toboolean(state, 3)); setBitfieldField(ptr, idx, size, lua_toboolean(state, 3));

@ -335,8 +335,14 @@ void VMethodInterposeLinkBase::on_host_delete(virtual_identity *from)
} }
} }
bool VMethodInterposeLinkBase::apply() bool VMethodInterposeLinkBase::apply(bool enable)
{ {
if (!enable)
{
remove();
return true;
}
if (is_applied()) if (is_applied())
return true; return true;
if (!host->vtable_ptr) if (!host->vtable_ptr)

@ -159,7 +159,7 @@ namespace DFHack
~VMethodInterposeLinkBase(); ~VMethodInterposeLinkBase();
bool is_applied() { return applied; } bool is_applied() { return applied; }
bool apply(); bool apply(bool enable = true);
void remove(); void remove();
}; };