зеркало из https://github.com/github/ruby.git
* ext/dl/handle.c (rb_dlhandle_sym) removing unnecessary code. Adding
documentation and tests for current functionality. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25459 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
a631b5df36
Коммит
c30de1e38e
|
@ -205,16 +205,21 @@ rb_dlhandle_to_i(VALUE self)
|
||||||
|
|
||||||
static VALUE dlhandle_sym(void *handle, const char *symbol);
|
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
|
VALUE
|
||||||
rb_dlhandle_sym(VALUE self, VALUE sym)
|
rb_dlhandle_sym(VALUE self, VALUE sym)
|
||||||
{
|
{
|
||||||
struct dl_handle *dlhandle;
|
struct dl_handle *dlhandle;
|
||||||
const char *name;
|
|
||||||
|
|
||||||
rb_secure(2);
|
rb_secure(2);
|
||||||
|
|
||||||
name = StringValuePtr(sym);
|
|
||||||
|
|
||||||
TypedData_Get_Struct(self, struct dl_handle, &dlhandle_data_type, dlhandle);
|
TypedData_Get_Struct(self, struct dl_handle, &dlhandle_data_type, dlhandle);
|
||||||
if( ! dlhandle->open ){
|
if( ! dlhandle->open ){
|
||||||
rb_raise(rb_eDLError, "closed handle");
|
rb_raise(rb_eDLError, "closed handle");
|
||||||
|
|
|
@ -2,6 +2,31 @@ require 'test_base'
|
||||||
|
|
||||||
module DL
|
module DL
|
||||||
class TestHandle < TestBase
|
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
|
def test_handle_close
|
||||||
handle = DL::Handle.new(LIBC_SO)
|
handle = DL::Handle.new(LIBC_SO)
|
||||||
assert_equal 0, handle.close
|
assert_equal 0, handle.close
|
||||||
|
|
Загрузка…
Ссылка в новой задаче