Merge remote-tracking branch 'jjyg/master'

develop
Kelly Martin 2012-10-12 20:33:07 -05:00
commit 0003fe0b2a
3 changed files with 64 additions and 16 deletions

@ -232,7 +232,11 @@ sub render_global_class {
render_struct_fields($type); render_struct_fields($type);
my $vms = $type->findnodes('child::virtual-methods')->[0]; my $vms = $type->findnodes('child::virtual-methods')->[0];
render_class_vmethods($vms) if $vms; if ($vms)
{
my $voff = render_class_vmethods_voff($parent);
render_class_vmethods($vms, $voff);
}
}; };
push @lines_rb, "end\n"; push @lines_rb, "end\n";
} }
@ -275,7 +279,6 @@ sub render_struct_field_refs {
my ($parent, $field, $name) = @_; my ($parent, $field, $name) = @_;
my $reftg = $field->getAttribute('ref-target'); my $reftg = $field->getAttribute('ref-target');
render_field_reftarget($parent, $field, $name, $reftg) if ($reftg);
my $refto = $field->getAttribute('refers-to'); my $refto = $field->getAttribute('refers-to');
render_field_refto($parent, $name, $refto) if ($refto); render_field_refto($parent, $name, $refto) if ($refto);
@ -285,6 +288,8 @@ sub render_struct_field_refs {
if ($meta and $meta eq 'container' and $item) { if ($meta and $meta eq 'container' and $item) {
my $itemreftg = $item->getAttribute('ref-target'); my $itemreftg = $item->getAttribute('ref-target');
render_container_reftarget($parent, $item, $name, $itemreftg) if $itemreftg; render_container_reftarget($parent, $item, $name, $itemreftg) if $itemreftg;
} elsif ($reftg) {
render_field_reftarget($parent, $field, $name, $reftg);
} }
} }
@ -368,9 +373,29 @@ sub render_container_reftarget {
} }
} }
# return the size of the parent's vtables
sub render_class_vmethods_voff {
my ($name) = @_;
return 0 if !$name;
my $type = $global_types{$name};
my $parent = $type->getAttribute('inherits-from');
my $voff = render_class_vmethods_voff($parent);
my $vms = $type->findnodes('child::virtual-methods')->[0];
for my $meth ($vms->findnodes('child::vmethod'))
{
$voff += 4 if $meth->getAttribute('is-destructor') and $os eq 'linux';
$voff += 4;
}
return $voff;
}
sub render_class_vmethods { sub render_class_vmethods {
my ($vms) = @_; my ($vms, $voff) = @_;
my $voff = 0;
for my $meth ($vms->findnodes('child::vmethod')) for my $meth ($vms->findnodes('child::vmethod'))
{ {

@ -282,6 +282,10 @@ module DFHack
DFHack.memory_read_int32(@_memaddr) & 0xffffffff DFHack.memory_read_int32(@_memaddr) & 0xffffffff
end end
def _setp(v)
DFHack.memory_write_int32(@_memaddr, v)
end
def _get def _get
addr = _getp addr = _getp
return if addr == 0 return if addr == 0
@ -294,7 +298,15 @@ module DFHack
case v case v
when Pointer; DFHack.memory_write_int32(@_memaddr, v._getp) when Pointer; DFHack.memory_write_int32(@_memaddr, v._getp)
when MemStruct; DFHack.memory_write_int32(@_memaddr, v._memaddr) when MemStruct; DFHack.memory_write_int32(@_memaddr, v._memaddr)
when Integer; DFHack.memory_write_int32(@_memaddr, v) when Integer
if @_tg and @_tg.kind_of?(MemHack::Number)
if _getp == 0
_setp(DFHack.malloc(@_tg._bits/8))
end
@_tg._at(_getp)._set(v)
else
DFHack.memory_write_int32(@_memaddr, v)
end
when nil; DFHack.memory_write_int32(@_memaddr, 0) when nil; DFHack.memory_write_int32(@_memaddr, 0)
else _get._set(v) else _get._set(v)
end end

@ -118,18 +118,8 @@ DFhackCExport command_result plugin_shutdown ( color_ostream &out )
return CR_OK; return CR_OK;
} }
// send a single ruby line to be evaluated by the ruby thread static command_result do_plugin_eval_ruby(color_ostream &out, const char *command)
DFhackCExport command_result plugin_eval_ruby( color_ostream &out, const char *command)
{ {
// if dlopen failed
if (!r_thread)
return CR_FAILURE;
// wrap all ruby code inside a suspend block
// if we dont do that and rely on ruby code doing it, we'll deadlock in
// onupdate
CoreSuspender suspend;
command_result ret; command_result ret;
// ensure ruby thread is idle // ensure ruby thread is idle
@ -159,6 +149,27 @@ DFhackCExport command_result plugin_eval_ruby( color_ostream &out, const char *c
return ret; return ret;
} }
// send a single ruby line to be evaluated by the ruby thread
DFhackCExport command_result plugin_eval_ruby( color_ostream &out, const char *command)
{
// if dlopen failed
if (!r_thread)
return CR_FAILURE;
if (!strncmp(command, "nolock ", 7)) {
// debug only!
// run ruby commands without locking the main thread
// useful when the game is frozen after a segfault
return do_plugin_eval_ruby(out, command+7);
} else {
// wrap all ruby code inside a suspend block
// if we dont do that and rely on ruby code doing it, we'll deadlock in
// onupdate
CoreSuspender suspend;
return do_plugin_eval_ruby(out, command);
}
}
DFhackCExport command_result plugin_onupdate ( color_ostream &out ) DFhackCExport command_result plugin_onupdate ( color_ostream &out )
{ {
if (!r_thread) if (!r_thread)