[前][次][番号順一覧][スレッド一覧]

ruby-changes:13674

From: tenderlove <ko1@a...>
Date: Sun, 25 Oct 2009 09:11:28 +0900 (JST)
Subject: [ruby-changes:13674] Ruby:r25459 (trunk): * ext/dl/handle.c (rb_dlhandle_sym) removing unnecessary code. Adding

tenderlove	2009-10-25 09:11:02 +0900 (Sun, 25 Oct 2009)

  New Revision: 25459

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=25459

  Log:
    * ext/dl/handle.c (rb_dlhandle_sym) removing unnecessary code. Adding
      documentation and tests for current functionality.

  Modified files:
    trunk/ext/dl/handle.c
    trunk/test/dl/test_handle.rb

Index: ext/dl/handle.c
===================================================================
--- ext/dl/handle.c	(revision 25458)
+++ ext/dl/handle.c	(revision 25459)
@@ -205,16 +205,21 @@
 
 static VALUE dlhandle_sym(void *handle, const char *symbol);
 
+/*
+ * Document-method: sym
+ * Document-method: []
+ *
+ * call-seq: sym(name)
+ *
+ * Get the address as an Integer for the function named +name+.
+ */
 VALUE
 rb_dlhandle_sym(VALUE self, VALUE sym)
 {
     struct dl_handle *dlhandle;
-    const char *name;
 
     rb_secure(2);
 
-    name = StringValuePtr(sym);
-
     TypedData_Get_Struct(self, struct dl_handle, &dlhandle_data_type, dlhandle);
     if( ! dlhandle->open ){
 	rb_raise(rb_eDLError, "closed handle");
Index: test/dl/test_handle.rb
===================================================================
--- test/dl/test_handle.rb	(revision 25458)
+++ test/dl/test_handle.rb	(revision 25459)
@@ -2,6 +2,31 @@
 
 module DL
   class TestHandle < TestBase
+    def test_sym_closed_handle
+      handle = DL::Handle.new(LIBC_SO)
+      handle.close
+      assert_raises(DL::DLError) { handle.sym("calloc") }
+      assert_raises(DL::DLError) { handle["calloc"] }
+    end
+
+    def test_sym_unknown
+      handle = DL::Handle.new(LIBC_SO)
+      assert_raises(DL::DLError) { handle.sym('fooo') }
+      assert_raises(DL::DLError) { handle['fooo'] }
+    end
+
+    def test_sym_with_bad_args
+      handle = DL::Handle.new(LIBC_SO)
+      assert_raises(TypeError) { handle.sym(nil) }
+      assert_raises(TypeError) { handle[nil] }
+    end
+
+    def test_sym
+      handle = DL::Handle.new(LIBC_SO)
+      assert handle.sym('calloc')
+      assert handle['calloc']
+    end
+
     def test_handle_close
       handle = DL::Handle.new(LIBC_SO)
       assert_equal 0, handle.close

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]