mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/dl: made indent style insistent.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22982 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
1b6808913a
commit
f797bdae70
3 changed files with 157 additions and 157 deletions
|
@ -45,66 +45,66 @@ rb_dl_set_win32_last_error(VALUE self, VALUE val)
|
||||||
void
|
void
|
||||||
dlcfunc_free(struct cfunc_data *data)
|
dlcfunc_free(struct cfunc_data *data)
|
||||||
{
|
{
|
||||||
if( data->name ){
|
if( data->name ){
|
||||||
xfree(data->name);
|
xfree(data->name);
|
||||||
}
|
}
|
||||||
xfree(data);
|
xfree(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_dlcfunc_new(void (*func)(), int type, const char *name, ID calltype)
|
rb_dlcfunc_new(void (*func)(), int type, const char *name, ID calltype)
|
||||||
{
|
{
|
||||||
VALUE val;
|
VALUE val;
|
||||||
struct cfunc_data *data;
|
struct cfunc_data *data;
|
||||||
|
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
if( func ){
|
if( func ){
|
||||||
val = Data_Make_Struct(rb_cDLCFunc, struct cfunc_data, 0, dlcfunc_free, data);
|
val = Data_Make_Struct(rb_cDLCFunc, struct cfunc_data, 0, dlcfunc_free, data);
|
||||||
data->ptr = func;
|
data->ptr = func;
|
||||||
data->name = name ? strdup(name) : NULL;
|
data->name = name ? strdup(name) : NULL;
|
||||||
data->type = type;
|
data->type = type;
|
||||||
data->calltype = calltype;
|
data->calltype = calltype;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
val = Qnil;
|
val = Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
rb_dlcfunc2ptr(VALUE val)
|
rb_dlcfunc2ptr(VALUE val)
|
||||||
{
|
{
|
||||||
struct cfunc_data *data;
|
struct cfunc_data *data;
|
||||||
void * func;
|
void * func;
|
||||||
|
|
||||||
if( rb_obj_is_kind_of(val, rb_cDLCFunc) ){
|
if( rb_obj_is_kind_of(val, rb_cDLCFunc) ){
|
||||||
Data_Get_Struct(val, struct cfunc_data, data);
|
Data_Get_Struct(val, struct cfunc_data, data);
|
||||||
func = data->ptr;
|
func = data->ptr;
|
||||||
}
|
}
|
||||||
else if( val == Qnil ){
|
else if( val == Qnil ){
|
||||||
func = NULL;
|
func = NULL;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
rb_raise(rb_eTypeError, "DL::CFunc was expected");
|
rb_raise(rb_eTypeError, "DL::CFunc was expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
return func;
|
return func;
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_dlcfunc_s_allocate(VALUE klass)
|
rb_dlcfunc_s_allocate(VALUE klass)
|
||||||
{
|
{
|
||||||
VALUE obj;
|
VALUE obj;
|
||||||
struct cfunc_data *data;
|
struct cfunc_data *data;
|
||||||
|
|
||||||
obj = Data_Make_Struct(klass, struct cfunc_data, 0, dlcfunc_free, data);
|
obj = Data_Make_Struct(klass, struct cfunc_data, 0, dlcfunc_free, data);
|
||||||
data->ptr = 0;
|
data->ptr = 0;
|
||||||
data->name = 0;
|
data->name = 0;
|
||||||
data->type = 0;
|
data->type = 0;
|
||||||
data->calltype = CFUNC_CDECL;
|
data->calltype = CFUNC_CDECL;
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
|
@ -374,7 +374,7 @@ rb_dlcfunc_call(VALUE self, VALUE ary)
|
||||||
switch( cfunc->type ){
|
switch( cfunc->type ){
|
||||||
case DLTYPE_VOID:
|
case DLTYPE_VOID:
|
||||||
#define CASE(n) case n: { \
|
#define CASE(n) case n: { \
|
||||||
DECL_FUNC_STDCALL(f,void,DLSTACK_PROTO##n##_) = cfunc->ptr; \
|
DECL_FUNC_STDCALL(f,void,DLSTACK_PROTO##n##_) = cfunc->ptr; \
|
||||||
f(DLSTACK_ARGS##n(stack)); \
|
f(DLSTACK_ARGS##n(stack)); \
|
||||||
result = Qnil; \
|
result = Qnil; \
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,11 +14,11 @@ static ID id_to_ptr;
|
||||||
static void
|
static void
|
||||||
dlptr_free(struct ptr_data *data)
|
dlptr_free(struct ptr_data *data)
|
||||||
{
|
{
|
||||||
if (data->ptr) {
|
if (data->ptr) {
|
||||||
if (data->free) {
|
if (data->free) {
|
||||||
(*(data->free))(data->ptr);
|
(*(data->free))(data->ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -29,79 +29,79 @@ dlptr_mark(struct ptr_data *data)
|
||||||
void
|
void
|
||||||
dlptr_init(VALUE val)
|
dlptr_init(VALUE val)
|
||||||
{
|
{
|
||||||
struct ptr_data *data;
|
struct ptr_data *data;
|
||||||
|
|
||||||
Data_Get_Struct(val, struct ptr_data, data);
|
Data_Get_Struct(val, struct ptr_data, data);
|
||||||
OBJ_TAINT(val);
|
OBJ_TAINT(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_dlptr_new2(VALUE klass, void *ptr, long size, freefunc_t func)
|
rb_dlptr_new2(VALUE klass, void *ptr, long size, freefunc_t func)
|
||||||
{
|
{
|
||||||
struct ptr_data *data;
|
struct ptr_data *data;
|
||||||
VALUE val;
|
VALUE val;
|
||||||
|
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
val = Data_Make_Struct(klass, struct ptr_data,
|
val = Data_Make_Struct(klass, struct ptr_data,
|
||||||
0, dlptr_free, data);
|
0, dlptr_free, data);
|
||||||
data->ptr = ptr;
|
data->ptr = ptr;
|
||||||
data->free = func;
|
data->free = func;
|
||||||
data->size = size;
|
data->size = size;
|
||||||
dlptr_init(val);
|
dlptr_init(val);
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_dlptr_new(void *ptr, long size, freefunc_t func)
|
rb_dlptr_new(void *ptr, long size, freefunc_t func)
|
||||||
{
|
{
|
||||||
return rb_dlptr_new2(rb_cDLCPtr, ptr, size, func);
|
return rb_dlptr_new2(rb_cDLCPtr, ptr, size, func);
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_dlptr_malloc(long size, freefunc_t func)
|
rb_dlptr_malloc(long size, freefunc_t func)
|
||||||
{
|
{
|
||||||
void *ptr;
|
void *ptr;
|
||||||
|
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
ptr = ruby_xmalloc((size_t)size);
|
ptr = ruby_xmalloc((size_t)size);
|
||||||
memset(ptr,0,(size_t)size);
|
memset(ptr,0,(size_t)size);
|
||||||
return rb_dlptr_new(ptr, size, func);
|
return rb_dlptr_new(ptr, size, func);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
rb_dlptr2cptr(VALUE val)
|
rb_dlptr2cptr(VALUE val)
|
||||||
{
|
{
|
||||||
struct ptr_data *data;
|
struct ptr_data *data;
|
||||||
void *ptr;
|
void *ptr;
|
||||||
|
|
||||||
if (rb_obj_is_kind_of(val, rb_cDLCPtr)) {
|
if (rb_obj_is_kind_of(val, rb_cDLCPtr)) {
|
||||||
Data_Get_Struct(val, struct ptr_data, data);
|
Data_Get_Struct(val, struct ptr_data, data);
|
||||||
ptr = data->ptr;
|
ptr = data->ptr;
|
||||||
}
|
}
|
||||||
else if (val == Qnil) {
|
else if (val == Qnil) {
|
||||||
ptr = NULL;
|
ptr = NULL;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
rb_raise(rb_eTypeError, "DL::PtrData was expected");
|
rb_raise(rb_eTypeError, "DL::PtrData was expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_dlptr_s_allocate(VALUE klass)
|
rb_dlptr_s_allocate(VALUE klass)
|
||||||
{
|
{
|
||||||
VALUE obj;
|
VALUE obj;
|
||||||
struct ptr_data *data;
|
struct ptr_data *data;
|
||||||
|
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
obj = Data_Make_Struct(klass, struct ptr_data, dlptr_mark, dlptr_free, data);
|
obj = Data_Make_Struct(klass, struct ptr_data, dlptr_mark, dlptr_free, data);
|
||||||
data->ptr = 0;
|
data->ptr = 0;
|
||||||
data->size = 0;
|
data->size = 0;
|
||||||
data->free = 0;
|
data->free = 0;
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
|
144
ext/dl/handle.c
144
ext/dl/handle.c
|
@ -10,123 +10,123 @@ VALUE rb_cDLHandle;
|
||||||
void
|
void
|
||||||
dlhandle_free(struct dl_handle *dlhandle)
|
dlhandle_free(struct dl_handle *dlhandle)
|
||||||
{
|
{
|
||||||
if( dlhandle->ptr && dlhandle->open && dlhandle->enable_close ){
|
if( dlhandle->ptr && dlhandle->open && dlhandle->enable_close ){
|
||||||
dlclose(dlhandle->ptr);
|
dlclose(dlhandle->ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_dlhandle_close(VALUE self)
|
rb_dlhandle_close(VALUE self)
|
||||||
{
|
{
|
||||||
struct dl_handle *dlhandle;
|
struct dl_handle *dlhandle;
|
||||||
|
|
||||||
Data_Get_Struct(self, struct dl_handle, dlhandle);
|
Data_Get_Struct(self, struct dl_handle, dlhandle);
|
||||||
dlhandle->open = 0;
|
dlhandle->open = 0;
|
||||||
return INT2NUM(dlclose(dlhandle->ptr));
|
return INT2NUM(dlclose(dlhandle->ptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_dlhandle_s_allocate(VALUE klass)
|
rb_dlhandle_s_allocate(VALUE klass)
|
||||||
{
|
{
|
||||||
VALUE obj;
|
VALUE obj;
|
||||||
struct dl_handle *dlhandle;
|
struct dl_handle *dlhandle;
|
||||||
|
|
||||||
obj = Data_Make_Struct(rb_cDLHandle, struct dl_handle, 0,
|
obj = Data_Make_Struct(rb_cDLHandle, struct dl_handle, 0,
|
||||||
dlhandle_free, dlhandle);
|
dlhandle_free, dlhandle);
|
||||||
dlhandle->ptr = 0;
|
dlhandle->ptr = 0;
|
||||||
dlhandle->open = 0;
|
dlhandle->open = 0;
|
||||||
dlhandle->enable_close = 0;
|
dlhandle->enable_close = 0;
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_dlhandle_initialize(int argc, VALUE argv[], VALUE self)
|
rb_dlhandle_initialize(int argc, VALUE argv[], VALUE self)
|
||||||
{
|
{
|
||||||
void *ptr;
|
void *ptr;
|
||||||
struct dl_handle *dlhandle;
|
struct dl_handle *dlhandle;
|
||||||
VALUE lib, flag;
|
VALUE lib, flag;
|
||||||
char *clib;
|
char *clib;
|
||||||
int cflag;
|
int cflag;
|
||||||
const char *err;
|
const char *err;
|
||||||
|
|
||||||
switch( rb_scan_args(argc, argv, "02", &lib, &flag) ){
|
switch( rb_scan_args(argc, argv, "02", &lib, &flag) ){
|
||||||
case 0:
|
case 0:
|
||||||
clib = NULL;
|
clib = NULL;
|
||||||
cflag = RTLD_LAZY | RTLD_GLOBAL;
|
cflag = RTLD_LAZY | RTLD_GLOBAL;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
clib = NIL_P(lib) ? NULL : StringValuePtr(lib);
|
clib = NIL_P(lib) ? NULL : StringValuePtr(lib);
|
||||||
cflag = RTLD_LAZY | RTLD_GLOBAL;
|
cflag = RTLD_LAZY | RTLD_GLOBAL;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
clib = NIL_P(lib) ? NULL : StringValuePtr(lib);
|
clib = NIL_P(lib) ? NULL : StringValuePtr(lib);
|
||||||
cflag = NUM2INT(flag);
|
cflag = NUM2INT(flag);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
rb_bug("rb_dlhandle_new");
|
rb_bug("rb_dlhandle_new");
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(HAVE_WINDOWS_H)
|
#if defined(HAVE_WINDOWS_H)
|
||||||
if( !clib ){
|
if( !clib ){
|
||||||
HANDLE rb_libruby_handle(void);
|
HANDLE rb_libruby_handle(void);
|
||||||
ptr = rb_libruby_handle();
|
ptr = rb_libruby_handle();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
ptr = dlopen(clib, cflag);
|
ptr = dlopen(clib, cflag);
|
||||||
#if defined(HAVE_DLERROR)
|
#if defined(HAVE_DLERROR)
|
||||||
if( !ptr && (err = dlerror()) ){
|
if( !ptr && (err = dlerror()) ){
|
||||||
rb_raise(rb_eDLError, "%s", err);
|
rb_raise(rb_eDLError, "%s", err);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if( !ptr ){
|
if( !ptr ){
|
||||||
err = dlerror();
|
err = dlerror();
|
||||||
rb_raise(rb_eDLError, "%s", err);
|
rb_raise(rb_eDLError, "%s", err);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
Data_Get_Struct(self, struct dl_handle, dlhandle);
|
Data_Get_Struct(self, struct dl_handle, dlhandle);
|
||||||
if( dlhandle->ptr && dlhandle->open && dlhandle->enable_close ){
|
if( dlhandle->ptr && dlhandle->open && dlhandle->enable_close ){
|
||||||
dlclose(dlhandle->ptr);
|
dlclose(dlhandle->ptr);
|
||||||
}
|
}
|
||||||
dlhandle->ptr = ptr;
|
dlhandle->ptr = ptr;
|
||||||
dlhandle->open = 1;
|
dlhandle->open = 1;
|
||||||
dlhandle->enable_close = 0;
|
dlhandle->enable_close = 0;
|
||||||
|
|
||||||
if( rb_block_given_p() ){
|
if( rb_block_given_p() ){
|
||||||
rb_ensure(rb_yield, self, rb_dlhandle_close, self);
|
rb_ensure(rb_yield, self, rb_dlhandle_close, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_dlhandle_enable_close(VALUE self)
|
rb_dlhandle_enable_close(VALUE self)
|
||||||
{
|
{
|
||||||
struct dl_handle *dlhandle;
|
struct dl_handle *dlhandle;
|
||||||
|
|
||||||
Data_Get_Struct(self, struct dl_handle, dlhandle);
|
Data_Get_Struct(self, struct dl_handle, dlhandle);
|
||||||
dlhandle->enable_close = 1;
|
dlhandle->enable_close = 1;
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_dlhandle_disable_close(VALUE self)
|
rb_dlhandle_disable_close(VALUE self)
|
||||||
{
|
{
|
||||||
struct dl_handle *dlhandle;
|
struct dl_handle *dlhandle;
|
||||||
|
|
||||||
Data_Get_Struct(self, struct dl_handle, dlhandle);
|
Data_Get_Struct(self, struct dl_handle, dlhandle);
|
||||||
dlhandle->enable_close = 0;
|
dlhandle->enable_close = 0;
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_dlhandle_to_i(VALUE self)
|
rb_dlhandle_to_i(VALUE self)
|
||||||
{
|
{
|
||||||
struct dl_handle *dlhandle;
|
struct dl_handle *dlhandle;
|
||||||
|
|
||||||
Data_Get_Struct(self, struct dl_handle, dlhandle);
|
Data_Get_Struct(self, struct dl_handle, dlhandle);
|
||||||
return PTR2NUM(dlhandle);
|
return PTR2NUM(dlhandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue