Skip to content

Commit

Permalink
Fix missing C declarations causing compiler warnings
Browse files Browse the repository at this point in the history
This fixes declarations for ruby-2.0 and newer.
rubies < 2.0 don't define ruby/thread.h, so that the warnings are still present there.

compiling ../../../../ext/ffi_c/Call.c
In file included from ../../../../ext/ffi_c/Call.h:36:0,
                 from ../../../../ext/ffi_c/Function.h:48,
                 from ../../../../ext/ffi_c/Call.c:57:
../../../../ext/ffi_c/Call.c: In function ‘rbffi_do_blocking_call’:
../../../../ext/ffi_c/Thread.h:78:39: warning: implicit declaration of function ‘rb_thread_call_without_gvl’; did you mean ‘rb_thread_wait_for’? [-Wimplicit-function-declaration]
 # define rbffi_thread_blocking_region rb_thread_call_without_gvl
                                       ^
../../../../ext/ffi_c/Call.c:334:5: note: in expansion of macro ‘rbffi_thread_blocking_region’
     rbffi_thread_blocking_region(call_blocking_function, data, (void *) -1, NULL);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
compiling ../../../../ext/ffi_c/Function.c
../../../../ext/ffi_c/Function.c: In function ‘async_cb_event’:
../../../../ext/ffi_c/Function.c:569:9: warning: implicit declaration of function ‘rb_thread_call_without_gvl’; did you mean ‘rb_thread_call_with_gvl’? [-Wimplicit-function-declaration]
         rb_thread_call_without_gvl(async_cb_wait, &w, async_cb_stop, &w);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~
         rb_thread_call_with_gvl
  • Loading branch information
larskanis committed Jun 2, 2018
1 parent f569788 commit bf48d44
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
7 changes: 5 additions & 2 deletions ext/ffi_c/Call.c
Expand Up @@ -43,6 +43,9 @@
#endif
#include <errno.h>
#include <ruby.h>
#if defined(HAVE_RUBY_THREAD_H)
#include <ruby/thread.h>
#endif
#if defined(HAVE_NATIVETHREAD) && (defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)) && !defined(_WIN32)
# include <signal.h>
# include <pthread.h>
Expand Down Expand Up @@ -317,15 +320,15 @@ rbffi_SetupCallParams(int argc, VALUE* argv, int paramCount, Type** paramTypes,
}
}

static VALUE
static void *
call_blocking_function(void* data)
{
rbffi_blocking_call_t* b = (rbffi_blocking_call_t *) data;
b->frame->has_gvl = false;
ffi_call(&b->cif, FFI_FN(b->function), b->retval, b->ffiValues);
b->frame->has_gvl = true;

return Qnil;
return NULL;
}

VALUE
Expand Down
13 changes: 8 additions & 5 deletions ext/ffi_c/Function.c
Expand Up @@ -47,6 +47,9 @@
# endif
#endif
#include <ruby.h>
#if defined(HAVE_RUBY_THREAD_H)
#include <ruby/thread.h>
#endif

#include <ffi.h>
#if defined(HAVE_NATIVETHREAD) && !defined(_WIN32)
Expand Down Expand Up @@ -554,7 +557,7 @@ struct async_wait {
bool stop;
};

static VALUE async_cb_wait(void *);
static void * async_cb_wait(void *);
static void async_cb_stop(void *);

#if defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
Expand Down Expand Up @@ -643,7 +646,7 @@ async_cb_event(void* unused)
#endif

#ifdef _WIN32
static VALUE
static void *
async_cb_wait(void *data)
{
struct async_wait* w = (struct async_wait *) data;
Expand All @@ -665,7 +668,7 @@ async_cb_wait(void *data)

LeaveCriticalSection(&async_cb_lock);

return Qnil;
return NULL;
}

static void
Expand All @@ -680,7 +683,7 @@ async_cb_stop(void *data)
}

#else
static VALUE
static void *
async_cb_wait(void *data)
{
struct async_wait* w = (struct async_wait *) data;
Expand All @@ -700,7 +703,7 @@ async_cb_wait(void *data)

pthread_mutex_unlock(&async_cb_mutex);

return Qnil;
return NULL;
}

static void
Expand Down
1 change: 1 addition & 0 deletions ext/ffi_c/extconf.rb
Expand Up @@ -26,6 +26,7 @@
end

have_header('shlwapi.h')
have_header('ruby/thread.h') # for compat with ruby < 2.0
have_func('rb_thread_blocking_region')
have_func('rb_thread_call_with_gvl')
have_func('rb_thread_call_without_gvl')
Expand Down

0 comments on commit bf48d44

Please sign in to comment.