ruby-changes:16560
From: tenderlove <ko1@a...>
Date: Tue, 6 Jul 2010 08:38:53 +0900 (JST)
Subject: [ruby-changes:16560] Ruby:r28552 (trunk): * ext/dl/lib/dl/import.rb (handler): add a more helpful error message
tenderlove 2010-07-06 08:38:35 +0900 (Tue, 06 Jul 2010) New Revision: 28552 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=28552 Log: * ext/dl/lib/dl/import.rb (handler): add a more helpful error message when calling import_symbol or import_function without calling dlload. Thanks nobu! [ruby-core:30996] Modified files: trunk/ChangeLog trunk/ext/dl/lib/dl/import.rb trunk/test/dl/test_import.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 28551) +++ ChangeLog (revision 28552) @@ -1,3 +1,9 @@ +Tue Jul 6 08:35:58 2010 Aaron Patterson <aaron@t...> + + * ext/dl/lib/dl/import.rb (handler): add a more helpful error message + when calling import_symbol or import_function without calling + dlload. Thanks nobu! [ruby-core:30996] + Tue Jul 6 00:34:50 2010 Yusuke Endoh <mame@t...> * vm.c (thread_free): free altstack to prevent memory leak. a patch Index: ext/dl/lib/dl/import.rb =================================================================== --- ext/dl/lib/dl/import.rb (revision 28551) +++ ext/dl/lib/dl/import.rb (revision 28552) @@ -194,8 +194,12 @@ return ptr end + def handler + @handler or raise "call dlload before importing symbols and functions" + end + def import_symbol(name) - addr = @handler.sym(name) + addr = handler.sym(name) if( !addr ) raise(DLError, "cannot find the symbol: #{name}") end @@ -203,7 +207,7 @@ end def import_function(name, ctype, argtype, call_type = nil) - addr = @handler.sym(name) + addr = handler.sym(name) if( !addr ) raise(DLError, "cannot find the function: #{name}()") end Index: test/dl/test_import.rb =================================================================== --- test/dl/test_import.rb (revision 28551) +++ test/dl/test_import.rb (revision 28552) @@ -41,6 +41,15 @@ end class TestImport < TestBase + def test_ensure_call_dlload + err = assert_raises(RuntimeError) do + Class.new do + extend DL::Importer + extern "void *strcpy(char*, char*)" + end + end + end + def test_malloc() s1 = LIBC::Timeval.malloc() s2 = LIBC::Timeval.malloc() -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/