From 424c37c0ea23cd9fb822ce61a3964e16502478f8 Mon Sep 17 00:00:00 2001 From: jj Date: Thu, 11 Oct 2012 17:51:49 +0200 Subject: [PATCH 1/5] ruby: fix codegen to handle composite vtables --- plugins/ruby/codegen.pl | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/plugins/ruby/codegen.pl b/plugins/ruby/codegen.pl index a615ab964..8dae55597 100755 --- a/plugins/ruby/codegen.pl +++ b/plugins/ruby/codegen.pl @@ -232,7 +232,11 @@ sub render_global_class { render_struct_fields($type); 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"; } @@ -368,9 +372,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 { - my ($vms) = @_; - my $voff = 0; + my ($vms, $voff) = @_; for my $meth ($vms->findnodes('child::vmethod')) { From 0547ee7f831e9e10442ea52bbe0ebfeb344f9f90 Mon Sep 17 00:00:00 2001 From: jj Date: Fri, 12 Oct 2012 11:12:31 +0200 Subject: [PATCH 2/5] ruby: add magic "nolock " prefix to run ruby without Suspending main df --- plugins/ruby/ruby.cpp | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/plugins/ruby/ruby.cpp b/plugins/ruby/ruby.cpp index 7bd6d13e8..13190f70d 100644 --- a/plugins/ruby/ruby.cpp +++ b/plugins/ruby/ruby.cpp @@ -118,18 +118,8 @@ DFhackCExport command_result plugin_shutdown ( color_ostream &out ) return CR_OK; } -// send a single ruby line to be evaluated by the ruby thread -DFhackCExport command_result plugin_eval_ruby( color_ostream &out, const char *command) +static command_result do_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; // ensure ruby thread is idle @@ -159,6 +149,27 @@ DFhackCExport command_result plugin_eval_ruby( color_ostream &out, const char *c 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 ) { if (!r_thread) From 1f88c0eeed1999a252b0b3f0dd40252a7b983f99 Mon Sep 17 00:00:00 2001 From: jj Date: Fri, 12 Oct 2012 11:42:42 +0200 Subject: [PATCH 3/5] ruby: codegen: avoid bad vector_reftg accessor --- plugins/ruby/codegen.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/ruby/codegen.pl b/plugins/ruby/codegen.pl index 8dae55597..ff69853af 100755 --- a/plugins/ruby/codegen.pl +++ b/plugins/ruby/codegen.pl @@ -279,7 +279,6 @@ sub render_struct_field_refs { my ($parent, $field, $name) = @_; my $reftg = $field->getAttribute('ref-target'); - render_field_reftarget($parent, $field, $name, $reftg) if ($reftg); my $refto = $field->getAttribute('refers-to'); render_field_refto($parent, $name, $refto) if ($refto); @@ -289,6 +288,8 @@ sub render_struct_field_refs { if ($meta and $meta eq 'container' and $item) { my $itemreftg = $item->getAttribute('ref-target'); render_container_reftarget($parent, $item, $name, $itemreftg) if $itemreftg; + } elsif ($reftg) { + render_field_reftarget($parent, $field, $name, $reftg); } } From c089534f7315190b6df7d6ce6390b99fc3adc6b0 Mon Sep 17 00:00:00 2001 From: jj Date: Fri, 12 Oct 2012 13:33:58 +0200 Subject: [PATCH 4/5] ruby: fix assigning value to pointer to number --- plugins/ruby/ruby-autogen-defs.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/plugins/ruby/ruby-autogen-defs.rb b/plugins/ruby/ruby-autogen-defs.rb index 4470c8022..d5bcb08f4 100644 --- a/plugins/ruby/ruby-autogen-defs.rb +++ b/plugins/ruby/ruby-autogen-defs.rb @@ -282,6 +282,10 @@ module DFHack DFHack.memory_read_int32(@_memaddr) & 0xffffffff end + def _setp(v) + DFHack.memory_write_int32(@_memaddr, v) + end + def _get addr = _getp return if addr == 0 @@ -294,7 +298,15 @@ module DFHack case v when Pointer; DFHack.memory_write_int32(@_memaddr, v._getp) 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) else _get._set(v) end From 8fd1dd04bb72eecb8056f9b262a10e828c639bdd Mon Sep 17 00:00:00 2001 From: Kelly Martin Date: Tue, 16 Oct 2012 19:27:48 -0500 Subject: [PATCH 5/5] Display dfhack version number at end of baseline 'help' message. --- library/Core.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/Core.cpp b/library/Core.cpp index a8000070f..7766b3591 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -374,6 +374,8 @@ command_result Core::runCommand(color_ostream &con, const std::string &first, ve " unload PLUGIN|all - Unload a plugin or all loaded plugins.\n" " reload PLUGIN|all - Reload a plugin or all loaded plugins.\n" ); + + con.print("\nDFHack version " DFHACK_VERSION ".\n"); } else if (parts.size() == 1) {