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
|
||||
dlcfunc_free(struct cfunc_data *data)
|
||||
{
|
||||
if( data->name ){
|
||||
xfree(data->name);
|
||||
}
|
||||
xfree(data);
|
||||
if( data->name ){
|
||||
xfree(data->name);
|
||||
}
|
||||
xfree(data);
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_dlcfunc_new(void (*func)(), int type, const char *name, ID calltype)
|
||||
{
|
||||
VALUE val;
|
||||
struct cfunc_data *data;
|
||||
VALUE val;
|
||||
struct cfunc_data *data;
|
||||
|
||||
rb_secure(4);
|
||||
if( func ){
|
||||
val = Data_Make_Struct(rb_cDLCFunc, struct cfunc_data, 0, dlcfunc_free, data);
|
||||
data->ptr = func;
|
||||
data->name = name ? strdup(name) : NULL;
|
||||
data->type = type;
|
||||
data->calltype = calltype;
|
||||
}
|
||||
else{
|
||||
val = Qnil;
|
||||
}
|
||||
rb_secure(4);
|
||||
if( func ){
|
||||
val = Data_Make_Struct(rb_cDLCFunc, struct cfunc_data, 0, dlcfunc_free, data);
|
||||
data->ptr = func;
|
||||
data->name = name ? strdup(name) : NULL;
|
||||
data->type = type;
|
||||
data->calltype = calltype;
|
||||
}
|
||||
else{
|
||||
val = Qnil;
|
||||
}
|
||||
|
||||
return val;
|
||||
return val;
|
||||
}
|
||||
|
||||
void *
|
||||
rb_dlcfunc2ptr(VALUE val)
|
||||
{
|
||||
struct cfunc_data *data;
|
||||
void * func;
|
||||
struct cfunc_data *data;
|
||||
void * func;
|
||||
|
||||
if( rb_obj_is_kind_of(val, rb_cDLCFunc) ){
|
||||
Data_Get_Struct(val, struct cfunc_data, data);
|
||||
func = data->ptr;
|
||||
}
|
||||
else if( val == Qnil ){
|
||||
func = NULL;
|
||||
}
|
||||
else{
|
||||
rb_raise(rb_eTypeError, "DL::CFunc was expected");
|
||||
}
|
||||
if( rb_obj_is_kind_of(val, rb_cDLCFunc) ){
|
||||
Data_Get_Struct(val, struct cfunc_data, data);
|
||||
func = data->ptr;
|
||||
}
|
||||
else if( val == Qnil ){
|
||||
func = NULL;
|
||||
}
|
||||
else{
|
||||
rb_raise(rb_eTypeError, "DL::CFunc was expected");
|
||||
}
|
||||
|
||||
return func;
|
||||
return func;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_dlcfunc_s_allocate(VALUE klass)
|
||||
{
|
||||
VALUE obj;
|
||||
struct cfunc_data *data;
|
||||
VALUE obj;
|
||||
struct cfunc_data *data;
|
||||
|
||||
obj = Data_Make_Struct(klass, struct cfunc_data, 0, dlcfunc_free, data);
|
||||
data->ptr = 0;
|
||||
data->name = 0;
|
||||
data->type = 0;
|
||||
data->calltype = CFUNC_CDECL;
|
||||
obj = Data_Make_Struct(klass, struct cfunc_data, 0, dlcfunc_free, data);
|
||||
data->ptr = 0;
|
||||
data->name = 0;
|
||||
data->type = 0;
|
||||
data->calltype = CFUNC_CDECL;
|
||||
|
||||
return obj;
|
||||
return obj;
|
||||
}
|
||||
|
||||
VALUE
|
||||
|
@ -374,7 +374,7 @@ rb_dlcfunc_call(VALUE self, VALUE ary)
|
|||
switch( cfunc->type ){
|
||||
case DLTYPE_VOID:
|
||||
#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)); \
|
||||
result = Qnil; \
|
||||
}
|
||||
|
|
|
@ -14,11 +14,11 @@ static ID id_to_ptr;
|
|||
static void
|
||||
dlptr_free(struct ptr_data *data)
|
||||
{
|
||||
if (data->ptr) {
|
||||
if (data->free) {
|
||||
(*(data->free))(data->ptr);
|
||||
}
|
||||
}
|
||||
if (data->ptr) {
|
||||
if (data->free) {
|
||||
(*(data->free))(data->ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -29,79 +29,79 @@ dlptr_mark(struct ptr_data *data)
|
|||
void
|
||||
dlptr_init(VALUE val)
|
||||
{
|
||||
struct ptr_data *data;
|
||||
struct ptr_data *data;
|
||||
|
||||
Data_Get_Struct(val, struct ptr_data, data);
|
||||
OBJ_TAINT(val);
|
||||
Data_Get_Struct(val, struct ptr_data, data);
|
||||
OBJ_TAINT(val);
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_dlptr_new2(VALUE klass, void *ptr, long size, freefunc_t func)
|
||||
{
|
||||
struct ptr_data *data;
|
||||
VALUE val;
|
||||
struct ptr_data *data;
|
||||
VALUE val;
|
||||
|
||||
rb_secure(4);
|
||||
val = Data_Make_Struct(klass, struct ptr_data,
|
||||
0, dlptr_free, data);
|
||||
data->ptr = ptr;
|
||||
data->free = func;
|
||||
data->size = size;
|
||||
dlptr_init(val);
|
||||
rb_secure(4);
|
||||
val = Data_Make_Struct(klass, struct ptr_data,
|
||||
0, dlptr_free, data);
|
||||
data->ptr = ptr;
|
||||
data->free = func;
|
||||
data->size = size;
|
||||
dlptr_init(val);
|
||||
|
||||
return val;
|
||||
return val;
|
||||
}
|
||||
|
||||
VALUE
|
||||
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
|
||||
rb_dlptr_malloc(long size, freefunc_t func)
|
||||
{
|
||||
void *ptr;
|
||||
void *ptr;
|
||||
|
||||
rb_secure(4);
|
||||
ptr = ruby_xmalloc((size_t)size);
|
||||
memset(ptr,0,(size_t)size);
|
||||
return rb_dlptr_new(ptr, size, func);
|
||||
rb_secure(4);
|
||||
ptr = ruby_xmalloc((size_t)size);
|
||||
memset(ptr,0,(size_t)size);
|
||||
return rb_dlptr_new(ptr, size, func);
|
||||
}
|
||||
|
||||
void *
|
||||
rb_dlptr2cptr(VALUE val)
|
||||
{
|
||||
struct ptr_data *data;
|
||||
void *ptr;
|
||||
struct ptr_data *data;
|
||||
void *ptr;
|
||||
|
||||
if (rb_obj_is_kind_of(val, rb_cDLCPtr)) {
|
||||
Data_Get_Struct(val, struct ptr_data, data);
|
||||
ptr = data->ptr;
|
||||
}
|
||||
else if (val == Qnil) {
|
||||
ptr = NULL;
|
||||
}
|
||||
else{
|
||||
rb_raise(rb_eTypeError, "DL::PtrData was expected");
|
||||
}
|
||||
if (rb_obj_is_kind_of(val, rb_cDLCPtr)) {
|
||||
Data_Get_Struct(val, struct ptr_data, data);
|
||||
ptr = data->ptr;
|
||||
}
|
||||
else if (val == Qnil) {
|
||||
ptr = NULL;
|
||||
}
|
||||
else{
|
||||
rb_raise(rb_eTypeError, "DL::PtrData was expected");
|
||||
}
|
||||
|
||||
return ptr;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
rb_dlptr_s_allocate(VALUE klass)
|
||||
{
|
||||
VALUE obj;
|
||||
struct ptr_data *data;
|
||||
VALUE obj;
|
||||
struct ptr_data *data;
|
||||
|
||||
rb_secure(4);
|
||||
obj = Data_Make_Struct(klass, struct ptr_data, dlptr_mark, dlptr_free, data);
|
||||
data->ptr = 0;
|
||||
data->size = 0;
|
||||
data->free = 0;
|
||||
rb_secure(4);
|
||||
obj = Data_Make_Struct(klass, struct ptr_data, dlptr_mark, dlptr_free, data);
|
||||
data->ptr = 0;
|
||||
data->size = 0;
|
||||
data->free = 0;
|
||||
|
||||
return obj;
|
||||
return obj;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
|
144
ext/dl/handle.c
144
ext/dl/handle.c
|
@ -10,123 +10,123 @@ VALUE rb_cDLHandle;
|
|||
void
|
||||
dlhandle_free(struct dl_handle *dlhandle)
|
||||
{
|
||||
if( dlhandle->ptr && dlhandle->open && dlhandle->enable_close ){
|
||||
dlclose(dlhandle->ptr);
|
||||
}
|
||||
if( dlhandle->ptr && dlhandle->open && dlhandle->enable_close ){
|
||||
dlclose(dlhandle->ptr);
|
||||
}
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_dlhandle_close(VALUE self)
|
||||
{
|
||||
struct dl_handle *dlhandle;
|
||||
struct dl_handle *dlhandle;
|
||||
|
||||
Data_Get_Struct(self, struct dl_handle, dlhandle);
|
||||
dlhandle->open = 0;
|
||||
return INT2NUM(dlclose(dlhandle->ptr));
|
||||
Data_Get_Struct(self, struct dl_handle, dlhandle);
|
||||
dlhandle->open = 0;
|
||||
return INT2NUM(dlclose(dlhandle->ptr));
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_dlhandle_s_allocate(VALUE klass)
|
||||
{
|
||||
VALUE obj;
|
||||
struct dl_handle *dlhandle;
|
||||
VALUE obj;
|
||||
struct dl_handle *dlhandle;
|
||||
|
||||
obj = Data_Make_Struct(rb_cDLHandle, struct dl_handle, 0,
|
||||
dlhandle_free, dlhandle);
|
||||
dlhandle->ptr = 0;
|
||||
dlhandle->open = 0;
|
||||
dlhandle->enable_close = 0;
|
||||
obj = Data_Make_Struct(rb_cDLHandle, struct dl_handle, 0,
|
||||
dlhandle_free, dlhandle);
|
||||
dlhandle->ptr = 0;
|
||||
dlhandle->open = 0;
|
||||
dlhandle->enable_close = 0;
|
||||
|
||||
return obj;
|
||||
return obj;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_dlhandle_initialize(int argc, VALUE argv[], VALUE self)
|
||||
{
|
||||
void *ptr;
|
||||
struct dl_handle *dlhandle;
|
||||
VALUE lib, flag;
|
||||
char *clib;
|
||||
int cflag;
|
||||
const char *err;
|
||||
void *ptr;
|
||||
struct dl_handle *dlhandle;
|
||||
VALUE lib, flag;
|
||||
char *clib;
|
||||
int cflag;
|
||||
const char *err;
|
||||
|
||||
switch( rb_scan_args(argc, argv, "02", &lib, &flag) ){
|
||||
case 0:
|
||||
clib = NULL;
|
||||
cflag = RTLD_LAZY | RTLD_GLOBAL;
|
||||
break;
|
||||
case 1:
|
||||
clib = NIL_P(lib) ? NULL : StringValuePtr(lib);
|
||||
cflag = RTLD_LAZY | RTLD_GLOBAL;
|
||||
break;
|
||||
case 2:
|
||||
clib = NIL_P(lib) ? NULL : StringValuePtr(lib);
|
||||
cflag = NUM2INT(flag);
|
||||
break;
|
||||
default:
|
||||
rb_bug("rb_dlhandle_new");
|
||||
}
|
||||
switch( rb_scan_args(argc, argv, "02", &lib, &flag) ){
|
||||
case 0:
|
||||
clib = NULL;
|
||||
cflag = RTLD_LAZY | RTLD_GLOBAL;
|
||||
break;
|
||||
case 1:
|
||||
clib = NIL_P(lib) ? NULL : StringValuePtr(lib);
|
||||
cflag = RTLD_LAZY | RTLD_GLOBAL;
|
||||
break;
|
||||
case 2:
|
||||
clib = NIL_P(lib) ? NULL : StringValuePtr(lib);
|
||||
cflag = NUM2INT(flag);
|
||||
break;
|
||||
default:
|
||||
rb_bug("rb_dlhandle_new");
|
||||
}
|
||||
|
||||
#if defined(HAVE_WINDOWS_H)
|
||||
if( !clib ){
|
||||
HANDLE rb_libruby_handle(void);
|
||||
ptr = rb_libruby_handle();
|
||||
}
|
||||
else
|
||||
if( !clib ){
|
||||
HANDLE rb_libruby_handle(void);
|
||||
ptr = rb_libruby_handle();
|
||||
}
|
||||
else
|
||||
#endif
|
||||
ptr = dlopen(clib, cflag);
|
||||
ptr = dlopen(clib, cflag);
|
||||
#if defined(HAVE_DLERROR)
|
||||
if( !ptr && (err = dlerror()) ){
|
||||
rb_raise(rb_eDLError, "%s", err);
|
||||
}
|
||||
if( !ptr && (err = dlerror()) ){
|
||||
rb_raise(rb_eDLError, "%s", err);
|
||||
}
|
||||
#else
|
||||
if( !ptr ){
|
||||
err = dlerror();
|
||||
rb_raise(rb_eDLError, "%s", err);
|
||||
}
|
||||
if( !ptr ){
|
||||
err = dlerror();
|
||||
rb_raise(rb_eDLError, "%s", err);
|
||||
}
|
||||
#endif
|
||||
Data_Get_Struct(self, struct dl_handle, dlhandle);
|
||||
if( dlhandle->ptr && dlhandle->open && dlhandle->enable_close ){
|
||||
dlclose(dlhandle->ptr);
|
||||
}
|
||||
dlhandle->ptr = ptr;
|
||||
dlhandle->open = 1;
|
||||
dlhandle->enable_close = 0;
|
||||
Data_Get_Struct(self, struct dl_handle, dlhandle);
|
||||
if( dlhandle->ptr && dlhandle->open && dlhandle->enable_close ){
|
||||
dlclose(dlhandle->ptr);
|
||||
}
|
||||
dlhandle->ptr = ptr;
|
||||
dlhandle->open = 1;
|
||||
dlhandle->enable_close = 0;
|
||||
|
||||
if( rb_block_given_p() ){
|
||||
rb_ensure(rb_yield, self, rb_dlhandle_close, self);
|
||||
}
|
||||
if( rb_block_given_p() ){
|
||||
rb_ensure(rb_yield, self, rb_dlhandle_close, self);
|
||||
}
|
||||
|
||||
return Qnil;
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_dlhandle_enable_close(VALUE self)
|
||||
{
|
||||
struct dl_handle *dlhandle;
|
||||
struct dl_handle *dlhandle;
|
||||
|
||||
Data_Get_Struct(self, struct dl_handle, dlhandle);
|
||||
dlhandle->enable_close = 1;
|
||||
return Qnil;
|
||||
Data_Get_Struct(self, struct dl_handle, dlhandle);
|
||||
dlhandle->enable_close = 1;
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_dlhandle_disable_close(VALUE self)
|
||||
{
|
||||
struct dl_handle *dlhandle;
|
||||
struct dl_handle *dlhandle;
|
||||
|
||||
Data_Get_Struct(self, struct dl_handle, dlhandle);
|
||||
dlhandle->enable_close = 0;
|
||||
return Qnil;
|
||||
Data_Get_Struct(self, struct dl_handle, dlhandle);
|
||||
dlhandle->enable_close = 0;
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_dlhandle_to_i(VALUE self)
|
||||
{
|
||||
struct dl_handle *dlhandle;
|
||||
struct dl_handle *dlhandle;
|
||||
|
||||
Data_Get_Struct(self, struct dl_handle, dlhandle);
|
||||
return PTR2NUM(dlhandle);
|
||||
Data_Get_Struct(self, struct dl_handle, dlhandle);
|
||||
return PTR2NUM(dlhandle);
|
||||
}
|
||||
|
||||
VALUE
|
||||
|
|
Loading…
Reference in a new issue