2005-02-04 16:35:37 +03:00
|
|
|
/* -*- C -*-
|
|
|
|
* $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <ruby.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include "dl.h"
|
|
|
|
|
|
|
|
VALUE rb_cDLCFunc;
|
|
|
|
|
|
|
|
static ID id_last_error;
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_dl_get_last_error(VALUE self)
|
|
|
|
{
|
|
|
|
return rb_thread_local_aref(rb_thread_current(), id_last_error);
|
|
|
|
}
|
|
|
|
|
2010-02-26 01:49:20 +03:00
|
|
|
static VALUE
|
2005-02-04 16:35:37 +03:00
|
|
|
rb_dl_set_last_error(VALUE self, VALUE val)
|
|
|
|
{
|
|
|
|
rb_thread_local_aset(rb_thread_current(), id_last_error, val);
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2011-01-05 06:13:18 +03:00
|
|
|
#if defined(_WIN32)
|
2005-02-04 16:35:37 +03:00
|
|
|
#include <windows.h>
|
|
|
|
static ID id_win32_last_error;
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_dl_get_win32_last_error(VALUE self)
|
|
|
|
{
|
|
|
|
return rb_thread_local_aref(rb_thread_current(), id_win32_last_error);
|
|
|
|
}
|
|
|
|
|
2010-02-26 01:49:20 +03:00
|
|
|
static VALUE
|
2005-02-04 16:35:37 +03:00
|
|
|
rb_dl_set_win32_last_error(VALUE self, VALUE val)
|
|
|
|
{
|
|
|
|
rb_thread_local_aset(rb_thread_current(), id_win32_last_error, val);
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-07-27 21:15:09 +04:00
|
|
|
static void
|
|
|
|
dlcfunc_mark(void *ptr)
|
|
|
|
{
|
|
|
|
struct cfunc_data *data = ptr;
|
|
|
|
if (data->wrap) {
|
|
|
|
rb_gc_mark(data->wrap);
|
|
|
|
}
|
|
|
|
}
|
2005-02-04 16:35:37 +03:00
|
|
|
|
2009-09-09 16:19:28 +04:00
|
|
|
static void
|
2009-05-10 06:13:20 +04:00
|
|
|
dlcfunc_free(void *ptr)
|
2005-02-04 16:35:37 +03:00
|
|
|
{
|
2009-05-10 06:13:20 +04:00
|
|
|
struct cfunc_data *data = ptr;
|
2009-03-17 04:15:35 +03:00
|
|
|
if( data->name ){
|
|
|
|
xfree(data->name);
|
|
|
|
}
|
|
|
|
xfree(data);
|
2005-02-04 16:35:37 +03:00
|
|
|
}
|
|
|
|
|
2009-09-09 16:19:28 +04:00
|
|
|
static size_t
|
|
|
|
dlcfunc_memsize(const void *ptr)
|
|
|
|
{
|
|
|
|
const struct cfunc_data *data = ptr;
|
|
|
|
size_t size = 0;
|
|
|
|
if( data ){
|
|
|
|
size += sizeof(*data);
|
|
|
|
if( data->name ){
|
|
|
|
size += strlen(data->name) + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
const rb_data_type_t dlcfunc_data_type = {
|
|
|
|
"dl/cfunc",
|
2011-07-27 21:15:09 +04:00
|
|
|
{dlcfunc_mark, dlcfunc_free, dlcfunc_memsize,},
|
2009-09-09 16:19:28 +04:00
|
|
|
};
|
|
|
|
|
2005-02-04 16:35:37 +03:00
|
|
|
VALUE
|
|
|
|
rb_dlcfunc_new(void (*func)(), int type, const char *name, ID calltype)
|
|
|
|
{
|
2009-03-17 04:15:35 +03:00
|
|
|
VALUE val;
|
|
|
|
struct cfunc_data *data;
|
|
|
|
|
|
|
|
rb_secure(4);
|
|
|
|
if( func ){
|
2009-09-09 16:19:28 +04:00
|
|
|
val = TypedData_Make_Struct(rb_cDLCFunc, struct cfunc_data, &dlcfunc_data_type, data);
|
2010-05-21 13:10:23 +04:00
|
|
|
data->ptr = (void *)(VALUE)func;
|
2009-03-17 04:15:35 +03:00
|
|
|
data->name = name ? strdup(name) : NULL;
|
|
|
|
data->type = type;
|
|
|
|
data->calltype = calltype;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
val = Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
2005-02-04 16:35:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
rb_dlcfunc2ptr(VALUE val)
|
|
|
|
{
|
2009-03-17 04:15:35 +03:00
|
|
|
struct cfunc_data *data;
|
|
|
|
void * func;
|
|
|
|
|
2009-09-09 16:19:28 +04:00
|
|
|
if( rb_typeddata_is_kind_of(val, &dlcfunc_data_type) ){
|
|
|
|
data = DATA_PTR(val);
|
2009-03-17 04:15:35 +03:00
|
|
|
func = data->ptr;
|
|
|
|
}
|
|
|
|
else if( val == Qnil ){
|
|
|
|
func = NULL;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
rb_raise(rb_eTypeError, "DL::CFunc was expected");
|
|
|
|
}
|
|
|
|
|
|
|
|
return func;
|
2005-02-04 16:35:37 +03:00
|
|
|
}
|
|
|
|
|
2009-11-08 03:21:41 +03:00
|
|
|
static VALUE
|
2005-02-04 16:35:37 +03:00
|
|
|
rb_dlcfunc_s_allocate(VALUE klass)
|
|
|
|
{
|
2009-03-17 04:15:35 +03:00
|
|
|
VALUE obj;
|
|
|
|
struct cfunc_data *data;
|
2005-02-04 16:35:37 +03:00
|
|
|
|
2009-09-09 16:19:28 +04:00
|
|
|
obj = TypedData_Make_Struct(klass, struct cfunc_data, &dlcfunc_data_type, data);
|
2009-03-17 04:15:35 +03:00
|
|
|
data->ptr = 0;
|
|
|
|
data->name = 0;
|
|
|
|
data->type = 0;
|
|
|
|
data->calltype = CFUNC_CDECL;
|
2005-02-04 16:35:37 +03:00
|
|
|
|
2009-03-17 04:15:35 +03:00
|
|
|
return obj;
|
2005-02-04 16:35:37 +03:00
|
|
|
}
|
|
|
|
|
2009-05-10 06:13:20 +04:00
|
|
|
int
|
|
|
|
rb_dlcfunc_kind_p(VALUE func)
|
|
|
|
{
|
2009-09-09 16:19:28 +04:00
|
|
|
return rb_typeddata_is_kind_of(func, &dlcfunc_data_type);
|
2009-05-10 06:13:20 +04:00
|
|
|
}
|
|
|
|
|
2009-11-07 01:50:40 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* DL::CFunc.new(address, type=DL::TYPE_VOID, name=nil, calltype=:cdecl)
|
|
|
|
*
|
|
|
|
* Create a new function that points to +address+ with an optional return type
|
|
|
|
* of +type+, a name of +name+ and a calltype of +calltype+.
|
|
|
|
*/
|
|
|
|
static VALUE
|
2005-02-04 16:35:37 +03:00
|
|
|
rb_dlcfunc_initialize(int argc, VALUE argv[], VALUE self)
|
|
|
|
{
|
2011-07-27 21:15:09 +04:00
|
|
|
VALUE addr, name, type, calltype, addrnum;
|
2005-02-04 16:35:37 +03:00
|
|
|
struct cfunc_data *data;
|
|
|
|
void *saddr;
|
|
|
|
const char *sname;
|
2010-04-22 12:04:13 +04:00
|
|
|
|
2005-02-04 16:35:37 +03:00
|
|
|
rb_scan_args(argc, argv, "13", &addr, &type, &name, &calltype);
|
2010-04-22 12:04:13 +04:00
|
|
|
|
2011-07-27 21:15:09 +04:00
|
|
|
addrnum = rb_Integer(addr);
|
|
|
|
saddr = (void*)(NUM2PTR(addrnum));
|
2005-02-04 16:35:37 +03:00
|
|
|
sname = NIL_P(name) ? NULL : StringValuePtr(name);
|
2010-04-22 12:04:13 +04:00
|
|
|
|
2009-09-09 16:19:28 +04:00
|
|
|
TypedData_Get_Struct(self, struct cfunc_data, &dlcfunc_data_type, data);
|
2005-02-04 16:35:37 +03:00
|
|
|
if( data->name ) xfree(data->name);
|
|
|
|
data->ptr = saddr;
|
|
|
|
data->name = sname ? strdup(sname) : 0;
|
2009-11-07 01:50:40 +03:00
|
|
|
data->type = NIL_P(type) ? DLTYPE_VOID : NUM2INT(type);
|
|
|
|
data->calltype = NIL_P(calltype) ? CFUNC_CDECL : SYM2ID(calltype);
|
2011-07-27 21:15:09 +04:00
|
|
|
data->wrap = (addrnum == addr) ? 0 : addr;
|
2005-02-04 16:35:37 +03:00
|
|
|
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2009-11-07 01:50:40 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* name => str
|
|
|
|
*
|
|
|
|
* Get the name of this function
|
|
|
|
*/
|
|
|
|
static VALUE
|
2005-02-04 16:35:37 +03:00
|
|
|
rb_dlcfunc_name(VALUE self)
|
|
|
|
{
|
|
|
|
struct cfunc_data *cfunc;
|
|
|
|
|
2009-09-09 16:19:28 +04:00
|
|
|
TypedData_Get_Struct(self, struct cfunc_data, &dlcfunc_data_type, cfunc);
|
2005-02-04 16:35:37 +03:00
|
|
|
return cfunc->name ? rb_tainted_str_new2(cfunc->name) : Qnil;
|
|
|
|
}
|
|
|
|
|
2009-11-07 01:50:40 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* cfunc.ctype => num
|
|
|
|
*
|
|
|
|
* Get the C function return value type. See DL for a list of constants
|
|
|
|
* corresponding to this method's return value.
|
|
|
|
*/
|
|
|
|
static VALUE
|
2005-02-04 16:35:37 +03:00
|
|
|
rb_dlcfunc_ctype(VALUE self)
|
|
|
|
{
|
|
|
|
struct cfunc_data *cfunc;
|
|
|
|
|
2009-09-09 16:19:28 +04:00
|
|
|
TypedData_Get_Struct(self, struct cfunc_data, &dlcfunc_data_type, cfunc);
|
2005-02-04 16:35:37 +03:00
|
|
|
return INT2NUM(cfunc->type);
|
|
|
|
}
|
|
|
|
|
2009-11-07 01:50:40 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* cfunc.ctype = type
|
|
|
|
*
|
|
|
|
* Set the C function return value type to +type+.
|
|
|
|
*/
|
|
|
|
static VALUE
|
2005-02-04 16:35:37 +03:00
|
|
|
rb_dlcfunc_set_ctype(VALUE self, VALUE ctype)
|
|
|
|
{
|
|
|
|
struct cfunc_data *cfunc;
|
|
|
|
|
2009-09-09 16:19:28 +04:00
|
|
|
TypedData_Get_Struct(self, struct cfunc_data, &dlcfunc_data_type, cfunc);
|
2005-02-04 16:35:37 +03:00
|
|
|
cfunc->type = NUM2INT(ctype);
|
|
|
|
return ctype;
|
|
|
|
}
|
|
|
|
|
2009-11-07 01:50:40 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* cfunc.calltype => symbol
|
|
|
|
*
|
|
|
|
* Get the call type of this function.
|
|
|
|
*/
|
|
|
|
static VALUE
|
2005-02-04 16:35:37 +03:00
|
|
|
rb_dlcfunc_calltype(VALUE self)
|
|
|
|
{
|
|
|
|
struct cfunc_data *cfunc;
|
|
|
|
|
2009-09-09 16:19:28 +04:00
|
|
|
TypedData_Get_Struct(self, struct cfunc_data, &dlcfunc_data_type, cfunc);
|
2005-02-04 16:35:37 +03:00
|
|
|
return ID2SYM(cfunc->calltype);
|
|
|
|
}
|
|
|
|
|
2009-11-07 01:50:40 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* cfunc.calltype = symbol
|
|
|
|
*
|
|
|
|
* Set the call type for this function.
|
|
|
|
*/
|
|
|
|
static VALUE
|
2005-02-04 16:35:37 +03:00
|
|
|
rb_dlcfunc_set_calltype(VALUE self, VALUE sym)
|
|
|
|
{
|
|
|
|
struct cfunc_data *cfunc;
|
|
|
|
|
2009-09-09 16:19:28 +04:00
|
|
|
TypedData_Get_Struct(self, struct cfunc_data, &dlcfunc_data_type, cfunc);
|
2005-02-04 16:35:37 +03:00
|
|
|
cfunc->calltype = SYM2ID(sym);
|
|
|
|
return sym;
|
|
|
|
}
|
|
|
|
|
2009-11-08 03:21:41 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* cfunc.ptr
|
|
|
|
*
|
|
|
|
* Get the underlying function pointer as a DL::CPtr object.
|
|
|
|
*/
|
|
|
|
static VALUE
|
2005-02-04 16:35:37 +03:00
|
|
|
rb_dlcfunc_ptr(VALUE self)
|
|
|
|
{
|
|
|
|
struct cfunc_data *cfunc;
|
|
|
|
|
2009-09-09 16:19:28 +04:00
|
|
|
TypedData_Get_Struct(self, struct cfunc_data, &dlcfunc_data_type, cfunc);
|
2005-02-04 16:35:37 +03:00
|
|
|
return PTR2NUM(cfunc->ptr);
|
|
|
|
}
|
|
|
|
|
2009-11-08 03:21:41 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* cfunc.ptr = pointer
|
|
|
|
*
|
|
|
|
* Set the underlying function pointer to a DL::CPtr named +pointer+.
|
|
|
|
*/
|
|
|
|
static VALUE
|
2005-02-04 16:35:37 +03:00
|
|
|
rb_dlcfunc_set_ptr(VALUE self, VALUE addr)
|
|
|
|
{
|
|
|
|
struct cfunc_data *cfunc;
|
|
|
|
|
2009-09-09 16:19:28 +04:00
|
|
|
TypedData_Get_Struct(self, struct cfunc_data, &dlcfunc_data_type, cfunc);
|
2005-02-04 16:35:37 +03:00
|
|
|
cfunc->ptr = NUM2PTR(addr);
|
|
|
|
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2009-11-08 03:21:41 +03:00
|
|
|
/*
|
|
|
|
* call-seq: inspect
|
|
|
|
*
|
|
|
|
* Returns a string formatted with an easily readable representation of the
|
|
|
|
* internal state of the DL::CFunc
|
|
|
|
*/
|
|
|
|
static VALUE
|
2005-02-04 16:35:37 +03:00
|
|
|
rb_dlcfunc_inspect(VALUE self)
|
|
|
|
{
|
2010-06-04 05:46:36 +04:00
|
|
|
VALUE val;
|
2005-02-04 16:35:37 +03:00
|
|
|
struct cfunc_data *cfunc;
|
2010-04-22 12:04:13 +04:00
|
|
|
|
2009-09-09 16:19:28 +04:00
|
|
|
TypedData_Get_Struct(self, struct cfunc_data, &dlcfunc_data_type, cfunc);
|
2010-04-22 12:04:13 +04:00
|
|
|
|
2010-06-04 05:46:36 +04:00
|
|
|
val = rb_sprintf("#<DL::CFunc:%p ptr=%p type=%d name='%s'>",
|
2005-02-04 16:35:37 +03:00
|
|
|
cfunc,
|
|
|
|
cfunc->ptr,
|
|
|
|
cfunc->type,
|
|
|
|
cfunc->name ? cfunc->name : "");
|
2010-06-04 05:46:36 +04:00
|
|
|
OBJ_TAINT(val);
|
|
|
|
return val;
|
2005-02-04 16:35:37 +03:00
|
|
|
}
|
|
|
|
|
2006-07-06 23:59:31 +04:00
|
|
|
|
2010-05-21 13:10:23 +04:00
|
|
|
# define DECL_FUNC_CDECL(f,ret,args,val) \
|
2011-02-11 17:17:24 +03:00
|
|
|
ret (FUNC_CDECL(*(f)))(args) = (ret (FUNC_CDECL(*))(args))(VALUE)(val)
|
2009-03-01 13:02:06 +03:00
|
|
|
#ifdef FUNC_STDCALL
|
2010-05-21 13:10:23 +04:00
|
|
|
# define DECL_FUNC_STDCALL(f,ret,args,val) \
|
2011-02-11 17:17:24 +03:00
|
|
|
ret (FUNC_STDCALL(*(f)))(args) = (ret (FUNC_STDCALL(*))(args))(VALUE)(val)
|
2009-03-01 13:02:06 +03:00
|
|
|
#endif
|
2005-02-04 16:35:37 +03:00
|
|
|
|
2006-09-02 18:42:08 +04:00
|
|
|
#define CALL_CASE switch( RARRAY_LEN(ary) ){ \
|
2005-02-04 16:35:37 +03:00
|
|
|
CASE(0); break; \
|
|
|
|
CASE(1); break; CASE(2); break; CASE(3); break; CASE(4); break; CASE(5); break; \
|
|
|
|
CASE(6); break; CASE(7); break; CASE(8); break; CASE(9); break; CASE(10);break; \
|
|
|
|
CASE(11);break; CASE(12);break; CASE(13);break; CASE(14);break; CASE(15);break; \
|
|
|
|
CASE(16);break; CASE(17);break; CASE(18);break; CASE(19);break; CASE(20);break; \
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
default: rb_raise(rb_eArgError, "too many arguments"); \
|
2005-02-04 16:35:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-24 22:46:24 +04:00
|
|
|
#if defined(_MSC_VER) && defined(_M_AMD64) && _MSC_VER == 1500
|
|
|
|
# pragma optimize("", off)
|
|
|
|
#endif
|
2009-11-08 03:21:41 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* dlcfunc.call(ary) => some_value
|
|
|
|
* dlcfunc[ary] => some_value
|
|
|
|
*
|
|
|
|
* Calls the function pointer passing in +ary+ as values to the underlying
|
|
|
|
* C function. The return value depends on the ctype.
|
|
|
|
*/
|
2009-11-07 01:50:40 +03:00
|
|
|
static VALUE
|
2005-02-04 16:35:37 +03:00
|
|
|
rb_dlcfunc_call(VALUE self, VALUE ary)
|
|
|
|
{
|
|
|
|
struct cfunc_data *cfunc;
|
|
|
|
int i;
|
|
|
|
DLSTACK_TYPE stack[DLSTACK_SIZE];
|
|
|
|
VALUE result = Qnil;
|
|
|
|
|
|
|
|
rb_secure_update(self);
|
|
|
|
|
|
|
|
memset(stack, 0, sizeof(DLSTACK_TYPE) * DLSTACK_SIZE);
|
|
|
|
Check_Type(ary, T_ARRAY);
|
2010-04-22 12:04:13 +04:00
|
|
|
|
2009-09-09 16:19:28 +04:00
|
|
|
TypedData_Get_Struct(self, struct cfunc_data, &dlcfunc_data_type, cfunc);
|
2005-02-04 16:35:37 +03:00
|
|
|
|
|
|
|
if( cfunc->ptr == 0 ){
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
rb_raise(rb_eDLError, "can't call null-function");
|
2005-02-04 16:35:37 +03:00
|
|
|
return Qnil;
|
|
|
|
}
|
2010-04-22 12:04:13 +04:00
|
|
|
|
2006-09-02 18:42:08 +04:00
|
|
|
for( i = 0; i < RARRAY_LEN(ary); i++ ){
|
2010-05-02 12:25:15 +04:00
|
|
|
VALUE arg;
|
2010-02-26 01:49:20 +03:00
|
|
|
if( i >= DLSTACK_SIZE ){
|
|
|
|
rb_raise(rb_eDLError, "too many arguments (stack overflow)");
|
2005-02-04 16:35:37 +03:00
|
|
|
}
|
2010-05-02 12:25:15 +04:00
|
|
|
arg = rb_to_int(RARRAY_PTR(ary)[i]);
|
|
|
|
rb_check_safe_obj(arg);
|
|
|
|
if (FIXNUM_P(arg)) {
|
|
|
|
stack[i] = (DLSTACK_TYPE)FIX2LONG(arg);
|
|
|
|
}
|
|
|
|
else if (RB_TYPE_P(arg, T_BIGNUM)) {
|
|
|
|
stack[i] = (DLSTACK_TYPE)rb_big2ulong_pack(arg);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Check_Type(arg, T_FIXNUM);
|
|
|
|
}
|
2005-02-04 16:35:37 +03:00
|
|
|
}
|
2010-04-22 12:04:13 +04:00
|
|
|
|
2005-02-04 16:35:37 +03:00
|
|
|
/* calltype == CFUNC_CDECL */
|
2009-03-01 13:02:06 +03:00
|
|
|
if( cfunc->calltype == CFUNC_CDECL
|
|
|
|
#ifndef FUNC_STDCALL
|
|
|
|
|| cfunc->calltype == CFUNC_STDCALL
|
|
|
|
#endif
|
|
|
|
){
|
2005-02-04 16:35:37 +03:00
|
|
|
switch( cfunc->type ){
|
|
|
|
case DLTYPE_VOID:
|
|
|
|
#define CASE(n) case n: { \
|
2010-05-21 13:10:23 +04:00
|
|
|
DECL_FUNC_CDECL(f,void,DLSTACK_PROTO##n,cfunc->ptr); \
|
2005-02-04 16:35:37 +03:00
|
|
|
f(DLSTACK_ARGS##n(stack)); \
|
|
|
|
result = Qnil; \
|
|
|
|
}
|
|
|
|
CALL_CASE;
|
|
|
|
#undef CASE
|
|
|
|
break;
|
|
|
|
case DLTYPE_VOIDP:
|
|
|
|
#define CASE(n) case n: { \
|
2010-05-21 13:10:23 +04:00
|
|
|
DECL_FUNC_CDECL(f,void*,DLSTACK_PROTO##n,cfunc->ptr); \
|
2005-02-04 16:35:37 +03:00
|
|
|
void * ret; \
|
|
|
|
ret = f(DLSTACK_ARGS##n(stack)); \
|
|
|
|
result = PTR2NUM(ret); \
|
|
|
|
}
|
|
|
|
CALL_CASE;
|
|
|
|
#undef CASE
|
|
|
|
break;
|
|
|
|
case DLTYPE_CHAR:
|
|
|
|
#define CASE(n) case n: { \
|
2010-05-21 13:10:23 +04:00
|
|
|
DECL_FUNC_CDECL(f,char,DLSTACK_PROTO##n,cfunc->ptr); \
|
2005-02-04 16:35:37 +03:00
|
|
|
char ret; \
|
|
|
|
ret = f(DLSTACK_ARGS##n(stack)); \
|
|
|
|
result = CHR2FIX(ret); \
|
|
|
|
}
|
|
|
|
CALL_CASE;
|
|
|
|
#undef CASE
|
|
|
|
break;
|
|
|
|
case DLTYPE_SHORT:
|
|
|
|
#define CASE(n) case n: { \
|
2010-05-21 13:10:23 +04:00
|
|
|
DECL_FUNC_CDECL(f,short,DLSTACK_PROTO##n,cfunc->ptr); \
|
2005-02-04 16:35:37 +03:00
|
|
|
short ret; \
|
|
|
|
ret = f(DLSTACK_ARGS##n(stack)); \
|
|
|
|
result = INT2NUM((int)ret); \
|
|
|
|
}
|
|
|
|
CALL_CASE;
|
|
|
|
#undef CASE
|
|
|
|
break;
|
|
|
|
case DLTYPE_INT:
|
|
|
|
#define CASE(n) case n: { \
|
2010-05-21 13:10:23 +04:00
|
|
|
DECL_FUNC_CDECL(f,int,DLSTACK_PROTO##n,cfunc->ptr); \
|
2005-02-04 16:35:37 +03:00
|
|
|
int ret; \
|
|
|
|
ret = f(DLSTACK_ARGS##n(stack)); \
|
|
|
|
result = INT2NUM(ret); \
|
|
|
|
}
|
|
|
|
CALL_CASE;
|
|
|
|
#undef CASE
|
|
|
|
break;
|
|
|
|
case DLTYPE_LONG:
|
|
|
|
#define CASE(n) case n: { \
|
2010-05-21 13:10:23 +04:00
|
|
|
DECL_FUNC_CDECL(f,long,DLSTACK_PROTO##n,cfunc->ptr); \
|
2005-02-04 16:35:37 +03:00
|
|
|
long ret; \
|
|
|
|
ret = f(DLSTACK_ARGS##n(stack)); \
|
|
|
|
result = LONG2NUM(ret); \
|
|
|
|
}
|
|
|
|
CALL_CASE;
|
|
|
|
#undef CASE
|
|
|
|
break;
|
|
|
|
#if HAVE_LONG_LONG /* used in ruby.h */
|
|
|
|
case DLTYPE_LONG_LONG:
|
|
|
|
#define CASE(n) case n: { \
|
2010-05-21 13:10:23 +04:00
|
|
|
DECL_FUNC_CDECL(f,LONG_LONG,DLSTACK_PROTO##n,cfunc->ptr); \
|
2005-02-04 16:35:37 +03:00
|
|
|
LONG_LONG ret; \
|
2009-03-01 13:02:06 +03:00
|
|
|
ret = f(DLSTACK_ARGS##n(stack)); \
|
2005-02-04 16:35:37 +03:00
|
|
|
result = LL2NUM(ret); \
|
|
|
|
}
|
|
|
|
CALL_CASE;
|
|
|
|
#undef CASE
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case DLTYPE_FLOAT:
|
|
|
|
#define CASE(n) case n: { \
|
2010-05-21 13:10:23 +04:00
|
|
|
DECL_FUNC_CDECL(f,float,DLSTACK_PROTO##n,cfunc->ptr); \
|
2005-02-04 16:35:37 +03:00
|
|
|
float ret; \
|
2009-03-01 13:02:06 +03:00
|
|
|
ret = f(DLSTACK_ARGS##n(stack)); \
|
2005-02-04 16:35:37 +03:00
|
|
|
result = rb_float_new(ret); \
|
|
|
|
}
|
|
|
|
CALL_CASE;
|
|
|
|
#undef CASE
|
|
|
|
break;
|
|
|
|
case DLTYPE_DOUBLE:
|
|
|
|
#define CASE(n) case n: { \
|
2010-05-21 13:10:23 +04:00
|
|
|
DECL_FUNC_CDECL(f,double,DLSTACK_PROTO##n,cfunc->ptr); \
|
2005-02-04 16:35:37 +03:00
|
|
|
double ret; \
|
2009-03-01 13:02:06 +03:00
|
|
|
ret = f(DLSTACK_ARGS##n(stack)); \
|
2005-02-04 16:35:37 +03:00
|
|
|
result = rb_float_new(ret); \
|
|
|
|
}
|
|
|
|
CALL_CASE;
|
|
|
|
#undef CASE
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rb_raise(rb_eDLTypeError, "unknown type %d", cfunc->type);
|
|
|
|
}
|
|
|
|
}
|
2009-03-01 13:02:06 +03:00
|
|
|
#ifdef FUNC_STDCALL
|
2005-02-04 16:35:37 +03:00
|
|
|
else if( cfunc->calltype == CFUNC_STDCALL ){
|
|
|
|
/* calltype == CFUNC_STDCALL */
|
|
|
|
switch( cfunc->type ){
|
|
|
|
case DLTYPE_VOID:
|
|
|
|
#define CASE(n) case n: { \
|
2010-05-21 13:10:23 +04:00
|
|
|
DECL_FUNC_STDCALL(f,void,DLSTACK_PROTO##n##_,cfunc->ptr); \
|
2005-02-04 16:35:37 +03:00
|
|
|
f(DLSTACK_ARGS##n(stack)); \
|
|
|
|
result = Qnil; \
|
|
|
|
}
|
|
|
|
CALL_CASE;
|
|
|
|
#undef CASE
|
|
|
|
break;
|
|
|
|
case DLTYPE_VOIDP:
|
|
|
|
#define CASE(n) case n: { \
|
2010-05-21 13:10:23 +04:00
|
|
|
DECL_FUNC_STDCALL(f,void*,DLSTACK_PROTO##n##_,cfunc->ptr); \
|
2005-02-04 16:35:37 +03:00
|
|
|
void * ret; \
|
|
|
|
ret = f(DLSTACK_ARGS##n(stack)); \
|
|
|
|
result = PTR2NUM(ret); \
|
|
|
|
}
|
|
|
|
CALL_CASE;
|
|
|
|
#undef CASE
|
|
|
|
break;
|
|
|
|
case DLTYPE_CHAR:
|
|
|
|
#define CASE(n) case n: { \
|
2010-05-21 13:10:23 +04:00
|
|
|
DECL_FUNC_STDCALL(f,char,DLSTACK_PROTO##n##_,cfunc->ptr); \
|
2005-02-04 16:35:37 +03:00
|
|
|
char ret; \
|
|
|
|
ret = f(DLSTACK_ARGS##n(stack)); \
|
|
|
|
result = CHR2FIX(ret); \
|
|
|
|
}
|
|
|
|
CALL_CASE;
|
|
|
|
#undef CASE
|
|
|
|
break;
|
|
|
|
case DLTYPE_SHORT:
|
|
|
|
#define CASE(n) case n: { \
|
2010-05-21 13:10:23 +04:00
|
|
|
DECL_FUNC_STDCALL(f,short,DLSTACK_PROTO##n##_,cfunc->ptr); \
|
2005-02-04 16:35:37 +03:00
|
|
|
short ret; \
|
|
|
|
ret = f(DLSTACK_ARGS##n(stack)); \
|
|
|
|
result = INT2NUM((int)ret); \
|
|
|
|
}
|
|
|
|
CALL_CASE;
|
|
|
|
#undef CASE
|
|
|
|
break;
|
|
|
|
case DLTYPE_INT:
|
|
|
|
#define CASE(n) case n: { \
|
2010-05-21 13:10:23 +04:00
|
|
|
DECL_FUNC_STDCALL(f,int,DLSTACK_PROTO##n##_,cfunc->ptr); \
|
2005-02-04 16:35:37 +03:00
|
|
|
int ret; \
|
|
|
|
ret = f(DLSTACK_ARGS##n(stack)); \
|
|
|
|
result = INT2NUM(ret); \
|
|
|
|
}
|
|
|
|
CALL_CASE;
|
|
|
|
#undef CASE
|
|
|
|
break;
|
|
|
|
case DLTYPE_LONG:
|
|
|
|
#define CASE(n) case n: { \
|
2010-05-21 13:10:23 +04:00
|
|
|
DECL_FUNC_STDCALL(f,long,DLSTACK_PROTO##n##_,cfunc->ptr); \
|
2005-02-04 16:35:37 +03:00
|
|
|
long ret; \
|
|
|
|
ret = f(DLSTACK_ARGS##n(stack)); \
|
|
|
|
result = LONG2NUM(ret); \
|
|
|
|
}
|
|
|
|
CALL_CASE;
|
|
|
|
#undef CASE
|
|
|
|
break;
|
|
|
|
#if HAVE_LONG_LONG /* used in ruby.h */
|
|
|
|
case DLTYPE_LONG_LONG:
|
|
|
|
#define CASE(n) case n: { \
|
2010-05-21 13:10:23 +04:00
|
|
|
DECL_FUNC_STDCALL(f,LONG_LONG,DLSTACK_PROTO##n##_,cfunc->ptr); \
|
2005-02-04 16:35:37 +03:00
|
|
|
LONG_LONG ret; \
|
2009-03-01 13:02:06 +03:00
|
|
|
ret = f(DLSTACK_ARGS##n(stack)); \
|
2005-02-04 16:35:37 +03:00
|
|
|
result = LL2NUM(ret); \
|
|
|
|
}
|
|
|
|
CALL_CASE;
|
|
|
|
#undef CASE
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case DLTYPE_FLOAT:
|
|
|
|
#define CASE(n) case n: { \
|
2010-05-21 13:10:23 +04:00
|
|
|
DECL_FUNC_STDCALL(f,float,DLSTACK_PROTO##n##_,cfunc->ptr); \
|
2005-02-04 16:35:37 +03:00
|
|
|
float ret; \
|
2009-03-01 13:02:06 +03:00
|
|
|
ret = f(DLSTACK_ARGS##n(stack)); \
|
2005-02-04 16:35:37 +03:00
|
|
|
result = rb_float_new(ret); \
|
|
|
|
}
|
|
|
|
CALL_CASE;
|
|
|
|
#undef CASE
|
|
|
|
break;
|
|
|
|
case DLTYPE_DOUBLE:
|
|
|
|
#define CASE(n) case n: { \
|
2010-05-21 13:10:23 +04:00
|
|
|
DECL_FUNC_STDCALL(f,double,DLSTACK_PROTO##n##_,cfunc->ptr); \
|
2005-02-04 16:35:37 +03:00
|
|
|
double ret; \
|
2009-03-01 13:02:06 +03:00
|
|
|
ret = f(DLSTACK_ARGS##n(stack)); \
|
2005-02-04 16:35:37 +03:00
|
|
|
result = rb_float_new(ret); \
|
|
|
|
}
|
|
|
|
CALL_CASE;
|
|
|
|
#undef CASE
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rb_raise(rb_eDLTypeError, "unknown type %d", cfunc->type);
|
|
|
|
}
|
|
|
|
}
|
2009-03-01 13:02:06 +03:00
|
|
|
#endif
|
2005-02-04 16:35:37 +03:00
|
|
|
else{
|
2010-10-12 19:03:51 +04:00
|
|
|
const char *name = rb_id2name(cfunc->calltype);
|
|
|
|
if( name ){
|
|
|
|
rb_raise(rb_eDLError, "unsupported call type: %s",
|
|
|
|
name);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
rb_raise(rb_eDLError, "unsupported call type: %"PRIxVALUE,
|
|
|
|
cfunc->calltype);
|
|
|
|
}
|
2005-02-04 16:35:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
rb_dl_set_last_error(self, INT2NUM(errno));
|
2011-01-05 06:13:18 +03:00
|
|
|
#if defined(_WIN32)
|
2005-02-04 16:35:37 +03:00
|
|
|
rb_dl_set_win32_last_error(self, INT2NUM(GetLastError()));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2010-08-24 22:46:24 +04:00
|
|
|
#if defined(_MSC_VER) && defined(_M_AMD64) && _MSC_VER == 1500
|
|
|
|
# pragma optimize("", on)
|
|
|
|
#endif
|
2005-02-04 16:35:37 +03:00
|
|
|
|
2009-11-08 03:21:41 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* dlfunc.to_i => integer
|
|
|
|
*
|
|
|
|
* Returns the memory location of this function pointer as an integer.
|
|
|
|
*/
|
|
|
|
static VALUE
|
2005-02-04 16:35:37 +03:00
|
|
|
rb_dlcfunc_to_i(VALUE self)
|
|
|
|
{
|
|
|
|
struct cfunc_data *cfunc;
|
|
|
|
|
2009-09-09 16:19:28 +04:00
|
|
|
TypedData_Get_Struct(self, struct cfunc_data, &dlcfunc_data_type, cfunc);
|
2005-02-04 16:35:37 +03:00
|
|
|
return PTR2NUM(cfunc->ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-09 09:25:14 +03:00
|
|
|
Init_dlcfunc(void)
|
2005-02-04 16:35:37 +03:00
|
|
|
{
|
|
|
|
id_last_error = rb_intern("__DL2_LAST_ERROR__");
|
2011-01-05 06:13:18 +03:00
|
|
|
#if defined(_WIN32)
|
2005-02-04 16:35:37 +03:00
|
|
|
id_win32_last_error = rb_intern("__DL2_WIN32_LAST_ERROR__");
|
|
|
|
#endif
|
2011-08-16 04:34:51 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Document-class: DL::CFunc
|
|
|
|
*
|
|
|
|
* A direct accessor to a function in a C library
|
|
|
|
*
|
|
|
|
* == Example
|
|
|
|
*
|
|
|
|
* libc_so = "/lib64/libc.so.6"
|
|
|
|
* => "/lib64/libc.so.6"
|
|
|
|
* libc = DL::dlopen(libc_so)
|
|
|
|
* => #<DL::Handle:0x00000000e05b00>
|
|
|
|
* @cfunc = DL::CFunc.new(libc,['strcpy'], DL::TYPE_VOIDP, 'strcpy')
|
|
|
|
* => #<DL::CFunc:0x000000012daec0 ptr=0x007f62ca5a8300 type=1 name='strcpy'>
|
|
|
|
*
|
|
|
|
*/
|
2005-02-04 16:35:37 +03:00
|
|
|
rb_cDLCFunc = rb_define_class_under(rb_mDL, "CFunc", rb_cObject);
|
|
|
|
rb_define_alloc_func(rb_cDLCFunc, rb_dlcfunc_s_allocate);
|
2011-08-16 04:34:51 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Document-method: last_error
|
|
|
|
*
|
|
|
|
* Returns the last error for the current executing thread
|
|
|
|
*/
|
2005-02-04 16:35:37 +03:00
|
|
|
rb_define_module_function(rb_cDLCFunc, "last_error", rb_dl_get_last_error, 0);
|
2011-01-05 06:13:18 +03:00
|
|
|
#if defined(_WIN32)
|
2011-08-16 04:34:51 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Document-method: win32_last_error
|
|
|
|
*
|
|
|
|
* Returns the last win32 error for the current executing thread
|
|
|
|
*/
|
2005-02-04 16:35:37 +03:00
|
|
|
rb_define_module_function(rb_cDLCFunc, "win32_last_error", rb_dl_get_win32_last_error, 0);
|
|
|
|
#endif
|
|
|
|
rb_define_method(rb_cDLCFunc, "initialize", rb_dlcfunc_initialize, -1);
|
|
|
|
rb_define_method(rb_cDLCFunc, "call", rb_dlcfunc_call, 1);
|
|
|
|
rb_define_method(rb_cDLCFunc, "[]", rb_dlcfunc_call, 1);
|
|
|
|
rb_define_method(rb_cDLCFunc, "name", rb_dlcfunc_name, 0);
|
|
|
|
rb_define_method(rb_cDLCFunc, "ctype", rb_dlcfunc_ctype, 0);
|
|
|
|
rb_define_method(rb_cDLCFunc, "ctype=", rb_dlcfunc_set_ctype, 1);
|
|
|
|
rb_define_method(rb_cDLCFunc, "calltype", rb_dlcfunc_calltype, 0);
|
|
|
|
rb_define_method(rb_cDLCFunc, "calltype=", rb_dlcfunc_set_calltype, 1);
|
|
|
|
rb_define_method(rb_cDLCFunc, "ptr", rb_dlcfunc_ptr, 0);
|
|
|
|
rb_define_method(rb_cDLCFunc, "ptr=", rb_dlcfunc_set_ptr, 1);
|
|
|
|
rb_define_method(rb_cDLCFunc, "inspect", rb_dlcfunc_inspect, 0);
|
|
|
|
rb_define_method(rb_cDLCFunc, "to_s", rb_dlcfunc_inspect, 0);
|
|
|
|
rb_define_method(rb_cDLCFunc, "to_i", rb_dlcfunc_to_i, 0);
|
|
|
|
}
|