From fac0211221d70b94c0301f977e8a6ba429d79ef8 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 11 Mar 2011 16:05:12 -0800 Subject: use unsigned values for all counters We can't have negative values --- ext/raindrops/linux_inet_diag.c | 8 ++++---- ext/raindrops/raindrops.c | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ext/raindrops/linux_inet_diag.c b/ext/raindrops/linux_inet_diag.c index b219b5a..18f5ce8 100644 --- a/ext/raindrops/linux_inet_diag.c +++ b/ext/raindrops/linux_inet_diag.c @@ -52,8 +52,8 @@ static unsigned g_seq; static VALUE cListenStats; struct listen_stats { - long active; - long queued; + unsigned long active; + unsigned long queued; }; #define OPLEN (sizeof(struct inet_diag_bc_op) + \ @@ -69,8 +69,8 @@ struct nogvl_args { static VALUE rb_listen_stats(struct listen_stats *stats) { VALUE rv = rb_struct_alloc_noinit(cListenStats); - VALUE active = LONG2NUM(stats->active); - VALUE queued = LONG2NUM(stats->queued); + VALUE active = ULONG2NUM(stats->active); + VALUE queued = ULONG2NUM(stats->queued); #ifdef RSTRUCT_PTR VALUE *ptr = RSTRUCT_PTR(rv); diff --git a/ext/raindrops/raindrops.c b/ext/raindrops/raindrops.c index 7bd6f31..6cc0d12 100644 --- a/ext/raindrops/raindrops.c +++ b/ext/raindrops/raindrops.c @@ -31,7 +31,7 @@ struct raindrop { /* allow mmap-ed regions to store more than one raindrop */ struct raindrops { - long size; + size_t size; size_t capa; pid_t pid; struct raindrop *drops; @@ -92,7 +92,7 @@ static VALUE init(VALUE self, VALUE size) if (r->drops != MAP_FAILED) rb_raise(rb_eRuntimeError, "already initialized"); - r->size = NUM2LONG(size); + r->size = NUM2SIZET(size); if (r->size < 1) rb_raise(rb_eArgError, "size must be >= 1"); @@ -150,7 +150,7 @@ static void resize(struct raindrops *r, size_t new_rd_size) r->drops = rv; r->size = new_rd_size; r->capa = new_size / raindrop_size; - assert(r->capa >= (size_t)r->size && "bad sizing"); + assert(r->capa >= r->size && "bad sizing"); } #else /* ! HAVE_MREMAP */ /* @@ -207,7 +207,7 @@ static VALUE init_copy(VALUE dest, VALUE source) struct raindrops *dst = DATA_PTR(dest); struct raindrops *src = get(source); - init(dest, LONG2NUM(src->size)); + init(dest, SIZET2NUM(src->size)); memcpy(dst->drops, src->drops, raindrop_size * src->size); return dest; @@ -271,7 +271,7 @@ static VALUE to_ary(VALUE self) { struct raindrops *r = get(self); VALUE rv = rb_ary_new2(r->size); - long i; + size_t i; unsigned long base = (unsigned long)r->drops; for (i = 0; i < r->size; i++) { @@ -292,7 +292,7 @@ static VALUE to_ary(VALUE self) */ static VALUE size(VALUE self) { - return LONG2NUM(get(self)->size); + return SIZET2NUM(get(self)->size); } /* -- cgit v1.2.3-24-ge0c7