Kevin Howe said:
> This runs without errors, but returns a value of 68, with the "out" string
> remaining unchanged.

I corrected that as follows.

require 'dl/import'

module Tidylib
  extend DL::Importable

  dlload "libtidy.so"

  extern "void *tidyCreate()"
  extern "int tidyParseString(void*, char*)"
  extern "int tidyCleanAndRepair(void*)"
  extern "int tidySaveString(void*, char*, unsigned int ref)"
  extern "int tidySaveStdout(void*)"
  extern "int tidyRunDiagnostics(void*)"

  module_function

  def create()
    tidyCreate()
  end

  def parse_string(doc, str)
    tidyParseString(doc, str)
  end

  def clean_and_repair(doc)
    tidyCleanAndRepair(doc)
  end

  def save_string(doc)
    str = " " * 1024
    ret = tidySaveString(doc, str, str.size)
    len = @args[2]
    str = @args[1]
    str[0,len]
  end

  def save_stdout(doc)
    tidySaveStdout(doc)
  end

  def run_diagnostics(doc)
    tidyRunDiagnostics(doc)
  end
end

doc = Tidylib.create()
Tidylib.parse_string(doc, <<EOS)
<title></title>
EOS
Tidylib.clean_and_repair(doc)
Tidylib.run_diagnostics(doc)
puts Tidylib.save_string(doc)

-- 
Takaaki Tateishi <ttate / ttsky.net>