summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/bigdecimal/bigdecimal.c4
-rw-r--r--ext/digest/digest.c4
-rw-r--r--ext/digest/rmd160/rmd160ossl.c2
-rw-r--r--ext/digest/sha1/sha1ossl.c2
-rw-r--r--ext/nkf/nkf.c10
-rw-r--r--ext/thread/thread.c57
6 files changed, 32 insertions, 47 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index 5a26ea79d9..efbf29f92d 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -332,7 +332,7 @@ BigDecimal_load(VALUE self, VALUE str)
unsigned long m=0;
SafeStringValue(str);
- pch = RSTRING_PTR(str);
+ pch = (unsigned char *)RSTRING_PTR(str);
/* First get max prec */
while((*pch)!=(unsigned char)'\0' && (ch=*pch++)!=(unsigned char)':') {
if(!ISDIGIT(ch)) {
@@ -341,7 +341,7 @@ BigDecimal_load(VALUE self, VALUE str)
m = m*10 + (unsigned long)(ch-'0');
}
if(m>VpBaseFig()) m -= VpBaseFig();
- GUARD_OBJ(pv,VpNewRbClass(m,pch,self));
+ GUARD_OBJ(pv,VpNewRbClass(m,(char *)pch,self));
m /= VpBaseFig();
if(m && pv->MaxPrec>m) pv->MaxPrec = m+1;
return ToValue(pv);
diff --git a/ext/digest/digest.c b/ext/digest/digest.c
index c4a58cf3f6..07484f897f 100644
--- a/ext/digest/digest.c
+++ b/ext/digest/digest.c
@@ -519,7 +519,7 @@ rb_digest_base_update(VALUE self, VALUE str)
Data_Get_Struct(self, void, pctx);
StringValue(str);
- algo->update_func(pctx, RSTRING_PTR(str), RSTRING_LEN(str));
+ algo->update_func(pctx, (unsigned char *)RSTRING_PTR(str), RSTRING_LEN(str));
return self;
}
@@ -537,7 +537,7 @@ rb_digest_base_finish(VALUE self)
Data_Get_Struct(self, void, pctx);
str = rb_str_new(0, algo->digest_len);
- algo->finish_func(pctx, RSTRING_PTR(str));
+ algo->finish_func(pctx, (unsigned char *)RSTRING_PTR(str));
/* avoid potential coredump caused by use of a finished context */
algo->init_func(pctx);
diff --git a/ext/digest/rmd160/rmd160ossl.c b/ext/digest/rmd160/rmd160ossl.c
index 5d8c5ba470..f24e63e3d8 100644
--- a/ext/digest/rmd160/rmd160ossl.c
+++ b/ext/digest/rmd160/rmd160ossl.c
@@ -4,5 +4,5 @@
#include "rmd160ossl.h"
void RMD160_Finish(RMD160_CTX *ctx, char *buf) {
- RIPEMD160_Final(buf, ctx);
+ RIPEMD160_Final((unsigned char *)buf, ctx);
}
diff --git a/ext/digest/sha1/sha1ossl.c b/ext/digest/sha1/sha1ossl.c
index adf5cf267c..452cf35084 100644
--- a/ext/digest/sha1/sha1ossl.c
+++ b/ext/digest/sha1/sha1ossl.c
@@ -6,5 +6,5 @@
void
SHA1_Finish(SHA1_CTX *ctx, char *buf)
{
- SHA1_Final(buf, ctx);
+ SHA1_Final((unsigned char *)buf, ctx);
}
diff --git a/ext/nkf/nkf.c b/ext/nkf/nkf.c
index 8eb92b6cd6..2bb0340a64 100644
--- a/ext/nkf/nkf.c
+++ b/ext/nkf/nkf.c
@@ -63,7 +63,7 @@ rb_nkf_putchar(c)
o_len += incsize;
rb_str_resize(result, o_len);
incsize *= 2;
- output = RSTRING(result)->ptr;
+ output = (unsigned char *)RSTRING(result)->ptr;
}
output[output_ctr++] = c;
@@ -158,13 +158,13 @@ rb_nkf_kconv(obj, opt, src)
input_ctr = 0;
StringValue(src);
- input = RSTRING(src)->ptr;
+ input = (unsigned char *)RSTRING(src)->ptr;
i_len = RSTRING(src)->len;
result = rb_str_new(0, i_len*3 + 10);
v = result;
output_ctr = 0;
- output = RSTRING(result)->ptr;
+ output = (unsigned char *)RSTRING(result)->ptr;
o_len = RSTRING(result)->len;
*output = '\0';
@@ -213,7 +213,7 @@ rb_nkf_guess1(obj, src)
int sequence_counter = 0;
StringValue(src);
- p = RSTRING(src)->ptr;
+ p = (unsigned char *)RSTRING(src)->ptr;
pend = p + RSTRING(src)->len;
if (p == pend) return INT2FIX(_UNKNOWN);
@@ -328,7 +328,7 @@ rb_nkf_guess2(obj, src)
input_ctr = 0;
StringValue(src);
- input = RSTRING(src)->ptr;
+ input = (unsigned char *)RSTRING(src)->ptr;
i_len = RSTRING(src)->len;
if(x0201_f == WISH_TRUE)
diff --git a/ext/thread/thread.c b/ext/thread/thread.c
index c65c4bbe52..354e1445e7 100644
--- a/ext/thread/thread.c
+++ b/ext/thread/thread.c
@@ -18,21 +18,14 @@ static VALUE rb_cConditionVariable;
static VALUE rb_cQueue;
static VALUE rb_cSizedQueue;
-static VALUE
-thread_exclusive_do()
-{
- rb_thread_critical = Qtrue;
-
- return rb_yield(Qundef);
-}
+static VALUE set_critical(VALUE value);
static VALUE
-thread_exclusive_ensure(val)
- VALUE val;
+thread_exclusive_do(void)
{
- rb_thread_critical = val;
+ rb_thread_critical = 1;
- return Qundef;
+ return rb_yield(Qundef);
}
/*
@@ -45,9 +38,9 @@ thread_exclusive_ensure(val)
*/
static VALUE
-rb_thread_exclusive()
+rb_thread_exclusive(void)
{
- return rb_ensure(thread_exclusive_do, Qundef, thread_exclusive_ensure, rb_thread_critical);
+ return rb_ensure(thread_exclusive_do, Qundef, set_critical, rb_thread_critical);
}
typedef struct _Entry {
@@ -86,7 +79,7 @@ free_entries(Entry *first)
Entry *next;
while (first) {
next = first->next;
- free(first);
+ xfree(first);
first = next;
}
}
@@ -107,7 +100,7 @@ push_list(List *list, VALUE value)
entry = list->entry_pool;
list->entry_pool = entry->next;
} else {
- entry = (Entry *)malloc(sizeof(Entry));
+ entry = (Entry *)xmalloc(sizeof(Entry));
}
entry->value = value;
@@ -254,9 +247,7 @@ static VALUE
wait_list_cleanup(List *list)
{
/* cleanup in case of spurious wakeups */
- rb_thread_critical = 1;
remove_one(list, rb_thread_current());
- rb_thread_critical = 0;
return Qnil;
}
@@ -325,7 +316,7 @@ free_mutex(Mutex *mutex)
{
assert_no_survivors(&mutex->waiting, "mutex", mutex);
finalize_mutex(mutex);
- free(mutex);
+ xfree(mutex);
}
static void
@@ -347,7 +338,7 @@ static VALUE
rb_mutex_alloc(VALUE klass)
{
Mutex *mutex;
- mutex = (Mutex *)malloc(sizeof(Mutex));
+ mutex = (Mutex *)xmalloc(sizeof(Mutex));
init_mutex(mutex);
return Data_Wrap_Struct(klass, mark_mutex, free_mutex, mutex);
}
@@ -381,20 +372,14 @@ static VALUE
rb_mutex_try_lock(VALUE self)
{
Mutex *mutex;
- VALUE result;
Data_Get_Struct(self, Mutex, mutex);
- result = Qfalse;
-
- rb_thread_critical = 1;
- if (!RTEST(mutex->owner)) {
- mutex->owner = rb_thread_current();
- result = Qtrue;
- }
- rb_thread_critical = 0;
+ if (RTEST(mutex->owner))
+ return Qfalse;
- return result;
+ mutex->owner = rb_thread_current();
+ return Qtrue;
}
/*
@@ -456,7 +441,7 @@ static VALUE
set_critical(VALUE value)
{
rb_thread_critical = (int)value;
- return Qnil;
+ return Qundef;
}
static VALUE
@@ -598,7 +583,7 @@ free_condvar(ConditionVariable *condvar)
{
assert_no_survivors(&condvar->waiting, "condition variable", condvar);
finalize_condvar(condvar);
- free(condvar);
+ xfree(condvar);
}
static void
@@ -620,7 +605,7 @@ rb_condvar_alloc(VALUE klass)
{
ConditionVariable *condvar;
- condvar = (ConditionVariable *)malloc(sizeof(ConditionVariable));
+ condvar = (ConditionVariable *)xmalloc(sizeof(ConditionVariable));
init_condvar(condvar);
return Data_Wrap_Struct(klass, mark_condvar, free_condvar, condvar);
@@ -639,11 +624,11 @@ wait_condvar(ConditionVariable *condvar, Mutex *mutex)
{
rb_thread_critical = 1;
if (!RTEST(mutex->owner)) {
- rb_thread_critical = Qfalse;
+ rb_thread_critical = 0;
return;
}
if (mutex->owner != rb_thread_current()) {
- rb_thread_critical = Qfalse;
+ rb_thread_critical = 0;
rb_raise(rb_eThreadError, "Not owner");
}
mutex->owner = Qnil;
@@ -806,7 +791,7 @@ free_queue(Queue *queue)
assert_no_survivors(&queue->space_available.waiting, "queue", queue);
assert_no_survivors(&queue->value_available.waiting, "queue", queue);
finalize_queue(queue);
- free(queue);
+ xfree(queue);
}
static void
@@ -831,7 +816,7 @@ static VALUE
rb_queue_alloc(VALUE klass)
{
Queue *queue;
- queue = (Queue *)malloc(sizeof(Queue));
+ queue = (Queue *)xmalloc(sizeof(Queue));
init_queue(queue);
return Data_Wrap_Struct(klass, mark_queue, free_queue, queue);
}