summaryrefslogtreecommitdiff
path: root/ext/dl/cptr.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-05-10 01:47:10 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-05-10 01:47:10 +0000
commit07b5520752bfe9217ff906189a32c878717a3917 (patch)
tree184dfbf4070927cc98d0e1824c6b1c80c44e52e8 /ext/dl/cptr.c
parent3fd6cac52c9b8fecb3a7b167528829f148fb0375 (diff)
* ext/dl/cptr.c: consistent indentation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23384 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/dl/cptr.c')
-rw-r--r--ext/dl/cptr.c314
1 files changed, 157 insertions, 157 deletions
diff --git a/ext/dl/cptr.c b/ext/dl/cptr.c
index 3e0da24c92..4f1456d164 100644
--- a/ext/dl/cptr.c
+++ b/ext/dl/cptr.c
@@ -107,75 +107,75 @@ rb_dlptr_s_allocate(VALUE klass)
static VALUE
rb_dlptr_initialize(int argc, VALUE argv[], VALUE self)
{
- VALUE ptr, sym, size;
- struct ptr_data *data;
- void *p = NULL;
- freefunc_t f = NULL;
- long s = 0;
-
- switch (rb_scan_args(argc, argv, "12", &ptr, &size, &sym)) {
- case 1:
- p = (void*)(NUM2PTR(rb_Integer(ptr)));
- break;
- case 2:
- p = (void*)(NUM2PTR(rb_Integer(ptr)));
- s = NUM2LONG(size);
- break;
- case 3:
- p = (void*)(NUM2PTR(rb_Integer(ptr)));
- s = NUM2LONG(size);
- f = NIL_P(sym) ? NULL : RCFUNC_DATA(sym)->ptr;
- break;
- default:
- rb_bug("rb_dlptr_initialize");
- }
-
- if (p) {
- Data_Get_Struct(self, struct ptr_data, data);
- if (data->ptr && data->free) {
- /* Free previous memory. Use of inappropriate initialize may cause SEGV. */
- (*(data->free))(data->ptr);
+ VALUE ptr, sym, size;
+ struct ptr_data *data;
+ void *p = NULL;
+ freefunc_t f = NULL;
+ long s = 0;
+
+ switch (rb_scan_args(argc, argv, "12", &ptr, &size, &sym)) {
+ case 1:
+ p = (void*)(NUM2PTR(rb_Integer(ptr)));
+ break;
+ case 2:
+ p = (void*)(NUM2PTR(rb_Integer(ptr)));
+ s = NUM2LONG(size);
+ break;
+ case 3:
+ p = (void*)(NUM2PTR(rb_Integer(ptr)));
+ s = NUM2LONG(size);
+ f = NIL_P(sym) ? NULL : RCFUNC_DATA(sym)->ptr;
+ break;
+ default:
+ rb_bug("rb_dlptr_initialize");
+ }
+
+ if (p) {
+ Data_Get_Struct(self, struct ptr_data, data);
+ if (data->ptr && data->free) {
+ /* Free previous memory. Use of inappropriate initialize may cause SEGV. */
+ (*(data->free))(data->ptr);
+ }
+ data->ptr = p;
+ data->size = s;
+ data->free = f;
}
- data->ptr = p;
- data->size = s;
- data->free = f;
- }
- return Qnil;
+ return Qnil;
}
static VALUE
rb_dlptr_s_malloc(int argc, VALUE argv[], VALUE klass)
{
- VALUE size, sym, obj;
- int s;
- freefunc_t f;
-
- switch (rb_scan_args(argc, argv, "11", &size, &sym)) {
- case 1:
- s = NUM2LONG(size);
- f = NULL;
- break;
- case 2:
- s = NUM2LONG(size);
- f = RCFUNC_DATA(sym)->ptr;
- break;
- default:
- rb_bug("rb_dlptr_s_malloc");
- }
-
- obj = rb_dlptr_malloc(s,f);
-
- return obj;
+ VALUE size, sym, obj;
+ int s;
+ freefunc_t f;
+
+ switch (rb_scan_args(argc, argv, "11", &size, &sym)) {
+ case 1:
+ s = NUM2LONG(size);
+ f = NULL;
+ break;
+ case 2:
+ s = NUM2LONG(size);
+ f = RCFUNC_DATA(sym)->ptr;
+ break;
+ default:
+ rb_bug("rb_dlptr_s_malloc");
+ }
+
+ obj = rb_dlptr_malloc(s,f);
+
+ return obj;
}
VALUE
rb_dlptr_to_i(VALUE self)
{
- struct ptr_data *data;
+ struct ptr_data *data;
- Data_Get_Struct(self, struct ptr_data, data);
- return PTR2NUM(data->ptr);
+ Data_Get_Struct(self, struct ptr_data, data);
+ return PTR2NUM(data->ptr);
}
VALUE
@@ -189,156 +189,156 @@ rb_dlptr_to_value(VALUE self)
VALUE
rb_dlptr_ptr(VALUE self)
{
- struct ptr_data *data;
+ struct ptr_data *data;
- Data_Get_Struct(self, struct ptr_data, data);
- return rb_dlptr_new(*((void**)(data->ptr)),0,0);
+ Data_Get_Struct(self, struct ptr_data, data);
+ return rb_dlptr_new(*((void**)(data->ptr)),0,0);
}
VALUE
rb_dlptr_ref(VALUE self)
{
- struct ptr_data *data;
+ struct ptr_data *data;
- Data_Get_Struct(self, struct ptr_data, data);
- return rb_dlptr_new(&(data->ptr),0,0);
+ Data_Get_Struct(self, struct ptr_data, data);
+ return rb_dlptr_new(&(data->ptr),0,0);
}
VALUE
rb_dlptr_null_p(VALUE self)
{
- struct ptr_data *data;
+ struct ptr_data *data;
- Data_Get_Struct(self, struct ptr_data, data);
- return data->ptr ? Qfalse : Qtrue;
+ Data_Get_Struct(self, struct ptr_data, data);
+ return data->ptr ? Qfalse : Qtrue;
}
VALUE
rb_dlptr_free_set(VALUE self, VALUE val)
{
- struct ptr_data *data;
- extern VALUE rb_cDLCFunc;
-
- Data_Get_Struct(self, struct ptr_data, data);
- if( rb_obj_is_kind_of(val, rb_cDLCFunc) == Qtrue ){
- data->free = RCFUNC_DATA(val)->ptr;
- }
- else{
- data->free = NUM2PTR(rb_Integer(val));
- }
-
- return Qnil;
+ struct ptr_data *data;
+ extern VALUE rb_cDLCFunc;
+
+ Data_Get_Struct(self, struct ptr_data, data);
+ if( rb_obj_is_kind_of(val, rb_cDLCFunc) == Qtrue ){
+ data->free = RCFUNC_DATA(val)->ptr;
+ }
+ else{
+ data->free = NUM2PTR(rb_Integer(val));
+ }
+
+ return Qnil;
}
VALUE
rb_dlptr_free_get(VALUE self)
{
- struct ptr_data *pdata;
+ struct ptr_data *pdata;
- Data_Get_Struct(self, struct ptr_data, pdata);
+ Data_Get_Struct(self, struct ptr_data, pdata);
- return rb_dlcfunc_new(pdata->free, DLTYPE_VOID, "free<anonymous>", CFUNC_CDECL);
+ return rb_dlcfunc_new(pdata->free, DLTYPE_VOID, "free<anonymous>", CFUNC_CDECL);
}
VALUE
rb_dlptr_to_s(int argc, VALUE argv[], VALUE self)
{
- struct ptr_data *data;
- VALUE arg1, val;
- int len;
-
- Data_Get_Struct(self, struct ptr_data, data);
- switch (rb_scan_args(argc, argv, "01", &arg1)) {
- case 0:
- val = rb_tainted_str_new2((char*)(data->ptr));
- break;
- case 1:
- len = NUM2INT(arg1);
- val = rb_tainted_str_new((char*)(data->ptr), len);
- break;
- default:
- rb_bug("rb_dlptr_to_s");
- }
-
- return val;
+ struct ptr_data *data;
+ VALUE arg1, val;
+ int len;
+
+ Data_Get_Struct(self, struct ptr_data, data);
+ switch (rb_scan_args(argc, argv, "01", &arg1)) {
+ case 0:
+ val = rb_tainted_str_new2((char*)(data->ptr));
+ break;
+ case 1:
+ len = NUM2INT(arg1);
+ val = rb_tainted_str_new((char*)(data->ptr), len);
+ break;
+ default:
+ rb_bug("rb_dlptr_to_s");
+ }
+
+ return val;
}
VALUE
rb_dlptr_to_str(int argc, VALUE argv[], VALUE self)
{
- struct ptr_data *data;
- VALUE arg1, val;
- int len;
-
- Data_Get_Struct(self, struct ptr_data, data);
- switch (rb_scan_args(argc, argv, "01", &arg1)) {
- case 0:
- val = rb_tainted_str_new((char*)(data->ptr),data->size);
- break;
- case 1:
- len = NUM2INT(arg1);
- val = rb_tainted_str_new((char*)(data->ptr), len);
- break;
- default:
- rb_bug("rb_dlptr_to_str");
- }
-
- return val;
+ struct ptr_data *data;
+ VALUE arg1, val;
+ int len;
+
+ Data_Get_Struct(self, struct ptr_data, data);
+ switch (rb_scan_args(argc, argv, "01", &arg1)) {
+ case 0:
+ val = rb_tainted_str_new((char*)(data->ptr),data->size);
+ break;
+ case 1:
+ len = NUM2INT(arg1);
+ val = rb_tainted_str_new((char*)(data->ptr), len);
+ break;
+ default:
+ rb_bug("rb_dlptr_to_str");
+ }
+
+ return val;
}
VALUE
rb_dlptr_inspect(VALUE self)
{
- struct ptr_data *data;
- char str[1024];
+ struct ptr_data *data;
+ char str[1024];
- Data_Get_Struct(self, struct ptr_data, data);
- snprintf(str, 1023, "#<%s:%p ptr=%p size=%ld free=%p>",
- rb_class2name(CLASS_OF(self)), data, data->ptr, data->size, data->free);
- return rb_str_new2(str);
+ Data_Get_Struct(self, struct ptr_data, data);
+ snprintf(str, 1023, "#<%s:%p ptr=%p size=%ld free=%p>",
+ rb_class2name(CLASS_OF(self)), data, data->ptr, data->size, data->free);
+ return rb_str_new2(str);
}
VALUE
rb_dlptr_eql(VALUE self, VALUE other)
{
- void *ptr1, *ptr2;
- ptr1 = rb_dlptr2cptr(self);
- ptr2 = rb_dlptr2cptr(other);
+ void *ptr1, *ptr2;
+ ptr1 = rb_dlptr2cptr(self);
+ ptr2 = rb_dlptr2cptr(other);
- return ptr1 == ptr2 ? Qtrue : Qfalse;
+ return ptr1 == ptr2 ? Qtrue : Qfalse;
}
VALUE
rb_dlptr_cmp(VALUE self, VALUE other)
{
- void *ptr1, *ptr2;
- ptr1 = rb_dlptr2cptr(self);
- ptr2 = rb_dlptr2cptr(other);
- return PTR2NUM((long)ptr1 - (long)ptr2);
+ void *ptr1, *ptr2;
+ ptr1 = rb_dlptr2cptr(self);
+ ptr2 = rb_dlptr2cptr(other);
+ return PTR2NUM((long)ptr1 - (long)ptr2);
}
VALUE
rb_dlptr_plus(VALUE self, VALUE other)
{
- void *ptr;
- long num, size;
+ void *ptr;
+ long num, size;
- ptr = rb_dlptr2cptr(self);
- size = RPTR_DATA(self)->size;
- num = NUM2LONG(other);
- return rb_dlptr_new((char *)ptr + num, size - num, 0);
+ ptr = rb_dlptr2cptr(self);
+ size = RPTR_DATA(self)->size;
+ num = NUM2LONG(other);
+ return rb_dlptr_new((char *)ptr + num, size - num, 0);
}
VALUE
rb_dlptr_minus(VALUE self, VALUE other)
{
- void *ptr;
- long num, size;
+ void *ptr;
+ long num, size;
- ptr = rb_dlptr2cptr(self);
- size = RPTR_DATA(self)->size;
- num = NUM2LONG(other);
- return rb_dlptr_new((char *)ptr - num, size + num, 0);
+ ptr = rb_dlptr2cptr(self);
+ size = RPTR_DATA(self)->size;
+ num = NUM2LONG(other);
+ return rb_dlptr_new((char *)ptr - num, size + num, 0);
}
VALUE
@@ -349,16 +349,16 @@ rb_dlptr_aref(int argc, VALUE argv[], VALUE self)
size_t offset, len;
switch( rb_scan_args(argc, argv, "11", &arg0, &arg1) ){
- case 1:
+ case 1:
offset = NUM2ULONG(arg0);
retval = INT2NUM(*((char*)RPTR_DATA(self)->ptr + offset));
break;
- case 2:
+ case 2:
offset = NUM2ULONG(arg0);
len = NUM2ULONG(arg1);
retval = rb_tainted_str_new((char *)RPTR_DATA(self)->ptr + offset, len);
break;
- default:
+ default:
rb_bug("rb_dlptr_aref()");
}
return retval;
@@ -373,12 +373,12 @@ rb_dlptr_aset(int argc, VALUE argv[], VALUE self)
void *mem;
switch( rb_scan_args(argc, argv, "21", &arg0, &arg1, &arg2) ){
- case 2:
+ case 2:
offset = NUM2ULONG(arg0);
((char*)RPTR_DATA(self)->ptr)[offset] = NUM2UINT(arg1);
retval = arg1;
break;
- case 3:
+ case 3:
offset = NUM2ULONG(arg0);
len = NUM2ULONG(arg1);
if( TYPE(arg2) == T_STRING ){
@@ -393,7 +393,7 @@ rb_dlptr_aset(int argc, VALUE argv[], VALUE self)
memcpy((char *)RPTR_DATA(self)->ptr + offset, mem, len);
retval = arg2;
break;
- default:
+ default:
rb_bug("rb_dlptr_aset()");
}
return retval;
@@ -402,15 +402,15 @@ rb_dlptr_aset(int argc, VALUE argv[], VALUE self)
VALUE
rb_dlptr_size(int argc, VALUE argv[], VALUE self)
{
- VALUE size;
-
- if (rb_scan_args(argc, argv, "01", &size) == 0){
- return LONG2NUM(RPTR_DATA(self)->size);
- }
- else{
- RPTR_DATA(self)->size = NUM2LONG(size);
- return size;
- }
+ VALUE size;
+
+ if (rb_scan_args(argc, argv, "01", &size) == 0){
+ return LONG2NUM(RPTR_DATA(self)->size);
+ }
+ else{
+ RPTR_DATA(self)->size = NUM2LONG(size);
+ return size;
+ }
}
VALUE